Deduplicate ingredient values in other constructor

This commit is contained in:
embeddedt 2025-07-03 21:44:23 -04:00
parent 96092c7189
commit 39a43398ba
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 13 additions and 1 deletions

View File

@ -14,4 +14,16 @@ public class IngredientMixin {
private static Stream<? extends Ingredient.Value> injectDeduplicationPass(Stream<? extends Ingredient.Value> stream) {
return stream.map(IngredientValueDeduplicator::deduplicate);
}
@ModifyVariable(method = "<init>([Lnet/minecraft/world/item/crafting/Ingredient$Value;)V", at = @At("HEAD"), argsOnly = true, ordinal = 0)
private static Ingredient.Value[] injectDeduplicationPassArray(Ingredient.Value[] values) {
if (values.length == 0) {
return values;
}
Ingredient.Value[] newValues = new Ingredient.Value[values.length];
for (int i = 0; i < values.length; i++) {
newValues[i] = IngredientValueDeduplicator.deduplicate(values[i]);
}
return newValues;
}
}

View File

@ -70,7 +70,7 @@ public class IngredientValueDeduplicator {
});
public static Ingredient.Value deduplicate(Ingredient.Value value) {
if (value.getClass() == Ingredient.ItemValue.class) {
if (value != null && value.getClass() == Ingredient.ItemValue.class) {
synchronized (VALUES) {
return VALUES.addOrGet((Ingredient.ItemValue)value);
}