mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-17 10:55:06 +00:00
add ic2 nei support
This commit is contained in:
1 parent
e8133a8522
commit
510bd94c5c
4 files changed
+131
No files matched your search
@@ -47,6 +47,19 @@ public class DefaultExtractorLoader implements Runnable {
|
||||
FluidRecipe.addRecipeMap(null, new ForestryRecipeExtractor(new NEIHandlerStill()));
|
||||
}
|
||||
|
||||
if (ModAndClassUtil.IC2) {
|
||||
FluidRecipe.addRecipeMap("blastfurnace", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("BlockCutter", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("centrifuge", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("compressor", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("extractor", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("fluidcanner", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("macerator", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("metalformer", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("oreWashing", new IndustrialCraftRecipeExtractor());
|
||||
FluidRecipe.addRecipeMap("solidcanner", new IndustrialCraftRecipeExtractor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package com.glodblock.github.nei.recipes.extractor;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import com.glodblock.github.nei.object.IRecipeExtractor;
|
||||
import com.glodblock.github.nei.object.OrderStack;
|
||||
import com.glodblock.github.util.Ae2Reflect;
|
||||
import ic2.neiIntegration.core.recipehandler.FluidCannerRecipeHandler;
|
||||
import ic2.neiIntegration.core.recipehandler.OreWashingRecipeHandler;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IndustrialCraftRecipeExtractor implements IRecipeExtractor {
|
||||
|
||||
@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;
|
||||
tmp.add(OrderStack.pack(rawInputs.get(i), i));
|
||||
}
|
||||
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;
|
||||
tmp.add(OrderStack.pack(rawOutputs.get(i), i));
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs, IRecipeHandler recipe, int index) {
|
||||
List<OrderStack<?>> stacks = new LinkedList<>();
|
||||
|
||||
if (recipe instanceof FluidCannerRecipeHandler) {
|
||||
FluidCannerRecipeHandler.CachedFluidCannerRecipe cachedRecipe = (FluidCannerRecipeHandler.CachedFluidCannerRecipe) ((FluidCannerRecipeHandler) recipe).arecipes.get(index);
|
||||
FluidStack input = ReflectIC2.getInputFluid(cachedRecipe);
|
||||
PositionedStack add = rawInputs.size() > 1 ? rawInputs.get(1) : null;
|
||||
stacks.add(OrderStack.pack(add, 0));
|
||||
stacks.add(new OrderStack<>(input, 1));
|
||||
}
|
||||
else if (recipe instanceof OreWashingRecipeHandler) {
|
||||
stacks = getInputIngredients(rawInputs);
|
||||
int water = ReflectIC2.getOreWasherWater((OreWashingRecipeHandler) recipe, index);
|
||||
stacks.add(new OrderStack<>(new FluidStack(FluidRegistry.WATER, water), stacks.size()));
|
||||
} else {
|
||||
stacks = getInputIngredients(rawInputs);
|
||||
}
|
||||
|
||||
return stacks.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs, IRecipeHandler recipe, int index) {
|
||||
List<OrderStack<?>> stacks = new LinkedList<>();
|
||||
|
||||
if (recipe instanceof FluidCannerRecipeHandler) {
|
||||
FluidCannerRecipeHandler.CachedFluidCannerRecipe cachedRecipe = (FluidCannerRecipeHandler.CachedFluidCannerRecipe) ((FluidCannerRecipeHandler) recipe).arecipes.get(index);
|
||||
FluidStack output = ReflectIC2.getOutputFluid(cachedRecipe);
|
||||
stacks.add(new OrderStack<>(output, 0));
|
||||
} else {
|
||||
stacks = getOutputIngredients(rawOutputs);
|
||||
}
|
||||
|
||||
return stacks.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static class ReflectIC2 {
|
||||
|
||||
private final static Field inputsF;
|
||||
private final static Field resultF;
|
||||
|
||||
private final static Method oreWasherWater;
|
||||
|
||||
static {
|
||||
try {
|
||||
inputsF = Ae2Reflect.reflectField(FluidCannerRecipeHandler.CachedFluidCannerRecipe.class, "fluidInput");
|
||||
resultF = Ae2Reflect.reflectField(FluidCannerRecipeHandler.CachedFluidCannerRecipe.class, "fluidOutput");
|
||||
oreWasherWater = Ae2Reflect.reflectMethod(OreWashingRecipeHandler.class, "getreqWater", int.class);
|
||||
} catch (NoSuchFieldException | NoSuchMethodException e) {
|
||||
throw new IllegalStateException("Failed to initialize IC2 reflection hacks!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static FluidStack getInputFluid(FluidCannerRecipeHandler.CachedFluidCannerRecipe recipe) {
|
||||
return Ae2Reflect.readField(recipe, inputsF);
|
||||
}
|
||||
|
||||
private static FluidStack getOutputFluid(FluidCannerRecipeHandler.CachedFluidCannerRecipe recipe) {
|
||||
return Ae2Reflect.readField(recipe, resultF);
|
||||
}
|
||||
|
||||
private static int getOreWasherWater(OreWashingRecipeHandler recipeHandler, int index) {
|
||||
try {
|
||||
return (int) oreWasherWater.invoke(recipeHandler, index);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + oreWasherWater, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public final class ModAndClassUtil {
|
||||
public static boolean OC = false;
|
||||
public static boolean ThE = false;
|
||||
public static boolean WCT = false;
|
||||
public static boolean IC2 = false;
|
||||
|
||||
public static boolean isDoubleButton;
|
||||
public static boolean isSaveText;
|
||||
@@ -112,6 +113,8 @@ public final class ModAndClassUtil {
|
||||
ThE = true;
|
||||
if (Loader.isModLoaded("ae2wct"))
|
||||
WCT = true;
|
||||
if (Loader.isModLoaded("IC2"))
|
||||
IC2 = true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user