11package org .embeddedt .modernfix .neoforge .recipe ;
22
3+ import com .google .common .math .IntMath ;
34import it .unimi .dsi .fastutil .Hash ;
45import it .unimi .dsi .fastutil .objects .ObjectOpenCustomHashSet ;
56import it .unimi .dsi .fastutil .objects .Reference2ObjectMaps ;
67import net .minecraft .world .item .ItemStack ;
7- import net .minecraft .world .item .ItemStackLinkedSet ;
88import net .minecraft .world .item .crafting .Ingredient ;
99import org .embeddedt .modernfix .neoforge .mixin .perf .ingredient_item_deduplication .PatchedDataComponentMapAccessor ;
1010
@@ -15,7 +15,23 @@ public class IngredientValueDeduplicator {
1515 private static final ObjectOpenCustomHashSet <Ingredient .ItemValue > VALUES = new ObjectOpenCustomHashSet <>(new Hash .Strategy <>() {
1616 @ Override
1717 public int hashCode (Ingredient .ItemValue o ) {
18- return o == null ? 0 : ItemStackLinkedSet .TYPE_AND_TAG .hashCode (o .item ());
18+ if (o == null ) {
19+ return 0 ;
20+ }
21+ var stack = o .item ();
22+ int hash = 31 * stack .getItem ().hashCode ();
23+ if (stack .getComponents () instanceof PatchedDataComponentMapAccessor comps ) {
24+ var patch = comps .mfix$getPatch ();
25+ for (var entry : Reference2ObjectMaps .fastIterable (patch )) {
26+ int keyHash = System .identityHashCode (entry .getKey ()) & 0xff ;
27+ var value = entry .getValue ();
28+ int valueHash = value .isPresent () ? System .identityHashCode (value .get ()) : 0 ;
29+ hash += IntMath .pow (31 , keyHash ) * valueHash ;
30+ }
31+ } else {
32+ hash += System .identityHashCode (stack .getComponents ());
33+ }
34+ return hash ;
1935 }
2036
2137 private boolean areComponentsSame (ItemStack a , ItemStack b ) {
0 commit comments