From 4f435ae75b176a9d90c7afa6b1ff40e9ba9c286a Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:06:01 +0000 Subject: + Added a new debug tool. + Added support for Crops++. + Added Custom Crops & framework to support more in future. + Added basic support for all GT++ Materials within Tinkers Construct. [WIP] + Moderately bad attempt at generating custom Plasma Cooling recipes in the Adv. Vacuum Freezer. [WIP #424] % Reworked logic for Material.java handling Durability, Tool Quality & Harvest Level. % Adjusted frequency of structural checks on the Cyclotron, Now 100x less frequent. % Cleaned up ReflectionUtils.java and made all getters cache their results, for much faster access. % Attempted to adjust logic of FFPP, but I probably broke it. [WIP] % Moved static array of Element Names from IonParticles.java -> ELEMENT.java. $ Greatly improved reflective performance across the mod. --- .../xmod/tinkers/material/BaseTinkersMaterial.java | 200 +++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java (limited to 'src/Java/gtPlusPlus/xmod/tinkers/material') diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java new file mode 100644 index 0000000000..a2ab894f53 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -0,0 +1,200 @@ +package gtPlusPlus.xmod.tinkers.material; + +import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt; + +import java.util.HashMap; + +import cpw.mods.fml.common.event.FMLInterModComms; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.core.util.Utils; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.FluidType; +import tconstruct.library.crafting.Smeltery; +import tconstruct.library.tools.ToolMaterial; +import tconstruct.smeltery.TinkerSmeltery; + +public class BaseTinkersMaterial { + + private static HashMap aInternalMaterialIdMap = new HashMap(); + private static int aNextFreeID = 440; + private final String mUnlocalName; + public final String mLocalName; + private final int aID; + + public BaseTinkersMaterial(Material aMaterial) { + mLocalName = Utils.sanitizeString(aMaterial.getLocalizedName()); + mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); + aID = aNextFreeID++; + aInternalMaterialIdMap.put(mUnlocalName, aID); + + + int id = aID; + if (id > 0) { + + ToolMaterial mat = new ToolMaterial(mLocalName, mUnlocalName, 4, 100, 700, 2, + 0.6F, 4, 0.0F, EnumChatFormatting.WHITE.toString(), 16777215); + + TConstructRegistry.addtoolMaterial(id, mat); + TConstructRegistry.addDefaultToolPartMaterial(id); + TConstructRegistry.addBowMaterial(id, calcBowDrawSpeed(aMaterial), 1.0F); + TConstructRegistry.addArrowMaterial(id, calcProjectileMass(aMaterial), calcProjectileFragility(aMaterial)); + + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("Id", id); + tag.setString("Name", mLocalName); + tag.setString("localizationString", mUnlocalName); + tag.setInteger("Durability", calcDurability(aMaterial)); // 97 + tag.setInteger("MiningSpeed", calcMiningSpeed(aMaterial)); // 150 + tag.setInteger("HarvestLevel", calcHarvestLevel(aMaterial)); // 1 + tag.setInteger("Attack", calcAttack(aMaterial)); // 0 + tag.setFloat("HandleModifier", calcHandleModifier(aMaterial)); // 1.0f + tag.setInteger("Reinforced", calcReinforced(aMaterial)); // 0 + tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(aMaterial)); // 3.0f + tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(aMaterial)); // 18 + tag.setFloat("Projectile_Mass", calcProjectileMass(aMaterial)); // 0.69f + tag.setFloat("Projectile_Fragility", calcProjectileFragility(aMaterial)); // 0.2f + tag.setString("Style", calcStyle(aMaterial)); + tag.setInteger("Color", calcColour(aMaterial)); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + + generateRecipes(aMaterial); + + + ItemStack itemstack = aMaterial.getIngot(1); + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + NBTTagCompound item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + tag.setInteger("Value", 2); // What is value for? + FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); + + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + tag.setInteger("Value", 2); // What is value for? + item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + + + } + + + + + + + + } + + public String getUnlocalName() { + return mUnlocalName; + } + + + private static int calcDurability(Material aMaterial) { + return safeCast_LongToInt(aMaterial.vDurability); + } + + private static int calcMiningSpeed(Material aMaterial) { + return (aMaterial.vHarvestLevel * 2)+aMaterial.vTier; + } + + private static int calcHarvestLevel(Material aMaterial) { + return aMaterial.vHarvestLevel; + } + + private static int calcAttack(Material aMaterial) { + return aMaterial.vHarvestLevel+aMaterial.vTier+aMaterial.vRadiationLevel; + } + + private static float calcHandleModifier(Material aMaterial) { + return 1f; + } + + private static int calcReinforced(Material aMaterial) { + return aMaterial.getMeltingPointC()/3600; + } + + private static int calcBowProjectileSpeed(Material aMaterial) { + return aMaterial.vHarvestLevel+2; + } + + private static int calcBowDrawSpeed(Material aMaterial) { + return aMaterial.vHarvestLevel+8; + } + + private static float calcProjectileMass(Material aMaterial) { + return (aMaterial.getMeltingPointC()/1800)*0.1f; + } + + private static float calcProjectileFragility(Material aMaterial) { + return 0f; + } + + private static String calcStyle(Material aMaterial) { + String aReturn = "" + EnumChatFormatting.WHITE; + int aTemp = aMaterial.getMeltingPointC(); + if (aTemp < 3600) { + aReturn = "" + EnumChatFormatting.WHITE; + } + else if (aTemp >= 3600) { + aReturn = "" + EnumChatFormatting.YELLOW; + } + else if (aTemp >= (3600*2)) { + aReturn = "" + EnumChatFormatting.GREEN; + } + else if (aTemp >= (3600*3)) { + aReturn = "" + EnumChatFormatting.RED; + } + else if (aTemp >= (3600*4)) { + aReturn = "" + EnumChatFormatting.DARK_RED; + } + else { + aReturn = "" + EnumChatFormatting.GOLD; + } + return aReturn; + } + + private static int calcColour(Material aMaterial) { + return aMaterial.getRgbAsHex(); + } + + private boolean generateRecipes(Material aMaterial) { + + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + + + + FluidType.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); + + Smeltery.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); + Smeltery.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); + + if (aMaterial.getMeltingPointC() <= 3600) { + ItemStack ingotcast = new ItemStack(TinkerSmeltery.metalPattern, 1, 0); + TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1), + aMaterial.getFluid(144*9), (ItemStack) null, true, 100); + TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), + aMaterial.getFluid(144), ingotcast, false, 50); + } + + + return true; + } + + + + + + + + + +} -- cgit From 5ffa0957e9d936ec999ee5157be771ff4b315aac Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 28 Feb 2019 23:49:40 +0000 Subject: + Enabled Tinkers compat for GT++ Materials. $ Migrated lots of TiCon code to be reflective. $ Upload missing class ItemDummyResearch.java. --- .../core/item/crafting/ItemDummyResearch.java | 111 +++++++ src/Java/gtPlusPlus/core/material/Material.java | 8 + .../gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java | 10 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 185 ++++++------ .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 330 ++++++++++++++++++--- 5 files changed, 516 insertions(+), 128 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java (limited to 'src/Java/gtPlusPlus/xmod/tinkers/material') diff --git a/src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java b/src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java new file mode 100644 index 0000000000..1c28f99ff8 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/crafting/ItemDummyResearch.java @@ -0,0 +1,111 @@ +package gtPlusPlus.core.item.crafting; + +import java.util.LinkedHashMap; +import java.util.Map; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.general.ItemGenericToken; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +public class ItemDummyResearch extends ItemGenericToken { + + public static enum ASSEMBLY_LINE_RESEARCH { + + + RESEARCH_1_CONTAINMENT("Containment Fields", "Advanced scientific study"), + RESEARCH_2_BASIC_CHEM("Basic Chemistry", "Time to start at the beginning"), + RESEARCH_3_ADV_CHEM("Advanced Chemistry", "Best learn more than chemical equations"), + RESEARCH_4_BASIC_PHYSICS("Basic Physics", "Fundamental laws of motion"), + RESEARCH_5_ADV_PHYSICS("Advanced Physics", "Advanced knowledge!"), + RESEARCH_6_BASIC_METALLURGY("Basic Metallurgy", "Information about material smelting"), + RESEARCH_7_ADV_METALLURGY("Advanced Metallurgy", "Advanced Material Sciences!"); + + + + + + + + + + + + + + + + + + + private String mName; + private String mDesc; + + private ASSEMBLY_LINE_RESEARCH(String aName, String aDesc) { + mName = aName; + mDesc = aDesc; + ModItems.itemDummyResearch.register(mName, mDesc); + } + + } + + + + + + + + + + + private static Map mInternalNameToIdMap = new LinkedHashMap(); + + public static ItemStack getResearchStack(ASSEMBLY_LINE_RESEARCH aResearchName, int aStacksize) { + Integer aMeta = mInternalNameToIdMap.get(Utils.sanitizeString(aResearchName.mName)); + if (aMeta == null) { + aMeta = 0; + } + return ItemUtils.simpleMetaStack(ModItems.itemDummyResearch, aMeta, aStacksize); + } + + private int aID = 0; + public ItemDummyResearch() { + super("dummyResearch", "Research", new String[] {"This object requires some further study"}, "research"); + + + + } + + /** + * + * @param aResearchType - What is the research for? + * @param aDescriptThe - tooltip for this research + * @return - Did we register a custom research item? + */ + public boolean register(String aResearchType, String aDescript) { + int aNewID = aID++; + mInternalNameToIdMap.put(Utils.sanitizeString(aResearchType), aNewID); + return register(aNewID, "Research on "+aResearchType, 1, aDescript); + } + + @Override + public boolean register(int id, String aLocalName, int aMaxStack, String aDescript) { + return register(id, aLocalName, 1, new String[] {aDescript, EnumChatFormatting.DARK_GRAY+"Used to further your knowledge"}, EnumRarity.common, EnumChatFormatting.LIGHT_PURPLE); + } + + @Override + @SideOnly(Side.CLIENT) + public final void registerIcons(final IIconRegister aIconRegister) { + for (int i = 0, j = mLocalNames.size(); i < j; i++) { + mIcons.put(i, aIconRegister.registerIcon(CORE.MODID + ":" + "research" + "/" + "note")); + } + } + +} diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index d996bed128..f0a2eb7152 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -15,6 +15,7 @@ import gregtech.api.enums.TextureSet; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.item.base.cell.BaseItemCell; +import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.state.MaterialState; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.data.StringUtils; @@ -23,6 +24,7 @@ import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; import gtPlusPlus.xmod.thaumcraft.aspect.GTPP_Aspects; +import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.Item; @@ -77,6 +79,8 @@ public class Material { public int vHarvestLevel; private GTPP_Aspects[] vAspects; + + public BaseTinkersMaterial vTiConHandler; public static AutoMap invalidMaterials = new AutoMap(); @@ -492,6 +496,10 @@ public class Material { } this.textureSet = setTextureSet(set, vTier); + + if (LoadedMods.TiCon) { + this.vTiConHandler = new BaseTinkersMaterial(this); + } Logger.MATERIALS("Creating a Material instance for "+materialName); Logger.MATERIALS("Formula: "+this.vChemicalFormula + " Smallest Stack: "+this.smallestStackSizeWhenProcessing+" Smallest Ratio:"+ratio); diff --git a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java index a6260d4246..9ba10fc40e 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java @@ -6,6 +6,7 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.tinkers.material.BaseTinkersMaterial; import gtPlusPlus.xmod.tinkers.util.TinkersUtils; import net.minecraft.block.Block; import net.minecraftforge.fluids.Fluid; @@ -13,6 +14,8 @@ import net.minecraftforge.fluids.FluidRegistry; public class HANDLER_Tinkers { + public static AutoMap mTinkerMaterials = new AutoMap(); + public static final void preInit() { if (LoadedMods.TiCon) { @@ -31,8 +34,13 @@ public class HANDLER_Tinkers { } } - public static final void postInit() { + public static final void postInit() { if (LoadedMods.TiCon) { + + for (BaseTinkersMaterial y : mTinkerMaterials) { + y.generate(); + } + Class aTinkersSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); AutoMap aTweakedFluids = new AutoMap(); if (aTinkersSmeltery != null) { diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index a2ab894f53..0730f5baba 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -5,98 +5,38 @@ import static gtPlusPlus.core.util.math.MathUtils.safeCast_LongToInt; import java.util.HashMap; import cpw.mods.fml.common.event.FMLInterModComms; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.tinkers.HANDLER_Tinkers; +import gtPlusPlus.xmod.tinkers.util.TinkersUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; -import tconstruct.library.TConstructRegistry; -import tconstruct.library.crafting.FluidType; -import tconstruct.library.crafting.Smeltery; -import tconstruct.library.tools.ToolMaterial; -import tconstruct.smeltery.TinkerSmeltery; public class BaseTinkersMaterial { private static HashMap aInternalMaterialIdMap = new HashMap(); private static int aNextFreeID = 440; - private final String mUnlocalName; + public final String mLocalName; - private final int aID; + + private final String mUnlocalName; + private final int mID; + private final Material mMaterial; public BaseTinkersMaterial(Material aMaterial) { mLocalName = Utils.sanitizeString(aMaterial.getLocalizedName()); mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); - aID = aNextFreeID++; - aInternalMaterialIdMap.put(mUnlocalName, aID); - - - int id = aID; - if (id > 0) { - - ToolMaterial mat = new ToolMaterial(mLocalName, mUnlocalName, 4, 100, 700, 2, - 0.6F, 4, 0.0F, EnumChatFormatting.WHITE.toString(), 16777215); - - TConstructRegistry.addtoolMaterial(id, mat); - TConstructRegistry.addDefaultToolPartMaterial(id); - TConstructRegistry.addBowMaterial(id, calcBowDrawSpeed(aMaterial), 1.0F); - TConstructRegistry.addArrowMaterial(id, calcProjectileMass(aMaterial), calcProjectileFragility(aMaterial)); - - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("Id", id); - tag.setString("Name", mLocalName); - tag.setString("localizationString", mUnlocalName); - tag.setInteger("Durability", calcDurability(aMaterial)); // 97 - tag.setInteger("MiningSpeed", calcMiningSpeed(aMaterial)); // 150 - tag.setInteger("HarvestLevel", calcHarvestLevel(aMaterial)); // 1 - tag.setInteger("Attack", calcAttack(aMaterial)); // 0 - tag.setFloat("HandleModifier", calcHandleModifier(aMaterial)); // 1.0f - tag.setInteger("Reinforced", calcReinforced(aMaterial)); // 0 - tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(aMaterial)); // 3.0f - tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(aMaterial)); // 18 - tag.setFloat("Projectile_Mass", calcProjectileMass(aMaterial)); // 0.69f - tag.setFloat("Projectile_Fragility", calcProjectileFragility(aMaterial)); // 0.2f - tag.setString("Style", calcStyle(aMaterial)); - tag.setInteger("Color", calcColour(aMaterial)); - FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); - - - generateRecipes(aMaterial); - - - ItemStack itemstack = aMaterial.getIngot(1); - tag = new NBTTagCompound(); - tag.setInteger("MaterialId", id); - NBTTagCompound item = new NBTTagCompound(); - itemstack.writeToNBT(item); - tag.setTag("Item", item); - tag.setInteger("Value", 2); // What is value for? - FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); - - tag = new NBTTagCompound(); - tag.setInteger("MaterialId", id); - tag.setInteger("Value", 2); // What is value for? - item = new NBTTagCompound(); - itemstack.writeToNBT(item); - tag.setTag("Item", item); - - FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); - - - } - - - - - - - + mMaterial = aMaterial; + mID = aNextFreeID++; + aInternalMaterialIdMap.put(mUnlocalName, mID); + HANDLER_Tinkers.mTinkerMaterials.put(this); } public String getUnlocalName() { return mUnlocalName; - } - + } private static int calcDurability(Material aMaterial) { return safeCast_LongToInt(aMaterial.vDurability); @@ -166,22 +106,95 @@ public class BaseTinkersMaterial { return aMaterial.getRgbAsHex(); } - private boolean generateRecipes(Material aMaterial) { - - //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + public Object generateToolMaterial(Material aMaterial) { + int level, dura, speed, dmg, reinf, primColour; + float handle, stonebound; + level = calcHarvestLevel(aMaterial); + dura = calcDurability(aMaterial); + speed = calcMiningSpeed(aMaterial); + dmg = calcAttack(aMaterial); + reinf = calcReinforced(aMaterial); + primColour = calcColour(aMaterial); + handle = calcHandleModifier(aMaterial); + //stonebound = calcHarvestLevel(aMaterial); + stonebound = 0; + return TinkersUtils.generateToolMaterial(aMaterial.getLocalizedName(), aMaterial.getUnlocalizedName(), level, dura, speed, dmg, handle, reinf, stonebound, calcStyle(aMaterial), primColour); + } + public void generate() { + + Logger.INFO("Trying to generate TiCon Material: "+mLocalName); + int id = mID; + if (id > 0) { + + Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); + Logger.INFO("Created TiCon Material: "+mLocalName); + + TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); + TinkersUtils.addDefaultToolPartMaterial(id); + TinkersUtils.addBowMaterial(id, calcBowDrawSpeed(mMaterial), 1.0F); + TinkersUtils.addArrowMaterial(id, calcProjectileMass(mMaterial), calcProjectileFragility(mMaterial)); + + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("Id", id); + tag.setString("Name", mLocalName); + tag.setString("localizationString", mUnlocalName); + tag.setInteger("Durability", calcDurability(mMaterial)); // 97 + tag.setInteger("MiningSpeed", calcMiningSpeed(mMaterial)); // 150 + tag.setInteger("HarvestLevel", calcHarvestLevel(mMaterial)); // 1 + tag.setInteger("Attack", calcAttack(mMaterial)); // 0 + tag.setFloat("HandleModifier", calcHandleModifier(mMaterial)); // 1.0f + tag.setInteger("Reinforced", calcReinforced(mMaterial)); // 0 + tag.setFloat("Bow_ProjectileSpeed", calcBowProjectileSpeed(mMaterial)); // 3.0f + tag.setInteger("Bow_DrawSpeed", calcBowDrawSpeed(mMaterial)); // 18 + tag.setFloat("Projectile_Mass", calcProjectileMass(mMaterial)); // 0.69f + tag.setFloat("Projectile_Fragility", calcProjectileFragility(mMaterial)); // 0.2f + tag.setString("Style", calcStyle(mMaterial)); + tag.setInteger("Color", calcColour(mMaterial)); + + Logger.INFO("Sending IMC to TConstruct: addMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + + generateRecipes(mMaterial); + + + ItemStack itemstack = mMaterial.getIngot(1); + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + NBTTagCompound item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + tag.setInteger("Value", 2); // What is value for? + + Logger.INFO("Sending IMC to TConstruct: addPartBuilderMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); + + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + tag.setInteger("Value", 2); // What is value for? + item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + + Logger.INFO("Sending IMC to TConstruct: addMaterialItem - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + + + } - - FluidType.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); - - Smeltery.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); - Smeltery.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); - + } + + private boolean generateRecipes(Material aMaterial) { + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); + TinkersUtils.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); + TinkersUtils.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); + TinkersUtils.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); if (aMaterial.getMeltingPointC() <= 3600) { - ItemStack ingotcast = new ItemStack(TinkerSmeltery.metalPattern, 1, 0); - TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1), + ItemStack ingotcast = TinkersUtils.getPattern(1); + TinkersUtils.addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100); - TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), + TinkersUtils.addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); } @@ -195,6 +208,4 @@ public class BaseTinkersMaterial { - - } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index 10eb93b4d7..b902e38a1e 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,44 +1,112 @@ package gtPlusPlus.xmod.tinkers.util; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.LinkedHashMap; + import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; -import tconstruct.library.TConstructRegistry; -import tconstruct.library.crafting.FluidType; -import tconstruct.library.crafting.Smeltery; -import tconstruct.smeltery.TinkerSmeltery; +import net.minecraftforge.fluids.FluidStack; public class TinkersUtils { private static Object mSmelteryInstance; private static Class mSmelteryClassInstance; + + private static Object mTinkersRegistryInstance; + private static Class mTinkersRegistryClass; + + private static final Class mToolMaterialClass; - public static Object getSmelteryInstance() { + private static final HashMap mMethodCache = new LinkedHashMap(); + + + static { + setRegistries(); + mToolMaterialClass = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); + } + + + /** + * + * @param aSwitch - The Registry to return + */ + private static Object getTiConDataInstance(int aSwitch) { if (!LoadedMods.TiCon) { return null; } else { - if (mSmelteryInstance == null || mSmelteryClassInstance == null) { - if (mSmelteryClassInstance == null) { - mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); - } - if (mSmelteryClassInstance != null) { - try { - mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); + + if (mTinkersRegistryClass == null || mSmelteryClassInstance == null) { + setRegistries(); + } + + // getSmelteryInstance + if (aSwitch == 0) { + + //Set Smeltery Instance + if (mSmelteryInstance == null || mSmelteryClassInstance == null) { + if (mSmelteryClassInstance == null) { + mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); } - catch (IllegalArgumentException | IllegalAccessException e) { + if (mSmelteryClassInstance != null) { + try { + mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); + } + catch (IllegalArgumentException | IllegalAccessException e) { + } } } - } - } - if (mSmelteryInstance != null) { - return mSmelteryInstance; - } - return null; + + //Return Smeltery Instance + if (mSmelteryInstance != null) { + return mSmelteryInstance; + } + } + + // getTableCastingInstance || getBasinCastingInstance + else if (aSwitch == 1) { + if (mTinkersRegistryClass == null || mTinkersRegistryInstance == null) { + if (mTinkersRegistryClass == null) { + mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + } + if (mTinkersRegistryClass != null) { + if (mTinkersRegistryInstance == null) { + try { + mTinkersRegistryInstance = ReflectionUtils.getField(mTinkersRegistryClass, "instance").get(null); + } + catch (IllegalArgumentException | IllegalAccessException e) { + } + } + } + } + + //Return Smeltery Instance + if (mTinkersRegistryInstance != null) { + return mTinkersRegistryInstance; + } + } + + return null; + } + } + + private static void setRegistries() { + if (mTinkersRegistryClass == null) { + mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + } + if (mSmelteryClassInstance == null) { + mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + } } public static final boolean isTiConFirstInOD() { @@ -75,56 +143,100 @@ public class TinkersUtils { * @param duration How long one "portion" of liquid fuels the smeltery. Lava is 10. */ public static void addSmelteryFuel (Fluid fluid, int power, int duration){ - ReflectionUtils.invokeVoid(getSmelteryInstance(), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration}); + ReflectionUtils.invokeVoid(getTiConDataInstance(0), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration}); } /** * Returns true if the liquid is a valid smeltery fuel. */ public static boolean isSmelteryFuel (Fluid fluid){ - return ReflectionUtils.invoke(getSmelteryInstance(), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid}); + return ReflectionUtils.invoke(getTiConDataInstance(0), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid}); } /** * Returns the power of a smeltery fuel or 0 if it's not a fuel. */ public static int getFuelPower (Fluid fluid){ - return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid}); + return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid}); } /** * Returns the duration of a smeltery fuel or 0 if it's not a fuel. */ public static int getFuelDuration (Fluid fluid){ - return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); + return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); } + + + + + + public static boolean registerFluidType(String name, Block block, int meta, int baseTemperature, Fluid fluid, boolean isToolpart) { - - - - //FluidType.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); - return false; + 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; + } } - public static boolean addMelting(Material aMaterial) { - Smeltery.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); - Smeltery.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); - return false; + + + + + + + + public static boolean addBaseMeltingRecipes(Material aMaterial) { + return addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)) && + addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); } - public static boolean addBasinRecipe(Material aMaterial) { - TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1), - aMaterial.getFluid(144*9), (ItemStack) null, true, 100); - return false; + public static boolean addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) { + if (mMethodCache.get("addMelting") == null) { + Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "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); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } } - public static boolean addCastingTableRecipe(Material aMaterial) { - ItemStack ingotcast = new ItemStack(TinkerSmeltery.metalPattern, 1, 0); - TConstructRegistry.getTableCasting().addCastingRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); - return false; + + + + + + + + + + + public static boolean addBaseBasinRecipes(Material aMaterial) { + return addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100); } + public static boolean 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); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } + } @@ -132,6 +244,24 @@ public class TinkersUtils { + public static boolean addBaseCastingRecipes(Material aMaterial) { + ItemStack ingotcast = getPattern(1); + return addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); + } + + public static boolean 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"), "addBasinRecipe", 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); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } + } + @@ -139,7 +269,127 @@ public class TinkersUtils { + public static Object getCastingInstance(int aType) { + if (aType == 0) { + return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); + } + else if (aType == 1) { + return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); + } + else { + return null; + } + } + + private static Item mTinkerMetalPattern; + public static ItemStack getPattern(int aType) { + if (mTinkerMetalPattern == null) { + Field m = ReflectionUtils.getField(ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"), "metalPattern"); + if (m != null) { + try { + mTinkerMetalPattern = (Item) m.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { + } + } + } + if (mTinkerMetalPattern != null) { + ItemStack ingotCast = new ItemStack(mTinkerMetalPattern, aType, 0); + return ingotCast; + } + return ItemUtils.getErrorStack(1, "Bad Tinkers Pattern"); + + + + + + + + } + /** + * Generates Tinkers {@link ToolMaterial}'s reflectively. + * @param name + * @param localizationString + * @param level + * @param durability + * @param speed + * @param damage + * @param handle + * @param reinforced + * @param stonebound + * @param style + * @param primaryColor + * @return + */ + public static Object generateToolMaterial(String name, String localizationString, int level, int durability, int speed, int damage, float handle, int reinforced, float stonebound, String style, int primaryColor) { + try { + Constructor constructor = mToolMaterialClass.getConstructor(String.class, String.class, int.class, int.class, int.class, int.class, float.class, int.class, float.class, String.class, int.class); + Object myObject = constructor.newInstance(name, localizationString, level, durability, speed, damage, handle, reinforced, stonebound, style, primaryColor); + return myObject; + } catch (Throwable t) { + t.printStackTrace(); + return null; + } + } + + + + + + + + + + + + public static void addToolMaterial(int id, Object aToolMaterial) { + setRegistries(); + if (mMethodCache.get("addToolMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addToolMaterial", int.class, mToolMaterialClass); + mMethodCache.put("addToolMaterial", m); + } + try { + mMethodCache.get("addToolMaterial").invoke(mTinkersRegistryClass, id, aToolMaterial); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + + } + } + + public static void addDefaultToolPartMaterial(int id) { + setRegistries(); + if (mMethodCache.get("addDefaultToolPartMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addDefaultToolPartMaterial", int.class); + mMethodCache.put("addDefaultToolPartMaterial", m); + } + try { + mMethodCache.get("addDefaultToolPartMaterial").invoke(mTinkersRegistryClass, id); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { + setRegistries(); + if (mMethodCache.get("addBowMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addBowMaterial", int.class, int.class, float.class); + mMethodCache.put("addBowMaterial", m); + } + try { + mMethodCache.get("addBowMaterial").invoke(mTinkersRegistryClass, id, drawspeed, maxSpeed); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + + public static void addArrowMaterial(int id, float mass, float fragility) { + setRegistries(); + if (mMethodCache.get("addArrowMaterial") == null) { + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addArrowMaterial", int.class, float.class, float.class); + mMethodCache.put("addArrowMaterial", m); + } + try { + mMethodCache.get("addArrowMaterial").invoke(mTinkersRegistryClass, id, mass, fragility); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } } -- cgit From 35522722af5dddea144c841a71f4fa9087e68966 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 1 Mar 2019 03:00:51 +0000 Subject: % More work on TiCon Compat. --- src/Java/gtPlusPlus/core/material/Material.java | 10 ++- .../gtPlusPlus/core/util/data/StringUtils.java | 15 ++++ .../core/util/reflect/ReflectionUtils.java | 29 +++++-- .../xmod/tinkers/material/BaseTinkersMaterial.java | 93 ++++++++++++++-------- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 27 +++++-- 5 files changed, 128 insertions(+), 46 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers/material') diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index 01503a1fc5..ba572efe90 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -498,7 +498,9 @@ public class Material { this.textureSet = setTextureSet(set, vTier); if (LoadedMods.TiCon && this.materialState == MaterialState.SOLID) { - this.vTiConHandler = new BaseTinkersMaterial(this); + if (this.getProtons() >= 98 || this.getComposites().size() > 1 || this.getMeltingPointC() >= 3600) { + this.vTiConHandler = new BaseTinkersMaterial(this); + } } Logger.MATERIALS("Creating a Material instance for "+materialName); @@ -753,7 +755,11 @@ public class Material { } final public Block getBlock(){ - return Block.getBlockFromItem(getBlock(1).getItem()); + Block b = Block.getBlockFromItem(getBlock(1).getItem()); + if (b == null) { + Logger.INFO("[ERROR] Tried to get invalid block for "+this.getLocalizedName()+", returning debug block instead."); + } + return b != null ? b : Blocks.lit_furnace; } public final ItemStack getBlock(final int stacksize){ diff --git a/src/Java/gtPlusPlus/core/util/data/StringUtils.java b/src/Java/gtPlusPlus/core/util/data/StringUtils.java index e58b68665a..b64266b5d4 100644 --- a/src/Java/gtPlusPlus/core/util/data/StringUtils.java +++ b/src/Java/gtPlusPlus/core/util/data/StringUtils.java @@ -116,4 +116,19 @@ public class StringUtils { String restLetters = data.substring(1).toLowerCase(); return firstLetter + restLetters; } + + public static String getDataStringFromArray(V[] parameterTypes) { + if (parameterTypes == null || parameterTypes.length == 0) { + return "empty/null"; + } + else { + String aData = ""; + for (V y : parameterTypes) { + if (y != null) { + aData += ", "+y.toString(); + } + } + return aData; + } + } } diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 372bf81fe9..88175b0a82 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -12,6 +12,7 @@ import java.util.Map; import com.google.common.reflect.ClassPath; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.data.StringUtils; public class ReflectionUtils { @@ -116,6 +117,19 @@ public class ReflectionUtils { } + + /** + * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. + * @param aObject - Object containing the Method. + * @param aMethodName - Method's name in {@link String} form. + * @param aTypes - Class Array of Types for {@link Method}'s constructor. + * @return - Valid, non-final, {@link Method} object, or {@link null}. + */ + public static Method getMethod(Object aObject, String aMethodName, Class[] aTypes) { + return getMethod(aObject.getClass(), aMethodName, aTypes); + } + + /** * Returns a cached {@link Method} object. * @param aClass - Class containing the Method. @@ -127,7 +141,7 @@ public class ReflectionUtils { String aMethodKey = aTypes.toString(); CachedMethod y = mCachedMethods.get(aMethodName + "." + aMethodKey); if (y == null) { - Method u = getMethod_Internal(aClass, aMethodKey, aTypes); + Method u = getMethod_Internal(aClass, aMethodName, aTypes); if (u != null) { Logger.REFLECTION("Caching Method: "+aMethodName + "." + aMethodKey); cacheMethod(u); @@ -457,6 +471,7 @@ public class ReflectionUtils { private static Method getMethod_Internal(Class aClass, String aMethodName, Class... aTypes) { Method m = null; try { + Logger.REFLECTION("Method: Internal Lookup: "+aMethodName); m = aClass.getDeclaredMethod(aMethodName, aTypes); if (m != null) { m.setAccessible(true); @@ -468,6 +483,7 @@ public class ReflectionUtils { } } catch (Throwable t) { + Logger.REFLECTION("Method: Internal Lookup Failed: "+aMethodName); try { m = getMethodRecursively(aClass, aMethodName); } catch (NoSuchMethodException e) { @@ -479,9 +495,10 @@ public class ReflectionUtils { return m; } - private static Method getMethodRecursively(final Class clazz, final String fieldName) throws NoSuchMethodException { + private static Method getMethodRecursively(final Class clazz, final String aMethodName) throws NoSuchMethodException { try { - Method k = clazz.getDeclaredMethod(fieldName); + Logger.REFLECTION("Method: Recursion Lookup: "+aMethodName); + Method k = clazz.getDeclaredMethod(aMethodName); makeMethodAccessible(k); return k; } catch (final NoSuchMethodException e) { @@ -489,7 +506,7 @@ public class ReflectionUtils { if (superClass == null || superClass == Object.class) { throw e; } - return getMethod_Internal(superClass, fieldName); + return getMethod_Internal(superClass, aMethodName); } } @@ -502,7 +519,7 @@ public class ReflectionUtils { Logger.INFO("Dumping all Methods."); for (Method method : methods) { - System.out.println(method.getName()); + System.out.println(method.getName()+" | "+StringUtils.getDataStringFromArray(method.getParameterTypes())); } Logger.INFO("Dumping all Fields."); for (Field f : fields) { @@ -510,7 +527,7 @@ public class ReflectionUtils { } Logger.INFO("Dumping all Constructors."); for (Constructor c : consts) { - System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+c.getParameterTypes().toString()); + System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes())); } } diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 0730f5baba..19ff630a92 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -10,14 +10,18 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.xmod.tinkers.HANDLER_Tinkers; import gtPlusPlus.xmod.tinkers.util.TinkersUtils; +import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.Fluid; public class BaseTinkersMaterial { + + private static HashMap aInternalMaterialIdMap = new HashMap(); - private static int aNextFreeID = 440; + private static int aNextFreeID; public final String mLocalName; @@ -25,11 +29,16 @@ public class BaseTinkersMaterial { private final int mID; private final Material mMaterial; + static { + aNextFreeID = Short.MAX_VALUE+420; + } + public BaseTinkersMaterial(Material aMaterial) { mLocalName = Utils.sanitizeString(aMaterial.getLocalizedName()); mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); mMaterial = aMaterial; mID = aNextFreeID++; + Logger.INFO("[TiCon] Assigning ID "+mID+" to "+mLocalName+"."); aInternalMaterialIdMap.put(mUnlocalName, mID); HANDLER_Tinkers.mTinkerMaterials.put(this); } @@ -123,12 +132,12 @@ public class BaseTinkersMaterial { public void generate() { - Logger.INFO("Trying to generate TiCon Material: "+mLocalName); + Logger.INFO("[TiCon] Trying to generate Material: "+mLocalName); int id = mID; if (id > 0) { Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); - Logger.INFO("Created TiCon Material: "+mLocalName); + Logger.INFO("[TiCon] Created Material: "+mLocalName); TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); TinkersUtils.addDefaultToolPartMaterial(id); @@ -152,33 +161,34 @@ public class BaseTinkersMaterial { tag.setString("Style", calcStyle(mMaterial)); tag.setInteger("Color", calcColour(mMaterial)); - Logger.INFO("Sending IMC to TConstruct: addMaterial - "+mLocalName+"."); - FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); - - - generateRecipes(mMaterial); - - ItemStack itemstack = mMaterial.getIngot(1); - tag = new NBTTagCompound(); - tag.setInteger("MaterialId", id); - NBTTagCompound item = new NBTTagCompound(); - itemstack.writeToNBT(item); - tag.setTag("Item", item); - tag.setInteger("Value", 2); // What is value for? - - Logger.INFO("Sending IMC to TConstruct: addPartBuilderMaterial - "+mLocalName+"."); - FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); - - tag = new NBTTagCompound(); - tag.setInteger("MaterialId", id); - tag.setInteger("Value", 2); // What is value for? - item = new NBTTagCompound(); - itemstack.writeToNBT(item); - tag.setTag("Item", item); + boolean generate = generateRecipes(mMaterial); - Logger.INFO("Sending IMC to TConstruct: addMaterialItem - "+mLocalName+"."); - FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + if (generate) { + Logger.INFO("[TiCon] Sending IMC: addMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + ItemStack itemstack = mMaterial.getIngot(1); + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + NBTTagCompound item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + tag.setInteger("Value", 2); // What is value for? + + Logger.INFO("[TiCon] Sending IMC: addPartBuilderMaterial - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addPartBuilderMaterial", tag); + + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", id); + tag.setInteger("Value", 2); // What is value for? + item = new NBTTagCompound(); + itemstack.writeToNBT(item); + tag.setTag("Item", item); + + Logger.INFO("[TiCon] Sending IMC: addMaterialItem - "+mLocalName+"."); + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + } } @@ -186,11 +196,30 @@ public class BaseTinkersMaterial { } private boolean generateRecipes(Material aMaterial) { + + Block aMatBlock; + Integer aMelt; + Fluid aFluid; + + try { + aMatBlock = aMaterial.getBlock(); + aMelt = aMaterial.getMeltingPointC(); + aFluid = aMaterial.getFluid(0).getFluid(); + } + catch (Throwable t) { + return false; + } + + if (aMatBlock == null || aMelt == null || aFluid == null) { + return false; + } + + //Smeltery.addMelting(new ItemStack(ExtraUtils.unstableIngot, 1, 0), ExtraUtils.decorative1, 5, 850, aMaterial.getFluid(72)); - TinkersUtils.registerFluidType(mLocalName, aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(0).getFluid(), true); - TinkersUtils.addMelting(aMaterial.getBlock(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144*9)); - TinkersUtils.addMelting(aMaterial.getIngot(1), aMaterial.getBlock(), 0, aMaterial.getMeltingPointC(), aMaterial.getFluid(144)); - if (aMaterial.getMeltingPointC() <= 3600) { + TinkersUtils.registerFluidType(mLocalName, aMatBlock, 0, aMelt, aFluid, true); + TinkersUtils.addMelting(aMaterial.getBlock(1), aMatBlock, 0, aMelt, aMaterial.getFluid(144*9)); + TinkersUtils.addMelting(aMaterial.getIngot(1), aMatBlock, 0, aMelt, aMaterial.getFluid(144)); + if (aMelt <= 3600) { ItemStack ingotcast = TinkersUtils.getPattern(1); TinkersUtils.addBasinRecipe(aMaterial.getBlock(1), aMaterial.getFluid(144*9), (ItemStack) null, true, 100); diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index b902e38a1e..450111a113 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -251,7 +251,7 @@ public class TinkersUtils { public static boolean 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"), "addBasinRecipe", ItemStack.class, FluidStack.class, ItemStack.class, boolean.class, int.class); + 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 { @@ -270,15 +270,30 @@ public class TinkersUtils { public static Object getCastingInstance(int aType) { + + + + Method m = null; if (aType == 0) { - return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); + m = ReflectionUtils.getMethod(getTiConDataInstance(1), "getTableCasting", new Class[] {}); + //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); } else if (aType == 1) { - return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); + m = ReflectionUtils.getMethod(getTiConDataInstance(1), "getBasinCasting", new Class[] {}); + //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); } else { - return null; - } + //return null; + } + + if (m != null) { + try { + return m.invoke(getTiConDataInstance(1), new Object[] {}); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + return null; } @@ -346,7 +361,7 @@ public class TinkersUtils { public static void addToolMaterial(int id, Object aToolMaterial) { setRegistries(); if (mMethodCache.get("addToolMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addToolMaterial", int.class, mToolMaterialClass); + Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addtoolMaterial", int.class, mToolMaterialClass); mMethodCache.put("addToolMaterial", m); } try { -- cgit From 9a0e88e397dc52476a0de92768c1022a3e53c9ed Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 1 Mar 2019 04:20:08 +0000 Subject: + Added casting recipes for all new materials (Hopefully). $ Fixed localization of new TiCon materials. $ Fixed bug where cached Fields/Methods may conflict, they're now stored with unique keys. --- .../core/util/reflect/ReflectionUtils.java | 20 +-- .../xmod/tinkers/material/BaseTinkersMaterial.java | 56 ++++-- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 187 ++++++++++++++++++--- 3 files changed, 221 insertions(+), 42 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers/material') diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 88175b0a82..827ffbf5fb 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -72,27 +72,27 @@ public class ReflectionUtils { return false; } - private static boolean cacheMethod(Method aMethod) { + private static boolean cacheMethod(Class aClass, Method aMethod) { if (aMethod == null) { return false; } boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); - CachedMethod y = mCachedMethods.get(aMethod.getName()+"."+aMethod.getParameterTypes().toString()); + CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethod.getName()+"."+aMethod.getParameterTypes().toString()); if (y == null) { - mCachedMethods.put(aMethod.getName()+"."+aMethod.getParameterTypes().toString(), new CachedMethod(aMethod, isStatic)); + mCachedMethods.put(aClass.getName()+"."+aMethod.getName()+"."+aMethod.getParameterTypes().toString(), new CachedMethod(aMethod, isStatic)); return true; } return false; } - private static boolean cacheField(Field aField) { + private static boolean cacheField(Class aClass, Field aField) { if (aField == null) { return false; } boolean isStatic = Modifier.isStatic(aField.getModifiers()); - CachedField y = mCachedFields.get(aField.getName()); + CachedField y = mCachedFields.get(aClass.getName()+"."+aField.getName()); if (y == null) { - mCachedFields.put(aField.getName(), new CachedField(aField, isStatic)); + mCachedFields.put(aClass.getName()+"."+aField.getName(), new CachedField(aField, isStatic)); return true; } return false; @@ -139,12 +139,12 @@ public class ReflectionUtils { */ public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { String aMethodKey = aTypes.toString(); - CachedMethod y = mCachedMethods.get(aMethodName + "." + aMethodKey); + CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethodName + "." + aMethodKey); if (y == null) { Method u = getMethod_Internal(aClass, aMethodName, aTypes); if (u != null) { Logger.REFLECTION("Caching Method: "+aMethodName + "." + aMethodKey); - cacheMethod(u); + cacheMethod(aClass, u); return u; } else { return null; @@ -163,14 +163,14 @@ public class ReflectionUtils { * @return - Valid, non-final, {@link Field} object, or {@link null}. */ public static Field getField(final Class aClass, final String aFieldName) { - CachedField y = mCachedFields.get(aFieldName); + CachedField y = mCachedFields.get(aClass.getName()+"."+aFieldName); if (y == null) { Field u; try { u = getField_Internal(aClass, aFieldName); if (u != null) { Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getCanonicalName()); - cacheField(u); + cacheField(aClass, u); return u; } } catch (NoSuchFieldException e) { diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 19ff630a92..0585eeafd8 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -34,7 +34,7 @@ public class BaseTinkersMaterial { } public BaseTinkersMaterial(Material aMaterial) { - mLocalName = Utils.sanitizeString(aMaterial.getLocalizedName()); + mLocalName = aMaterial.getLocalizedName(); mUnlocalName = "material.gtpp."+Utils.sanitizeString(mLocalName); mMaterial = aMaterial; mID = aNextFreeID++; @@ -136,18 +136,18 @@ public class BaseTinkersMaterial { int id = mID; if (id > 0) { - Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); - Logger.INFO("[TiCon] Created Material: "+mLocalName); + //Object aTinkersCustomMaterial = generateToolMaterial(mMaterial); + //Logger.INFO("[TiCon] Created Material: "+mLocalName); - TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); - TinkersUtils.addDefaultToolPartMaterial(id); - TinkersUtils.addBowMaterial(id, calcBowDrawSpeed(mMaterial), 1.0F); - TinkersUtils.addArrowMaterial(id, calcProjectileMass(mMaterial), calcProjectileFragility(mMaterial)); + //TinkersUtils.addToolMaterial(id, aTinkersCustomMaterial); + //TinkersUtils.addDefaultToolPartMaterial(id); + //TinkersUtils.addBowMaterial(id, calcBowDrawSpeed(mMaterial), 1.0F); + //TinkersUtils.addArrowMaterial(id, calcProjectileMass(mMaterial), calcProjectileFragility(mMaterial)); NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("Id", id); - tag.setString("Name", mLocalName); - tag.setString("localizationString", mUnlocalName); + tag.setString("Name", mUnlocalName); + tag.setString("localizationString", mLocalName); tag.setInteger("Durability", calcDurability(mMaterial)); // 97 tag.setInteger("MiningSpeed", calcMiningSpeed(mMaterial)); // 150 tag.setInteger("HarvestLevel", calcHarvestLevel(mMaterial)); // 1 @@ -162,7 +162,7 @@ public class BaseTinkersMaterial { tag.setInteger("Color", calcColour(mMaterial)); - boolean generate = generateRecipes(mMaterial); + boolean generate = generateRecipes(mMaterial, id); if (generate) { Logger.INFO("[TiCon] Sending IMC: addMaterial - "+mLocalName+"."); @@ -195,7 +195,7 @@ public class BaseTinkersMaterial { } - private boolean generateRecipes(Material aMaterial) { + private boolean generateRecipes(Material aMaterial, int aID) { Block aMatBlock; Integer aMelt; @@ -226,6 +226,40 @@ public class BaseTinkersMaterial { TinkersUtils.addCastingTableRecipe(aMaterial.getIngot(1), aMaterial.getFluid(144), ingotcast, false, 50); } + + boolean extended = TinkersUtils.generateCastingRecipes(aMaterial, aID); + + + + + + + //TConstructRegistry.getBasinCasting().addCastingRecipe(new ItemStack(ExtraUtils.decorative1, 1, 5), new FluidStack(unstable, 1296), (ItemStack)null, true, 100); + + + + + + + + + + + + + + + + + + + + + + + + + return true; diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index 450111a113..d8c773c014 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -4,8 +4,12 @@ import java.lang.reflect.Constructor; 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 gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; @@ -25,14 +29,34 @@ public class TinkersUtils { private static Object mTinkersRegistryInstance; private static Class mTinkersRegistryClass; - private static final Class mToolMaterialClass; - + private static final Class mToolMaterialClass; + + 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 Field mField_MoltenIronFluid; + + private static final Method mMethod_getFluidType; + private static final Method mMethod_getCastingRecipes; + private static final HashMap mMethodCache = new LinkedHashMap(); static { setRegistries(); mToolMaterialClass = 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"); + + mField_MoltenIronFluid = ReflectionUtils.getField(mSmelteryClassInstance, "moltenIronFluid"); + + mMethod_getFluidType = ReflectionUtils.getMethod(mClass_FluidType, "getFluidType", String.class); + mMethod_getCastingRecipes = ReflectionUtils.getMethod(getCastingInstance(0), "getCastingRecipes", new Class[] {}); + } @@ -40,9 +64,9 @@ public class TinkersUtils { * * @param aSwitch - The Registry to return */ - private static Object getTiConDataInstance(int aSwitch) { + private static void setTiConDataInstance() { if (!LoadedMods.TiCon) { - return null; + return; } else { @@ -51,7 +75,6 @@ public class TinkersUtils { } // getSmelteryInstance - if (aSwitch == 0) { //Set Smeltery Instance if (mSmelteryInstance == null || mSmelteryClassInstance == null) { @@ -69,12 +92,11 @@ public class TinkersUtils { //Return Smeltery Instance if (mSmelteryInstance != null) { - return mSmelteryInstance; + //return mSmelteryInstance; } - } + // getTableCastingInstance || getBasinCastingInstance - else if (aSwitch == 1) { if (mTinkersRegistryClass == null || mTinkersRegistryInstance == null) { if (mTinkersRegistryClass == null) { mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); @@ -92,11 +114,9 @@ public class TinkersUtils { //Return Smeltery Instance if (mTinkersRegistryInstance != null) { - return mTinkersRegistryInstance; - } - } + //return mTinkersRegistryInstance; + } - return null; } } @@ -143,28 +163,32 @@ public class TinkersUtils { * @param duration How long one "portion" of liquid fuels the smeltery. Lava is 10. */ public static void addSmelteryFuel (Fluid fluid, int power, int duration){ - ReflectionUtils.invokeVoid(getTiConDataInstance(0), "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration}); + setTiConDataInstance(); + ReflectionUtils.invokeVoid(mSmelteryInstance, "addSmelteryFuel", new Class[] {Fluid.class, int.class, int.class}, new Object[] {fluid, power, duration}); } /** * Returns true if the liquid is a valid smeltery fuel. */ public static boolean isSmelteryFuel (Fluid fluid){ - return ReflectionUtils.invoke(getTiConDataInstance(0), "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid}); + setTiConDataInstance(); + return ReflectionUtils.invoke(mSmelteryInstance, "isSmelteryFuel", new Class[] {Fluid.class}, new Object[] {fluid}); } /** * Returns the power of a smeltery fuel or 0 if it's not a fuel. */ public static int getFuelPower (Fluid fluid){ - return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid}); + setTiConDataInstance(); + return (int) ReflectionUtils.invokeNonBool(mSmelteryInstance, "getFuelPower", new Class[] {Fluid.class}, new Object[] {fluid}); } /** * Returns the duration of a smeltery fuel or 0 if it's not a fuel. */ public static int getFuelDuration (Fluid fluid){ - return (int) ReflectionUtils.invokeNonBool(getTiConDataInstance(0), "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); + setTiConDataInstance(); + return (int) ReflectionUtils.invokeNonBool(mSmelteryInstance, "getFuelDuration", new Class[] {Fluid.class}, new Object[] {fluid}); } @@ -210,6 +234,19 @@ public class TinkersUtils { return false; } } + + public static boolean addMelting(Object type, ItemStack input, int temperatureDifference, int fluidAmount) { + if (mMethodCache.get("addMelting") == null) { + Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); + mMethodCache.put("addMelting", m); + } + try { + mMethodCache.get("addMelting").invoke(null, type, input, temperatureDifference, fluidAmount); + return true; + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + return false; + } + } @@ -268,18 +305,22 @@ public class TinkersUtils { - + /** + * 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(getTiConDataInstance(1), "getTableCasting", new Class[] {}); + m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getTableCasting", new Class[] {}); //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getTableCasting", new Class[] {}, new Object[] {}); } else if (aType == 1) { - m = ReflectionUtils.getMethod(getTiConDataInstance(1), "getBasinCasting", new Class[] {}); + m = ReflectionUtils.getMethod(mTinkersRegistryInstance, "getBasinCasting", new Class[] {}); //return ReflectionUtils.invokeVoid(getTiConDataInstance(1), "getBasinCasting", new Class[] {}, new Object[] {}); } else { @@ -288,7 +329,7 @@ public class TinkersUtils { if (m != null) { try { - return m.invoke(getTiConDataInstance(1), new Object[] {}); + return m.invoke(mTinkersRegistryInstance, new Object[] {}); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); } @@ -406,5 +447,109 @@ public class TinkersUtils { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } + + 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 boolean generateCastingRecipes(Material aMaterial, int aID) { + + List newRecipies = new LinkedList(); + + if (true) { + Iterator i$ = getTableCastingRecipes().iterator(); + while (i$.hasNext()) { + CastingRecipeHandler recipe = new CastingRecipeHandler(i$.next()); + try { + if (recipe.valid && recipe.castingMetal.getFluid() == mField_MoltenIronFluid.get(null) && recipe.cast != null + && mClass_IPattern.isInstance(recipe.cast.getItem()) && mClass_DynamicToolPart.isInstance(recipe.getResult().getItem())) { + newRecipies.add(recipe); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + return false; + } + } + } + + if (true) { + Object ft; + try { + ft = mMethod_getFluidType.invoke(null, aMaterial.getLocalizedName()); + Iterator i$ = newRecipies.iterator(); + while (i$.hasNext()) { + CastingRecipeHandler recipe = new CastingRecipeHandler(i$.next()); + if (!recipe.valid){ + continue; + } + //CastingRecipe recipe = (CastingRecipe) i$.next(); + ItemStack output = recipe.getResult().copy(); + output.setItemDamage(aID); + FluidStack liquid2 = new FluidStack(aMaterial.getFluid(0).getFluid(), recipe.castingMetal.amount); + addCastingTableRecipe(output, liquid2, recipe.cast, recipe.consumeCast, recipe.coolTime); + addMelting(ft, output, 0, liquid2.amount / 2); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + return false; + } + } + return true; + } + + private static class CastingRecipeHandler { + + public ItemStack output; + public FluidStack castingMetal; + public ItemStack cast; + 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 boolean matches(FluidStack metal, ItemStack inputCast) { + return this.castingMetal.isFluidEqual(metal) && (this.cast != null && this.cast.getItemDamage() == 32767 + && inputCast.getItem() == this.cast.getItem() || ItemStack.areItemStacksEqual(this.cast, inputCast)); + } + + public ItemStack getResult() { + return this.output.copy(); + } + + } } -- cgit From b126379ca7e069c93c3b42a7e87e77c209a894c3 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Fri, 1 Mar 2019 05:15:22 +0000 Subject: $ Final fixes to TiCon reflective integration. Now to just tweak the added content and rebalance. $ Fixed hand mix Tumbaga recipe inconsistency. --- .../gtPlusPlus/core/recipe/RECIPES_General.java | 2 +- .../core/util/reflect/ReflectionUtils.java | 17 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 2 +- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 171 +++++++++------------ 4 files changed, 83 insertions(+), 109 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers/material') diff --git a/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java b/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java index c2fd4adc41..54380306cc 100644 --- a/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java +++ b/src/Java/gtPlusPlus/core/recipe/RECIPES_General.java @@ -178,7 +178,7 @@ public class RECIPES_General { ItemUtils.getSimpleStack(ModItems.dustTumbagaMix), ItemUtils.getSimpleStack(ModItems.dustTumbagaMix), ItemUtils.getSimpleStack(ModItems.dustTumbagaMix), - "dustCopper" + "dustGold" }, ALLOY.TUMBAGA.getDust(10))){ Logger.INFO("Added shapeless recipe for Tumbaga Dust."); diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 827ffbf5fb..617728cdec 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -9,6 +9,8 @@ import java.lang.reflect.Modifier; import java.util.LinkedHashMap; import java.util.Map; +import org.apache.commons.lang3.ArrayUtils; + import com.google.common.reflect.ClassPath; import gtPlusPlus.api.objects.Logger; @@ -77,9 +79,9 @@ public class ReflectionUtils { return false; } boolean isStatic = Modifier.isStatic(aMethod.getModifiers()); - CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethod.getName()+"."+aMethod.getParameterTypes().toString()); + CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethod.getName()+"."+ArrayUtils.toString(aMethod.getParameterTypes())); if (y == null) { - mCachedMethods.put(aClass.getName()+"."+aMethod.getName()+"."+aMethod.getParameterTypes().toString(), new CachedMethod(aMethod, isStatic)); + mCachedMethods.put(aClass.getName()+"."+aMethod.getName()+"."+ArrayUtils.toString(aMethod.getParameterTypes()), new CachedMethod(aMethod, isStatic)); return true; } return false; @@ -138,7 +140,8 @@ public class ReflectionUtils { * @return - Valid, non-final, {@link Method} object, or {@link null}. */ public static Method getMethod(Class aClass, String aMethodName, Class... aTypes) { - String aMethodKey = aTypes.toString(); + String aMethodKey = ArrayUtils.toString(aTypes); + //Logger.REFLECTION("Looking up method in cache: "+(aClass.getName()+"."+aMethodName + "." + aMethodKey)); CachedMethod y = mCachedMethods.get(aClass.getName()+"."+aMethodName + "." + aMethodKey); if (y == null) { Method u = getMethod_Internal(aClass, aMethodName, aTypes); @@ -169,7 +172,7 @@ public class ReflectionUtils { try { u = getField_Internal(aClass, aFieldName); if (u != null) { - Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getCanonicalName()); + Logger.REFLECTION("Caching Field '"+aFieldName+"' from "+aClass.getName()); cacheField(aClass, u); return u; } @@ -426,16 +429,20 @@ public class ReflectionUtils { private static Field getField_Internal(final Class clazz, final String fieldName) throws NoSuchFieldException { try { + Logger.REFLECTION("Field: Internal Lookup: "+fieldName); Field k = clazz.getDeclaredField(fieldName); makeFieldAccessible(k); //Logger.REFLECTION("Got Field from Class. "+fieldName+" did exist within "+clazz.getCanonicalName()+"."); return k; } catch (final NoSuchFieldException e) { + Logger.REFLECTION("Field: Internal Lookup Failed: "+fieldName); final Class superClass = clazz.getSuperclass(); if (superClass == null) { + Logger.REFLECTION("Unable to find field '"+fieldName+"'"); //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+"."); throw e; } + Logger.REFLECTION("Method: Recursion Lookup: "+fieldName+" - Checking in "+superClass.getName()); //Logger.REFLECTION("Failed to get Field from Class. "+fieldName+" does not existing within "+clazz.getCanonicalName()+". Trying super class."); return getField_Internal(superClass, fieldName); } @@ -511,7 +518,7 @@ public class ReflectionUtils { } private static void dumpClassInfo(Class aClass) { - Logger.INFO("We ran into an error processing reflection in "+aClass.getCanonicalName()+", dumping all data for debugging."); + Logger.INFO("We ran into an error processing reflection in "+aClass.getName()+", dumping all data for debugging."); // Get the methods Method[] methods = aClass.getDeclaredMethods(); Field[] fields = aClass.getDeclaredFields(); diff --git a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java index 0585eeafd8..6f47909a01 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java @@ -30,7 +30,7 @@ public class BaseTinkersMaterial { private final Material mMaterial; static { - aNextFreeID = Short.MAX_VALUE+420; + aNextFreeID = (Short.MAX_VALUE/2)+420; } public BaseTinkersMaterial(Material aMaterial) { diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index d8c773c014..f0c6d76b7c 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -11,6 +11,7 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import gregtech.api.enums.Materials; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.minecraft.ItemUtils; @@ -23,40 +24,41 @@ import net.minecraftforge.fluids.FluidStack; public class TinkersUtils { - private static Object mSmelteryInstance; - private static Class mSmelteryClassInstance; - - private static Object mTinkersRegistryInstance; - private static Class mTinkersRegistryClass; - - private static final Class mToolMaterialClass; - + 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 mMethodCache = new LinkedHashMap(); - static { - setRegistries(); - mToolMaterialClass = ReflectionUtils.getClass("tconstruct.library.tools.ToolMaterial"); + 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(mSmelteryClassInstance, "moltenIronFluid"); + 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[] {}); - + mMethod_getCastingRecipes = ReflectionUtils.getMethod(getCastingInstance(0), "getCastingRecipes", new Class[] {}); } @@ -67,65 +69,23 @@ public class TinkersUtils { private static void setTiConDataInstance() { if (!LoadedMods.TiCon) { return; - } - else { - - if (mTinkersRegistryClass == null || mSmelteryClassInstance == null) { - setRegistries(); - } - - // getSmelteryInstance - - //Set Smeltery Instance - if (mSmelteryInstance == null || mSmelteryClassInstance == null) { - if (mSmelteryClassInstance == null) { - mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + } else { + if (mSmelteryInstance == null) { + if (mClass_Smeltery != null) { + try { + mSmelteryInstance = ReflectionUtils.getField(mClass_Smeltery, "instance").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } - if (mSmelteryClassInstance != null) { - try { - mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); - } - catch (IllegalArgumentException | IllegalAccessException e) { - } - } - } - - //Return Smeltery Instance - if (mSmelteryInstance != null) { - //return mSmelteryInstance; } - - - // getTableCastingInstance || getBasinCastingInstance - if (mTinkersRegistryClass == null || mTinkersRegistryInstance == null) { - if (mTinkersRegistryClass == null) { - mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); + } + if (mTinkersRegistryInstance == null) { + if (mClass_TConstructRegistry != null) { + try { + mTinkersRegistryInstance = ReflectionUtils.getField(mClass_TConstructRegistry, "instance").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } - if (mTinkersRegistryClass != null) { - if (mTinkersRegistryInstance == null) { - try { - mTinkersRegistryInstance = ReflectionUtils.getField(mTinkersRegistryClass, "instance").get(null); - } - catch (IllegalArgumentException | IllegalAccessException e) { - } - } - } } - - //Return Smeltery Instance - if (mTinkersRegistryInstance != null) { - //return mTinkersRegistryInstance; - } - - } - } - - private static void setRegistries() { - if (mTinkersRegistryClass == null) { - mTinkersRegistryClass = ReflectionUtils.getClass("tconstruct.library.TConstructRegistry"); - } - if (mSmelteryClassInstance == null) { - mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); + } } } @@ -224,7 +184,7 @@ public class TinkersUtils { public static boolean addMelting(ItemStack input, Block block, int metadata, int temperature, FluidStack liquid) { if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "addMelting", ItemStack.class, Block.class, int.class, int.class, FluidStack.class); + Method m = ReflectionUtils.getMethod(mClass_Smeltery, "addMelting", ItemStack.class, Block.class, int.class, int.class, FluidStack.class); mMethodCache.put("addMelting", m); } try { @@ -237,7 +197,7 @@ public class TinkersUtils { public static boolean addMelting(Object type, ItemStack input, int temperatureDifference, int fluidAmount) { if (mMethodCache.get("addMelting") == null) { - Method m = ReflectionUtils.getMethod(mSmelteryClassInstance, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); + Method m = ReflectionUtils.getMethod(mClass_Smeltery, "addMelting", mClass_FluidType, ItemStack.class, int.class, int.class); mMethodCache.put("addMelting", m); } try { @@ -341,7 +301,7 @@ public class TinkersUtils { private static Item mTinkerMetalPattern; public static ItemStack getPattern(int aType) { if (mTinkerMetalPattern == null) { - Field m = ReflectionUtils.getField(ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"), "metalPattern"); + Field m = ReflectionUtils.getField(mClass_TinkerSmeltery, "metalPattern"); if (m != null) { try { mTinkerMetalPattern = (Item) m.get(null); @@ -380,7 +340,7 @@ public class TinkersUtils { */ public static Object generateToolMaterial(String name, String localizationString, int level, int durability, int speed, int damage, float handle, int reinforced, float stonebound, String style, int primaryColor) { try { - Constructor constructor = mToolMaterialClass.getConstructor(String.class, String.class, int.class, int.class, int.class, int.class, float.class, int.class, float.class, String.class, int.class); + Constructor constructor = mClass_ToolMaterial.getConstructor(String.class, String.class, int.class, int.class, int.class, int.class, float.class, int.class, float.class, String.class, int.class); Object myObject = constructor.newInstance(name, localizationString, level, durability, speed, damage, handle, reinforced, stonebound, style, primaryColor); return myObject; } catch (Throwable t) { @@ -399,51 +359,47 @@ public class TinkersUtils { - public static void addToolMaterial(int id, Object aToolMaterial) { - setRegistries(); + public static void addToolMaterial(int id, Object aToolMaterial) { if (mMethodCache.get("addToolMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addtoolMaterial", int.class, mToolMaterialClass); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addtoolMaterial", int.class, mClass_ToolMaterial); mMethodCache.put("addToolMaterial", m); } try { - mMethodCache.get("addToolMaterial").invoke(mTinkersRegistryClass, id, aToolMaterial); + mMethodCache.get("addToolMaterial").invoke(mClass_TConstructRegistry, id, aToolMaterial); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } - public static void addDefaultToolPartMaterial(int id) { - setRegistries(); + public static void addDefaultToolPartMaterial(int id) { if (mMethodCache.get("addDefaultToolPartMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addDefaultToolPartMaterial", int.class); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addDefaultToolPartMaterial", int.class); mMethodCache.put("addDefaultToolPartMaterial", m); } try { - mMethodCache.get("addDefaultToolPartMaterial").invoke(mTinkersRegistryClass, id); + mMethodCache.get("addDefaultToolPartMaterial").invoke(mClass_TConstructRegistry, id); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } - public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { - setRegistries(); + public static void addBowMaterial(int id, int drawspeed, float maxSpeed) { if (mMethodCache.get("addBowMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addBowMaterial", int.class, int.class, float.class); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addBowMaterial", int.class, int.class, float.class); mMethodCache.put("addBowMaterial", m); } try { - mMethodCache.get("addBowMaterial").invoke(mTinkersRegistryClass, id, drawspeed, maxSpeed); + mMethodCache.get("addBowMaterial").invoke(mClass_TConstructRegistry, id, drawspeed, maxSpeed); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } - public static void addArrowMaterial(int id, float mass, float fragility) { - setRegistries(); + public static void addArrowMaterial(int id, float mass, float fragility) { if (mMethodCache.get("addArrowMaterial") == null) { - Method m = ReflectionUtils.getMethod(mTinkersRegistryClass, "addArrowMaterial", int.class, float.class, float.class); + Method m = ReflectionUtils.getMethod(mClass_TConstructRegistry, "addArrowMaterial", int.class, float.class, float.class); mMethodCache.put("addArrowMaterial", m); } try { - mMethodCache.get("addArrowMaterial").invoke(mTinkersRegistryClass, id, mass, fragility); + mMethodCache.get("addArrowMaterial").invoke(mClass_TConstructRegistry, id, mass, fragility); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } } @@ -464,29 +420,40 @@ public class TinkersUtils { List newRecipies = new LinkedList(); - if (true) { - Iterator i$ = getTableCastingRecipes().iterator(); - while (i$.hasNext()) { - CastingRecipeHandler recipe = new CastingRecipeHandler(i$.next()); + + Iterator iterator1 = getTableCastingRecipes().iterator(); + Fluid aMoltenIron = null; + if (aMoltenIron == null) { try { - if (recipe.valid && recipe.castingMetal.getFluid() == mField_MoltenIronFluid.get(null) && recipe.cast != null + 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 | IllegalAccessException e) { + } catch (IllegalArgumentException e) { e.printStackTrace(); return false; } } - } - - if (true) { + + Object ft; try { ft = mMethod_getFluidType.invoke(null, aMaterial.getLocalizedName()); - Iterator i$ = newRecipies.iterator(); - while (i$.hasNext()) { - CastingRecipeHandler recipe = new CastingRecipeHandler(i$.next()); + Iterator iterator2 = newRecipies.iterator(); + while (iterator2.hasNext()) { + CastingRecipeHandler recipe = new CastingRecipeHandler(iterator2.next()); if (!recipe.valid){ continue; } @@ -501,7 +468,7 @@ public class TinkersUtils { e.printStackTrace(); return false; } - } + return true; } -- cgit