Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drain category improvements #7277

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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