diff options
Diffstat (limited to 'src/Java/gtPlusPlus/core')
3 files changed, 108 insertions, 36 deletions
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java index 8ecdab4bbc..d4f217bbfd 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java @@ -6,12 +6,26 @@ import java.lang.reflect.Method; import gregtech.GT_Mod; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; import gregtech.common.GT_Proxy; - +import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.chunk.Chunk; public class PollutionUtils { + private static boolean mIsPollutionEnabled = true; + + static { + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) { + mIsPollutionEnabled = mPollution(); + } + else { + mIsPollutionEnabled = false; + } + } + public static boolean mPollution() { try { GT_Proxy GT_Pollution = GT_Mod.gregtechproxy; @@ -21,11 +35,13 @@ public class PollutionUtils { return mPollution.getBoolean(GT_Pollution); } } - } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {} + } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } return false; } public static boolean addPollution(IGregTechTileEntity te, int pollutionValue) { + if (mIsPollutionEnabled) try { Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); if (GT_Pollution != null) { @@ -36,11 +52,13 @@ public class PollutionUtils { } } } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) {} + | IllegalArgumentException | InvocationTargetException e) { + } return false; } public static int getPollution(IGregTechTileEntity te) { + if (mIsPollutionEnabled) try { Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); if (GT_Pollution != null) { @@ -50,8 +68,39 @@ public class PollutionUtils { } } } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) {} + | IllegalArgumentException | InvocationTargetException e) { + } return 0; } + public static boolean addPollution(Object aTileOfSomeSort, int pollutionValue) { + if (mIsPollutionEnabled) + try { + Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution"); + if (GT_Pollution != null) { + Method addPollution = GT_Pollution.getMethod("addPollution", Chunk.class, int.class); + if (addPollution != null) { + IHasWorldObjectAndCoords j = (IHasWorldObjectAndCoords) aTileOfSomeSort; + if (j != null) { + Chunk c = j.getWorld().getChunkFromBlockCoords(j.getXCoord(), j.getZCoord()); + addPollution.invoke(null, c, pollutionValue); + return true; + } else { + TileEntity t = (TileEntity) aTileOfSomeSort; + if (t != null) { + Chunk c = t.getWorldObj().getChunkFromBlockCoords(t.xCoord, t.zCoord); + addPollution.invoke(null, c, pollutionValue); + return true; + } + } + + } + } + } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + } + return false; + + } + } diff --git a/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java new file mode 100644 index 0000000000..85599e4695 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java @@ -0,0 +1,55 @@ +package gtPlusPlus.core.util.reflect; + +import java.lang.reflect.Field; + +import cpw.mods.fml.common.SidedProxy; + +public class ProxyFinder { + + public static Object getServerProxy(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; + } + + public static Object getClientProxy(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<?> clientSideClass = Class.forName(sidedProxy.clientSide()); + if(clientSideClass.isAssignableFrom(fieldValue.getClass())) { + final Object clientProxy = clientSideClass.cast(fieldValue); + //do what you want with client proxy instance + return clientProxy; + } + + } catch (final NoClassDefFoundError err) { + //its server side + return null; + } + break; + } + } + return null; + } + +}
\ 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 deleted file mode 100644 index 38382b4a46..0000000000 --- a/src/Java/gtPlusPlus/core/util/reflect/ServerProxyFinder.java +++ /dev/null @@ -1,32 +0,0 @@ -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 |