More work on intelligent deconstructive philosopher stone recipes
Generalized private field accessing until FML is fully implemented client side
This commit is contained in:
parent
b4bbd519c3
commit
2958106a65
|
@ -1,9 +1,9 @@
|
|||
package ee3.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import ee3.core.interfaces.IProxy;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ModLoader;
|
||||
|
@ -15,6 +15,34 @@ public class EEProxy implements IProxy {
|
|||
|
||||
public EEProxy() { }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, int fieldIndex) {
|
||||
try {
|
||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
||||
f.setAccessible(true);
|
||||
return (T) f.get(instance);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ModLoader.getLogger().severe(String.format("There was a problem getting field %d from %s", fieldIndex, classToAccess.getName()));
|
||||
ModLoader.getLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, String fieldName) {
|
||||
try {
|
||||
Field f = classToAccess.getDeclaredField(fieldName);
|
||||
f.setAccessible(true);
|
||||
return (T) f.get(instance);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ModLoader.getLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName()));
|
||||
ModLoader.getLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRenderInformation() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.src.ItemStack;
|
|||
import net.minecraft.src.ModLoader;
|
||||
import net.minecraft.src.ShapedRecipes;
|
||||
import net.minecraft.src.ShapelessRecipes;
|
||||
import net.minecraft.src.mod_EE3;
|
||||
|
||||
public class RecipesPhilStone {
|
||||
|
||||
|
@ -35,11 +36,11 @@ public class RecipesPhilStone {
|
|||
|
||||
public static void initRecipes() {
|
||||
determineBaseMaterials();
|
||||
initTransmutationRecipes();
|
||||
initEquivalencyRecipes();
|
||||
initReconstructiveRecipes();
|
||||
initDestructorRecipes();
|
||||
initPortableSmeltingRecipes();
|
||||
//initTransmutationRecipes();
|
||||
//initEquivalencyRecipes();
|
||||
//initReconstructiveRecipes();
|
||||
//initDestructorRecipes();
|
||||
//initPortableSmeltingRecipes();
|
||||
}
|
||||
|
||||
public static void determineBaseMaterials() {
|
||||
|
@ -50,18 +51,34 @@ public class RecipesPhilStone {
|
|||
ShapedRecipes shapedRecipe;
|
||||
ShapelessRecipes shapelessRecipe;
|
||||
|
||||
ItemStack[] shapedInputs;
|
||||
List shapelessInputs;
|
||||
|
||||
Iterator<IRecipe> recipeIter = recipeList.iterator();
|
||||
|
||||
while (recipeIter.hasNext()) {
|
||||
recipe = recipeIter.next();
|
||||
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
System.out.println("Shaped");
|
||||
}
|
||||
else if (recipe instanceof ShapelessRecipes) {
|
||||
System.out.println("Shapeless");
|
||||
try {
|
||||
while (recipeIter.hasNext()) {
|
||||
recipe = recipeIter.next();
|
||||
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
shapedRecipe = (ShapedRecipes) recipe;
|
||||
shapedInputs = mod_EE3.proxy.getPrivateValue(ShapedRecipes.class, shapedRecipe, "recipeItems");
|
||||
|
||||
System.out.println("Shaped");
|
||||
System.out.println(shapedInputs.toString());
|
||||
}
|
||||
else if (recipe instanceof ShapelessRecipes) {
|
||||
shapelessRecipe = (ShapelessRecipes) recipe;
|
||||
shapelessInputs = mod_EE3.proxy.getPrivateValue(ShapelessRecipes.class, shapelessRecipe, "recipeItems");
|
||||
|
||||
System.out.println("Shapeless");
|
||||
System.out.println(shapelessInputs.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initTransmutationRecipes() {
|
||||
|
|
|
@ -4,10 +4,15 @@ import java.io.File;
|
|||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.NetworkManager;
|
||||
import net.minecraft.src.ShapedRecipes;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.forge.IGuiHandler;
|
||||
|
||||
public interface IProxy {
|
||||
|
||||
public abstract <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, int fieldIndex);
|
||||
|
||||
public abstract <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, String fieldName);
|
||||
|
||||
public abstract void registerRenderInformation();
|
||||
|
||||
|
@ -34,4 +39,5 @@ public interface IProxy {
|
|||
public abstract Object handleGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z);
|
||||
|
||||
public abstract void playSound(String soundName, float x, float y, float z, float volume, float pitch);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package ee3.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ReflectionHelper;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ModLoader;
|
||||
|
@ -12,6 +16,16 @@ public class EEProxy implements IProxy {
|
|||
|
||||
public EEProxy() { }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, int fieldIndex) {
|
||||
return ReflectionHelper.getPrivateValue(classToAccess, instance, fieldIndex);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, String fieldName) {
|
||||
return ReflectionHelper.getPrivateValue(classToAccess, instance, fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRenderInformation() {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -66,4 +80,5 @@ public class EEProxy implements IProxy {
|
|||
|
||||
@Override
|
||||
public void playSound(String soundName, float x, float y, float z, float volume, float pitch) { }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue