diff --git a/src/main/java/mekanism/common/tile/factory/TileEntityFactory.java b/src/main/java/mekanism/common/tile/factory/TileEntityFactory.java index 7d55a7204f5..303b20726a7 100644 --- a/src/main/java/mekanism/common/tile/factory/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/factory/TileEntityFactory.java @@ -2,9 +2,9 @@ import it.unimi.dsi.fastutil.ints.IntArraySet; import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -40,7 +40,6 @@ import mekanism.common.inventory.container.sync.SyncableLong; import mekanism.common.inventory.slot.EnergyInventorySlot; import mekanism.common.inventory.slot.FactoryInputInventorySlot; -import mekanism.common.lib.inventory.HashedItem; import mekanism.common.lib.transmitter.TransmissionType; import mekanism.common.recipe.lookup.IRecipeLookupHandler; import mekanism.common.recipe.lookup.monitor.FactoryRecipeCacheLookupMonitor; @@ -66,6 +65,7 @@ import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemStackLinkedSet; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -519,7 +519,7 @@ ItemStack getOutput(int process) throws ComputerException { //End methods IComputerTile private void sortInventory() { - Map> processes = new HashMap<>(); + Map> processes = new Object2ObjectOpenCustomHashMap<>(ItemStackLinkedSet.TYPE_AND_TAG); List emptyProcesses = new ArrayList<>(); for (ProcessInfo processInfo : processInfoSlots) { IInventorySlot inputSlot = processInfo.inputSlot(); @@ -527,8 +527,7 @@ private void sortInventory() { emptyProcesses.add(processInfo); } else { ItemStack inputStack = inputSlot.getStack(); - HashedItem item = HashedItem.raw(inputStack); - RecipeProcessInfo recipeProcessInfo = processes.computeIfAbsent(item, i -> new RecipeProcessInfo<>()); + RecipeProcessInfo recipeProcessInfo = processes.computeIfAbsent(inputStack, i -> new RecipeProcessInfo<>()); recipeProcessInfo.processes.add(processInfo); recipeProcessInfo.totalCount += inputStack.getCount(); if (recipeProcessInfo.lazyMinPerSlot == null && !CommonWorldTickHandler.flushTagAndRecipeCaches) { @@ -550,7 +549,7 @@ private void sortInventory() { //If all input slots are empty, just exit return; } - for (Entry> entry : processes.entrySet()) { + for (Entry> entry : processes.entrySet()) { RecipeProcessInfo recipeProcessInfo = entry.getValue(); if (recipeProcessInfo.lazyMinPerSlot == null) { recipeProcessInfo.item = entry.getKey(); @@ -561,8 +560,8 @@ private void sortInventory() { //Note: We put all of this logic in the lazy init, so that we don't actually call any of this // until it is needed. That way if we have no empty slots and all our input slots are filled // we don't do any extra processing here, and can properly short circuit - HashedItem item = (HashedItem) info.item; - ItemStack largerInput = item.createStack(Math.min(item.getMaxStackSize(), info.totalCount)); + ItemStack item = (ItemStack) info.item; + ItemStack largerInput = item.copyWithCount(Math.min(item.getMaxStackSize(), info.totalCount)); ProcessInfo processInfo = info.processes.getFirst(); //Try getting a recipe for our input with a larger size, and update the cache if we find one info.recipe = factory.getRecipeForInput(processInfo.process(), largerInput, processInfo.outputSlot(), processInfo.secondaryOutputSlot(), true); @@ -583,8 +582,8 @@ private void sortInventory() { distributeItems(processes); } - private void addEmptySlotsAsTargets(Map> processes, List emptyProcesses) { - for (Entry> entry : processes.entrySet()) { + private void addEmptySlotsAsTargets(Map> processes, List emptyProcesses) { + for (Entry> entry : processes.entrySet()) { RecipeProcessInfo recipeProcessInfo = entry.getValue(); int minPerSlot = recipeProcessInfo.getMinPerSlot(this); int maxSlots = recipeProcessInfo.totalCount / minPerSlot; @@ -599,7 +598,7 @@ private void addEmptySlotsAsTargets(Map> p continue; } //Note: This is some arbitrary input stack one of the stacks contained - ItemStack sourceStack = entry.getKey().getInternalStack(); + ItemStack sourceStack = entry.getKey(); int emptyToAdd = maxSlots - processCount; int added = 0; List toRemove = new ArrayList<>(); @@ -626,15 +625,15 @@ private void addEmptySlotsAsTargets(Map> p } } - private void distributeItems(Map> processes) { - for (Entry> entry : processes.entrySet()) { + private void distributeItems(Map> processes) { + for (Entry> entry : processes.entrySet()) { RecipeProcessInfo recipeProcessInfo = entry.getValue(); int processCount = recipeProcessInfo.processes.size(); if (processCount == 1) { //If there is only one process with the item in it; short-circuit, no balancing is needed continue; } - HashedItem item = entry.getKey(); + ItemStack item = entry.getKey(); //Note: This isn't based on any limits the slot may have (but we currently don't have any reduced ones here, so it doesn't matter) int maxStackSize = item.getMaxStackSize(); int numberPerSlot = recipeProcessInfo.totalCount / processCount; @@ -703,7 +702,7 @@ private void distributeItems(Map> processe // recipes to change. If this is the case, then we want to properly not crash, // but we would rather not add any extra overhead about revalidating the item // each time as it can get somewhat expensive. - inputSlot.setStackUnchecked(item.createStack(sizeForSlot)); + inputSlot.setStackUnchecked(item.copyWithCount(sizeForSlot)); } } else { //Slot is not currently empty