From d977fc73312beecc1caae95ab84c6a4bb55659e2 Mon Sep 17 00:00:00 2001 From: GlodBlock <1356392126@qq.com> Date: Thu, 12 May 2022 17:38:27 +0800 Subject: [PATCH] support for eio and gt6 --- dependencies.gradle | 11 +- .../github/inventory/gui/GuiType.java | 1 - .../glodblock/github/loader/RecipeLoader.java | 1 + .../github/nei/object/IRecipeExtractor.java | 9 ++ .../nei/recipes/DefaultExtractorLoader.java | 19 +++ .../github/nei/recipes/FluidRecipe.java | 4 +- .../extractor/EnderIORecipeExtractor.java | 124 ++++++++++++++++++ .../extractor/GregTech6RecipeExtractor.java | 104 +++++++++++++++ .../extractor/VanillaRecipeExtractor.java | 2 +- .../github/util/ModAndClassUtil.java | 3 + 10 files changed, 271 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/glodblock/github/nei/recipes/extractor/EnderIORecipeExtractor.java create mode 100644 src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java diff --git a/dependencies.gradle b/dependencies.gradle index ecfd8cbc..e2576511 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,14 +1,19 @@ // Add your dependencies here dependencies { - compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.40.41:dev') - compile('com.github.GTNewHorizons:StructureLib:1.0.15:dev') + compile('com.github.GTNewHorizons:NotEnoughItems:2.2.12-GTNH:dev') - compile('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-75-GTNH:dev') compile('curse.maven:cofh-core-69162:2388751') compile('com.github.GTNewHorizons:ExtraCells2:2.5.9:dev') {transitive = false} + compile("com.github.GTNewHorizons:ForestryMC:4.4.4:dev") + compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.27:dev") + compileOnly("com.github.GTNewHorizons:EnderCore:0.2.6:dev") + compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.40.41:dev') + compileOnly('com.github.GTNewHorizons:StructureLib:1.0.15:dev') + compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev') compileOnly('com.github.GTNewHorizons:AppleCore:3.1.9:dev') {transitive = false} compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.27:dev') {transitive = false} + compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") {transitive = false} } diff --git a/src/main/java/com/glodblock/github/inventory/gui/GuiType.java b/src/main/java/com/glodblock/github/inventory/gui/GuiType.java index 91e33d72..826cdcf9 100644 --- a/src/main/java/com/glodblock/github/inventory/gui/GuiType.java +++ b/src/main/java/com/glodblock/github/inventory/gui/GuiType.java @@ -6,7 +6,6 @@ import appeng.container.implementations.ContainerCraftingStatus; import com.glodblock.github.client.gui.*; import com.glodblock.github.client.gui.container.*; import com.glodblock.github.common.parts.FCBasePart; -import com.glodblock.github.common.parts.PartFluidPatternTerminal; import com.glodblock.github.common.tile.TileFluidPacketDecoder; import com.glodblock.github.common.tile.TileFluidPatternEncoder; import com.google.common.collect.ImmutableList; diff --git a/src/main/java/com/glodblock/github/loader/RecipeLoader.java b/src/main/java/com/glodblock/github/loader/RecipeLoader.java index 4b102841..724a328b 100644 --- a/src/main/java/com/glodblock/github/loader/RecipeLoader.java +++ b/src/main/java/com/glodblock/github/loader/RecipeLoader.java @@ -37,6 +37,7 @@ public class RecipeLoader implements Runnable { GameRegistry.addRecipe(new ShapedOreRecipe(DECODER.stack(), "IHI", "CFC", "IPI", 'I', "ingotIron", 'H', Blocks.hopper, 'C', AE2_GLASS_CABLE, 'F', INTERFACE, 'P', AE2_PROCESS_CAL)); GameRegistry.addRecipe(new ShapedOreRecipe(ENCODER.stack(), "LPL", "IWI", "III", 'I', "ingotIron", 'L', "blockLapis", 'P', AE2_PROCESS_ENG, 'W', AE2_WORK_BENCH)); GameRegistry.addShapelessRecipe(FLUID_TERMINAL.stack(), AE2_PATTERN_TERM, ENCODER); + GameRegistry.addShapelessRecipe(FLUID_TERMINAL_EX.stack(), FLUID_TERMINAL.stack(), AE2_PROCESS_CAL, AE2_PROCESS_ENG, AE2_PROCESS_LOG); if (Config.fluidCells) { OreDictionary.registerOre("anyCertusCrystal", AE2_PURE_CERTUS); diff --git a/src/main/java/com/glodblock/github/nei/object/IRecipeExtractor.java b/src/main/java/com/glodblock/github/nei/object/IRecipeExtractor.java index 9419c7a6..ff344c33 100644 --- a/src/main/java/com/glodblock/github/nei/object/IRecipeExtractor.java +++ b/src/main/java/com/glodblock/github/nei/object/IRecipeExtractor.java @@ -1,6 +1,7 @@ package com.glodblock.github.nei.object; import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; import java.util.List; @@ -10,4 +11,12 @@ public interface IRecipeExtractor { List> getOutputIngredients(List rawOutputs); + default List> getInputIngredients(List rawInputs, IRecipeHandler recipe, int index) { + return getInputIngredients(rawInputs); + } + + default List> getOutputIngredients(List rawOutputs, IRecipeHandler recipe, int index) { + return getOutputIngredients(rawOutputs); + } + } diff --git a/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java b/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java index 89c8083c..a91856d8 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java +++ b/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java @@ -1,8 +1,11 @@ package com.glodblock.github.nei.recipes; +import com.glodblock.github.nei.recipes.extractor.EnderIORecipeExtractor; import com.glodblock.github.nei.recipes.extractor.GregTech5RecipeExtractor; +import com.glodblock.github.nei.recipes.extractor.GregTech6RecipeExtractor; import com.glodblock.github.nei.recipes.extractor.VanillaRecipeExtractor; import com.glodblock.github.util.ModAndClassUtil; +import gregapi.recipes.Recipe; import gregtech.api.util.GT_Recipe; public class DefaultExtractorLoader implements Runnable { @@ -19,6 +22,22 @@ public class DefaultExtractorLoader implements Runnable { FluidRecipe.addRecipeMap(tMap.mNEIName, new GregTech5RecipeExtractor(tMap.mNEIName.equals("gt.recipe.scanner") || tMap.mNEIName.equals("gt.recipe.fakeAssemblylineProcess"))); } } + + if (ModAndClassUtil.GT6) { + for (Recipe.RecipeMap tMap : Recipe.RecipeMap.RECIPE_MAPS.values()) { + FluidRecipe.addRecipeMap(tMap.mNameNEI, new GregTech6RecipeExtractor(tMap)); + } + } + + if (ModAndClassUtil.EIO) { + FluidRecipe.addRecipeMap("EIOEnchanter", new EnderIORecipeExtractor()); + FluidRecipe.addRecipeMap("EnderIOAlloySmelter", new EnderIORecipeExtractor()); + FluidRecipe.addRecipeMap("EnderIOSagMill", new EnderIORecipeExtractor()); + FluidRecipe.addRecipeMap("EnderIOSliceAndSplice", new EnderIORecipeExtractor()); + FluidRecipe.addRecipeMap("EnderIOSoulBinder", new EnderIORecipeExtractor()); + FluidRecipe.addRecipeMap("EnderIOVat", new EnderIORecipeExtractor()); + } + } } 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 eb35a0f5..80181a4a 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/FluidRecipe.java +++ b/src/main/java/com/glodblock/github/nei/recipes/FluidRecipe.java @@ -25,7 +25,7 @@ public final class FluidRecipe { IRecipeExtractor extractor = IdentifierMap.get(tRecipe.getOverlayIdentifier()); if (extractor == null) return new ArrayList<>(); List tmp = new ArrayList<>(tRecipe.getIngredientStacks(index)); - return extractor.getInputIngredients(tmp); + return extractor.getInputIngredients(tmp, recipe, index); } public static List> getPackageOutputs(IRecipeHandler recipe, int index, boolean useOther) { @@ -35,7 +35,7 @@ public final class FluidRecipe { if (extractor == null) return new ArrayList<>(); List tmp = new ArrayList<>(Collections.singleton(tRecipe.getResultStack(index))); if (useOther) tmp.addAll(tRecipe.getOtherStacks(index)); - return extractor.getOutputIngredients(tmp); + return extractor.getOutputIngredients(tmp, recipe, index); } public static List getSupportRecipes() { diff --git a/src/main/java/com/glodblock/github/nei/recipes/extractor/EnderIORecipeExtractor.java b/src/main/java/com/glodblock/github/nei/recipes/extractor/EnderIORecipeExtractor.java new file mode 100644 index 00000000..3c1b79b9 --- /dev/null +++ b/src/main/java/com/glodblock/github/nei/recipes/extractor/EnderIORecipeExtractor.java @@ -0,0 +1,124 @@ +package com.glodblock.github.nei.recipes.extractor; + +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; +import codechicken.nei.recipe.TemplateRecipeHandler; +import com.glodblock.github.nei.object.IRecipeExtractor; +import com.glodblock.github.nei.object.OrderStack; +import com.glodblock.github.util.Ae2Reflect; +import crazypants.enderio.machine.crusher.CrusherRecipeManager; +import crazypants.enderio.nei.VatRecipeHandler; +import net.minecraftforge.fluids.FluidStack; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class EnderIORecipeExtractor implements IRecipeExtractor { + + public EnderIORecipeExtractor() { + } + + @Override + public List> getInputIngredients(List rawInputs) { + List> tmp = new LinkedList<>(); + for (int i = 0; i < rawInputs.size(); i ++) { + if (rawInputs.get(i) == null) continue; + OrderStack stack = OrderStack.pack(rawInputs.get(i), i); + if (stack != null) tmp.add(stack); + } + return tmp; + } + + @Override + public List> getOutputIngredients(List rawOutputs) { + List> tmp = new LinkedList<>(); + for (int i = 0; i < rawOutputs.size(); i ++) { + if (rawOutputs.get(i) == null) continue; + OrderStack stack = OrderStack.pack(rawOutputs.get(i), i); + if (stack != null) tmp.add(stack); + } + return tmp; + } + + @Override + public List> getInputIngredients(List rawInputs, IRecipeHandler recipe, int index) { + TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe; + List> tmp = new LinkedList<>(); + if (tRecipe.arecipes.get(index) instanceof VatRecipeHandler.InnerVatRecipe) { + VatRecipeHandler.InnerVatRecipe vatRecipe = (VatRecipeHandler.InnerVatRecipe) tRecipe.arecipes.get(index); + ArrayList inputs = ReflectEIO.getInputs(vatRecipe); + for (int i = 0; i < inputs.size(); i ++) { + if (inputs.get(i) == null) continue; + OrderStack stack = OrderStack.pack(rawInputs.get(i), i); + if (stack != null) tmp.add(stack); + } + FluidStack in = ReflectEIO.getInputFluid(vatRecipe); + if (in != null) { + tmp.add(new OrderStack<>(in, inputs.size())); + } + return tmp; + } else if (tRecipe.getOverlayIdentifier().equals("EnderIOSagMill")) { + for (int i = rawInputs.size() - 1; i >= 0; i --) { + PositionedStack stack = rawInputs.get(i); + if (stack != null && CrusherRecipeManager.getInstance().isValidSagBall(stack.items[0])) { + rawInputs.remove(i); + break; + } + } + return getInputIngredients(rawInputs); + } + else { + return getInputIngredients(rawInputs); + } + } + + @Override + public List> getOutputIngredients(List rawOutputs, IRecipeHandler recipe, int index) { + TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe; + List> tmp = new LinkedList<>(); + if (tRecipe.arecipes.get(index) instanceof VatRecipeHandler.InnerVatRecipe) { + VatRecipeHandler.InnerVatRecipe vatRecipe = (VatRecipeHandler.InnerVatRecipe) tRecipe.arecipes.get(index); + FluidStack result = ReflectEIO.getResult(vatRecipe); + if (result != null) { + tmp.add(new OrderStack<>(result, 0)); + } + return tmp; + } + else { + return getOutputIngredients(rawOutputs); + } + } + + private static class ReflectEIO { + + private final static Field inputsF; + private final static Field resultF; + private final static Field inFluidF; + + static { + try { + inputsF = Ae2Reflect.reflectField(VatRecipeHandler.InnerVatRecipe.class, "inputs"); + resultF = Ae2Reflect.reflectField(VatRecipeHandler.InnerVatRecipe.class, "result"); + inFluidF = Ae2Reflect.reflectField(VatRecipeHandler.InnerVatRecipe.class, "inFluid"); + } catch (NoSuchFieldException e) { + throw new IllegalStateException("Failed to initialize EIO reflection hacks!", e); + } + } + + private static ArrayList getInputs(VatRecipeHandler.InnerVatRecipe vat) { + return Ae2Reflect.readField(vat, inputsF); + } + + private static FluidStack getResult(VatRecipeHandler.InnerVatRecipe vat) { + return Ae2Reflect.readField(vat, resultF); + } + + private static FluidStack getInputFluid(VatRecipeHandler.InnerVatRecipe vat) { + return Ae2Reflect.readField(vat, inFluidF); + } + + } + +} diff --git a/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java b/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java new file mode 100644 index 00000000..90afa165 --- /dev/null +++ b/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java @@ -0,0 +1,104 @@ +package com.glodblock.github.nei.recipes.extractor; + +import codechicken.nei.PositionedStack; +import com.glodblock.github.nei.object.IRecipeExtractor; +import com.glodblock.github.nei.object.OrderStack; +import gregapi.item.ItemFluidDisplay; +import gregapi.recipes.Recipe; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class GregTech6RecipeExtractor implements IRecipeExtractor { + + private final Recipe.RecipeMap Recipes; + + public GregTech6RecipeExtractor(Recipe.RecipeMap aMap) { + Recipes = aMap; + } + + @Override + public List> getInputIngredients(List rawInputs) { + this.removeMachine(rawInputs); + List compressed = compress(rawInputs); + List> tmp = new LinkedList<>(); + for (int i = 0; i < compressed.size(); i ++) { + if (compressed.get(i) == null) continue; + ItemStack item = compressed.get(i).items[0]; + OrderStack stack; + if (item.getItem() instanceof ItemFluidDisplay) { + FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item); + if (fluid == null || fluid.amount <= 0) continue; + stack = new OrderStack<>(fluid, i); + tmp.add(stack); + } else { + stack = OrderStack.pack(compressed.get(i), i); + if (stack != null) tmp.add(stack); + } + } + return tmp; + } + + @Override + public List> getOutputIngredients(List rawOutputs) { + List compressed = compress(rawOutputs); + List> tmp = new LinkedList<>(); + for (int i = 0; i < compressed.size(); i ++) { + if (compressed.get(i) == null) continue; + ItemStack item = compressed.get(i).items[0]; + OrderStack stack; + if (item.getItem() instanceof ItemFluidDisplay) { + FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item); + if (fluid == null || fluid.amount <= 0) continue; + stack = new OrderStack<>(fluid, i); + tmp.add(stack); + } else { + stack = OrderStack.pack(compressed.get(i), i); + if (stack != null) tmp.add(stack); + } + } + return tmp; + } + + private void removeMachine(List list) { + for (int i = list.size() - 1; i >= 0; i --) { + PositionedStack positionedStack = list.get(i); + if (positionedStack != null) { + for (ItemStack machine : this.Recipes.mRecipeMachineList) { + if (positionedStack.items[0].isItemEqual(machine)) { + list.remove(i); + break; + } + } + } + } + } + + private List compress(List list) { + List comp = new LinkedList<>(); + for (PositionedStack positionedStack : list) { + if (positionedStack == null) continue; + ItemStack currentStack = positionedStack.items[0].copy(); + if (currentStack.stackSize == 0) continue; + boolean find = false; + for (PositionedStack storedStack : comp) { + if (storedStack == null) continue; + ItemStack firstStack = storedStack.items[0].copy(); + boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); + if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { + find = true; + storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize; + } + } + if (!find) { + comp.add(positionedStack.copy()); + } + } + return comp.stream().filter(Objects::nonNull).collect(Collectors.toList()); + } + +} diff --git a/src/main/java/com/glodblock/github/nei/recipes/extractor/VanillaRecipeExtractor.java b/src/main/java/com/glodblock/github/nei/recipes/extractor/VanillaRecipeExtractor.java index f56ed528..a278bbfa 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/extractor/VanillaRecipeExtractor.java +++ b/src/main/java/com/glodblock/github/nei/recipes/extractor/VanillaRecipeExtractor.java @@ -9,7 +9,7 @@ import java.util.List; public class VanillaRecipeExtractor implements IRecipeExtractor { - private boolean c; + private final boolean c; public VanillaRecipeExtractor(boolean isCraft) { c = isCraft; diff --git a/src/main/java/com/glodblock/github/util/ModAndClassUtil.java b/src/main/java/com/glodblock/github/util/ModAndClassUtil.java index 53acd8ee..30e142de 100644 --- a/src/main/java/com/glodblock/github/util/ModAndClassUtil.java +++ b/src/main/java/com/glodblock/github/util/ModAndClassUtil.java @@ -13,6 +13,7 @@ public final class ModAndClassUtil { public static boolean GT5 = false; public static boolean GT6 = false; public static boolean EC2 = false; + public static boolean EIO = false; public static boolean isDoubleButton; public static boolean isSaveText; @@ -68,6 +69,8 @@ public final class ModAndClassUtil { GT6 = true; if (Loader.isModLoaded("extracells")) EC2 = true; + if (Loader.isModLoaded("EnderIO")) + EIO = true; }