11package gregtech .common .metatileentities .storage ;
22
3+ import gregtech .api .util .ItemStackHashStrategy ;
4+
35import net .minecraft .item .ItemStack ;
46import net .minecraft .nbt .NBTTagCompound ;
57import net .minecraft .nbt .NBTTagList ;
1214import com .cleanroommc .modularui .network .NetworkUtils ;
1315import com .cleanroommc .modularui .utils .MouseData ;
1416import com .cleanroommc .modularui .value .sync .SyncHandler ;
17+ import it .unimi .dsi .fastutil .Hash ;
1518import it .unimi .dsi .fastutil .ints .Int2ObjectOpenHashMap ;
1619import org .jetbrains .annotations .NotNull ;
1720import org .jetbrains .annotations .Nullable ;
@@ -32,6 +35,11 @@ public class CraftingRecipeMemory extends SyncHandler {
3235 // server only
3336 public static final int MOUSE_CLICK = 2 ;
3437
38+ private final Hash .Strategy <ItemStack > strategy = ItemStackHashStrategy .builder ()
39+ .compareItem (true )
40+ .compareMetadata (true )
41+ .build ();
42+
3543 private final MemorizedRecipe [] memorizedRecipes ;
3644 private final IItemHandlerModifiable craftingMatrix ;
3745
@@ -84,16 +92,18 @@ private MemorizedRecipe findOrCreateRecipe(ItemStack resultItemStack) {
8492 MemorizedRecipe existing = null ;
8593 for (MemorizedRecipe memorizedRecipe : memorizedRecipes ) {
8694 if (memorizedRecipe != null &&
87- ItemStack . areItemStacksEqual (memorizedRecipe .recipeResult , resultItemStack )) {
95+ strategy . equals (memorizedRecipe .recipeResult , resultItemStack )) {
8896 existing = memorizedRecipe ;
8997 break ;
9098 }
9199 }
92100
93101 // we already have a recipe that matches
94102 // move it to the front
95- if (existing != null && !existing .recipeLocked ) {
96- if (existing .index == 0 ) return existing ; // it's already at the front
103+ if (existing != null ) {
104+ // it's already at the front or it's locked
105+ if (existing .index == 0 || existing .recipeLocked ) return existing ;
106+
97107 int removed = existing .index ;
98108 removeRecipe (existing .index );
99109 syncToClient (REMOVE_RECIPE , buffer -> buffer .writeByte (removed ));
0 commit comments