Changes in ReflectionHelper

This commit is contained in:
Zixxl committed 2015-07-06 17:42:39 +02:00
1 parent 17d9b78930
commit 6bf0797054
13 files changed
+115 -143

No files matched your search

@@ -1,13 +1,12 @@
package modtweaker2.mods.tconstruct;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mantle.utils.ItemMetaWrapper;
import modtweaker2.helpers.ReflectionHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
@@ -18,12 +17,11 @@ import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.DryingRackRecipes.DryingRecipe;
import tconstruct.library.crafting.ModifyBuilder;
import tconstruct.library.crafting.PatternBuilder.ItemKey;
import tconstruct.library.crafting.Smeltery;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.tools.ToolMaterial;
public class TConstructHelper {
public static HashMap<String, Integer> mappings = new HashMap();
public static HashMap<String, Integer> mappings = new HashMap<String, Integer>();
public static List<AlloyMix> alloys = null;
public static ArrayList<CastingRecipe> basinCasting = null;
public static ArrayList<CastingRecipe> tableCasting = null;
@@ -43,13 +41,13 @@ public class TConstructHelper {
basinCasting = TConstructRegistry.getBasinCasting().getCastingRecipes();
tableCasting = TConstructRegistry.getTableCasting().getCastingRecipes();
modifiers = ModifyBuilder.instance.itemModifiers;
modifiers_clone = new ArrayList(modifiers);
modifiers_clone = new ArrayList<ItemModifier>(modifiers);
for (Map.Entry<Integer, ToolMaterial> entry : TConstructRegistry.toolMaterials.entrySet()) {
mappings.put(entry.getValue().materialName, entry.getKey());
}
fuelList = getFuelList();
fuelList = ReflectionHelper.getObject(tconstruct.library.crafting.Smeltery.instance, "smelteryFuels");
} catch (Exception e) {}
}
@@ -60,31 +58,13 @@ public class TConstructHelper {
return -1;
} else return mappings.get(material);
}
public static Map<Fluid, Integer[]> getFuelList() {
Smeltery smelteryInstance = tconstruct.library.crafting.Smeltery.instance;
try {
Field smelteryFuels = Smeltery.class.getDeclaredField("smelteryFuels");
smelteryFuels.setAccessible(true);
return (Map<Fluid, Integer[]>)smelteryFuels.get(smelteryInstance);
} catch (Exception e) {
e.printStackTrace();
throw new NullPointerException("Failed to instantiate smeltery fuel map");
}
}
//Returns a Drying Recipe, using reflection as the constructor is not visible
public static DryingRecipe getDryingRecipe(ItemStack input, int time, ItemStack output) {
try {
Constructor constructor = DryingRecipe.class.getDeclaredConstructor(ItemStack.class, int.class, ItemStack.class);
constructor.setAccessible(true);
return (DryingRecipe) constructor.newInstance(input, time, output);
} catch (Exception e) {
e.printStackTrace();
throw new NullPointerException("Failed to instantiate DryingRecipe");
}
return ReflectionHelper.getInstance(ReflectionHelper.getConstructor(DryingRecipe.class, ItemStack.class, int.class, ItemStack.class),
input,
time,
output);
}
public static String getMaterialFromID(int id) {
@@ -92,13 +72,10 @@ public class TConstructHelper {
}
public static ItemKey getItemKey(Item item, int damage, int value, String material) {
try {
Constructor constructor = ItemKey.class.getDeclaredConstructor(ItemStack.class, int.class, int.class, String.class);
constructor.setAccessible(true);
return (ItemKey) constructor.newInstance(item, damage, value, material);
} catch (Exception e) {
e.printStackTrace();
throw new NullPointerException("Failed to instantiate ItemKey");
}
return ReflectionHelper.getInstance(ReflectionHelper.getConstructor(ItemKey.class, ItemStack.class, int.class, int.class, String.class),
item,
damage,
value,
material);
}
}
@@ -35,7 +35,6 @@ public class Modifiers {
}
}
//Searches through the modifiers and removes the first valid entry
private static class Remove extends BaseListRemoval<ItemModifier>{
public Remove(List<ItemModifier> recipes) {
super(Modifiers.name, TConstructHelper.modifiers, recipes);