From df9291355838fc71a6874399f2ab797ad1e1e635 Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Mon, 10 Jul 2017 06:16:29 +1000 Subject: + Add Missing Classes. --- .../core/util/reflect/AddGregtechRecipe.java | 29 ++++++++++++++++++++ .../core/util/reflect/ServerProxyFinder.java | 32 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java create mode 100644 src/Java/gtPlusPlus/core/util/reflect/ServerProxyFinder.java (limited to 'src/Java/gtPlusPlus/core/util/reflect') diff --git a/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java b/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java new file mode 100644 index 0000000000..19c09a8c21 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java @@ -0,0 +1,29 @@ +package gtPlusPlus.core.util.reflect; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public final class AddGregtechRecipe { + + public static boolean PyrolyseOven(final ItemStack p0, final FluidStack p1, final int p2, final ItemStack p3, + final FluidStack p4, final int p5, final int p6){ + + try { + Class GT_RecipeAdder = Class.forName("gregtech.common.GT_RecipeAdder"); + if (GT_RecipeAdder != null){ + Method addPollution = GT_RecipeAdder.getMethod("addPyrolyseRecipe", ItemStack.class, FluidStack.class, int.class, ItemStack.class, FluidStack.class, int.class, int.class); + if (addPollution != null){ + return (boolean) addPollution.invoke(p0, p1, p2, p3, p4, p5, p6); + } + } + } + catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } + return false; + } + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/reflect/ServerProxyFinder.java b/src/Java/gtPlusPlus/core/util/reflect/ServerProxyFinder.java new file mode 100644 index 0000000000..2fae02a9fd --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/reflect/ServerProxyFinder.java @@ -0,0 +1,32 @@ +package gtPlusPlus.core.util.reflect; + +import java.lang.reflect.Field; + +import cpw.mods.fml.common.SidedProxy; + +public class ServerProxyFinder { + + public static Object getInstance(final Object modInstance) throws ReflectiveOperationException { + for(final Field field : modInstance.getClass().getDeclaredFields()) { + if(field.isAnnotationPresent(SidedProxy.class)) { + final SidedProxy sidedProxy = field.getAnnotation(SidedProxy.class); + final Object fieldValue = field.get(modInstance); + try { + final Class serverSideClass = Class.forName(sidedProxy.serverSide()); + if(serverSideClass.isAssignableFrom(fieldValue.getClass())) { + final Object serverProxy = serverSideClass.cast(fieldValue); + //do what you want with server proxy instance + return serverProxy; + } + + } catch (final NoClassDefFoundError err) { + //its server side + return null; + } + break; + } + } + return null; + } + +} \ No newline at end of file -- cgit