Skip to content

Commit 169e041

Browse files
committed
Use mojang's builtin item stack hash strategy instead of rolling our own one, and make our fluid stack one be based off of the logic more closely
1 parent a2dd72e commit 169e041

File tree

4 files changed

+6
-34
lines changed

4 files changed

+6
-34
lines changed

src/main/java/mekanism/common/lib/collection/FluidHashStrategy.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import it.unimi.dsi.fastutil.Hash.Strategy;
44
import net.neoforged.neoforge.fluids.FluidStack;
55

6+
//Based on ItemStackLinkedSet#TYPE_AND_TAG
67
public class FluidHashStrategy implements Strategy<FluidStack> {
78

89
public static final FluidHashStrategy INSTANCE = new FluidHashStrategy();
@@ -12,16 +13,14 @@ private FluidHashStrategy() {
1213

1314
@Override
1415
public int hashCode(FluidStack stack) {
15-
return stack == null ? 0 : FluidStack.hashFluidAndComponents(stack);
16+
return FluidStack.hashFluidAndComponents(stack);
1617
}
1718

1819
@Override
1920
public boolean equals(FluidStack a, FluidStack b) {
2021
if (a == b) {
2122
return true;
22-
} else if (a == null || b == null) {
23-
return false;
2423
}
25-
return FluidStack.isSameFluidSameComponents(a, b);
24+
return a != null && b != null && a.isEmpty() == b.isEmpty() && FluidStack.isSameFluidSameComponents(a, b);
2625
}
2726
}

src/main/java/mekanism/common/lib/collection/ItemHashStrategy.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/main/java/mekanism/common/recipe/lookup/cache/type/ComponentSensitiveInputCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class ComponentSensitiveInputCache<KEY, INPUT, INGREDIENT extend
2424
*/
2525
private final Map<INPUT, Set<RECIPE>> componentInputCache;
2626

27-
protected ComponentSensitiveInputCache(Hash.Strategy<INPUT> componentHashStrategy) {
27+
protected ComponentSensitiveInputCache(Hash.Strategy<? super INPUT> componentHashStrategy) {
2828
this.componentInputCache = new Object2ObjectOpenCustomHashMap<>(componentHashStrategy);
2929
}
3030

src/main/java/mekanism/common/recipe/lookup/cache/type/ItemInputCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import mekanism.api.recipes.MekanismRecipe;
44
import mekanism.api.recipes.ingredients.ItemStackIngredient;
5-
import mekanism.common.lib.collection.ItemHashStrategy;
65
import net.minecraft.world.item.Item;
76
import net.minecraft.world.item.ItemStack;
7+
import net.minecraft.world.item.ItemStackLinkedSet;
88
import net.minecraft.world.item.crafting.Ingredient;
99
import net.neoforged.neoforge.common.crafting.CompoundIngredient;
1010
import net.neoforged.neoforge.common.crafting.DataComponentIngredient;
1111

1212
public class ItemInputCache<RECIPE extends MekanismRecipe> extends ComponentSensitiveInputCache<Item, ItemStack, ItemStackIngredient, RECIPE> {
1313

1414
public ItemInputCache() {
15-
super(ItemHashStrategy.INSTANCE);
15+
super(ItemStackLinkedSet.TYPE_AND_TAG);
1616
}
1717

1818
@Override

0 commit comments

Comments
 (0)