diff --git a/src/main/java/gregtech/api/capability/DualHandler.java b/src/main/java/gregtech/api/capability/DualHandler.java index 015017c769e..b20ad3dcca1 100644 --- a/src/main/java/gregtech/api/capability/DualHandler.java +++ b/src/main/java/gregtech/api/capability/DualHandler.java @@ -2,7 +2,7 @@ import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -17,9 +17,6 @@ public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler { - @NotNull - private static final ItemStackHashStrategy strategy = ItemStackHashStrategy.comparingAll(); - @NotNull protected IItemHandlerModifiable itemDelegate; @NotNull @@ -71,7 +68,7 @@ public int getSlots() { @Override public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { var remainder = itemDelegate.insertItem(slot, stack, simulate); - if (!simulate && !strategy.equals(remainder, stack)) + if (!simulate && !ItemStackHashStrategy.comparingAll.equals(remainder, stack)) onContentsChanged(); return remainder; } @@ -93,8 +90,9 @@ public int getSlotLimit(int slot) { public void setStackInSlot(int slot, @NotNull ItemStack stack) { var oldStack = itemDelegate.getStackInSlot(slot); itemDelegate.setStackInSlot(slot, stack); - if (!strategy.equals(oldStack, stack)) + if (!ItemStackHashStrategy.comparingAll.equals(oldStack, stack)) { onContentsChanged(); + } } @Override diff --git a/src/main/java/gregtech/api/items/armor/ArmorUtils.java b/src/main/java/gregtech/api/items/armor/ArmorUtils.java index 2729c46fa38..4199f028292 100644 --- a/src/main/java/gregtech/api/items/armor/ArmorUtils.java +++ b/src/main/java/gregtech/api/items/armor/ArmorUtils.java @@ -2,7 +2,7 @@ import gregtech.api.capability.GregtechCapabilities; import gregtech.api.capability.IElectricItem; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.common.ConfigHolder; import net.minecraft.client.Minecraft; @@ -185,8 +185,7 @@ public static ActionResult canEat(EntityPlayer player, ItemStack food * @return Formated list */ public static List format(List input) { - Object2IntMap items = new Object2IntOpenCustomHashMap<>( - ItemStackHashStrategy.comparingAllButCount()); + Object2IntMap items = new Object2IntOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount); List output = new ArrayList<>(); for (ItemStack itemStack : input) { if (items.containsKey(itemStack)) { diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index fc275cdf52f..680bb26a50a 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -12,7 +12,7 @@ import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.recipes.properties.RecipePropertyStorageImpl; import gregtech.api.util.GTUtility; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.integration.groovy.GroovyScriptModule; import net.minecraft.item.ItemStack; @@ -371,7 +371,7 @@ private int hashInputs() { for (GTRecipeInput recipeIngredient : this.inputs) { if (!recipeIngredient.isOreDict()) { for (ItemStack is : recipeIngredient.getInputStacks()) { - hash = 31 * hash + ItemStackHashStrategy.comparingAll().hashCode(is); + hash = 31 * hash + ItemStackHashStrategy.comparingAll.hashCode(is); } } else { hash = 31 * hash + recipeIngredient.getOreDict(); diff --git a/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java b/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java index 9d853cc19be..61eb5e5ace3 100644 --- a/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java +++ b/src/main/java/gregtech/api/recipes/logic/ParallelLogic.java @@ -6,12 +6,12 @@ import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.ingredients.GTRecipeInput; -import gregtech.api.util.FluidStackHashStrategy; import gregtech.api.util.GTHashMaps; import gregtech.api.util.GTUtility; -import gregtech.api.util.ItemStackHashStrategy; import gregtech.api.util.OverlayedFluidHandler; import gregtech.api.util.OverlayedItemHandler; +import gregtech.api.util.hash.FluidStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -182,7 +182,7 @@ public static int limitParallelByItemsIncremental(@NotNull List recip Object2IntMap recipeOutputsToAppend = GTHashMaps.fromItemStackCollection(outputsToAppend); Object2IntMap appendedResultMap = new Object2IntLinkedOpenCustomHashMap<>(recipeOutputs, - ItemStackHashStrategy.comparingAllButCount()); + ItemStackHashStrategy.comparingAllButCount); recipeOutputsToAppend .forEach((stackKey, amt) -> appendedResultMap.merge(stackKey, amt * multiplier, Integer::sum)); @@ -405,8 +405,6 @@ protected static int getMaxRatioFluid(@NotNull Object2IntMap countFl } } - FluidStackHashStrategy fluidStrategy = FluidStackHashStrategy.comparingAllButAmount(); - // Iterate through the recipe inputs, excluding the not consumable fluids from the fluid inventory map for (FluidStack notConsumableFluid : notConsumableMap.keySet()) { int needed = notConsumableMap.getInt(notConsumableFluid); @@ -416,7 +414,7 @@ protected static int getMaxRatioFluid(@NotNull Object2IntMap countFl // Strip the Non-consumable tags here, as FluidKey compares the tags, which causes finding matching // fluids // in the input tanks to fail, because there is nothing in those hatches with a non-consumable tag - if (fluidStrategy.equals(notConsumableFluid, inputFluid)) { + if (FluidStackHashStrategy.comparingAllButAmount.equals(notConsumableFluid, inputFluid)) { available = countFluid.getInt(inputFluid); if (available > needed) { countFluid.replace(inputFluid, available - needed); @@ -453,7 +451,7 @@ protected static int getMaxRatioFluid(@NotNull Object2IntMap countFl int available = 0; // For every fluid gathered from the fluid inputs. for (FluidStack inputFluid : countFluid.keySet()) { - if (fluidStrategy.equals(stack, inputFluid)) { + if (FluidStackHashStrategy.comparingAllButAmount.equals(stack, inputFluid)) { available += countFluid.getInt(inputFluid); } } diff --git a/src/main/java/gregtech/api/util/GTHashMaps.java b/src/main/java/gregtech/api/util/GTHashMaps.java index ce10d6b2a33..1e88faea1b8 100644 --- a/src/main/java/gregtech/api/util/GTHashMaps.java +++ b/src/main/java/gregtech/api/util/GTHashMaps.java @@ -1,5 +1,8 @@ package gregtech.api.util; +import gregtech.api.util.hash.FluidStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; + import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; @@ -101,8 +104,8 @@ public static Object2IntMap fromItemStackCollection(@NotNull Iterable */ @NotNull public static Object2IntMap createItemStackMap(boolean linked) { - ItemStackHashStrategy strategy = ItemStackHashStrategy.comparingAllButCount(); - return linked ? new Object2IntLinkedOpenCustomHashMap<>(strategy) : new Object2IntOpenCustomHashMap<>(strategy); + return linked ? new Object2IntLinkedOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount) : + new Object2IntOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount); } /** @@ -111,8 +114,8 @@ public static Object2IntMap createItemStackMap(boolean linked) { */ @NotNull public static Object2IntMap createFluidStackMap(boolean linked) { - var strategy = FluidStackHashStrategy.comparingAllButAmount(); - return linked ? new Object2IntLinkedOpenCustomHashMap<>(strategy) : new Object2IntOpenCustomHashMap<>(strategy); + return linked ? new Object2IntLinkedOpenCustomHashMap<>(FluidStackHashStrategy.comparingAllButAmount) : + new Object2IntOpenCustomHashMap<>(FluidStackHashStrategy.comparingAllButAmount); } /** diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index a4f44bb2bce..b8e5dbb1b12 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -20,6 +20,7 @@ import gregtech.api.unification.ore.OrePrefix; import gregtech.api.unification.stack.ItemAndMetadata; import gregtech.api.util.function.impl.TimedProgressSupplier; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.block.BlockRedstoneWire; import net.minecraft.block.BlockSnow; @@ -878,7 +879,7 @@ public static Set getAllSubItems(@NotNull Item item) { if (tab == null || tab == CreativeTabs.SEARCH) continue; item.getSubItems(tab, subItems); } - return new ObjectOpenCustomHashSet<>(subItems, ItemStackHashStrategy.comparingItemDamageCount()); + return new ObjectOpenCustomHashSet<>(subItems, ItemStackHashStrategy.comparingAllButNBT); } /** diff --git a/src/main/java/gregtech/api/util/IFluidTankPropertiesHashStrategy.java b/src/main/java/gregtech/api/util/IFluidTankPropertiesHashStrategy.java deleted file mode 100644 index 5158b38ae87..00000000000 --- a/src/main/java/gregtech/api/util/IFluidTankPropertiesHashStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -package gregtech.api.util; - -import net.minecraftforge.fluids.capability.IFluidTankProperties; - -import it.unimi.dsi.fastutil.Hash; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -public interface IFluidTankPropertiesHashStrategy extends Hash.Strategy { - - @NotNull - static IFluidTankPropertiesHashStrategy create() { - return new IFluidTankPropertiesHashStrategy() { - - @Override - public int hashCode(IFluidTankProperties o) { - int result = 17; - result = 31 * result + (o.getContents() == null ? 0 : o.getContents().hashCode()); - result = 31 * result + o.getCapacity(); - result = 31 * result + (o.canFill() ? 1 : 0); - result = 31 * result + (o.canDrain() ? 1 : 0); - return result; - } - - @Override - public boolean equals(IFluidTankProperties a, IFluidTankProperties b) { - if (a == b) return true; - if (b == null || a.getClass() != b.getClass()) return false; - return a.getCapacity() == b.getCapacity() && a.canFill() == b.canFill() && - a.canDrain() == b.canDrain() && Objects.equals(a.getContents(), b.getContents()); - } - }; - } -} diff --git a/src/main/java/gregtech/api/util/ItemStackHashStrategy.java b/src/main/java/gregtech/api/util/ItemStackHashStrategy.java deleted file mode 100644 index 20e12330ea9..00000000000 --- a/src/main/java/gregtech/api/util/ItemStackHashStrategy.java +++ /dev/null @@ -1,148 +0,0 @@ -package gregtech.api.util; - -import net.minecraft.item.ItemStack; - -import it.unimi.dsi.fastutil.Hash; -import org.jetbrains.annotations.Nullable; - -import java.util.Objects; - -/** - * A configurable generator of hashing strategies, allowing for consideration of select properties of ItemStacks when - * considering equality. - */ -public interface ItemStackHashStrategy extends Hash.Strategy { - - /** - * @return a builder object for producing a custom ItemStackHashStrategy. - */ - static Builder builder() { - return new Builder(); - } - - /** - * Generates an ItemStackHash configured to compare every aspect of ItemStacks. - * - * @return the ItemStackHashStrategy as described above. - */ - static ItemStackHashStrategy comparingAll() { - return builder().compareItem(true) - .compareCount(true) - .compareDamage(true) - .compareTag(true) - .build(); - } - - /** - * Generates an ItemStackHash configured to compare every aspect of ItemStacks except the number - * of items in the stack. - * - * @return the ItemStackHashStrategy as described above. - */ - static ItemStackHashStrategy comparingAllButCount() { - return builder().compareItem(true) - .compareDamage(true) - .compareTag(true) - .build(); - } - - static ItemStackHashStrategy comparingItemDamageCount() { - return builder().compareItem(true) - .compareDamage(true) - .compareCount(true) - .build(); - } - - /** - * Builder pattern class for generating customized ItemStackHashStrategy - */ - class Builder { - - private boolean item, count, damage, tag, meta; - - /** - * Defines whether the Item type should be considered for equality. - * - * @param choice {@code true} to consider this property, {@code false} to ignore it. - * @return {@code this} - */ - public Builder compareItem(boolean choice) { - item = choice; - return this; - } - - /** - * Defines whether stack size should be considered for equality. - * - * @param choice {@code true} to consider this property, {@code false} to ignore it. - * @return {@code this} - */ - public Builder compareCount(boolean choice) { - count = choice; - return this; - } - - /** - * Defines whether damage values should be considered for equality. - * - * @param choice {@code true} to consider this property, {@code false} to ignore it. - * @return {@code this} - */ - public Builder compareDamage(boolean choice) { - damage = choice; - return this; - } - - /** - * Defines whether metadata values should be considered for equality. - * - * @param choice {@code true} to consider this property, {@code false} to ignore it. - * @return {@code this} - */ - public Builder compareMetadata(boolean choice) { - meta = choice; - return this; - } - - /** - * Defines whether NBT Tags should be considered for equality. - * - * @param choice {@code true} to consider this property, {@code false} to ignore it. - * @return {@code this} - */ - public Builder compareTag(boolean choice) { - tag = choice; - return this; - } - - /** - * @return the ItemStackHashStrategy as configured by "compare" methods. - */ - public ItemStackHashStrategy build() { - return new ItemStackHashStrategy() { - - @Override - public int hashCode(@Nullable ItemStack o) { - return o == null || o.isEmpty() ? 0 : Objects.hash( - item ? o.getItem() : null, - count ? o.getCount() : null, - damage ? o.getItemDamage() : null, - tag ? o.getTagCompound() : null, - meta ? o.getMetadata() : null); - } - - @Override - public boolean equals(@Nullable ItemStack a, @Nullable ItemStack b) { - if (a == null || a.isEmpty()) return b == null || b.isEmpty(); - if (b == null || b.isEmpty()) return false; - - return (!item || a.getItem() == b.getItem()) && - (!count || a.getCount() == b.getCount()) && - (!damage || a.getItemDamage() == b.getItemDamage()) && - (!meta || a.getMetadata() == b.getMetadata()) && - (!tag || Objects.equals(a.getTagCompound(), b.getTagCompound())); - } - }; - } - } -} diff --git a/src/main/java/gregtech/api/util/OverlayedItemHandler.java b/src/main/java/gregtech/api/util/OverlayedItemHandler.java index dcd73ddb281..9aa54b2e3aa 100644 --- a/src/main/java/gregtech/api/util/OverlayedItemHandler.java +++ b/src/main/java/gregtech/api/util/OverlayedItemHandler.java @@ -1,5 +1,7 @@ package gregtech.api.util; +import gregtech.api.util.hash.ItemStackHashStrategy; + import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; @@ -56,7 +58,7 @@ public int insertStackedItemStack(@NotNull ItemStack stack, int amountToInsert) initSlot(i); // if it's the same item or there is no item in the slot ItemStack slotKey = this.slots[i].getItemStack(); - if (slotKey.isEmpty() || ItemStackHashStrategy.comparingAllButCount().equals(slotKey, stack)) { + if (slotKey.isEmpty() || ItemStackHashStrategy.comparingAllButCount.equals(slotKey, stack)) { // if the slot is not full int canInsertUpTo = Math.min(this.slots[i].getSlotLimit() - this.slots[i].getCount(), stack.getMaxStackSize()); @@ -140,7 +142,7 @@ public ItemStack getItemStack() { } public void setItemStack(@NotNull ItemStack itemStack) { - if (!ItemStackHashStrategy.comparingAllButCount().equals(this.itemStack, itemStack)) { + if (!ItemStackHashStrategy.comparingAllButCount.equals(this.itemStack, itemStack)) { this.itemStack = itemStack; this.slotLimit = Math.min(itemStack.getMaxStackSize(), slotLimit); } diff --git a/src/main/java/gregtech/api/util/FluidStackHashStrategy.java b/src/main/java/gregtech/api/util/hash/FluidStackHashStrategy.java similarity index 62% rename from src/main/java/gregtech/api/util/FluidStackHashStrategy.java rename to src/main/java/gregtech/api/util/hash/FluidStackHashStrategy.java index e3cc94ac6fe..cb8e1f49cd6 100644 --- a/src/main/java/gregtech/api/util/FluidStackHashStrategy.java +++ b/src/main/java/gregtech/api/util/hash/FluidStackHashStrategy.java @@ -1,4 +1,4 @@ -package gregtech.api.util; +package gregtech.api.util.hash; import net.minecraftforge.fluids.FluidStack; @@ -6,41 +6,43 @@ import java.util.Objects; +/** + * A configurable generator of hashing strategies, allowing for consideration of select properties of + * {@link FluidStack}s when considering equality. + */ public interface FluidStackHashStrategy extends Hash.Strategy { static Builder builder() { return new Builder(); } - static FluidStackHashStrategy comparingAll() { - return builder().compareFluid(true) - .compareAmount(true) - .compareNBT(true) - .build(); - } + FluidStackHashStrategy comparingAll = builder() + .compareFluid() + .compareAmount() + .compareNBT() + .build(); - static FluidStackHashStrategy comparingAllButAmount() { - return builder().compareFluid(true) - .compareNBT(true) - .build(); - } + FluidStackHashStrategy comparingAllButAmount = builder() + .compareFluid() + .compareNBT() + .build(); class Builder { - private boolean fluid, amount, nbt; + private boolean fluid, amount, nbt = false; - public Builder compareFluid(boolean choice) { - this.fluid = choice; + public Builder compareFluid() { + this.fluid = true; return this; } - public Builder compareAmount(boolean choice) { - this.amount = choice; + public Builder compareAmount() { + this.amount = true; return this; } - public Builder compareNBT(boolean choice) { - this.nbt = choice; + public Builder compareNBT() { + this.nbt = true; return this; } diff --git a/src/main/java/gregtech/api/util/hash/ItemStackHashStrategy.java b/src/main/java/gregtech/api/util/hash/ItemStackHashStrategy.java new file mode 100644 index 00000000000..feb01edbfab --- /dev/null +++ b/src/main/java/gregtech/api/util/hash/ItemStackHashStrategy.java @@ -0,0 +1,95 @@ +package gregtech.api.util.hash; + +import net.minecraft.item.ItemStack; + +import it.unimi.dsi.fastutil.Hash; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; + +/** + * A configurable generator of hashing strategies, allowing for consideration of select properties of {@link ItemStack}s + * when considering equality. + */ +public interface ItemStackHashStrategy extends Hash.Strategy { + + static Builder builder() { + return new Builder(); + } + + ItemStackHashStrategy comparingAll = builder() + .compareItem() + .compareCount() + .compareDamage() + .compareTag() + .build(); + + ItemStackHashStrategy comparingAllButCount = builder() + .compareItem() + .compareDamage() + .compareTag() + .build(); + + ItemStackHashStrategy comparingAllButNBT = builder() + .compareItem() + .compareDamage() + .compareCount() + .build(); + + class Builder { + + private boolean item, count, damage, tag, meta = false; + + public Builder compareItem() { + item = true; + return this; + } + + public Builder compareCount() { + count = true; + return this; + } + + public Builder compareDamage() { + damage = true; + return this; + } + + public Builder compareMetadata() { + meta = true; + return this; + } + + public Builder compareTag() { + tag = true; + return this; + } + + public ItemStackHashStrategy build() { + return new ItemStackHashStrategy() { + + @Override + public int hashCode(@Nullable ItemStack o) { + return o == null || o.isEmpty() ? 0 : Objects.hash( + item ? o.getItem() : null, + count ? o.getCount() : null, + damage ? o.getItemDamage() : null, + tag ? o.getTagCompound() : null, + meta ? o.getMetadata() : null); + } + + @Override + public boolean equals(@Nullable ItemStack a, @Nullable ItemStack b) { + if (a == null || a.isEmpty()) return b == null || b.isEmpty(); + if (b == null || b.isEmpty()) return false; + + return (!item || a.getItem() == b.getItem()) && + (!count || a.getCount() == b.getCount()) && + (!damage || a.getItemDamage() == b.getItemDamage()) && + (!meta || a.getMetadata() == b.getMetadata()) && + (!tag || Objects.equals(a.getTagCompound(), b.getTagCompound())); + } + }; + } + } +} diff --git a/src/main/java/gregtech/common/covers/CoverConveyor.java b/src/main/java/gregtech/common/covers/CoverConveyor.java index b037492f993..7269ed3ab1a 100644 --- a/src/main/java/gregtech/common/covers/CoverConveyor.java +++ b/src/main/java/gregtech/common/covers/CoverConveyor.java @@ -11,7 +11,7 @@ import gregtech.api.mui.GTGuiTextures; import gregtech.api.mui.GTGuis; import gregtech.api.util.GTTransferUtils; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer; import gregtech.common.covers.filter.ItemFilterContainer; @@ -390,7 +390,7 @@ public GroupItemInfo(int filterSlot, Set itemStackTypes, int totalCou @NotNull protected Map countInventoryItemsByType(@NotNull IItemHandler inventory) { Map result = new Object2ObjectOpenCustomHashMap<>( - ItemStackHashStrategy.comparingAllButCount()); + ItemStackHashStrategy.comparingAllButCount); for (int srcIndex = 0; srcIndex < inventory.getSlots(); srcIndex++) { ItemStack itemStack = inventory.getStackInSlot(srcIndex); if (itemStack.isEmpty()) { @@ -430,7 +430,7 @@ protected Map countInventoryItemsByMatchSlot(@NotNull II if (!result.containsKey(matchedSlot)) { GroupItemInfo itemInfo = new GroupItemInfo(matchedSlot, - new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount()), 0); + new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount), 0); itemInfo.itemStackTypes.add(itemStack.copy()); itemInfo.totalCount += itemStack.getCount(); result.put(matchedSlot, itemInfo); diff --git a/src/main/java/gregtech/common/inventory/SimpleItemInfo.java b/src/main/java/gregtech/common/inventory/SimpleItemInfo.java index 56775d0beee..e72d377b7f5 100644 --- a/src/main/java/gregtech/common/inventory/SimpleItemInfo.java +++ b/src/main/java/gregtech/common/inventory/SimpleItemInfo.java @@ -1,6 +1,6 @@ package gregtech.common.inventory; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.item.ItemStack; @@ -37,6 +37,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return ItemStackHashStrategy.comparingAllButCount().hashCode(this.itemStack); + return ItemStackHashStrategy.comparingAllButCount.hashCode(this.itemStack); } } diff --git a/src/main/java/gregtech/common/inventory/itemsource/ItemSources.java b/src/main/java/gregtech/common/inventory/itemsource/ItemSources.java index 2119cefc655..cbde6120e0c 100644 --- a/src/main/java/gregtech/common/inventory/itemsource/ItemSources.java +++ b/src/main/java/gregtech/common/inventory/itemsource/ItemSources.java @@ -1,6 +1,6 @@ package gregtech.common.inventory.itemsource; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.common.inventory.IItemInfo; import gregtech.common.inventory.IItemList; @@ -19,7 +19,7 @@ public class ItemSources implements IItemList { protected final World world; protected final List handlerInfoList = new ArrayList<>(); protected final Map itemInfoMap = new Object2ObjectLinkedOpenCustomHashMap<>( - ItemStackHashStrategy.comparingAllButCount()); + ItemStackHashStrategy.comparingAllButCount); private final Comparator comparator = Comparator.comparing(ItemSource::getPriority); private final Set storedItemsView = Collections.unmodifiableSet(itemInfoMap.keySet()); diff --git a/src/main/java/gregtech/common/inventory/itemsource/sources/InventoryItemSource.java b/src/main/java/gregtech/common/inventory/itemsource/sources/InventoryItemSource.java index fae123f74a6..3c3d8b77d6a 100644 --- a/src/main/java/gregtech/common/inventory/itemsource/sources/InventoryItemSource.java +++ b/src/main/java/gregtech/common/inventory/itemsource/sources/InventoryItemSource.java @@ -1,6 +1,6 @@ package gregtech.common.inventory.itemsource.sources; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.common.inventory.itemsource.ItemSource; import net.minecraft.item.ItemStack; @@ -18,7 +18,7 @@ public class InventoryItemSource extends ItemSource { protected final int priority; protected IItemHandler itemHandler = EmptyHandler.INSTANCE; private Object2IntMap itemStackByAmountMap = new Object2IntLinkedOpenCustomHashMap<>( - ItemStackHashStrategy.comparingAllButCount()); + ItemStackHashStrategy.comparingAllButCount); public InventoryItemSource(World world, int priority) { this.world = world; @@ -72,7 +72,7 @@ public int extractItem(ItemStack stack, int amount, boolean simulate, Object2Int for (int i = 0; i < itemHandler.getSlots(); i++) { ItemStack stackInSlot = itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty()) continue; - if (!ItemStackHashStrategy.comparingAllButCount().equals(stack, stackInSlot)) continue; + if (!ItemStackHashStrategy.comparingAllButCount.equals(stack, stackInSlot)) continue; ItemStack extractedStack = itemHandler.extractItem(i, amount - itemsExtracted, simulate); if (!extractedStack.isEmpty()) { itemsExtracted += extractedStack.getCount(); @@ -94,7 +94,7 @@ public Object2IntMap getStoredItems() { private void recomputeItemStackCount() { Object2IntMap amountMap = new Object2IntLinkedOpenCustomHashMap<>( - ItemStackHashStrategy.comparingAllButCount()); + ItemStackHashStrategy.comparingAllButCount); if (itemHandler == null) { this.itemStackByAmountMap = amountMap; return; diff --git a/src/main/java/gregtech/common/items/behaviors/DataItemBehavior.java b/src/main/java/gregtech/common/items/behaviors/DataItemBehavior.java index 6930abe4f28..dcc596a0962 100644 --- a/src/main/java/gregtech/common/items/behaviors/DataItemBehavior.java +++ b/src/main/java/gregtech/common/items/behaviors/DataItemBehavior.java @@ -6,7 +6,7 @@ import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.machines.IResearchRecipeMap; import gregtech.api.util.AssemblyLineManager; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; @@ -46,7 +46,7 @@ public static void collectResearchItems(String id, List lines) { .getDataStickEntry(id); if (recipes != null && !recipes.isEmpty()) { lines.add(I18n.format("behavior.data_item.assemblyline.title")); - Collection added = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount()); + Collection added = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount); for (Recipe recipe : recipes) { ItemStack output = recipe.getOutputs().get(0); if (added.add(output)) { diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java index ee036b768a2..a1e3ce9e25d 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java @@ -17,8 +17,8 @@ import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.machines.IResearchRecipeMap; import gregtech.api.util.AssemblyLineManager; -import gregtech.api.util.ItemStackHashStrategy; import gregtech.api.util.LocalizationUtils; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.client.renderer.texture.Textures; import gregtech.client.utils.TooltipHelper; import gregtech.common.ConfigHolder; @@ -191,7 +191,7 @@ public List getDataInfo() { list.add(new TextComponentTranslation("behavior.data_item.assemblyline.title")); list.add(new TextComponentString("")); - Collection itemsAdded = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAll()); + Collection itemsAdded = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAll); for (Recipe recipe : recipes) { ItemStack stack = recipe.getOutputs().get(0); if (!itemsAdded.contains(stack)) { diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java index ba324cf1dff..cf02bb90420 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java @@ -11,7 +11,7 @@ import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; import gregtech.api.mui.GTGuis; import gregtech.api.util.GTUtility; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.client.renderer.texture.Textures; import net.minecraft.client.resources.I18n; @@ -160,7 +160,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate } // If the stacks do not match, nothing can be inserted - if (!ItemStackHashStrategy.comparingAllButCount().equals(stack, this.getStackInSlot(slot)) && + if (!ItemStackHashStrategy.comparingAllButCount.equals(stack, this.getStackInSlot(slot)) && !this.getStackInSlot(slot).isEmpty()) { return stack; } @@ -204,7 +204,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { boolean slotMatches = this.getStackInSlot(slot).isEmpty() || - ItemStackHashStrategy.comparingAllButCount().equals(this.getStackInSlot(slot), stack); + ItemStackHashStrategy.comparingAllButCount.equals(this.getStackInSlot(slot), stack); MultiblockControllerBase controller = getController(); if (controller instanceof IMachineHatchMultiblock) diff --git a/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java b/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java index 073d662369b..41f78f35796 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java +++ b/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java @@ -4,7 +4,7 @@ import gregtech.api.util.DummyContainer; import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.common.crafting.ShapedOreEnergyTransferRecipe; import gregtech.common.mui.widget.workbench.CraftingInputSlot; @@ -52,8 +52,8 @@ public class CraftingRecipeLogic extends SyncHandler { private final World world; private IItemHandlerModifiable availableHandlers; private final Hash.Strategy strategy = ItemStackHashStrategy.builder() - .compareItem(true) - .compareMetadata(true) + .compareItem() + .compareMetadata() .build(); /** @@ -66,8 +66,7 @@ public class CraftingRecipeLogic extends SyncHandler { * List of items needed to complete the crafting recipe, filled by * {@link CraftingRecipeLogic#detectAndSendChanges(boolean)} )} **/ - private final Map requiredItems = new Object2IntOpenCustomHashMap<>( - this.strategy); + private final Map requiredItems = new Object2IntOpenCustomHashMap<>(this.strategy); private final Int2IntMap compactedIndexes = new Int2IntArrayMap(9); private final Int2IntMap slotMap = new Int2IntArrayMap(); @@ -199,7 +198,7 @@ protected boolean consumeRecipeItems() { */ public ItemStack findSubstitute(int craftingIndex, ItemStack stack) { Object2BooleanMap map = replaceAttemptMap.computeIfAbsent(craftingIndex, - (m) -> new Object2BooleanOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount())); + (m) -> new Object2BooleanOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount)); ItemStack substitute = ItemStack.EMPTY; diff --git a/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeMemory.java b/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeMemory.java index af7f20b0b0b..0bb6df2559e 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeMemory.java +++ b/src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeMemory.java @@ -1,6 +1,6 @@ package gregtech.common.metatileentities.storage; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -37,8 +37,8 @@ public class CraftingRecipeMemory extends SyncHandler { public static final int MOUSE_CLICK = 2; private final Hash.Strategy strategy = ItemStackHashStrategy.builder() - .compareItem(true) - .compareMetadata(true) + .compareItem() + .compareMetadata() .build(); private final MemorizedRecipe[] memorizedRecipes; @@ -98,8 +98,7 @@ private MemorizedRecipe findOrCreateRecipe(ItemStack resultItemStack) { // search preexisting recipe with identical recipe result MemorizedRecipe existing = null; for (MemorizedRecipe memorizedRecipe : memorizedRecipes) { - if (memorizedRecipe != null && - strategy.equals(memorizedRecipe.recipeResult, resultItemStack)) { + if (memorizedRecipe != null && strategy.equals(memorizedRecipe.recipeResult, resultItemStack)) { existing = memorizedRecipe; break; } diff --git a/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetHandler.java b/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetHandler.java index 20967af87e4..2e274f45d92 100644 --- a/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetHandler.java +++ b/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetHandler.java @@ -5,7 +5,7 @@ import gregtech.api.cover.CoverHolder; import gregtech.api.util.FacingPos; import gregtech.api.util.GTTransferUtils; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.common.covers.CoverConveyor; import gregtech.common.covers.CoverItemFilter; import gregtech.common.covers.CoverRoboticArm; @@ -411,7 +411,7 @@ public static int countStack(IItemHandler handler, ItemStack stack, CoverRobotic for (int i = 0; i < handler.getSlots(); i++) { ItemStack slot = handler.getStackInSlot(i); if (slot.isEmpty()) continue; - if (isStackSpecific ? ItemStackHashStrategy.comparingAllButCount().equals(stack, slot) : + if (isStackSpecific ? ItemStackHashStrategy.comparingAllButCount.equals(stack, slot) : arm.getItemFilterContainer().test(slot)) { count += slot.getCount(); } diff --git a/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java b/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java index b419cc4960b..90b95a93028 100644 --- a/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java +++ b/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java @@ -7,7 +7,7 @@ import gregtech.api.recipes.ingredients.GTRecipeOreInput; import gregtech.api.recipes.ingredients.nbtmatch.NBTCondition; import gregtech.api.recipes.ingredients.nbtmatch.NBTMatcher; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -116,7 +116,7 @@ private static GTRecipeInput getInputFromCTIngredient(@Nullable IIngredient ingr } else { // multiple inputs for a single input entry final Map> map = new Object2ObjectOpenCustomHashMap<>( - ItemStackHashStrategy.comparingItemDamageCount()); + ItemStackHashStrategy.comparingAllButNBT); ItemStack[] stacks = new ItemStack[items.size()]; for (int i = 0; i < stacks.length; i++) { diff --git a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java index 1e5dd465b99..d67c2b02f09 100644 --- a/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java +++ b/src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoRecipeWrapper.java @@ -11,7 +11,7 @@ import gregtech.api.util.BlockInfo; import gregtech.api.util.GTUtility; import gregtech.api.util.GregFakePlayer; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.client.renderer.scene.ImmediateWorldSceneRenderer; import gregtech.client.renderer.scene.WorldSceneRenderer; import gregtech.client.utils.RenderUtil; @@ -124,7 +124,7 @@ public MBPattern(final WorldSceneRenderer sceneRenderer, final List p @SuppressWarnings("NewExpressionSideOnly") public MultiblockInfoRecipeWrapper(@NotNull MultiblockControllerBase controller) { this.controller = controller; - Set drops = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount()); + Set drops = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount); this.patterns = controller.getMatchingShapes().stream() .map(it -> initializePattern(it, drops)) .toArray(MBPattern[]::new); @@ -513,7 +513,7 @@ ItemStack getItemStack() { private static Collection gatherStructureBlocks(World world, @NotNull Map blocks, Set parts) { Map partsMap = new Object2ObjectOpenCustomHashMap<>( - ItemStackHashStrategy.comparingAllButCount()); + ItemStackHashStrategy.comparingAllButCount); for (Entry entry : blocks.entrySet()) { BlockPos pos = entry.getKey(); IBlockState state = world.getBlockState(pos); diff --git a/src/main/java/gregtech/loaders/dungeon/ChestGenHooks.java b/src/main/java/gregtech/loaders/dungeon/ChestGenHooks.java index a4355e70973..b7eb8c5bc4a 100644 --- a/src/main/java/gregtech/loaders/dungeon/ChestGenHooks.java +++ b/src/main/java/gregtech/loaders/dungeon/ChestGenHooks.java @@ -2,7 +2,7 @@ import gregtech.api.util.GTLog; import gregtech.api.util.GTStringUtils; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.common.ConfigHolder; import net.minecraft.item.ItemStack; @@ -88,11 +88,10 @@ public static void addRolls(ResourceLocation tableLocation, int minAdd, int maxA rollValues.put(tableLocation, new RandomValueRange(minAdd, maxAdd)); } - private static final ItemStackHashStrategy HASH_STRATEGY = ItemStackHashStrategy.comparingAllButCount(); - private static @NotNull String createEntryName(@NotNull ItemStack stack, @NotNull String modid, int weight, @NotNull RandomWeightLootFunction function) { - int hashCode = Objects.hash(HASH_STRATEGY.hashCode(stack), modid, weight, function.getMinAmount(), + int hashCode = Objects.hash(ItemStackHashStrategy.comparingAllButCount.hashCode(stack), modid, weight, + function.getMinAmount(), function.getMaxAmount()); return String.format("#%s:loot_%s", modid, hashCode); } diff --git a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java index 6354772d0bd..893e3b24478 100644 --- a/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java +++ b/src/test/java/gregtech/api/recipes/logic/IParallelableRecipeLogicTest.java @@ -16,7 +16,7 @@ import gregtech.api.recipes.builders.BlastRecipeBuilder; import gregtech.api.unification.material.Materials; import gregtech.api.util.GTUtility; -import gregtech.api.util.ItemStackHashStrategy; +import gregtech.api.util.hash.ItemStackHashStrategy; import gregtech.api.util.world.DummyWorld; import gregtech.common.metatileentities.MetaTileEntities; import gregtech.common.metatileentities.multi.electric.MetaTileEntityElectricBlastFurnace; @@ -44,7 +44,7 @@ public class IParallelableRecipeLogicTest { - private static final ItemStackHashStrategy hashStrategy = ItemStackHashStrategy.comparingAll(); + private static final ItemStackHashStrategy hashStrategy = ItemStackHashStrategy.comparingAll; private static RecipeMapMultiblockController mbt; private static MetaTileEntityItemBus importItemBus; private static MetaTileEntityItemBus exportItemBus;