mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-27 23:33:10 +00:00
- Started implementation of furnace code
- Removed client code reference in the recipe manager - Fixed IC2 mod machine errors - Removed unnecessary print statements
This commit is contained in:
1 parent
93fe0bedc9
commit
8b00ce34b6
12 files changed
+306
-21
No files matched your search
@@ -22,7 +22,7 @@ public interface IFurnaceManager {
|
||||
public void remove(IIngredient ingredient);
|
||||
|
||||
@ZenMethod
|
||||
public void addRecipe(IIngredient output, IIngredient input, @Optional double xp);
|
||||
public void addRecipe(IItemStack output, IIngredient input, @Optional double xp);
|
||||
|
||||
@ZenMethod
|
||||
public void setFuel(IIngredient item, int fuel);
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
package minetweaker.mc172;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
@@ -19,17 +17,14 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.mc172.brackets.ItemBracketHandler;
|
||||
import minetweaker.mc172.brackets.LiquidBracketHandler;
|
||||
import minetweaker.mc172.brackets.OreBracketHandler;
|
||||
import minetweaker.mc172.furnace.TweakerFurnace;
|
||||
import minetweaker.mc172.network.MineTweakerLoadScriptsHandler;
|
||||
import minetweaker.mc172.network.MineTweakerLoadScriptsPacket;
|
||||
import minetweaker.mc172.oredict.OreDict;
|
||||
@@ -73,6 +68,7 @@ public class MineTweakerMod {
|
||||
MineTweakerAPI.oreDict = new OreDict();
|
||||
MineTweakerAPI.recipes = new MTRecipeManager();
|
||||
MineTweakerAPI.logger = new MineTweakerLogger();
|
||||
MineTweakerAPI.furnace = new TweakerFurnace();
|
||||
|
||||
/*List<Class> classes = new ArrayList<Class>();
|
||||
MineTweakerRegistry.getClasses(classes);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc172.furnace;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.common.IFuelHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
|
||||
public class FuelTweaker {
|
||||
public static final FuelTweaker INSTANCE = new FuelTweaker();
|
||||
|
||||
private List<IFuelHandler> original;
|
||||
private final HashMap<String, List<SetFuelPattern>> quickList = new HashMap<String, List<SetFuelPattern>>();
|
||||
|
||||
private FuelTweaker() {}
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers");
|
||||
fuelHandlers.setAccessible(true);
|
||||
original = (List<IFuelHandler>) fuelHandlers.get(null);
|
||||
List<IFuelHandler> modified = new ArrayList<IFuelHandler>();
|
||||
modified.add(new OverridingFuelHandler());
|
||||
fuelHandlers.set(null, modified);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not get GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
} catch (SecurityException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
} catch (IllegalAccessException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
}
|
||||
}
|
||||
|
||||
public void addFuelPattern(SetFuelPattern pattern) {
|
||||
List<IItemStack> items = pattern.getPattern().getItems();
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logger.logError("Cannot set fuel for <*>");
|
||||
return;
|
||||
}
|
||||
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
if (!quickList.containsKey(item.getName())) {
|
||||
quickList.put(item.getName(), new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(item.getName()).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFuelPattern(SetFuelPattern pattern) {
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
if (!quickList.containsKey(item.getName())) {
|
||||
quickList.put(item.getName(), new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(item.getName()).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
private class OverridingFuelHandler implements IFuelHandler {
|
||||
@Override
|
||||
public int getBurnTime(ItemStack fuel) {
|
||||
IItemStack stack = new TweakerItemStack(fuel);
|
||||
String name = fuel.getUnlocalizedName();
|
||||
if (quickList.containsKey(name)) {
|
||||
for (SetFuelPattern override : quickList.get(name)) {
|
||||
if (override.getPattern().matches(stack)) {
|
||||
return override.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
for (IFuelHandler handler : original) {
|
||||
max = Math.max(max, handler.getBurnTime(fuel));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.mc172.furnace;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
public class SetFuelPattern {
|
||||
private final IIngredient pattern;
|
||||
private final int value;
|
||||
|
||||
public SetFuelPattern(IIngredient pattern, int value) {
|
||||
this.pattern = pattern;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public IIngredient getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc172.furnace;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.mc172.util.MineTweakerUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class TweakerFurnace implements IFurnaceManager {
|
||||
public TweakerFurnace() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(IIngredient ingredient) {
|
||||
Map<ItemStack, ItemStack> smeltingList = FurnaceRecipes.smelting().getSmeltingList();
|
||||
|
||||
List<ItemStack> toRemove = new ArrayList<ItemStack>();
|
||||
List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
||||
for (Map.Entry<ItemStack, ItemStack> entry : smeltingList.entrySet()) {
|
||||
if (ingredient.matches(new TweakerItemStack(entry.getValue()))) {
|
||||
toRemove.add(entry.getKey());
|
||||
toRemoveValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.isEmpty()) {
|
||||
MineTweakerAPI.logger.logWarning("No furnace recipes for " + ingredient.toString());
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new RemoveAction(toRemove, toRemoveValues));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(IItemStack output, IIngredient input, double xp) {
|
||||
List<IItemStack> items = input.getItems();
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logger.logError("Cannot turn " + input.toString() + " into a furnace recipe");
|
||||
}
|
||||
|
||||
ItemStack[] items2 = MineTweakerUtil.getItemStacks(items);
|
||||
ItemStack output2 = (ItemStack) output.getInternal();
|
||||
MineTweakerAPI.tweaker.apply(new AddRecipeAction(items2, output2, xp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuel(IIngredient item, int fuel) {
|
||||
// TODO: complete this method
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFuel(IItemStack item) {
|
||||
return GameRegistry.getFuelValue((ItemStack) item.getInternal());
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class RemoveAction implements IUndoableAction {
|
||||
private final List<ItemStack> items;
|
||||
private final List<ItemStack> values;
|
||||
|
||||
public RemoveAction(List<ItemStack> items, List<ItemStack> values) {
|
||||
this.items = items;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (ItemStack item : items) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
FurnaceRecipes.smelting().getSmeltingList().put(items.get(i), values.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + items.size() + " furnace recipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + items.size() + " furnace recipes";
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final ItemStack[] input;
|
||||
private final ItemStack output;
|
||||
private final double xp;
|
||||
|
||||
public AddRecipeAction(ItemStack[] input, ItemStack output, double xp) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (ItemStack inputStack : input) {
|
||||
FurnaceRecipes.smelting().func_151396_a(inputStack.getItem(), output, (float) xp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,11 @@ import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.mc172.oredict.OreDictEntry;
|
||||
import minetweaker.mc172.util.MineTweakerHacks;import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.mc172.util.MineTweakerHacks;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.recipes.IRecipeFunction;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -251,8 +251,7 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
for (int i = 0; i < iContents.length; i++) {
|
||||
inventory.setInventorySlotContents(i, iContents[i]);
|
||||
}
|
||||
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, Minecraft.getMinecraft().theWorld);
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, null);
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
@@ -27,7 +27,18 @@ public class MineTweakerUtil {
|
||||
return output;
|
||||
}
|
||||
|
||||
public static IItemStack[] getItemStacks(ItemStack... items) {
|
||||
public static ItemStack[] getItemStacks(List<IItemStack> items) {
|
||||
ItemStack[] output = new ItemStack[items.size()];
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Object internal = items.get(i).getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static IItemStack[] getIItemStacks(ItemStack... items) {
|
||||
IItemStack[] result = new IItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new TweakerItemStack(items[i]);
|
||||
@@ -35,7 +46,7 @@ public class MineTweakerUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IItemStack[] getItemStacks(List<ItemStack> items) {
|
||||
public static IItemStack[] getIItemStacks(List<ItemStack> items) {
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new TweakerItemStack(items.get(i));
|
||||
|
||||
+4
-1
@@ -58,7 +58,10 @@ public class Compressor {
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
RecipeOutput output = Recipes.compressor.getOutputFor((ItemStack) input.getInternal(), false);
|
||||
if (output == null || output.items.size() > 0) return null;
|
||||
if (output == null || output.items.size() > 0) {
|
||||
System.out.println("No output");
|
||||
return null;
|
||||
}
|
||||
return new TweakerItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -20,7 +20,7 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@ZenClass("mods.ic2.OreWasher")
|
||||
public class OreWasher {
|
||||
@ZenMethod
|
||||
public void addRecipe(IItemStack[] output, IIngredient input, int millibuckets) {
|
||||
public static void addRecipe(IItemStack[] output, IIngredient input, int millibuckets) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setInteger("amount", millibuckets);
|
||||
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
|
||||
@@ -32,7 +32,7 @@ public class OreWasher {
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack[] getOutput(IItemStack input) {
|
||||
public static IItemStack[] getOutput(IItemStack input) {
|
||||
RecipeOutput output = Recipes.oreWashing.getOutputFor((ItemStack) input.getInternal(), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return MineTweakerUtil.getItemStacks(output.items);
|
||||
|
||||
+3
-3
@@ -39,10 +39,10 @@ public class ThermalCentrifuge {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("minHeat", minHeat);
|
||||
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
|
||||
"compressor",
|
||||
Recipes.compressor,
|
||||
"thermal centrifuge",
|
||||
Recipes.centrifuge,
|
||||
MineTweakerUtil.getItemStacks(output),
|
||||
null,
|
||||
tag,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,6 @@ public class ExpressionTable extends Expression {
|
||||
|
||||
@Override
|
||||
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
|
||||
System.out.println("Casting Table to " + type.getName());
|
||||
|
||||
if (type instanceof ZenTypeAssociative) {
|
||||
ZenTypeAssociative keyType = (ZenTypeAssociative) type;
|
||||
Expression[] newKeys = new Expression[keys.length];
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
@@ -429,6 +430,7 @@ public class ZenTypeNative extends ZenType {
|
||||
*/
|
||||
private static boolean canCastImplicit(Class cls, ZenType type) {
|
||||
if (isEqual(cls, type)) return true;
|
||||
if (type == BOOL) return true;
|
||||
if (cls.getSuperclass() != null) {
|
||||
if (canCastImplicit(cls.getSuperclass(), type)) return true;
|
||||
}
|
||||
@@ -447,6 +449,7 @@ public class ZenTypeNative extends ZenType {
|
||||
*/
|
||||
private static boolean canCastImplicit(ZenType type, Class cls) {
|
||||
if (isEqual(cls, type)) return true;
|
||||
if (type == BOOL) return true;
|
||||
if (type instanceof ZenTypeNative) {
|
||||
Class clsFrom = ((ZenTypeNative) type).cls;
|
||||
return cls.isAssignableFrom(clsFrom);
|
||||
@@ -778,6 +781,14 @@ public class ZenTypeNative extends ZenType {
|
||||
}
|
||||
|
||||
MethodOutput output = environment.getOutput();
|
||||
if (toType == BOOL) {
|
||||
Label lbl = new Label();
|
||||
output.iConst0();
|
||||
output.ifNull(lbl);
|
||||
output.iConst1();
|
||||
output.label(lbl);
|
||||
return;
|
||||
}
|
||||
for (ZenNativeCaster caster : casters) {
|
||||
if (caster.getCasterClass() == toType.toJavaClass()) {
|
||||
caster.compile(output);
|
||||
|
||||
Reference in new issue
Block a user