Skip to content

Commit

Permalink
Drain category improvements (#7277)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored Jan 12, 2025
1 parent 0870d34 commit be026ec
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -41,6 +44,7 @@ public ItemDrainCategory(Info<EmptyingRecipe> info) {
}

public static void consumeRecipes(Consumer<EmptyingRecipe> consumer, IIngredientManager ingredientManager) {
ObjectOpenCustomHashSet<ItemStack> emptiedItems = new ObjectOpenCustomHashSet<>(ItemStackLinkedSet.TYPE_AND_TAG);
for (ItemStack stack : ingredientManager.getAllIngredients(VanillaTypes.ITEM_STACK)) {
if (PotionFluidHandler.isPotionItem(stack)) {
FluidStack fluidFromPotionItem = PotionFluidHandler.getFluidFromPotionItem(stack);
Expand Down Expand Up @@ -68,6 +72,11 @@ public static void consumeRecipes(Consumer<EmptyingRecipe> 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());
Expand Down

0 comments on commit be026ec

Please sign in to comment.