aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2017-07-10 06:16:29 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2017-07-10 06:16:29 +1000
commitdf9291355838fc71a6874399f2ab797ad1e1e635 (patch)
tree3607b74f7b204c158163c58796c20a03cb1f6329 /src/Java/gtPlusPlus/core/util
parent99ebf8e09d19c949af4986fa20459c8f87c455ea (diff)
downloadGT5-Unofficial-df9291355838fc71a6874399f2ab797ad1e1e635.tar.gz
GT5-Unofficial-df9291355838fc71a6874399f2ab797ad1e1e635.tar.bz2
GT5-Unofficial-df9291355838fc71a6874399f2ab797ad1e1e635.zip
+ Add Missing Classes.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
-rw-r--r--src/Java/gtPlusPlus/core/util/PollutionUtils.java65
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/AddGregtechRecipe.java29
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ServerProxyFinder.java32
3 files changed, 126 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/PollutionUtils.java b/src/Java/gtPlusPlus/core/util/PollutionUtils.java
new file mode 100644
index 0000000000..71a91d7aaf
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/PollutionUtils.java
@@ -0,0 +1,65 @@
+package gtPlusPlus.core.util;
+
+import java.lang.reflect.*;
+
+import gregtech.GT_Mod;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.common.GT_Proxy;
+
+public class PollutionUtils {
+
+ public static boolean mPollution (){
+
+ try {
+ GT_Proxy GT_Pollution = GT_Mod.gregtechproxy;
+ if (GT_Pollution != null){
+ Field mPollution = GT_Pollution.getClass().getField("mPollution");
+ if (mPollution != null){
+ return mPollution.getBoolean(GT_Pollution);
+ }
+
+ }
+ }
+ catch (SecurityException | IllegalArgumentException | NoSuchFieldException | IllegalAccessException e) {
+ return false;
+ }
+
+ return false;
+ }
+
+ public static boolean addPollution(IGregTechTileEntity te, int pollutionValue){
+ try {
+ Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
+ if (GT_Pollution != null){
+ Method addPollution = GT_Pollution.getMethod("addPollution", IGregTechTileEntity.class, int.class);
+ if (addPollution != null){
+ addPollution.invoke(te, pollutionValue);
+ return true;
+ }
+
+ }
+ }
+ catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ return false;
+ }
+ return false;
+ }
+
+ public static int getPollution(IGregTechTileEntity te){
+ try {
+ Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
+ if (GT_Pollution != null){
+ Method addPollution = GT_Pollution.getMethod("getPollution", IGregTechTileEntity.class);
+ if (addPollution != null){
+ return (int) addPollution.invoke(te);
+ }
+
+ }
+ }
+ catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ return 0;
+ }
+ return 0;
+ }
+
+}
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