diff options
| author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
| commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
| tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/xmod/gregtech/loaders | |
| parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
| download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip | |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/loaders')
36 files changed, 6579 insertions, 6320 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java index 4c8707e5e8..894d45ee39 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java @@ -1,290 +1,279 @@ package gtPlusPlus.xmod.gregtech.loaders; -import java.lang.reflect.*; -import java.util.HashMap; -import java.util.Map; - import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; - import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import java.lang.reflect.*; +import java.util.HashMap; +import java.util.Map; public class GT_Material_Loader { - private volatile static GT_Material_Loader instance = new GT_Material_Loader(); - private volatile Object mProxyObject; - private static AutoMap<Materials> mMaterials = new AutoMap<Materials>(); - private static volatile boolean mHasRun = false; - - public synchronized GT_Material_Loader getInstance(){ - return GT_Material_Loader.instance; - } - - public synchronized boolean getRunAbility(){ - return (mHasRun ? false : true); - } - public synchronized void setRunAbility(boolean b){ - mHasRun = Utils.invertBoolean(b); - } - - public GT_Material_Loader() { - if (getRunAbility()){ - //Set Singleton Instance - instance = this; - - //Try Reflectively add ourselves to the GT loader. - Class mInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); - if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && mInterface != null){ - - //Make this class Dynamically implement IMaterialHandler - if (mProxyObject == null){ - mProxyObject = Proxy.newProxyInstance( - mInterface.getClassLoader(), new Class[] { mInterface }, - new MaterialHandler(getInstance())); - } - - if (ReflectionUtils.invoke(Materials.class, "add", new Class[]{ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler")}, new Object[]{mProxyObject})){ - Logger.REFLECTION("Successfully invoked add, on the proxied object implementing IMaterialHandler."); - - - Logger.REFLECTION("Examining Proxy to ensure it implements the correct Interface."); - Class[] i = mProxyObject.getClass().getInterfaces(); - for (int r=0;r<i.length;r++){ - Logger.REFLECTION("Contains "+i[r].getCanonicalName()+"."); - if (i[r] == mInterface){ - Logger.REFLECTION("Found gregtech.api.interfaces.IMaterialHandler. This Proxy is valid."); - } - } - } - else { - Logger.REFLECTION("Failed to invoke add, on the proxied object implementing IMaterialHandler."); - } - } - //Materials.add(this); - - //Stupid shit running twice, I don't think so. - setRunAbility(false); - } - } - - public void onMaterialsInit() { - Logger.DEBUG_MATERIALS("onMaterialsInit()"); - } - - public void onComponentInit() { - Logger.DEBUG_MATERIALS("onComponentInit()"); - if (!mMaterials.isEmpty()){ - Logger.DEBUG_MATERIALS("Found "+mMaterials.size()+" materials to re-enable."); - for (Materials M : mMaterials.values()){ - String name = MaterialUtils.getMaterialName(M); - Logger.DEBUG_MATERIALS("Trying to enable "+name+"."); - boolean success = tryEnableAllComponentsForMaterial(M); - if (success){ - Logger.DEBUG_MATERIALS("Success! Enabled "+name+"."); - } - else { - Logger.DEBUG_MATERIALS("Failure... Did not enable "+name+"."); - } - } - } - } - - public void onComponentIteration(Materials aMaterial) { - Logger.DEBUG_MATERIALS("onComponentIteration()"); - } - - public synchronized boolean enableMaterial(Materials m){ - if (mMaterials.setValue(m)){ - Logger.DEBUG_MATERIALS("Added "+MaterialUtils.getMaterialName(m)+" to internal Map."); - return true; - } - Logger.DEBUG_MATERIALS("Failed to add "+MaterialUtils.getMaterialName(m)+" to internal Map."); - return false; - } - - - - - - - /* - * Static internal handler methods - */ - - private static synchronized boolean tryEnableMaterial(Materials mMaterial){ - if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){ - return false; - } - - boolean value = ReflectionUtils.setField(mMaterial, "mHasParentMod", true); - if (value){ - Logger.DEBUG_MATERIALS("Set mHasParentMod true for "+mMaterial.mDefaultLocalName); - } - else { - Logger.DEBUG_MATERIALS("Failed to set mHasParentMod true for "+mMaterial.mDefaultLocalName); - } - return value; - } - - private static synchronized boolean tryEnableMaterialPart(OrePrefixes prefix, Materials mMaterial){ - if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){ - return false; - } - try { - Method enableComponent = ReflectionUtils.getClass("gregtech.api.enums.OrePrefixes").getDeclaredMethod("enableComponent", Materials.class); - enableComponent.invoke(prefix, mMaterial); - Logger.DEBUG_MATERIALS("Enabled "+prefix.name()+" for "+mMaterial.mDefaultLocalName+"."); - return true; - } - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException error) { - Logger.DEBUG_MATERIALS("Failed to enabled "+prefix.name()+" for "+mMaterial.mDefaultLocalName+". Caught "+error.getCause().toString()+"."); - error.printStackTrace(); - } - Logger.DEBUG_MATERIALS("Did not enable "+prefix.name()+" for "+mMaterial.mDefaultLocalName+". Report this error to Alkalus on Github."); - return false; - } - - private static synchronized boolean tryEnableAllComponentsForMaterial(Materials material){ - if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){ - return false; - } - try { - tryEnableMaterial(material); - int mValid = 0; - for(OrePrefixes ore:OrePrefixes.values()){ - if (tryEnableMaterialPart(ore, material)){ - mValid++; - } - } - if (mValid > 0){ - Logger.DEBUG_MATERIALS("Success - Re-enabled all components for "+MaterialUtils.getMaterialName(material)); - } - else { - Logger.DEBUG_MATERIALS("Failure - Did not enable any components for "+MaterialUtils.getMaterialName(material)); - } - return mValid > 0; - } - catch (SecurityException | IllegalArgumentException e) { - Logger.DEBUG_MATERIALS("Total Failure - Unable to re-enable "+MaterialUtils.getMaterialName(material)+". Most likely an IllegalArgumentException, but small chance it's a SecurityException."); - return false; - } - } - - - - - - - - - - /** - * Special Dynamic Interface Class - */ - - public class MaterialHandler implements InvocationHandler { - - private final Map<String, Method> methods = new HashMap<String, Method>(); - private Object target; - - public MaterialHandler(Object target) { - Logger.REFLECTION("Created a Proxy Interface which implements IMaterialHandler."); - this.target = target; - for(Method method: target.getClass().getDeclaredMethods()) { - Logger.REFLECTION("Adding "+method.getName()+" to internal method map."); - this.methods.put(method.getName(), method); - } - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - long start = System.nanoTime(); - Object result = methods.get(method.getName()).invoke(target, args); - long elapsed = System.nanoTime() - start; - Logger.INFO("[Debug] Executed "+method.getName()+" in "+elapsed+" ns"); - return result; - } - } - - - /* - public static class ProxyListener implements java.lang.reflect.InvocationHandler { - - public static Object IMaterialHandlerProxy; - - ProxyListener(){ - - Logger.REFLECTION("Failed setting IMaterialHandler Proxy instance."); - } - - //Loading the class at runtime - public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { - Class<?> someInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); - Object instance = Proxy.newProxyInstance(someInterface.getClassLoader(), new Class<?>[]{someInterface}, new InvocationHandler() { - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - //Handle the invocations - if(method.getName().equals("onMaterialsInit")){ - Logger.REFLECTION("Invoked onMaterialsInit() via IMaterialHandler proxy"); - return 1; - } - else if(method.getName().equals("onComponentInit")){ - Logger.REFLECTION("Invoked onComponentInit() via IMaterialHandler proxy"); - return 2; - } - else if(method.getName().equals("onComponentIteration")){ - Logger.REFLECTION("Invoked onComponentIteration() via IMaterialHandler proxy"); - return 3; - } - else { - return -1; - } - } - }); - System.out.println(instance.getClass().getDeclaredMethod("someMethod", (Class<?>[])null).invoke(instance, new Object[]{})); - } - - private static class MaterialHandler implements InvocationHandler { - private final Object original; - - public MaterialHandler(Object original) { - this.original = original; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws IllegalAccessException, IllegalArgumentException, - InvocationTargetException { - System.out.println("BEFORE"); - method.invoke(original, args); - System.out.println("AFTER"); - return null; - } - } - - public static void init(){ - - Class<?> someInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); - GT_Material_Loader original = GT_Material_Loader.instance; - MaterialHandler handler = new MaterialHandler(original); - - Object f = Proxy.newProxyInstance(someInterface.getClassLoader(), - new Class[] { someInterface }, - handler); - - f.originalMethod("Hallo"); - } - - - - } - - */ + private static volatile GT_Material_Loader instance = new GT_Material_Loader(); + private volatile Object mProxyObject; + private static AutoMap<Materials> mMaterials = new AutoMap<Materials>(); + private static volatile boolean mHasRun = false; + + public synchronized GT_Material_Loader getInstance() { + return GT_Material_Loader.instance; + } + + public synchronized boolean getRunAbility() { + return (mHasRun ? false : true); + } + + public synchronized void setRunAbility(boolean b) { + mHasRun = Utils.invertBoolean(b); + } + + public GT_Material_Loader() { + if (getRunAbility()) { + // Set Singleton Instance + instance = this; + + // Try Reflectively add ourselves to the GT loader. + Class mInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); + if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && mInterface != null) { + + // Make this class Dynamically implement IMaterialHandler + if (mProxyObject == null) { + mProxyObject = Proxy.newProxyInstance( + mInterface.getClassLoader(), new Class[] {mInterface}, new MaterialHandler(getInstance())); + } + + if (ReflectionUtils.invoke( + Materials.class, + "add", + new Class[] {ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler")}, + new Object[] {mProxyObject})) { + Logger.REFLECTION("Successfully invoked add, on the proxied object implementing IMaterialHandler."); + + Logger.REFLECTION("Examining Proxy to ensure it implements the correct Interface."); + Class[] i = mProxyObject.getClass().getInterfaces(); + for (int r = 0; r < i.length; r++) { + Logger.REFLECTION("Contains " + i[r].getCanonicalName() + "."); + if (i[r] == mInterface) { + Logger.REFLECTION("Found gregtech.api.interfaces.IMaterialHandler. This Proxy is valid."); + } + } + } else { + Logger.REFLECTION("Failed to invoke add, on the proxied object implementing IMaterialHandler."); + } + } + // Materials.add(this); + + // Stupid shit running twice, I don't think so. + setRunAbility(false); + } + } + + public void onMaterialsInit() { + Logger.DEBUG_MATERIALS("onMaterialsInit()"); + } + + public void onComponentInit() { + Logger.DEBUG_MATERIALS("onComponentInit()"); + if (!mMaterials.isEmpty()) { + Logger.DEBUG_MATERIALS("Found " + mMaterials.size() + " materials to re-enable."); + for (Materials M : mMaterials.values()) { + String name = MaterialUtils.getMaterialName(M); + Logger.DEBUG_MATERIALS("Trying to enable " + name + "."); + boolean success = tryEnableAllComponentsForMaterial(M); + if (success) { + Logger.DEBUG_MATERIALS("Success! Enabled " + name + "."); + } else { + Logger.DEBUG_MATERIALS("Failure... Did not enable " + name + "."); + } + } + } + } + + public void onComponentIteration(Materials aMaterial) { + Logger.DEBUG_MATERIALS("onComponentIteration()"); + } + + public synchronized boolean enableMaterial(Materials m) { + if (mMaterials.setValue(m)) { + Logger.DEBUG_MATERIALS("Added " + MaterialUtils.getMaterialName(m) + " to internal Map."); + return true; + } + Logger.DEBUG_MATERIALS("Failed to add " + MaterialUtils.getMaterialName(m) + " to internal Map."); + return false; + } + + /* + * Static internal handler methods + */ + + private static synchronized boolean tryEnableMaterial(Materials mMaterial) { + if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return false; + } + + boolean value = ReflectionUtils.setField(mMaterial, "mHasParentMod", true); + if (value) { + Logger.DEBUG_MATERIALS("Set mHasParentMod true for " + mMaterial.mDefaultLocalName); + } else { + Logger.DEBUG_MATERIALS("Failed to set mHasParentMod true for " + mMaterial.mDefaultLocalName); + } + return value; + } + + private static synchronized boolean tryEnableMaterialPart(OrePrefixes prefix, Materials mMaterial) { + if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return false; + } + try { + Method enableComponent = ReflectionUtils.getClass("gregtech.api.enums.OrePrefixes") + .getDeclaredMethod("enableComponent", Materials.class); + enableComponent.invoke(prefix, mMaterial); + Logger.DEBUG_MATERIALS("Enabled " + prefix.name() + " for " + mMaterial.mDefaultLocalName + "."); + return true; + } catch (IllegalAccessException + | IllegalArgumentException + | InvocationTargetException + | NoSuchMethodException + | SecurityException error) { + Logger.DEBUG_MATERIALS("Failed to enabled " + prefix.name() + " for " + mMaterial.mDefaultLocalName + + ". Caught " + error.getCause().toString() + "."); + error.printStackTrace(); + } + Logger.DEBUG_MATERIALS("Did not enable " + prefix.name() + " for " + mMaterial.mDefaultLocalName + + ". Report this error to Alkalus on Github."); + return false; + } + + private static synchronized boolean tryEnableAllComponentsForMaterial(Materials material) { + if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK) { + return false; + } + try { + tryEnableMaterial(material); + int mValid = 0; + for (OrePrefixes ore : OrePrefixes.values()) { + if (tryEnableMaterialPart(ore, material)) { + mValid++; + } + } + if (mValid > 0) { + Logger.DEBUG_MATERIALS( + "Success - Re-enabled all components for " + MaterialUtils.getMaterialName(material)); + } else { + Logger.DEBUG_MATERIALS( + "Failure - Did not enable any components for " + MaterialUtils.getMaterialName(material)); + } + return mValid > 0; + } catch (SecurityException | IllegalArgumentException e) { + Logger.DEBUG_MATERIALS("Total Failure - Unable to re-enable " + MaterialUtils.getMaterialName(material) + + ". Most likely an IllegalArgumentException, but small chance it's a SecurityException."); + return false; + } + } + + /** + * Special Dynamic Interface Class + */ + public class MaterialHandler implements InvocationHandler { + + private final Map<String, Method> methods = new HashMap<String, Method>(); + private Object target; + + public MaterialHandler(Object target) { + Logger.REFLECTION("Created a Proxy Interface which implements IMaterialHandler."); + this.target = target; + for (Method method : target.getClass().getDeclaredMethods()) { + Logger.REFLECTION("Adding " + method.getName() + " to internal method map."); + this.methods.put(method.getName(), method); + } + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + long start = System.nanoTime(); + Object result = methods.get(method.getName()).invoke(target, args); + long elapsed = System.nanoTime() - start; + Logger.INFO("[Debug] Executed " + method.getName() + " in " + elapsed + " ns"); + return result; + } + } + + /* + public static class ProxyListener implements java.lang.reflect.InvocationHandler { + + public static Object IMaterialHandlerProxy; + + ProxyListener(){ + + Logger.REFLECTION("Failed setting IMaterialHandler Proxy instance."); + } + + //Loading the class at runtime + public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { + Class<?> someInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); + Object instance = Proxy.newProxyInstance(someInterface.getClassLoader(), new Class<?>[]{someInterface}, new InvocationHandler() { + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + //Handle the invocations + if(method.getName().equals("onMaterialsInit")){ + Logger.REFLECTION("Invoked onMaterialsInit() via IMaterialHandler proxy"); + return 1; + } + else if(method.getName().equals("onComponentInit")){ + Logger.REFLECTION("Invoked onComponentInit() via IMaterialHandler proxy"); + return 2; + } + else if(method.getName().equals("onComponentIteration")){ + Logger.REFLECTION("Invoked onComponentIteration() via IMaterialHandler proxy"); + return 3; + } + else { + return -1; + } + } + }); + System.out.println(instance.getClass().getDeclaredMethod("someMethod", (Class<?>[])null).invoke(instance, new Object[]{})); + } + + private static class MaterialHandler implements InvocationHandler { + private final Object original; + + public MaterialHandler(Object original) { + this.original = original; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + System.out.println("BEFORE"); + method.invoke(original, args); + System.out.println("AFTER"); + return null; + } + } + + public static void init(){ + + Class<?> someInterface = ReflectionUtils.getClass("gregtech.api.interfaces.IMaterialHandler"); + GT_Material_Loader original = GT_Material_Loader.instance; + MaterialHandler handler = new MaterialHandler(original); + + Object f = Proxy.newProxyInstance(someInterface.getClassLoader(), + new Class[] { someInterface }, + handler); + + f.originalMethod("Hallo"); + } + + + + } + + */ } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/Gregtech_Blocks.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/Gregtech_Blocks.java index 724f352975..47257b404f 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/Gregtech_Blocks.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/Gregtech_Blocks.java @@ -5,20 +5,19 @@ import gtPlusPlus.xmod.gregtech.common.blocks.*; public class Gregtech_Blocks { - public static void run(){ - - //Casing Blocks - ModBlocks.blockCasingsMisc = new GregtechMetaCasingBlocks(); - ModBlocks.blockCasings2Misc = new GregtechMetaCasingBlocks2(); - ModBlocks.blockCasings3Misc = new GregtechMetaCasingBlocks3(); - ModBlocks.blockCasings4Misc = new GregtechMetaCasingBlocks4(); - ModBlocks.blockCasings5Misc = new GregtechMetaCasingBlocks5(); + public static void run() { - ModBlocks.blockCasingsTieredGTPP = new GregtechMetaTieredCasingBlocks1(); - ModBlocks.blockSpecialMultiCasings = new GregtechMetaSpecialMultiCasings(); - ModBlocks.blockSpecialMultiCasings2 = new GregtechMetaSpecialMultiCasings2(); - ModBlocks.blockCustomMachineCasings = new GregtechMetaSpecialMachineCasings(); - ModBlocks.blockCustomPipeGearCasings = new GregtechMetaCasingBlocksPipeGearbox(); + // Casing Blocks + ModBlocks.blockCasingsMisc = new GregtechMetaCasingBlocks(); + ModBlocks.blockCasings2Misc = new GregtechMetaCasingBlocks2(); + ModBlocks.blockCasings3Misc = new GregtechMetaCasingBlocks3(); + ModBlocks.blockCasings4Misc = new GregtechMetaCasingBlocks4(); + ModBlocks.blockCasings5Misc = new GregtechMetaCasingBlocks5(); - } + ModBlocks.blockCasingsTieredGTPP = new GregtechMetaTieredCasingBlocks1(); + ModBlocks.blockSpecialMultiCasings = new GregtechMetaSpecialMultiCasings(); + ModBlocks.blockSpecialMultiCasings2 = new GregtechMetaSpecialMultiCasings2(); + ModBlocks.blockCustomMachineCasings = new GregtechMetaSpecialMachineCasings(); + ModBlocks.blockCustomPipeGearCasings = new GregtechMetaCasingBlocksPipeGearbox(); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/ProcessingAngleGrinder.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/ProcessingAngleGrinder.java index 51316f024a..f43a255534 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/ProcessingAngleGrinder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/ProcessingAngleGrinder.java @@ -1,4 +1,3 @@ - package gtPlusPlus.xmod.gregtech.loaders; import gregtech.api.enums.GT_Values; @@ -20,116 +19,132 @@ import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; |
