From ab7769a45da71eecaedae24c6f839ef9f6eb7f2e Mon Sep 17 00:00:00 2001 From: asdflj <854865755@qq.com> Date: Mon, 6 Mar 2023 18:35:54 +0800 Subject: [PATCH] add default method --- .../github/nei/recipes/FluidRecipe.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/glodblock/github/nei/recipes/FluidRecipe.java b/src/main/java/com/glodblock/github/nei/recipes/FluidRecipe.java index e5c62371..8617d386 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/FluidRecipe.java +++ b/src/main/java/com/glodblock/github/nei/recipes/FluidRecipe.java @@ -1,9 +1,7 @@ package com.glodblock.github.nei.recipes; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -30,7 +28,8 @@ public final class FluidRecipe { public static List> getPackageInputs(IRecipeHandler recipe, int index, boolean priority) { TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe; - if (tRecipe == null || !IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return new ArrayList<>(); + if (tRecipe == null) return new ArrayList<>(); + if (!IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return getDefaultPackageInputs(tRecipe, index); if (tRecipe.getOverlayIdentifier() == null) return getPackageInputsLegacy(recipe, index); IRecipeExtractor extractor = IdentifierMap.get(tRecipe.getOverlayIdentifier()); if (extractor == null) return new ArrayList<>(); @@ -54,9 +53,26 @@ public final class FluidRecipe { return out; } + private static List> getDefaultPackageInputs(TemplateRecipeHandler tRecipe, int index) { + List> tmp = new LinkedList<>(); + AtomicInteger i = new AtomicInteger(0); + tRecipe.getIngredientStacks(index) + .forEach(ps -> tmp.add(new OrderStack<>(ps.item, i.getAndIncrement(), ps.items))); + return tmp; + } + + private static List> getDefaultPackageOutputs(TemplateRecipeHandler tRecipe, int index) { + List> tmp = new LinkedList<>(); + AtomicInteger i = new AtomicInteger(0); + tmp.add(new OrderStack<>(tRecipe.getResultStack(index).item, i.getAndIncrement())); + tRecipe.getOtherStacks(index).forEach(ps -> tmp.add(new OrderStack<>(ps.item, i.getAndIncrement()))); + return tmp; + } + public static List> getPackageOutputs(IRecipeHandler recipe, int index, boolean useOther) { TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe; - if (tRecipe == null || !IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return new ArrayList<>(); + if (tRecipe == null) return new ArrayList<>(); + if (!IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return getDefaultPackageOutputs(tRecipe, index); if (tRecipe.getOverlayIdentifier() == null) return getPackageOutputsLegacy(recipe, index, useOther); IRecipeExtractor extractor = IdentifierMap.get(tRecipe.getOverlayIdentifier()); if (extractor == null) return new ArrayList<>();