aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus')
-rw-r--r--src/Java/gtPlusPlus/core/material/Material.java10
-rw-r--r--src/Java/gtPlusPlus/core/util/data/StringUtils.java15
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java29
-rw-r--r--src/Java/gtPlusPlus/xmod/tinkers/material/BaseTinkersMaterial.java93
-rw-r--r--src/Java/gtPlusPlus/xmod/tinkers/util/TinkersUtils.java27
5 files changed, 128 insertions, 46 deletions
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 <V> 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<String, Integer> aInternalMaterialIdMap = new HashMap<String, Integer>();
- 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 {