From 8fd4fef38b18244b2e728dce895728b043c70ce7 Mon Sep 17 00:00:00 2001 From: miozune Date: Wed, 8 Feb 2023 17:40:18 +0900 Subject: Remove a bunch of reflections against GT (#531) * Remove a bunch of reflections against GT * missed this one --- .../xmod/gregtech/loaders/GT_Material_Loader.java | 229 --------------------- .../xmod/gregtech/loaders/RecipeGen_Extruder.java | 6 +- .../xmod/gregtech/loaders/RecipeGen_Fluids.java | 211 ++++++++----------- .../gregtech/loaders/misc/AssLineAchievements.java | 16 +- 4 files changed, 92 insertions(+), 370 deletions(-) delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/loaders') 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 deleted file mode 100644 index 3d66558c4f..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/GT_Material_Loader.java +++ /dev/null @@ -1,229 +0,0 @@ -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.util.Utils; -import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; - -public class GT_Material_Loader { - - private static volatile GT_Material_Loader instance = new GT_Material_Loader(); - private volatile Object mProxyObject; - private static AutoMap mMaterials = new AutoMap(); - 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 (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) { - 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) { - 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) { - 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 methods = new HashMap(); - 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/RecipeGen_Extruder.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Extruder.java index 3d2ed68a3f..5c294ae403 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Extruder.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Extruder.java @@ -16,11 +16,9 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; public class RecipeGen_Extruder extends RecipeGen_Base { public static final Set> mRecipeGenMap = new HashSet>(); - private static boolean mRotorShapeEnabled = false; static { MaterialGenerator.mRecipeMapsToGenerate.put(mRecipeGenMap); - mRotorShapeEnabled = ItemUtils.doesItemListEntryExist("Shape_Extruder_Rotor"); } public RecipeGen_Extruder(final Material M) { @@ -145,11 +143,11 @@ public class RecipeGen_Extruder extends RecipeGen_Base { // Rotor Recipe // Shape_Extruder_Rotor - if (mRotorShapeEnabled && ItemUtils.checkForInvalidItems(material.getIngot(1)) + if (ItemUtils.checkForInvalidItems(material.getIngot(1)) && ItemUtils.checkForInvalidItems(material.getRotor(1))) if (GT_Values.RA.addExtruderRecipe( material.getIngot(5), - ItemUtils.getValueOfItemList("Shape_Extruder_Rotor", 0, ItemUtils.getErrorStack(1)), + ItemList.Shape_Extruder_Rotor.get(0), material.getRotor(1), 200, 60)) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java index 35d1a987e2..fa08380596 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_Fluids.java @@ -14,11 +14,9 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; public class RecipeGen_Fluids extends RecipeGen_Base { public static final Set> mRecipeGenMap = new HashSet>(); - private static boolean mRotorShapeEnabled = false; static { MaterialGenerator.mRecipeMapsToGenerate.put(mRecipeGenMap); - mRotorShapeEnabled = ItemUtils.doesItemListEntryExist("Shape_Extruder_Rotor"); } public RecipeGen_Fluids(final Material M) { @@ -119,139 +117,104 @@ public class RecipeGen_Fluids extends RecipeGen_Base { // GTNH - // Shape_Mold_Rod - // Shape_Mold_Rod_Long - // Shape_Mold_Bolt, - // Shape_Mold_Screw, - // Shape_Mold_Ring, - - ItemList mold_Rod = ItemUtils.getValueOfItemList("Shape_Mold_Rod", null); - ItemList mold_Rod_Long = ItemUtils.getValueOfItemList("Shape_Mold_Rod_Long", null); - ItemList mold_Bolt = ItemUtils.getValueOfItemList("Shape_Mold_Bolt", null); - ItemList mold_Screw = ItemUtils.getValueOfItemList("Shape_Mold_Screw", null); - ItemList mold_Ring = ItemUtils.getValueOfItemList("Shape_Mold_Ring", null); - ItemList mold_Rotor = ItemUtils.getValueOfItemList("Shape_Mold_Rotor", null); - // Rod - if (ItemUtils.checkForInvalidItems(material.getRod(1))) - if (mold_Rod != null && GT_Values.RA.addFluidSolidifierRecipe( - mold_Rod.get(0), // Item Shape - material.getFluidStack(72), // Fluid Input - material.getRod(1), // output - 150, // Duration - material.vVoltageMultiplier // Eu Tick - )) { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 rod Recipe: " - + material.getLocalizedName() - + " - Success"); - } else { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 rod Recipe: " - + material.getLocalizedName() - + " - Failed"); - } + if (ItemUtils.checkForInvalidItems(material.getRod(1))) if (GT_Values.RA.addFluidSolidifierRecipe( + ItemList.Shape_Mold_Rod.get(0), // Item Shape + material.getFluidStack(72), // Fluid Input + material.getRod(1), // output + 150, // Duration + material.vVoltageMultiplier // Eu Tick + )) { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 rod Recipe: " + material.getLocalizedName() + " - Success"); + } else { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 rod Recipe: " + material.getLocalizedName() + " - Failed"); + } // Rod Long - if (ItemUtils.checkForInvalidItems(material.getLongRod(1))) - if (mold_Rod_Long != null && GT_Values.RA.addFluidSolidifierRecipe( - mold_Rod_Long.get(0), // Item - // Shape - material.getFluidStack(144), // Fluid Input - material.getLongRod(1), // output - 300, // Duration - material.vVoltageMultiplier // Eu Tick - )) { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 rod long Recipe: " - + material.getLocalizedName() - + " - Success"); - } else { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 rod long Recipe: " - + material.getLocalizedName() - + " - Failed"); - } + if (ItemUtils.checkForInvalidItems(material.getLongRod(1))) if (GT_Values.RA.addFluidSolidifierRecipe( + ItemList.Shape_Mold_Rod_Long.get(0), // Item + // Shape + material.getFluidStack(144), // Fluid Input + material.getLongRod(1), // output + 300, // Duration + material.vVoltageMultiplier // Eu Tick + )) { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 rod long Recipe: " + + material.getLocalizedName() + + " - Success"); + } else { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 rod long Recipe: " + + material.getLocalizedName() + + " - Failed"); + } // Bolt - if (ItemUtils.checkForInvalidItems(material.getBolt(1))) - if (mold_Bolt != null && GT_Values.RA.addFluidSolidifierRecipe( - mold_Bolt.get(0), // Item Shape - material.getFluidStack(18), // Fluid Input - material.getBolt(1), // output - 50, // Duration - material.vVoltageMultiplier // Eu Tick - )) { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 bolt Recipe: " - + material.getLocalizedName() - + " - Success"); - } else { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 bolt Recipe: " - + material.getLocalizedName() - + " - Failed"); - } + if (ItemUtils.checkForInvalidItems(material.getBolt(1))) if (GT_Values.RA.addFluidSolidifierRecipe( + ItemList.Shape_Mold_Bolt.get(0), // Item Shape + material.getFluidStack(18), // Fluid Input + material.getBolt(1), // output + 50, // Duration + material.vVoltageMultiplier // Eu Tick + )) { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 bolt Recipe: " + material.getLocalizedName() + " - Success"); + } else { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 bolt Recipe: " + material.getLocalizedName() + " - Failed"); + } // Screw - if (ItemUtils.checkForInvalidItems(material.getScrew(1))) - if (mold_Screw != null && GT_Values.RA.addFluidSolidifierRecipe( - mold_Screw.get(0), // Item Shape - material.getFluidStack(18), // Fluid Input - material.getScrew(1), // output - 50, // Duration - material.vVoltageMultiplier // Eu Tick - )) { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 screw Recipe: " - + material.getLocalizedName() - + " - Success"); - } else { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 screw Recipe: " - + material.getLocalizedName() - + " - Failed"); - } + if (ItemUtils.checkForInvalidItems(material.getScrew(1))) if (GT_Values.RA.addFluidSolidifierRecipe( + ItemList.Shape_Mold_Screw.get(0), // Item Shape + material.getFluidStack(18), // Fluid Input + material.getScrew(1), // output + 50, // Duration + material.vVoltageMultiplier // Eu Tick + )) { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 screw Recipe: " + + material.getLocalizedName() + + " - Success"); + } else { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 screw Recipe: " + material.getLocalizedName() + " - Failed"); + } // Ring - if (ItemUtils.checkForInvalidItems(material.getRing(1))) - if (mold_Ring != null && GT_Values.RA.addFluidSolidifierRecipe( - mold_Ring.get(0), // Item Shape - material.getFluidStack(36), // Fluid Input - material.getRing(1), // output - 100, // Duration - material.vVoltageMultiplier // Eu Tick - )) { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 ring Recipe: " - + material.getLocalizedName() - + " - Success"); - } else { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 ring Recipe: " - + material.getLocalizedName() - + " - Failed"); - } + if (ItemUtils.checkForInvalidItems(material.getRing(1))) if (GT_Values.RA.addFluidSolidifierRecipe( + ItemList.Shape_Mold_Ring.get(0), // Item Shape + material.getFluidStack(36), // Fluid Input + material.getRing(1), // output + 100, // Duration + material.vVoltageMultiplier // Eu Tick + )) { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 ring Recipe: " + material.getLocalizedName() + " - Success"); + } else { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 ring Recipe: " + material.getLocalizedName() + " - Failed"); + } // Rotor - if (ItemUtils.checkForInvalidItems(material.getRotor(1))) - if (mold_Rotor != null && GT_Values.RA.addFluidSolidifierRecipe( - mold_Rotor.get(0), // Item Shape - material.getFluidStack(612), // Fluid Input - material.getRotor(1), // output - 100, // Duration - material.vVoltageMultiplier // Eu Tick - )) { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 rotor Recipe: " - + material.getLocalizedName() - + " - Success"); - } else { - Logger.WARNING( - (144 * 9) + "l fluid molder from 1 rotor Recipe: " - + material.getLocalizedName() - + " - Failed"); - } + if (ItemUtils.checkForInvalidItems(material.getRotor(1))) if (GT_Values.RA.addFluidSolidifierRecipe( + ItemList.Shape_Mold_Rotor.get(0), // Item Shape + material.getFluidStack(612), // Fluid Input + material.getRotor(1), // output + 100, // Duration + material.vVoltageMultiplier // Eu Tick + )) { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 rotor Recipe: " + + material.getLocalizedName() + + " - Success"); + } else { + Logger.WARNING( + (144 * 9) + "l fluid molder from 1 rotor Recipe: " + material.getLocalizedName() + " - Failed"); + } } } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/misc/AssLineAchievements.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/misc/AssLineAchievements.java index be7023433e..e05e32331d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/misc/AssLineAchievements.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/misc/AssLineAchievements.java @@ -18,7 +18,6 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.xmod.gregtech.common.StaticFields59; public class AssLineAchievements { @@ -42,12 +41,7 @@ public class AssLineAchievements { private static void init() { if (!ready) { active = GT_Mod.gregtechproxy.mAchievements; - try { - recipeTotal = ((GT_Recipe.GT_Recipe_Map) StaticFields59.mAssLineVisualMapNEI.get(null)).mRecipeList - .size(); - } catch (IllegalArgumentException | IllegalAccessException e) { - recipeTotal = 0; - } + recipeTotal = GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.mRecipeList.size(); mAchievementMap = new ConcurrentHashMap(); mIssuedAchievementMap = new ConcurrentHashMap(); ready = true; @@ -151,19 +145,15 @@ public class AssLineAchievements { return; } - if (StaticFields59.sAssemblylineVisualRecipes == null) { - return; - } - Logger.INFO("Trying to check for achievements"); // Debug scanner unlocks all AL recipes in creative if (player.capabilities.isCreativeMode && aPickupUnlocalSafe.equals("gt.metaitem.01.32761")) { - for (GT_Recipe recipe : StaticFields59.sAssemblylineVisualRecipes.mRecipeList) { + for (GT_Recipe recipe : GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.mRecipeList) { issueAchievement(player, recipe.getOutput(0).getUnlocalizedName()); recipe.mHidden = false; } } - for (GT_Recipe recipe : StaticFields59.sAssemblylineVisualRecipes.mRecipeList) { + for (GT_Recipe recipe : GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.mRecipeList) { String aSafeUnlocalName; if (recipe.getOutput(0) == null) { -- cgit