diff options
author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-09-07 05:40:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-07 03:40:03 +0000 |
commit | 82604eadb847335e4b4ddf2e90a28b325786837b (patch) | |
tree | b5c34fa3ab38181fc47ec20c8537a5db34e285e1 /src/main/java/gtPlusPlus/xmod | |
parent | ba7a419aacf0b0eb33afbde5663640a0908b77ce (diff) | |
download | GT5-Unofficial-82604eadb847335e4b4ddf2e90a28b325786837b.tar.gz GT5-Unofficial-82604eadb847335e4b4ddf2e90a28b325786837b.tar.bz2 GT5-Unofficial-82604eadb847335e4b4ddf2e90a28b325786837b.zip |
Remove a bunch more reflection (#3074)
Co-authored-by: boubou19 <miisterunknown@gmail.com>
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod')
11 files changed, 137 insertions, 684 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java b/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java index b1e97782af..272b2dacf5 100644 --- a/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java +++ b/src/main/java/gtPlusPlus/xmod/bop/BiomesOPlentyHandler.java @@ -1,178 +1,27 @@ package gtPlusPlus.xmod.bop; -import static gregtech.api.enums.Mods.BiomesOPlenty; - -import java.lang.reflect.Field; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import biomesoplenty.api.content.BOPCItems; +import gregtech.api.enums.Mods; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.bop.blocks.BOPBlockRegistrator; public class BiomesOPlentyHandler { - public static Item mPineCone; - - public static Block logs1; - public static Block logs2; - public static Block logs3; - public static Block logs4; - - public static Block leaves1; - public static Block leaves2; - public static Block leaves3; - public static Block leaves4; - - public static Block colorizedLeaves1; - public static Block colorizedLeaves2; - - public static Block saplings; - public static Block colorizedSaplings; - public static void preInit() { BOPBlockRegistrator.run(); - if (BiomesOPlenty.isModLoaded()) { - setFields(); - registerPineconeToOreDict(); + if (Mods.BiomesOPlenty.isModLoaded()) { + if (BOPCItems.misc != null) { + ItemStack aPinecone = ItemUtils.simpleMetaStack(BOPCItems.misc, 13, 1); + if (aPinecone != null) { + ItemUtils.addItemToOreDictionary(aPinecone, "pinecone"); + } + } } } public static void postInit() { BOPBlockRegistrator.recipes(); } - - private static void registerPineconeToOreDict() { - if (mPineCone != null) { - ItemStack aPinecone = ItemUtils.simpleMetaStack(mPineCone, 13, 1); - if (aPinecone != null) { - ItemUtils.addItemToOreDictionary(aPinecone, "pinecone"); - } - } - } - - public static ItemStack getStack(Block aBlock, int aMeta, int aSize) { - return ItemUtils.simpleMetaStack(aBlock, aMeta, aSize); - } - - // BOPCBlocks.logs4 - 0 - // BOPCBlocks.colorizedLeaves2 - 1 - - private static void setFields() { - Field aBopMiscItem = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCItems"), "misc"); - - Field aBopBlock1 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs1"); - Field aBopBlock2 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs2"); - Field aBopBlock3 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs3"); - Field aBopBlock4 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "logs4"); - - Field aBopLeaves1 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves1"); - Field aBopLeaves2 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves2"); - Field aBopLeaves3 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves3"); - Field aBopLeaves4 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "leaves4"); - - Field aBopColouredLeaves1 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedLeaves1"); - Field aBopColouredLeaves2 = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedLeaves2"); - - Field aBopSapling = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "saplings"); - Field aBopColouredSapling = ReflectionUtils - .getField(ReflectionUtils.getClass("biomesoplenty.api.content.BOPCBlocks"), "colorizedSaplings"); - - if (aBopMiscItem != null) { - Item aMiscItem = ReflectionUtils.getFieldValue(aBopMiscItem); - if (aMiscItem != null) { - mPineCone = aMiscItem; - } - } - - if (aBopBlock1 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock1); - if (aBlock != null) { - logs1 = aBlock; - } - } - if (aBopBlock2 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock2); - if (aBlock != null) { - logs2 = aBlock; - } - } - if (aBopBlock3 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock3); - if (aBlock != null) { - logs3 = aBlock; - } - } - if (aBopBlock4 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopBlock4); - if (aBlock != null) { - logs4 = aBlock; - } - } - - if (aBopLeaves1 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves1); - if (aBlock != null) { - leaves1 = aBlock; - } - } - if (aBopLeaves2 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves2); - if (aBlock != null) { - leaves2 = aBlock; - } - } - if (aBopLeaves3 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves3); - if (aBlock != null) { - leaves3 = aBlock; - } - } - if (aBopLeaves4 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopLeaves4); - if (aBlock != null) { - leaves4 = aBlock; - } - } - - if (aBopColouredLeaves1 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopColouredLeaves1); - if (aBlock != null) { - colorizedLeaves1 = aBlock; - } - } - if (aBopColouredLeaves2 != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopColouredLeaves2); - if (aBlock != null) { - colorizedLeaves2 = aBlock; - } - } - - if (aBopSapling != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopSapling); - if (aBlock != null) { - saplings = aBlock; - } - } - if (aBopColouredSapling != null) { - Block aBlock = ReflectionUtils.getFieldValue(aBopColouredSapling); - if (aBlock != null) { - colorizedSaplings = aBlock; - } - } - } } diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java index 11397e3ef3..95813e45bd 100644 --- a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java +++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_BeeDefinition.java @@ -8,7 +8,6 @@ import static forestry.api.apiculture.EnumBeeChromosome.TEMPERATURE_TOLERANCE; import static forestry.api.core.EnumHumidity.ARID; import static gregtech.api.enums.Mods.Forestry; -import java.lang.reflect.Field; import java.util.Arrays; import java.util.Locale; import java.util.function.Consumer; @@ -47,7 +46,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.MaterialsElements.STANDALONE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.forestry.bees.handler.GTPPCombType; public enum GTPP_BeeDefinition implements IBeeDefinition { @@ -65,7 +63,11 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { AlleleHelper.instance.set(template, TEMPERATURE_TOLERANCE, Tolerance.BOTH_3); AlleleHelper.instance.set(template, HUMIDITY_TOLERANCE, Tolerance.BOTH_3); }, dis -> { - IBeeMutationCustom tMutation = dis.registerMutation("DRAGONESSENCE", "NEUTRONIUM", 2); + IBeeMutationCustom tMutation = dis.registerMutation( + GTBeeDefinition.DRAGONESSENCE.getSpecies(), + GTBeeDefinition.NEUTRONIUM.getSpecies(), + 2, + 1f); tMutation.restrictHumidity(ARID); tMutation.requireResource(STANDALONE.DRAGON_METAL.getBlock(), 1); tMutation.addMutationCondition(new GTBees.DimensionMutationCondition(1, "End")); // End Dim @@ -84,7 +86,8 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { AlleleHelper.instance.set(template, TEMPERATURE_TOLERANCE, Tolerance.BOTH_1); AlleleHelper.instance.set(template, HUMIDITY_TOLERANCE, Tolerance.BOTH_1); }, dis -> { - IBeeMutationCustom tMutation = dis.registerMutation("STEEL", "GOLD", 10); + IBeeMutationCustom tMutation = dis + .registerMutation(GTBeeDefinition.STEEL.getSpecies(), GTBeeDefinition.GOLD.getSpecies(), 10, 1f); tMutation.restrictHumidity(ARID); tMutation.restrictBiomeType(BiomeDictionary.Type.HOT); }),; @@ -185,15 +188,15 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { return ret; } - private final void setSpeciesProperties(GTPPAlleleBeeSpecies species2) { + private void setSpeciesProperties(GTPPAlleleBeeSpecies species2) { this.mSpeciesProperties.accept(species2); } - private final void setAlleles(IAllele[] template) { + private void setAlleles(IAllele[] template) { this.mAlleles.accept(template); } - private final void registerMutations() { + private void registerMutations() { this.mMutations.accept(this); } @@ -209,59 +212,47 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { BeeManager.beeRoot.registerTemplate(template); } - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, - int chance) { + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, - int chance) { + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, - int chance) { + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, - int chance) { + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, int chance) { return registerMutation(parent1, parent2, chance, 1f); } - private final IBeeMutationCustom registerMutation(String parent1, String parent2, int chance) { - return registerMutation(getGregtechBeeType(parent1), getGregtechBeeType(parent2), chance, 1f); - } - /** * Diese neue Funtion erlaubt Mutationsraten unter 1%. Setze dazu die Mutationsrate als Bruch mit chance / * chancedivider This new function allows Mutation percentages under 1%. Set them as a fraction with chance / * chancedivider */ - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, int chance, + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, IAlleleBeeSpecies parent2, int chance, float chancedivider) { return new GTPPBeeMutation(parent1, parent2, this.getTemplate(), chance, chancedivider); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, int chance, + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, IAlleleBeeSpecies parent2, int chance, float chancedivider) { return registerMutation(parent1.species, parent2, chance, chancedivider); } - private final IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, int chance, + private IBeeMutationCustom registerMutation(IAlleleBeeSpecies parent1, GTPP_BeeDefinition parent2, int chance, float chancedivider) { return registerMutation(parent1, parent2.species, chance, chancedivider); } - private final IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, - int chance, float chancedivider) { + private IBeeMutationCustom registerMutation(GTPP_BeeDefinition parent1, GTPP_BeeDefinition parent2, int chance, + float chancedivider) { return registerMutation(parent1.species, parent2, chance, chancedivider); } - private final IBeeMutationCustom registerMutation(String parent1, String parent2, int chance, float chancedivider) { - return registerMutation(getGregtechBeeType(parent1), getGregtechBeeType(parent2), chance, chancedivider); - } - @Override public final IAllele[] getTemplate() { return Arrays.copyOf(template, template.length); @@ -285,16 +276,4 @@ public enum GTPP_BeeDefinition implements IBeeDefinition { public final IBeeDefinition getRainResist() { return new BeeVariation.RainResist(this); } - - public static IAlleleBeeSpecies getGregtechBeeType(String name) { - try { - // This is still cursed, but the species field is private and I don't want to go modify that right now - GTBeeDefinition aBeeObject = GTBeeDefinition.valueOf(name); - Field gtBeesField = ReflectionUtils.getField(GTBeeDefinition.class, "species"); - return ReflectionUtils.getFieldValue(gtBeesField, aBeeObject); - } catch (Throwable t) { - t.printStackTrace(); - return null; - } - } } diff --git a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java index bfdddcca8b..7ba5bc326a 100644 --- a/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java +++ b/src/main/java/gtPlusPlus/xmod/forestry/bees/registry/GTPP_Bees.java @@ -7,7 +7,6 @@ import java.util.HashMap; import gregtech.GTMod; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.forestry.bees.handler.GTPPCombType; import gtPlusPlus.xmod.forestry.bees.handler.GTPPDropType; import gtPlusPlus.xmod.forestry.bees.handler.GTPPPollenType; @@ -45,7 +44,12 @@ public class GTPP_Bees { combs = new GTPPComb(); Logger.BEES("Loading types."); - initTypes(); + // call values() to force initialization of enum entries + GTPP_BeeDefinition.values(); + GTPPCombType.values(); + GTPPDropType.values(); + GTPPPollenType.values(); + GTPPPropolisType.values(); Logger.BEES("Adding recipes."); GTPPDrop.initDropsRecipes(); @@ -58,13 +62,4 @@ public class GTPP_Bees { Logger.BEES("Done!"); } } - - private static void initTypes() { - // This is stupid - ReflectionUtils.loadClass(GTPP_BeeDefinition.class.getName()); - ReflectionUtils.loadClass(GTPPCombType.class.getName()); - ReflectionUtils.loadClass(GTPPDropType.class.getName()); - ReflectionUtils.loadClass(GTPPPollenType.class.getName()); - ReflectionUtils.loadClass(GTPPPropolisType.class.getName()); - } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java index 43e43a1d4e..90db739be7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/MTEHatchNaquadah.java @@ -120,30 +120,26 @@ public class MTEHatchNaquadah extends MTEHatchInput { private static String[] aDescCache = new String[3]; - private String formatFluidString(FluidStack f) { - FluidStack mLockedStack = f; - Integer mLockedTemp = 0;; - String mTempMod = "" + EnumChatFormatting.RESET; - mLockedTemp = mLockedStack.getFluid() + private String formatFluidString(FluidStack fluidStack) { + String mTempMod = EnumChatFormatting.RESET.toString(); + int mLockedTemp = fluidStack.getFluid() .getTemperature(); - if (mLockedTemp != null) { - if (mLockedTemp <= -3000) { - mTempMod = "" + EnumChatFormatting.DARK_PURPLE; - } else if (mLockedTemp >= -2999 && mLockedTemp <= -500) { - mTempMod = "" + EnumChatFormatting.DARK_BLUE; - } else if (mLockedTemp >= -499 && mLockedTemp <= -50) { - mTempMod = "" + EnumChatFormatting.BLUE; - } else if (mLockedTemp >= 30 && mLockedTemp <= 300) { - mTempMod = "" + EnumChatFormatting.AQUA; - } else if (mLockedTemp >= 301 && mLockedTemp <= 800) { - mTempMod = "" + EnumChatFormatting.YELLOW; - } else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { - mTempMod = "" + EnumChatFormatting.GOLD; - } else if (mLockedTemp >= 1501) { - mTempMod = "" + EnumChatFormatting.RED; - } + if (mLockedTemp <= -3000) { + mTempMod = "" + EnumChatFormatting.DARK_PURPLE; + } else if (mLockedTemp <= -500) { + mTempMod = "" + EnumChatFormatting.DARK_BLUE; + } else if (mLockedTemp <= -50) { + mTempMod = "" + EnumChatFormatting.BLUE; + } else if (mLockedTemp >= 30 && mLockedTemp <= 300) { + mTempMod = "" + EnumChatFormatting.AQUA; + } else if (mLockedTemp >= 301 && mLockedTemp <= 800) { + mTempMod = "" + EnumChatFormatting.YELLOW; + } else if (mLockedTemp >= 801 && mLockedTemp <= 1500) { + mTempMod = "" + EnumChatFormatting.GOLD; + } else if (mLockedTemp >= 1501) { + mTempMod = "" + EnumChatFormatting.RED; } - return mTempMod + mLockedStack.getLocalizedName(); + return mTempMod + fluidStack.getLocalizedName(); } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java index 738afb0d90..b1af2451aa 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java @@ -2,7 +2,6 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base; import static gregtech.api.util.GTUtility.filterValidMTEs; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -208,7 +207,7 @@ public abstract class GTPPMultiBlockBase<T extends MTEExtendedPowerMultiBlockBas + ": " + EnumChatFormatting.YELLOW + GTValues.VN[GTUtility.getTier(getMaxInputVoltage())] - + EnumChatFormatting.RESET));; + + EnumChatFormatting.RESET)); } if (!this.mAllDynamoHatches.isEmpty()) { long storedEnergy = getStoredEnergyInAllDynamoHatches(); @@ -843,43 +842,11 @@ public abstract class GTPPMultiBlockBase<T extends MTEExtendedPowerMultiBlockBas * Enable Texture Casing Support if found in GT 5.09 */ public boolean updateTexture(final IMetaTileEntity aTileEntity, int aCasingID) { - try { // gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch.updateTexture(int) - - final IMetaTileEntity aMetaTileEntity = aTileEntity; - if (aMetaTileEntity == null) { - return false; - } - Method mProper = ReflectionUtils.getMethod(MTEHatch.class, "updateTexture", int.class); - if (mProper != null) { - if (MTEHatch.class.isInstance(aMetaTileEntity)) { - mProper.setAccessible(true); - mProper.invoke(aMetaTileEntity, aCasingID); - // log("Good Method Call for updateTexture."); - return true; - } - } else { - log("Bad Method Call for updateTexture."); - if (MTEHatch.class.isInstance(aMetaTileEntity)) { - if (aCasingID <= Byte.MAX_VALUE) { - ((MTEHatch) aTileEntity).updateTexture(aCasingID); - log( - "Good Method Call for updateTexture. Used fallback method of setting mMachineBlock as casing id was <= 128."); - return true; - } else { - log("updateTexture returning false. 1.2"); - } - } else { - log("updateTexture returning false. 1.3"); - } - } - log("updateTexture returning false. 1"); - return false; - } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - log("updateTexture returning false."); - log("updateTexture returning false. 2"); - e.printStackTrace(); - return false; + if (aTileEntity instanceof MTEHatch mteHatch) { + mteHatch.updateTexture(aCasingID); + return true; } + return false; } /** diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenFluidCanning.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenFluidCanning.java index c9f627c0d5..a334fd7de4 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenFluidCanning.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenFluidCanning.java @@ -13,7 +13,6 @@ import gtPlusPlus.api.interfaces.RunnableWithInfo; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class RecipeGenFluidCanning implements Runnable { @@ -206,13 +205,7 @@ public class RecipeGenFluidCanning implements Runnable { } private void dumpStack() { - int parents = 2; - for (int i = 0; i < 6; i++) { - Logger.INFO( - (disableOptional ? "EXTRACTING" : "CANNING") + " DEBUG | " - + (i == 0 ? "Called from: " : "Parent: ") - + ReflectionUtils.getMethodName(i + parents)); - } + Logger.modLogger.info((disableOptional ? "EXTRACTING" : "CANNING") + " DEBUG ", new Exception()); } private int getMapSize(RecipeMap<?> aMap) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java index 8fe051dd71..305422ccea 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGenRecycling.java @@ -28,7 +28,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.state.MaterialState; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class RecipeGenRecycling implements Runnable { @@ -252,11 +251,7 @@ public class RecipeGenRecycling implements Runnable { public static ItemStack get(final Object aName, final ItemStack aReplacement, final long aAmount, final boolean aMentionPossibleTypos, final boolean aNoInvalidAmounts) { if (aNoInvalidAmounts && (aAmount < 1L)) { - Logger.WARNING("Returning Null. Method: " + ReflectionUtils.getMethodName(0)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(1)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(2)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(3)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(4)); + Logger.modLogger.warn("Returning Null. Method: ", new Exception()); return null; } if (!mNameMap.containsKey(aName.toString()) && aMentionPossibleTypos) { @@ -269,11 +264,7 @@ public class RecipeGenRecycling implements Runnable { public static ItemStack getFirstOre(final Object aName, final long aAmount) { if (GTUtility.isStringInvalid(aName)) { - Logger.WARNING("Returning Null. Method: " + ReflectionUtils.getMethodName(0)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(1)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(2)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(3)); - Logger.WARNING("Called from method: " + ReflectionUtils.getMethodName(4)); + Logger.modLogger.warn("Returning Null. Method: ", new Exception()); return null; } final ItemStack tStack = mNameMap.get(aName.toString()); diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java b/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java index 5dbde33493..faa94542b9 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/HandlerTinkers.java @@ -1,10 +1,9 @@ package gtPlusPlus.xmod.tinkers; -import static gregtech.api.enums.Mods.TinkerConstruct; - import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; +import gregtech.api.enums.Mods; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import gtPlusPlus.xmod.tinkers.util.TinkersDryingRecipe; @@ -15,7 +14,7 @@ public class HandlerTinkers { public static AutoMap<BaseTinkersMaterial> mTinkerMaterials = new AutoMap<>(); public static void postInit() { - if (TinkerConstruct.isModLoaded()) { + if (Mods.TinkerConstruct.isModLoaded()) { Fluid pyrotheumFluid = FluidRegistry.getFluid("pyrotheum"); if (pyrotheumFluid != null) { diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 5a4984a898..68685b7b8b 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -165,20 +165,12 @@ public class BaseTinkersMaterial { private boolean generateRecipes(Material aMaterial, int aID) { - Block aMatBlock; - Integer aMelt; - Fluid aFluid; - - try { - aMatBlock = aMaterial.getBlock(); - aMelt = aMaterial.getMeltingPointC(); - aFluid = aMaterial.getFluidStack(0) - .getFluid(); - } catch (Throwable t) { - return false; - } + Block aMatBlock = aMaterial.getBlock(); + int aMelt = aMaterial.getMeltingPointC(); + Fluid aFluid = aMaterial.getFluidStack(0) + .getFluid(); - if (aMatBlock == null || aMelt == null || aFluid == null) { + if (aMatBlock == null || aFluid == null) { return false; } @@ -192,7 +184,6 @@ public class BaseTinkersMaterial { TinkersUtils .addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluidStack(144), ingotcast, false, 50); } - TinkersUtils.generateCastingRecipes(aMaterial, aID); return true; diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java index 4adac363e8..4136b54309 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersDryingRecipe.java @@ -1,9 +1,7 @@ package gtPlusPlus.xmod.tinkers.util; -import static gregtech.api.enums.Mods.TinkerConstruct; import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes; -import java.lang.reflect.Field; import java.util.List; import net.minecraft.item.ItemStack; @@ -14,7 +12,7 @@ import gregtech.api.enums.TierEU; import gregtech.api.util.GTUtility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.util.reflect.ReflectionUtils; +import tconstruct.library.crafting.DryingRackRecipes; public class TinkersDryingRecipe { @@ -24,20 +22,25 @@ public class TinkersDryingRecipe { public final ItemStack input; public final ItemStack result; + public TinkersDryingRecipe(final ItemStack input, final int time, final ItemStack result) { + this.time = time; + this.input = input; + this.result = result; + Logger.INFO( + "Generating Drying Recipe. Input: " + input.getDisplayName() + ", Output: " + result.getDisplayName()); + } + public static void generateAllDryingRecipes() { - List<?> aRecipes = TinkersUtils.getDryingRecipes(); - if (aRecipes != null && aRecipes.size() > 0) { - for (Object o : aRecipes) { + List<DryingRackRecipes.DryingRecipe> aRecipes = TinkersDryingRecipe.getDryingRecipes(); + if (!aRecipes.isEmpty()) { + for (DryingRackRecipes.DryingRecipe recipe : aRecipes) { Logger.INFO( - "Trying to generate recipe using object of type " + o.getClass() + "Trying to generate recipe using object of type " + recipe.getClass() .getSimpleName()); - generateFromTinkersRecipeObject(o); + generateFromTinkersRecipe(recipe); } } else { - Logger.INFO( - "Error generating Drying recipes, map was either null or empty. Null? " + (aRecipes != null) - + ", Size: " - + aRecipes.size()); + Logger.INFO("Error generating Drying recipes, map was empty. Size: " + aRecipes.size()); } if (!recipes.isEmpty()) { Logger.INFO("Adding " + recipes.size() + " drying rack recipes to the dehydrator."); @@ -52,61 +55,19 @@ public class TinkersDryingRecipe { } } - public static TinkersDryingRecipe generateFromTinkersRecipeObject(Object o) { - Field aTime; - Field aInput; - Field aOutput; - Class aTinkerClass = ReflectionUtils.getClass("tconstruct.library.crafting.DryingRackRecipes.DryingRecipe"); // o.getClass(); - if (aTinkerClass == null || TinkerConstruct.isModLoaded()) { - Logger.INFO( - "Error generating Drying Recipe, could not find class. Exists? " - + ReflectionUtils.doesClassExist("tconstruct.library.crafting.DryingRackRecipes.DryingRecipe")); - Class clazz = ReflectionUtils.getClass("tconstruct.library.crafting.DryingRackRecipes"); - Class[] y = clazz.getDeclaredClasses(); - if (y == null || y.length <= 0) { - Logger.INFO("No hidden inner classes."); - return null; - } else { - boolean found = false; - for (Class h : y) { - Logger.INFO("Found hidden inner class: " + h.getCanonicalName()); - if (h.getSimpleName() - .toLowerCase() - .equals("dryingrecipe")) { - Logger.INFO("Found correct recipe. Caching at correct location."); - ReflectionUtils.mCachedClasses - .put("tconstruct.library.crafting.DryingRackRecipes.DryingRecipe", h); - aTinkerClass = h; - found = true; - break; - } - } - if (!found) { - return null; - } - } - } - aTime = ReflectionUtils.getField(aTinkerClass, "time"); - aInput = ReflectionUtils.getField(aTinkerClass, "input"); - aOutput = ReflectionUtils.getField(aTinkerClass, "result"); - try { - int time_internal = aTime.getInt(o); - ItemStack input_internal = (ItemStack) aInput.get(o); - ItemStack result_internal = (ItemStack) aOutput.get(o); - return new TinkersDryingRecipe(input_internal, time_internal, result_internal); - } catch (Throwable b) { - b.printStackTrace(); - } - return null; + private static void generateFromTinkersRecipe(DryingRackRecipes.DryingRecipe recipe) { + recipes.add(new TinkersDryingRecipe(recipe.input, recipe.time, recipe.result)); } - public TinkersDryingRecipe(final ItemStack input, final int time, final ItemStack result) { - this.time = time; - this.input = input; - this.result = result; - Logger.INFO( - "Generating Drying Recipe. Input: " + input.getDisplayName() + ", Output: " + result.getDisplayName()); - recipes.add(this); + private static List<DryingRackRecipes.DryingRecipe> getDryingRecipes() { + AutoMap<DryingRackRecipes.DryingRecipe> aData = new AutoMap<>(); + int aCount = 0; + for (DryingRackRecipes.DryingRecipe recipe : DryingRackRecipes.recipes) { + aData.put(recipe); + aCount++; + } + Logger.INFO("Found " + aCount + " Tinkers drying rack recipes."); + return aData; } public boolean matches(ItemStack input) { diff --git a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index 8b173d5b62..09633f5810 100644 --- a/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/main/java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,339 +1,89 @@ package gtPlusPlus.xmod.tinkers.util; -import static gregtech.api.enums.Mods.TinkerConstruct; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import net.minecraft.block.Block; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; -import gregtech.api.enums.Materials; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.CastingRecipe; +import tconstruct.library.crafting.FluidType; +import tconstruct.library.crafting.LiquidCasting; +import tconstruct.library.crafting.Smeltery; +import tconstruct.library.tools.DynamicToolPart; +import tconstruct.library.util.IPattern; +import tconstruct.smeltery.TinkerSmeltery; public class TinkersUtils { - private static final Class<?> mClass_Smeltery; - private static final Class<?> mClass_TConstructRegistry; - private static final Class<?> mClass_ToolMaterial; - private static final Class<?> mClass_IPattern; - private static final Class<?> mClass_DynamicToolPart; - private static final Class<?> mClass_FluidType; - private static final Class<?> mClass_CastingRecipe; - private static final Class<?> mClass_TinkerSmeltery; - - private static final Field mField_MoltenIronFluid; - - private static final Method mMethod_getFluidType; - private static final Method mMethod_getCastingRecipes; - - private static Object mSmelteryInstance; - private static Object mTinkersRegistryInstance; - - private static final HashMap<String, Method> mMethodCache = new LinkedHashMap<>(); - - static { - mClass_Smeltery = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); - mClass_TConstructRegistry = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); - - mClass_ToolMaterial = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); - mClass_IPattern = ReflectionUtils.getClass("tconstruct.library.util.IPattern"); - mClass_DynamicToolPart = ReflectionUtils.getClass("tconstruct.library.tools.DynamicToolPart"); - mClass_FluidType = ReflectionUtils.getClass("tconstruct.library.crafting.FluidType"); - mClass_CastingRecipe = ReflectionUtils.getClass("tconstruct.library.crafting.CastingRecipe"); - mClass_TinkerSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); - - mField_MoltenIronFluid = ReflectionUtils.getField(mClass_TinkerSmeltery, "moltenIronFluid"); - - mMethod_getFluidType = ReflectionUtils.getMethod(mClass_FluidType, "getFluidType", String.class); - mMethod_getCastingRecipes = ReflectionUtils - .getMethod(getCastingInstance(0), "getCastingRecipes", new Class[] {}); - } - - private static void setTiConDataInstance() { - if (!TinkerConstruct.isModLoaded()) { - return; - } - - if (mSmelteryInstance == null) { - if (mClass_Smeltery != null) { - try { - mSmelteryInstance = ReflectionUtils.getField(mClass_Smeltery, "instance") - .get(null); - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - } - } - if (mTinkersRegistryInstance == null) { - if (mClass_TConstructRegistry != null) { - try { - mTinkersRegistryInstance = ReflectionUtils.getField(mClass_TConstructRegistry, "instance") - .get(null); - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - } - } - } - /** * Add a new fluid as a valid Smeltery fuel. - * + * * @param fluid The fluid. * @param power The temperature of the fluid. This also influences the melting speed. Lava is 1000. * @param duration How long one "portion" of liquid fuels the smeltery. Lava is 10. */ public static void addSmelteryFuel(Fluid fluid, int power, int duration) { - setTiConDataInstance(); - ReflectionUtils.invokeVoid( - mSmelteryInstance, - "addSmelteryFuel", - new Class[] { Fluid.class, int.class, int.class }, - new Object[] { fluid, power, duration }); + Smeltery.addSmelteryFuel(fluid, power, duration); } public static boolean registerFluidType(String name, Block block, int meta, int baseTemperature, Fluid fluid, boolean isToolpart) { - if (mMethodCache.get("registerFluidType") == null) { - Method m = ReflectionUtils.getMethod( - ReflectionUtils.getClass("tconstruct.library.crafting.FluidType"), - "registerFluidType", - String.class, - Block.class, - int.class, - int.class, - Fluid.class, - boolean.class); - mMethodCache.put("registerFluidType", m); - } - try { - mMethodCache.get("registerFluidType") - .invoke(null, name, block, meta, baseTemperature, fluid, isToolpart); - return true; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - return false; - } + FluidType.registerFluidType(name, block, meta, baseTemperature, fluid, isToolpart); + return true; } public static void addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) { - if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils.getMethod( - mClass_Smeltery, - "addMelting", - ItemStack.class, - Block.class, - int.class, - int.class, - FluidStack.class); - mMethodCache.put("addMelting", m); - } - try { - mMethodCache.get("addMelting") - .invoke(null, input, block, metadata, temperature, liquid); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + Smeltery.addMelting(input, block, metadata, temperature, liquid); } - public static void addMelting(Object type, ItemStack input, int temperatureDifference, int fluidAmount) { - if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils - .getMethod(mClass_Smeltery, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); - mMethodCache.put("addMelting", m); - } - try { - mMethodCache.get("addMelting") - .invoke(null, type, input, temperatureDifference, fluidAmount); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + public static void addMelting(FluidType type, ItemStack input, int temperatureDifference, int fluidAmount) { + Smeltery.addMelting(type, input, temperatureDifference, fluidAmount); } public static void addBasinRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) { - if (mMethodCache.get("addBasinRecipe") == null) { - Method m = ReflectionUtils.getMethod( - ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), - "addCastingRecipe", - ItemStack.class, - FluidStack.class, - ItemStack.class, - boolean.class, - int.class); - mMethodCache.put("addBasinRecipe", m); - } - try { - mMethodCache.get("addBasinRecipe") - .invoke(getCastingInstance(0), output, metal, cast, consume, delay); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + LiquidCasting tableCasting = TConstructRegistry.getTableCasting(); + tableCasting.addCastingRecipe(output, metal, cast, consume, delay); } public static void addCastingTableRecipe(ItemStack output, FluidStack metal, ItemStack cast, boolean consume, int delay) { - if (mMethodCache.get("addCastingTableRecipe") == null) { - Method m = ReflectionUtils.getMethod( - ReflectionUtils.getClass("tconstruct.library.crafting.LiquidCasting"), - "addCastingRecipe", - ItemStack.class, - FluidStack.class, - ItemStack.class, - boolean.class, - int.class); - mMethodCache.put("addCastingTableRecipe", m); - } - try { - mMethodCache.get("addCastingTableRecipe") - .invoke(getCastingInstance(1), output, metal, cast, consume, delay); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {} + LiquidCasting basinCasting = TConstructRegistry.getBasinCasting(); + basinCasting.addCastingRecipe(output, metal, cast, consume, delay); } - /** - * 0 For Table, 1 For Basin. - * - * @param aType - Casting Type - * @return - The casting instance. - */ - public static Object getCastingInstance(int aType) { - - setTiConDataInstance(); - - Method m = null; - if (aType == 0) { - m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getTableCasting", new Class[] {}); - } else if (aType == 1) { - m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getBasinCasting", new Class[] {}); - } // return null; - - if (m != null) { - try { - return m.invoke(mTinkersRegistryInstance, new Object[] {}); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - } - return null; - } - - private static Item mTinkerMetalPattern; - - public static ItemStack getPattern(int aType) { - if (mTinkerMetalPattern == null) { - Field m = ReflectionUtils.getField(mClass_TinkerSmeltery, "metalPattern"); - if (m != null) { - try { - mTinkerMetalPattern = (Item) m.get(null); - } catch (IllegalArgumentException | IllegalAccessException ignored) {} - } - } - if (mTinkerMetalPattern != null) { - return new ItemStack(mTinkerMetalPattern, aType, 0); - } - return ItemUtils.getErrorStack(1, "Bad Tinkers Pattern"); - } - - private static AutoMap<?> mDryingRackRecipes; - - public static List<?> getDryingRecipes() { - if (mDryingRackRecipes != null) { - return mDryingRackRecipes; - } - AutoMap<Object> aData = new AutoMap<>(); - int aCount = 0; - try { - ArrayList<?> recipes = (ArrayList<?>) ReflectionUtils - .getField(ReflectionUtils.getClass("tconstruct.library.crafting.DryingRackRecipes"), "recipes") - .get(null); - if (recipes != null) { - for (Object o : recipes) { - aData.put(o); - aCount++; - } - Logger.INFO("Found " + aCount + " Tinkers drying rack recipes."); - } else { - Logger.INFO("Failed to find any Tinkers drying rack recipes."); - } - } catch (IllegalArgumentException | IllegalAccessException e) { - Logger.INFO("Failed to find any Tinkers drying rack recipes."); - } - mDryingRackRecipes = aData; - return aData; - } - - public static List<?> getTableCastingRecipes() { - Object aCastingTableHandlerInstance = getCastingInstance(0); - List<?> aTemp; - try { - aTemp = (List<?>) mMethod_getCastingRecipes.invoke(aCastingTableHandlerInstance, new Object[] {}); - return aTemp; - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - return new ArrayList<>(); + public static List<CastingRecipe> getTableCastingRecipes() { + LiquidCasting tableCasting = TConstructRegistry.getTableCasting(); + return tableCasting.getCastingRecipes(); } public static void generateCastingRecipes(Material aMaterial, int aID) { - - List<CastingRecipeHandler> newRecipies = new LinkedList<>(); - - Iterator<?> iterator1 = getTableCastingRecipes().iterator(); - Fluid aMoltenIron = null; - if (aMoltenIron == null) { - try { - aMoltenIron = (Fluid) mField_MoltenIronFluid.get(null); - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - aMoltenIron = Materials.Iron.getMolten(0) - .getFluid(); - } - } - while (iterator1.hasNext()) { - CastingRecipeHandler recipe = new CastingRecipeHandler(iterator1.next()); - if (recipe == null || !recipe.valid) { - continue; - } - try { - if (recipe.castingMetal.getFluid() == aMoltenIron && recipe.cast != null - && mClass_IPattern.isInstance(recipe.cast.getItem()) - && mClass_DynamicToolPart.isInstance( - recipe.getResult() - .getItem())) { - newRecipies.add(recipe); - } - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return; - } - } - - Object ft; - try { - ft = mMethod_getFluidType.invoke(null, aMaterial.getLocalizedName()); - for (CastingRecipeHandler newRecipy : newRecipies) { - CastingRecipeHandler recipe = new CastingRecipeHandler(newRecipy); - if (!recipe.valid) { - continue; - } - // CastingRecipe recipe = (CastingRecipe) i$.next(); - ItemStack output = recipe.getResult() + Fluid aMoltenIron = TinkerSmeltery.moltenIronFluid; + FluidType fluidType = FluidType.getFluidType(aMaterial.getLocalizedName()); + for (CastingRecipe recipe : getTableCastingRecipes()) { + CastingRecipeHandler newRecipe = new CastingRecipeHandler(recipe); + if (newRecipe.castingMetal.getFluid() == aMoltenIron && newRecipe.cast != null + && newRecipe.cast.getItem() instanceof IPattern + && newRecipe.getResult() + .getItem() instanceof DynamicToolPart) { + ItemStack output = newRecipe.getResult() .copy(); output.setItemDamage(aID); - FluidStack liquid2 = new FluidStack( + FluidStack liquid = new FluidStack( aMaterial.getFluidStack(0) .getFluid(), - recipe.castingMetal.amount); - addCastingTableRecipe(output, liquid2, recipe.cast, recipe.consumeCast, recipe.coolTime); - addMelting(ft, output, 0, liquid2.amount / 2); + newRecipe.castingMetal.amount); + addCastingTableRecipe(output, liquid, newRecipe.cast, newRecipe.consumeCast, newRecipe.coolTime); + addMelting(fluidType, output, 0, liquid.amount / 2); } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); } + } + public static ItemStack getPattern(int aType) { + return new ItemStack(TinkerSmeltery.metalPattern, aType, 0); } private static class CastingRecipeHandler { @@ -344,30 +94,12 @@ public class TinkersUtils { public boolean consumeCast; public int coolTime; - public boolean valid; - - public CastingRecipeHandler(Object aCastingRecipe) { - if (mClass_CastingRecipe.isInstance(aCastingRecipe)) { - try { - Field aF_output = ReflectionUtils.getField(mClass_CastingRecipe, "output"); - Field aF_castingMetal = ReflectionUtils.getField(mClass_CastingRecipe, "castingMetal"); - Field aF_cast = ReflectionUtils.getField(mClass_CastingRecipe, "cast"); - Field aF_consumeCast = ReflectionUtils.getField(mClass_CastingRecipe, "consumeCast"); - Field aF_coolTime = ReflectionUtils.getField(mClass_CastingRecipe, "coolTime"); - - output = (ItemStack) aF_output.get(aCastingRecipe); - castingMetal = (FluidStack) aF_castingMetal.get(aCastingRecipe); - cast = (ItemStack) aF_cast.get(aCastingRecipe); - consumeCast = (boolean) aF_consumeCast.get(aCastingRecipe); - coolTime = (int) aF_coolTime.get(aCastingRecipe); - valid = true; - } catch (Throwable t) { - t.printStackTrace(); - valid = false; - } - } else { - valid = false; - } + public CastingRecipeHandler(CastingRecipe castingRecipe) { + this.output = castingRecipe.output; + this.castingMetal = castingRecipe.castingMetal; + this.cast = castingRecipe.cast; + this.consumeCast = castingRecipe.consumeCast; + this.coolTime = castingRecipe.coolTime; } public ItemStack getResult() { |