mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 11:49:06 +00:00
feat: add enderio support
This commit is contained in:
1 parent
e6abec978a
commit
b07551f3c0
4 files changed
+92
-3
No files matched your search
@@ -39,6 +39,10 @@ public class Adapter {
|
||||
JustEnoughCalculation.logger.info("Avaritia installed");
|
||||
adapters.add(new Avaritia());
|
||||
}
|
||||
if (Loader.isModLoaded("EnderIO")) {
|
||||
JustEnoughCalculation.logger.info("EnderIO installed");
|
||||
adapters.add(new EnderIO());
|
||||
}
|
||||
JustEnoughCalculation.logger.info("=====Just Enough Calculation Init Finish=====");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package me.towdium.jecalculation.nei.adapter;
|
||||
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class EnderIO implements IAdapter {
|
||||
|
||||
@Override
|
||||
public Set<String> getAllOverlayIdentifier() {
|
||||
return new HashSet<>(
|
||||
Arrays.asList("EnderIOAlloySmelter", "EIOEnchanter", "EnderIOSagMill", "EnderIOSliceAndSplice",
|
||||
"EnderIOSoulBinder", "EnderIOVat"));
|
||||
}
|
||||
|
||||
private final static Set<Class<?>> defaultHandlers;
|
||||
private final static Class<?> vat;
|
||||
|
||||
static {
|
||||
List<String> handlers = Stream.of("SagMillRecipeHandler")
|
||||
.map(name -> "crazypants.enderio.nei." + name)
|
||||
.collect(Collectors.toList());
|
||||
defaultHandlers = new HashSet<>();
|
||||
for (String handler : handlers) {
|
||||
try {
|
||||
defaultHandlers.add(Class.forName(handler));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Class<?> innerVat = null;
|
||||
try {
|
||||
innerVat = Class.forName("crazypants.enderio.nei.VatRecipeHandler");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
vat = innerVat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRecipe(IRecipeHandler recipe, int index, List<Object[]> inputs, List<Object[]> outputs) {
|
||||
if (defaultHandlers.stream().anyMatch(aClass -> aClass.isInstance(recipe))) {
|
||||
List<ItemStack[]> otherStacks = recipe.getOtherStacks(index)
|
||||
.stream()
|
||||
.map(positionedStack -> positionedStack.items)
|
||||
.collect(Collectors.toList());
|
||||
outputs.addAll(otherStacks);
|
||||
} else {
|
||||
try {
|
||||
if (vat != null && vat.isInstance(recipe)) {
|
||||
Class<?> vatInnerRecipe = Class.forName("crazypants.enderio.nei.VatRecipeHandler$InnerVatRecipe");
|
||||
|
||||
Field arecipes = vat.getField("arecipes");
|
||||
@SuppressWarnings("unchecked")
|
||||
TemplateRecipeHandler.CachedRecipe cachedRecipe = ((ArrayList<TemplateRecipeHandler.CachedRecipe>) arecipes
|
||||
.get(recipe)).get(index);
|
||||
|
||||
Field resultField = vatInnerRecipe.getDeclaredField("result");
|
||||
Field inFluidField = vatInnerRecipe.getDeclaredField("inFluid");
|
||||
resultField.setAccessible(true);
|
||||
inFluidField.setAccessible(true);
|
||||
|
||||
FluidStack result = (FluidStack) resultField.get(cachedRecipe);
|
||||
FluidStack inFluid = (FluidStack) inFluidField.get(cachedRecipe);
|
||||
inputs.add(new Object[]{inFluid});
|
||||
outputs.add(new Object[]{result});
|
||||
resultField.setAccessible(false);
|
||||
inFluidField.setAccessible(false);
|
||||
}
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,14 @@ public class GTPP extends GregTech {
|
||||
"GT_NEI_DefaultHandler", "GT_NEI_Dehydrator", "GT_NEI_MultiBlockHandler", "GTPP_NEI_CustomMapHandler",
|
||||
"GTPP_NEI_DefaultHandlerEx"
|
||||
|
||||
).map(name -> "gtPlusPlus.nei." + name).collect(Collectors.toList()); defaultHandlers = new HashSet<>();
|
||||
).map(name -> "gtPlusPlus.nei." + name).collect(Collectors.toList());
|
||||
|
||||
defaultHandlers = new HashSet<>();
|
||||
for (String handler : handlers) {
|
||||
try {
|
||||
defaultHandlers.add(Class.forName(handler));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user