Skip to content

Commit 39a4339

Browse files
committed
Deduplicate ingredient values in other constructor
1 parent 96092c7 commit 39a4339

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

neoforge/src/main/java/org/embeddedt/modernfix/neoforge/mixin/perf/ingredient_item_deduplication/IngredientMixin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ public class IngredientMixin {
1414
private static Stream<? extends Ingredient.Value> injectDeduplicationPass(Stream<? extends Ingredient.Value> stream) {
1515
return stream.map(IngredientValueDeduplicator::deduplicate);
1616
}
17+
18+
@ModifyVariable(method = "<init>([Lnet/minecraft/world/item/crafting/Ingredient$Value;)V", at = @At("HEAD"), argsOnly = true, ordinal = 0)
19+
private static Ingredient.Value[] injectDeduplicationPassArray(Ingredient.Value[] values) {
20+
if (values.length == 0) {
21+
return values;
22+
}
23+
Ingredient.Value[] newValues = new Ingredient.Value[values.length];
24+
for (int i = 0; i < values.length; i++) {
25+
newValues[i] = IngredientValueDeduplicator.deduplicate(values[i]);
26+
}
27+
return newValues;
28+
}
1729
}

neoforge/src/main/java/org/embeddedt/modernfix/neoforge/recipe/IngredientValueDeduplicator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean equals(Ingredient.ItemValue a, Ingredient.ItemValue b) {
7070
});
7171

7272
public static Ingredient.Value deduplicate(Ingredient.Value value) {
73-
if (value.getClass() == Ingredient.ItemValue.class) {
73+
if (value != null && value.getClass() == Ingredient.ItemValue.class) {
7474
synchronized (VALUES) {
7575
return VALUES.addOrGet((Ingredient.ItemValue)value);
7676
}

0 commit comments

Comments
 (0)