From 8eeb952e8a95c95a71f34382486863c1309c1f6b Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:55:03 -0500 Subject: [PATCH] Drain category improvements --- .../create/compat/jei/category/ItemDrainCategory.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java index 15bb777f6a..a1e398c78a 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java @@ -10,8 +10,10 @@ import com.simibubi.create.content.fluids.transfer.EmptyingRecipe; import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder; import com.simibubi.create.foundation.gui.AllGuiTextures; +import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.utility.RegisteredObjects; +import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.forge.ForgeTypes; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; @@ -22,6 +24,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemStackLinkedSet; import net.minecraft.world.item.Items; import net.minecraft.world.item.PotionItem; import net.minecraft.world.item.crafting.Ingredient; @@ -41,6 +44,7 @@ public ItemDrainCategory(Info info) { } public static void consumeRecipes(Consumer consumer, IIngredientManager ingredientManager) { + ObjectOpenCustomHashSet emptiedItems = new ObjectOpenCustomHashSet<>(ItemStackLinkedSet.TYPE_AND_TAG); for (ItemStack stack : ingredientManager.getAllIngredients(VanillaTypes.ITEM_STACK)) { if (PotionFluidHandler.isPotionItem(stack)) { FluidStack fluidFromPotionItem = PotionFluidHandler.getFluidFromPotionItem(stack); @@ -68,6 +72,11 @@ public static void consumeRecipes(Consumer consumer, IIngredient if (result.isEmpty()) continue; + // There can be a lot of duplicate empty tanks (e.g. from emptying tanks with different fluids). Merge + // them to reduce memory usage. If the item is exactly the same as the input, just use the input stack + // instead of the copy. + result = ItemHelper.sameItem(stack, result) ? stack : emptiedItems.addOrGet(result); + Ingredient ingredient = Ingredient.of(stack); ResourceLocation itemName = RegisteredObjects.getKeyOrThrow(stack.getItem()); ResourceLocation fluidName = RegisteredObjects.getKeyOrThrow(extracted.getFluid());