support for eio and gt6

This commit is contained in:
GlodBlock committed 2022-05-12 17:38:27 +08:00
1 parent 3e76b36c49
commit d977fc7331
10 files changed
+271 -7

No files matched your search

@@ -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;
@@ -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);
@@ -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<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs);
default List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs, IRecipeHandler recipe, int index) {
return getInputIngredients(rawInputs);
}
default List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs, IRecipeHandler recipe, int index) {
return getOutputIngredients(rawOutputs);
}
}
@@ -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());
}
}
}
@@ -25,7 +25,7 @@ public final class FluidRecipe {
IRecipeExtractor extractor = IdentifierMap.get(tRecipe.getOverlayIdentifier());
if (extractor == null) return new ArrayList<>();
List<PositionedStack> tmp = new ArrayList<>(tRecipe.getIngredientStacks(index));
return extractor.getInputIngredients(tmp);
return extractor.getInputIngredients(tmp, recipe, index);
}
public static List<OrderStack<?>> getPackageOutputs(IRecipeHandler recipe, int index, boolean useOther) {
@@ -35,7 +35,7 @@ public final class FluidRecipe {
if (extractor == null) return new ArrayList<>();
List<PositionedStack> 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<String> getSupportRecipes() {
@@ -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<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
List<OrderStack<?>> 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<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
List<OrderStack<?>> 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<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs, IRecipeHandler recipe, int index) {
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
List<OrderStack<?>> tmp = new LinkedList<>();
if (tRecipe.arecipes.get(index) instanceof VatRecipeHandler.InnerVatRecipe) {
VatRecipeHandler.InnerVatRecipe vatRecipe = (VatRecipeHandler.InnerVatRecipe) tRecipe.arecipes.get(index);
ArrayList<PositionedStack> 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<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs, IRecipeHandler recipe, int index) {
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
List<OrderStack<?>> 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<PositionedStack> 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);
}
}
}
@@ -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<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
this.removeMachine(rawInputs);
List<PositionedStack> compressed = compress(rawInputs);
List<OrderStack<?>> 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<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
List<PositionedStack> compressed = compress(rawOutputs);
List<OrderStack<?>> 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<PositionedStack> 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<PositionedStack> compress(List<PositionedStack> list) {
List<PositionedStack> 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());
}
}
@@ -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;
@@ -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;
}