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. --- .../gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java | 4 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 200 +++++++++++++++++++++ .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 66 +++++-- 3 files changed, 258 insertions(+), 12 deletions(-) create mode 100644 src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java (limited to 'src/Java/gtPlusPlus/xmod/tinkers') diff --git a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java index 501fe6579a..a6260d4246 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java @@ -33,7 +33,7 @@ public class HANDLER_Tinkers { public static final void postInit() { if (LoadedMods.TiCon) { - Class aTinkersSmeltery = ReflectionUtils.getClassByName("tconstruct.smeltery.TinkerSmeltery"); + Class aTinkersSmeltery = ReflectionUtils.getClass("tconstruct.smeltery.TinkerSmeltery"); AutoMap aTweakedFluids = new AutoMap(); if (aTinkersSmeltery != null) { try { @@ -84,7 +84,7 @@ public class HANDLER_Tinkers { } } } - } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { } } } 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; + } + + + + + + + + + +} diff --git a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java index aed5b46e0a..10eb93b4d7 100644 --- a/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java +++ b/src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java @@ -1,9 +1,16 @@ package gtPlusPlus.xmod.tinkers.util; 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.ItemStack; import net.minecraftforge.fluids.Fluid; +import tconstruct.library.TConstructRegistry; +import tconstruct.library.crafting.FluidType; +import tconstruct.library.crafting.Smeltery; +import tconstruct.smeltery.TinkerSmeltery; public class TinkersUtils { @@ -17,16 +24,13 @@ public class TinkersUtils { else { if (mSmelteryInstance == null || mSmelteryClassInstance == null) { if (mSmelteryClassInstance == null) { - try { - mSmelteryClassInstance = Class.forName("tconstruct.library.crafting.Smeltery"); - } - catch (ClassNotFoundException e) {} + mSmelteryClassInstance = ReflectionUtils.getClass("tconstruct.library.crafting.Smeltery"); } if (mSmelteryClassInstance != null) { try { mSmelteryInstance = ReflectionUtils.getField(mSmelteryClassInstance, "instance").get(null); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + catch (IllegalArgumentException | IllegalAccessException e) { } } } @@ -40,9 +44,8 @@ public class TinkersUtils { public static final boolean isTiConFirstInOD() { if (LoadedMods.TiCon) { try { - return (boolean) ReflectionUtils.getField(Class.forName("PHConstruct"), "tconComesFirst").get(null); - } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + return (boolean) ReflectionUtils.getField(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst").get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { } } return false; @@ -51,8 +54,8 @@ public class TinkersUtils { public static final boolean stopTiconLoadingFirst() { if (isTiConFirstInOD()) { try { - ReflectionUtils.setFieldValue(Class.forName("PHConstruct"), "tconComesFirst", false); - if ((boolean) ReflectionUtils.getField(Class.forName("PHConstruct"), "tconComesFirst").get(null) == false) { + ReflectionUtils.setFinalFieldValue(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst", false); + if ((boolean) ReflectionUtils.getField(ReflectionUtils.getClass("PHConstruct"), "tconComesFirst").get(null) == false) { return true; } //Did not work, let's see where TiCon uses this and prevent it. @@ -95,5 +98,48 @@ public class TinkersUtils { public static int getFuelDuration (Fluid fluid){ return (int) ReflectionUtils.invokeNonBool(getSmelteryInstance(), "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; + } + + 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 addBasinRecipe(Material aMaterial) { + TConstructRegistry.getBasinCasting().addCastingRecipe(aMaterial.getBlock(1), + aMaterial.getFluid(144*9), (ItemStack) null, true, 100); + 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; + } + + + + + + + + + + + + + + + + + } -- 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. --- .../gtPlusPlus/xmod/tinkers/HANDLER_Tinkers.java | 10 +- .../xmod/tinkers/material/BaseTinkersMaterial.java | 185 ++++++------ .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 330 ++++++++++++++++++--- 3 files changed, 397 insertions(+), 128 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers') 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. --- .../xmod/tinkers/material/BaseTinkersMaterial.java | 93 ++++++++++++++-------- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 27 +++++-- 2 files changed, 82 insertions(+), 38 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers') 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. --- .../xmod/tinkers/material/BaseTinkersMaterial.java | 56 ++++-- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 187 ++++++++++++++++++--- 2 files changed, 211 insertions(+), 32 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers') 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. --- .../xmod/tinkers/material/BaseTinkersMaterial.java | 2 +- .../gtPlusPlus/xmod/tinkers/util/TinkersUtils.java | 171 +++++++++------------ 2 files changed, 70 insertions(+), 103 deletions(-) (limited to 'src/Java/gtPlusPlus/xmod/tinkers') 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/gtPlu