aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-03-01 04:20:08 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-03-01 04:20:08 +0000
commit9a0e88e397dc52476a0de92768c1022a3e53c9ed (patch)
tree857daacdc3ed3a0ff7f7051aa8ba2b3ff72d5f9e /src
parent35522722af5dddea144c841a71f4fa9087e68966 (diff)
downloadGT5-Unofficial-9a0e88e397dc52476a0de92768c1022a3e53c9ed.tar.gz
GT5-Unofficial-9a0e88e397dc52476a0de92768c1022a3e53c9ed.tar.bz2
GT5-Unofficial-9a0e88e397dc52476a0de92768c1022a3e53c9ed.zip
+ 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.
Diffstat (limited to 'src')
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java20
-rw-r--r--src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java56
-rw-r--r--src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java187
3 files changed, 221 insertions, 42 deletions
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;
@@ -227,6 +227,40 @@ public class BaseTinkersMaterial {
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<String, Method> mMethodCache = new LinkedHashMap<String, Method>();
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();
+ }
+
+ }
}