Added projects and basic build scripts. Project for scripting engine, API, Main 1.7 version and one for each mod supported in 1.7.

This commit is contained in:
Stan Hebben committed 2014-06-09 20:33:30 +02:00
1 parent 219106f392
commit 38b78ce305
281 files changed
+25090 -49

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
.nb-gradle
build
.gradle
run
+14
View File
@@ -0,0 +1,14 @@
apply plugin: 'java'
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
task run << {
println "I'm a library!"
}
dependencies {
dependencies {
compile project(':ZenScript')
}
}
@@ -0,0 +1,19 @@
/*
* 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;
/**
*
* @author Stan
*/
public class GlobalFunctions {
private GlobalFunctions() {}
public static void print(String message) {
MineTweakerAPI.logger.logInfo(message);
}
}
@@ -0,0 +1,211 @@
/*
* 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;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import minetweaker.minecraft.item.IIngredient;
import stanhebben.zenscript.IZenErrorLogger;
import stanhebben.zenscript.TypeExpansion;
import stanhebben.zenscript.annotations.ZenExpansion;
import stanhebben.zenscript.compiler.TypeRegistry;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
import stanhebben.zenscript.symbols.IZenSymbol;
import stanhebben.zenscript.symbols.SymbolJavaStaticField;
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
import stanhebben.zenscript.symbols.SymbolPackage;
import stanhebben.zenscript.type.ZenTypeNative;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stan
*/
public class GlobalRegistry {
private static final Map<String, IZenSymbol> globals = new HashMap<String, IZenSymbol>();
private static final List<IRecipeRemover> removers = new ArrayList<IRecipeRemover>();
private static final List<IBracketHandler> bracketHandlers = new ArrayList<IBracketHandler>();
private static final TypeRegistry types = new TypeRegistry();
private static final SymbolPackage root = new SymbolPackage();
private static final IZenErrorLogger errors = new MyErrorLogger();
private static final IZenCompileEnvironment environment = new MyCompileEnvironment();
private static final Map<String, TypeExpansion> expansions = new HashMap<String, TypeExpansion>();
static {
register("print", getStaticFunction(GlobalFunctions.class, "print", String.class));
register("max", getStaticFunction(Math.class, "max", int.class, int.class));
register("min", getStaticFunction(Math.class, "min", int.class, int.class));
register("logger", getStaticField(MineTweakerAPI.class, "logger"));
register("minetweaker", getStaticField(MineTweakerAPI.class, "tweaker"));
register("recipes", getStaticField(MineTweakerAPI.class, "recipes"));
register("furnace", getStaticField(MineTweakerAPI.class, "furnace"));
register("oreDict", getStaticField(MineTweakerAPI.class, "oreDict"));
/*registerExpansion(ExpandAnyArray.class);
registerExpansion(ExpandAnyDict.class);
registerExpansion(ExpandBool.class);
registerExpansion(ExpandByte.class);
registerExpansion(ExpandDouble.class);
registerExpansion(ExpandFloat.class);
registerExpansion(ExpandInt.class);
registerExpansion(ExpandLong.class);
registerExpansion(ExpandShort.class);
registerExpansion(ExpandString.class);*/
/*registerNativeClass(IData.class);
registerNativeClass(IIngredient.class);
registerNativeClass(IItemCondition.class);
registerNativeClass(IItemDefinition.class);
registerNativeClass(IItemStack.class);
registerNativeClass(IItemTransformer.class);
registerNativeClass(Condition.class);
registerNativeClass(Transform.class);
registerNativeClass(ILiquidDefinition.class);
registerNativeClass(ILiquidStack.class);
registerNativeClass(IOreDict.class);
registerNativeClass(IOreDictEntry.class);
registerNativeClass(ICraftingInventory.class);
registerNativeClass(IFurnaceManager.class);
registerNativeClass(IRecipeFunction.class);*/
}
private GlobalRegistry() {}
public static void register(String name, IZenSymbol symbol) {
if (globals.containsKey(name)) {
throw new IllegalArgumentException("symbol already exists: " + name);
}
globals.put(name, symbol);
}
public static void registerExpansion(Class cls) {
for (Annotation annotation : cls.getAnnotationsByType(ZenExpansion.class)) {
ZenExpansion eAnnotation = (ZenExpansion) annotation;
if (!expansions.containsKey(eAnnotation.value())) {
expansions.put(eAnnotation.value(), new TypeExpansion());
}
expansions.get(eAnnotation.value()).expand(cls, types);
}
}
public static void registerRemover(IRecipeRemover remover) {
removers.add(remover);
}
public static void registerBracketHandler(IBracketHandler handler) {
bracketHandlers.add(handler);
}
public static void registerNativeClass(Class cls) {
ZenTypeNative type = new ZenTypeNative(cls);
type.complete(types);
root.put(type.getName(), root, errors);
}
public static TypeRegistry getTypeRegistry() {
return types;
}
public static void remove(IIngredient ingredient) {
for (IRecipeRemover remover : removers) {
remover.remove(ingredient);
}
}
public static IZenSymbol resolveBracket(List<Token> tokens) {
for (IBracketHandler handler : bracketHandlers) {
IZenSymbol symbol = handler.resolve(tokens);
if (symbol != null) {
return symbol;
}
}
return null;
}
public static IZenSymbol getStaticFunction(Class cls, String name, Class... arguments) {
JavaMethod method = JavaMethod.get(types, cls, name, arguments);
if (method == null) return null;
return new SymbolJavaStaticMethod(method);
}
public static IZenSymbol getStaticField(Class cls, String name) {
try {
Field field = cls.getDeclaredField(name);
return new SymbolJavaStaticField(cls, field, types);
} catch (NoSuchFieldException ex) {
Logger.getLogger(GlobalRegistry.class.getName()).log(Level.SEVERE, null, ex);
return null;
} catch (SecurityException ex) {
Logger.getLogger(GlobalRegistry.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
private static class MyErrorLogger implements IZenErrorLogger {
@Override
public void error(ZenPosition position, String message) {
MineTweakerAPI.logger.logError(position.toString() + ": " + message);
}
@Override
public void warning(ZenPosition position, String message) {
MineTweakerAPI.logger.logWarning(position.toString() + ": " + message);
}
}
private static class MyCompileEnvironment implements IZenCompileEnvironment {
@Override
public IZenErrorLogger getErrorLogger() {
return errors;
}
@Override
public IZenSymbol getGlobal(String name) {
if (globals.containsKey(name)) {
return globals.get(name);
} else {
return root.get(name);
}
}
@Override
public IZenSymbol getDollar(String name) {
return null;
}
@Override
public IZenSymbol getBracketed(List<Token> tokens) {
return resolveBracket(tokens);
}
@Override
public TypeRegistry getTypeRegistry() {
return types;
}
@Override
public TypeExpansion getExpansion(String type) {
return expansions.get(type);
}
}
}
@@ -0,0 +1,19 @@
/*
* 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;
import java.util.List;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
/**
*
* @author Stan
*/
public interface IBracketHandler {
public IZenSymbol resolve(List<Token> tokens);
}
@@ -0,0 +1,24 @@
/*
* 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;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
public interface ILogger {
@ZenMethod
public void logInfo(String message);
@ZenMethod
public void logWarning(String message);
@ZenMethod
public void logError(String message);
}
@@ -0,0 +1,44 @@
/*
* 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;
import java.util.List;
import minetweaker.minecraft.item.IIngredient;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
@ZenClass("minetweaker.MineTweaker")
public interface IMineTweaker {
/**
* Executes a specified MineTweaker action. Will print a log message and
* adds the action to the undo list.
*
* @param action action to execute
*/
public void apply(IUndoableAction action);
/**
* Removes a specific item from all known recipes handlers.
*
* @param items items to remove
*/
@ZenMethod
public void remove(IIngredient items);
/**
* Rolls back all actions performed by MineTweaker. Returns the list of
* actions that could not be rolled back (the "stuck" ones that are not
* undoable).
*
* @return stuck action list
*/
public List<IUndoableAction> rollback();
}
@@ -0,0 +1,17 @@
/*
* 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;
import minetweaker.minecraft.item.IIngredient;
/**
*
* @author Stan
*/
public interface IRecipeRemover {
public void remove(IIngredient ingredient);
}
@@ -0,0 +1,63 @@
package minetweaker;
/**
* Defines a (possibly) undoable action.
*
* Every modification made by a command must be registered to the Tweaker with
* the Tweaker.apply method. This enables MineTweaker to keep track of actions
* that have been performed, and enables them to be rolled back later on.
*
* Actions exist in two flavors: undoable and permanent. If an action returns
* canUndo(), the action is undoable, otherwise it is permanent. Permanent
* actions cannot be used in server scripts.
*
* @author Stan Hebben
*/
public interface IUndoableAction {
/**
* Executes what the action is supposed to do. This method can be called
* again if undo() has been called in between.
*/
public void apply();
/**
* Checks if this action can be undone. If this method returns true, it
* must implement undo() properly. If this method returns false, the action
* is considered permanent, undo() will never be called, and the action
* cannot be executed as part of a server script. Additionally, the
* minetweaker.clear() function will not work and minetweaker.canClear
* will return false.
*
* @return undoable status
*/
public boolean canUndo();
/**
* Undoes the action. Will only be called after apply() has been executed.
* After an undo, apply may be called again. They could be done multiple
* times in certain scenarios.
*/
public void undo();
/**
* Describes, in a single human-readable sentence, what this specific action
* is doing. Used in logging messages, lists, ...
*
* Try to be as descriptive as possible without being too verbose.
*
* Examples:
* - Adding Peach planks to the woodPlanks ore dictionary entry
* - Removing a recipe for Iron Ore
*
* @return the description of this action
*/
public String describe();
/**
* Describes what this action does if it is undone. Similar to the describe()
* method. No implementation is needed if the action cannot be undone.
*
* @return the description of this action, when undone
*/
public String describeUndo();
}
@@ -0,0 +1,53 @@
package minetweaker;
import minetweaker.minecraft.recipes.IRecipeManager;
import minetweaker.minecraft.oredict.IOreDict;
import minetweaker.minecraft.recipes.IFurnaceManager;
/**
* Provides access to the MineTweaker API.
*
* An implementing platform needs to do the following:
* - Set a logger
* - Set the ore dictionary
* - Set the recipe manager
* - Set the furnace manager
*
* - Register additional global symbols to the GlobalRegistry (recipes,
* minetweaker, oreDict, logger, as well as the official set of functions)
* - Register native classes using the GlobalRegistry
* - Register bracket handlers to resolve block/item/... references using the
* bracket syntax
*
* @author Stan Hebben
*/
public class MineTweakerAPI {
private MineTweakerAPI() {}
/**
* The Tweaker is where you apply undoable actions. Any kind of action that
* reloads with the scripts should always be submitted to the tweaker.
*/
public static final IMineTweaker tweaker = new Tweaker();
/**
* The logger can be used to write logging messages to the client. Error and
* warning messages should be relayed to admins for further handling.
*/
public static ILogger logger = null;
/**
* Access point to the ore dictionary.
*/
public static IOreDict oreDict = null;
/**
* Access point to the recipe manager.
*/
public static IRecipeManager recipes = null;
/**
* Access point to the furnace manager.
*/
public static IFurnaceManager furnace = null;
}
@@ -0,0 +1,26 @@
/*
* 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;
/**
*
* @author Stanneke
*/
public abstract class OneWayAction implements IUndoableAction {
@Override
public boolean canUndo() {
return false;
}
@Override
public void undo() {}
@Override
public String describeUndo() {
return "impossibru!";
}
}
@@ -0,0 +1,50 @@
/*
* 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;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import minetweaker.minecraft.item.IIngredient;
/**
*
*
* @author Stan Hebben
*/
public class Tweaker implements IMineTweaker {
List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
Set<IUndoableAction> wereStuck = new HashSet<IUndoableAction>();
@Override
public void apply(IUndoableAction action) {
MineTweakerAPI.logger.logInfo(action.describe());
action.apply();
}
@Override
public void remove(IIngredient items) {
GlobalRegistry.remove(items);
}
@Override
public List<IUndoableAction> rollback() {
List<IUndoableAction> stuck = new ArrayList<IUndoableAction>();
for (int i = actions.size() - 1; i >= 0; i--) {
IUndoableAction action = actions.get(i);
if (action.canUndo()) {
MineTweakerAPI.logger.logInfo(action.describeUndo());
action.undo();
} else {
stuck.add(0, action);
wereStuck.add(action);
}
}
return stuck;
}
}
@@ -0,0 +1,22 @@
/*
* 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.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
* @author Stan
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ModOnly {
public String value();
}
@@ -0,0 +1,25 @@
/*
* 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.expand;
import java.util.Arrays;
import minetweaker.minecraft.data.DataList;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("any[]")
public class ExpandAnyArray {
@ZenCaster
public IData asData(IData[] values) {
return new DataList(Arrays.asList(values), true);
}
}
@@ -0,0 +1,25 @@
/*
* 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.expand;
import java.util.Map;
import minetweaker.minecraft.data.DataMap;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("any[any]")
public class ExpandAnyDict {
@ZenCaster
public IData asData(Map<String, IData> values) {
return new DataMap(values, true);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataBool;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("bool")
public class ExpandBool {
@ZenCaster
public IData asData(boolean value) {
return new DataBool(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataByte;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("byte")
public class ExpandByte {
@ZenCaster
public IData asData(byte value) {
return new DataByte(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataDouble;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("double")
public class ExpandDouble {
@ZenCaster
public IData asData(double value) {
return new DataDouble(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataFloat;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("float")
public class ExpandFloat {
@ZenCaster
public IData asData(float value) {
return new DataFloat(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataInt;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("int")
public class ExpandInt {
@ZenCaster
public IData toData(int value) {
return new DataInt(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataLong;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("long")
public class ExpandLong {
@ZenCaster
public IData asData(long value) {
return new DataLong(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataShort;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("short")
public class ExpandShort {
@ZenCaster
public IData asNBT(short value) {
return new DataShort(value);
}
}
@@ -0,0 +1,24 @@
/*
* 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.expand;
import minetweaker.minecraft.data.DataString;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenExpansion;
/**
*
* @author Stanneke
*/
@ZenExpansion("string")
public class ExpandString {
@ZenCaster
public IData asData(String value) {
return new DataString(value);
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataBool implements IData {
private final boolean value;
public DataBool(boolean value) {
this.value = value;
}
@Override
public boolean asBool() {
return value;
}
@Override
public byte asByte() {
return (byte) (value ? 1 : 0);
}
@Override
public short asShort() {
return (short) (value ? 1 : 0);
}
@Override
public int asInt() {
return value ? 1 : 0;
}
@Override
public long asLong() {
return value ? 1 : 0;
}
@Override
public float asFloat() {
return value ? 1 : 0;
}
@Override
public double asDouble() {
return value ? 1 : 0;
}
@Override
public String asString() {
return Boolean.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a bool to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a bool to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("cannot cast a bool to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("cannot cast a bool to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("a bool is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("a bool is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("a bool is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("a bool is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asBool() == value;
}
@Override
public boolean equals(IData other) {
return value == other.asBool();
}
@Override
public int compareTo(IData other) {
throw new UnsupportedOperationException("Cannot compare bool values");
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromBool(value);
}
@Override
public IData add(IData other) {
throw new UnsupportedOperationException("Cannot add bool values");
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract bool values");
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply bool values");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide bool values");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on bool values");
}
@Override
public IData and(IData other) {
return new DataBool(value & other.asBool());
}
@Override
public IData or(IData other) {
return new DataBool(value | other.asBool());
}
@Override
public IData xor(IData other) {
return new DataBool(value ^ other.asBool());
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate a bool value");
}
@Override
public IData not() {
return new DataBool(!value);
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataByte implements IData {
private final byte value;
public DataByte(byte value) {
this.value = value;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot cast a byte to a bool");
}
@Override
public byte asByte() {
return value;
}
@Override
public short asShort() {
return value;
}
@Override
public int asInt() {
return value;
}
@Override
public long asLong() {
return value;
}
@Override
public float asFloat() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public String asString() {
return Byte.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot convert a byte to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot convert a byte to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a byte to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a byte to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("A byte is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("A byte is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("A byte is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("A byte is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asByte() == value;
}
@Override
public boolean equals(IData data) {
return value == data.asByte();
}
@Override
public int compareTo(IData data) {
return Byte.compare(value, data.asByte());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromByte(value);
}
@Override
public IData add(IData other) {
return new DataByte((byte) (value + other.asByte()));
}
@Override
public IData sub(IData other) {
return new DataByte((byte) (value - other.asByte()));
}
@Override
public IData mul(IData other) {
return new DataByte((byte) (value * other.asByte()));
}
@Override
public IData div(IData other) {
return new DataByte((byte) (value / other.asByte()));
}
@Override
public IData mod(IData other) {
return new DataByte((byte) (value % other.asByte()));
}
@Override
public IData and(IData other) {
return new DataByte((byte) (value & other.asByte()));
}
@Override
public IData or(IData other) {
return new DataByte((byte) (value | other.asByte()));
}
@Override
public IData xor(IData other) {
return new DataByte((byte) (value ^ other.asByte()));
}
@Override
public IData neg() {
return new DataByte((byte) (- value));
}
@Override
public IData not() {
return new DataByte((byte) (~ value));
}
}
@@ -0,0 +1,220 @@
/*
* 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.minecraft.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataByteArray implements IData {
private final byte[] data;
private final boolean immutable;
public DataByteArray(byte[] data, boolean immutable) {
this.data = data;
this.immutable = immutable;
}
@Override
public IData add(IData other) {
byte[] otherData = other.asByteArray();
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
System.arraycopy(otherData, 0, result, data.length, otherData.length);
return new DataByteArray(result, immutable);
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract from a byte array");
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply with an arary");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide an array");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on an array");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate arrays");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public boolean asBool() {
throw new UnsupportedOperationException("Cannot cast an array to bool");
}
@Override
public byte asByte() {
throw new UnsupportedOperationException("Cannot cast an array to byte");
}
@Override
public short asShort() {
throw new UnsupportedOperationException("Cannot cast an array to short");
}
@Override
public int asInt() {
throw new UnsupportedOperationException("Cannot cast an array to int");
}
@Override
public long asLong() {
throw new UnsupportedOperationException("Cannot cast an array to long");
}
@Override
public float asFloat() {
throw new UnsupportedOperationException("Cannot cast an array to float");
}
@Override
public double asDouble() {
throw new UnsupportedOperationException("Cannot cast an array to double");
}
@Override
public String asString() {
StringBuilder result = new StringBuilder();
result.append("X\"");
for (byte value : data) {
String str = Integer.toHexString(value);
if (str.length() == 1) {
result.append('0');
}
result.append(str);
}
result.append('"');
return result.toString();
}
@Override
public List<IData> asList() {
List<IData> result = new ArrayList<IData>();
for (byte value : data) {
result.add(new DataByte(value));
}
return result;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot convert list to map");
}
@Override
public byte[] asByteArray() {
return data;
}
@Override
public int[] asIntArray() {
int[] result = new int[data.length];
for (int i = 0; i < result.length; i++) {
result[i] = data[i];
}
return result;
}
@Override
public IData getAt(int i) {
return new DataByte(data[i]);
}
@Override
public void setAt(int i, IData value) {
if (immutable) {
throw new UnsupportedOperationException("Cannot modify this byte array");
} else {
data[i] = value.asByte();
}
}
@Override
public IData memberGet(String name) {
throw new UnsupportedOperationException("byte[] doesn't have members");
}
@Override
public void memberSet(String name, IData data) {
throw new UnsupportedOperationException("cannot set byte[] members");
}
@Override
public int length() {
return data.length;
}
@Override
public boolean contains(IData data) {
return equals(data);
}
@Override
public int compareTo(IData data) {
throw new UnsupportedOperationException("Cannot compare arrays");
}
@Override
public boolean equals(IData data) {
return Arrays.equals(this.data, data.asByteArray());
}
@Override
public IData immutable() {
if (immutable) {
return this;
} else {
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
}
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromByteArray(this.data);
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataDouble implements IData {
private final double value;
public DataDouble(double value) {
this.value = value;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot cast a double to a bool");
}
@Override
public byte asByte() {
return (byte) value;
}
@Override
public short asShort() {
return (short) value;
}
@Override
public int asInt() {
return (int) value;
}
@Override
public long asLong() {
return (long) value;
}
@Override
public float asFloat() {
return (float) value;
}
@Override
public double asDouble() {
return value;
}
@Override
public String asString() {
return Double.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a double to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a double to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a double to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a double to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("A double is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("A double is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("A double is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("A double is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asDouble() == value;
}
@Override
public boolean equals(IData other) {
return value == other.asDouble();
}
@Override
public int compareTo(IData other) {
return Double.compare(value, other.asDouble());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromDouble(value);
}
@Override
public IData add(IData other) {
return new DataDouble(value + other.asDouble());
}
@Override
public IData sub(IData other) {
return new DataDouble(value - other.asDouble());
}
@Override
public IData mul(IData other) {
return new DataDouble(value * other.asDouble());
}
@Override
public IData div(IData other) {
return new DataDouble(value / other.asDouble());
}
@Override
public IData mod(IData other) {
return new DataDouble(value % other.asDouble());
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
}
@Override
public IData neg() {
return new DataDouble(- value);
}
@Override
public IData not() {
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataFloat implements IData {
private final float value;
public DataFloat(float value) {
this.value = value;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot cast a float to a bool");
}
@Override
public byte asByte() {
return (byte) value;
}
@Override
public short asShort() {
return (short) value;
}
@Override
public int asInt() {
return (int) value;
}
@Override
public long asLong() {
return (long) value;
}
@Override
public float asFloat() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public String asString() {
return Float.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a float to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a float to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a float to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a float to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("A float is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("A float is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("A float is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("A float is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asFloat() == value;
}
@Override
public boolean equals(IData data) {
return value == data.asFloat();
}
@Override
public int compareTo(IData data) {
return Float.compare(value, data.asFloat());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromFloat(value);
}
@Override
public IData add(IData other) {
return new DataFloat(value + other.asFloat());
}
@Override
public IData sub(IData other) {
return new DataFloat(value - other.asFloat());
}
@Override
public IData mul(IData other) {
return new DataFloat(value * other.asFloat());
}
@Override
public IData div(IData other) {
return new DataFloat(value / other.asFloat());
}
@Override
public IData mod(IData other) {
return new DataFloat(value % other.asFloat());
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
}
@Override
public IData neg() {
return new DataFloat(- value);
}
@Override
public IData not() {
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataInt implements IData {
private final int value;
public DataInt(int value) {
this.value = value;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot cast an int to a bool");
}
@Override
public byte asByte() {
return (byte) value;
}
@Override
public short asShort() {
return (short) value;
}
@Override
public int asInt() {
return value;
}
@Override
public long asLong() {
return value;
}
@Override
public float asFloat() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public String asString() {
return Integer.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast an int to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast an int to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast an int to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast an int to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("An int is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("An int is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("An int is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("An int is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asInt() == value;
}
@Override
public boolean equals(IData data) {
return value == data.asInt();
}
@Override
public int compareTo(IData data) {
return Integer.compare(value, data.asInt());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromInt(value);
}
@Override
public IData add(IData other) {
return new DataInt(value + other.asInt());
}
@Override
public IData sub(IData other) {
return new DataInt(value - other.asInt());
}
@Override
public IData mul(IData other) {
return new DataInt(value * other.asInt());
}
@Override
public IData div(IData other) {
return new DataInt(value / other.asInt());
}
@Override
public IData mod(IData other) {
return new DataInt(value % other.asInt());
}
@Override
public IData and(IData other) {
return new DataInt(value & other.asInt());
}
@Override
public IData or(IData other) {
return new DataInt(value | other.asInt());
}
@Override
public IData xor(IData other) {
return new DataInt(value ^ other.asInt());
}
@Override
public IData neg() {
return new DataInt(- value);
}
@Override
public IData not() {
return new DataInt(~ value);
}
}
@@ -0,0 +1,222 @@
/*
* 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.minecraft.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataIntArray implements IData {
private final int[] data;
private final boolean immutable;
public DataIntArray(int[] data, boolean immutable) {
this.data = data;
this.immutable = immutable;
}
@Override
public IData add(IData other) {
int[] otherData = other.asIntArray();
int[] result = Arrays.copyOf(data, data.length + otherData.length);
System.arraycopy(otherData, 0, result, data.length, otherData.length);
return new DataIntArray(result, immutable);
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract from an int array");
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply with an arary");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide an array");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on an array");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate arrays");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
}
@Override
public boolean asBool() {
throw new UnsupportedOperationException("Cannot cast an array to bool");
}
@Override
public byte asByte() {
throw new UnsupportedOperationException("Cannot cast an array to byte");
}
@Override
public short asShort() {
throw new UnsupportedOperationException("Cannot cast an array to short");
}
@Override
public int asInt() {
throw new UnsupportedOperationException("Cannot cast an array to int");
}
@Override
public long asLong() {
throw new UnsupportedOperationException("Cannot cast an array to long");
}
@Override
public float asFloat() {
throw new UnsupportedOperationException("Cannot cast an array to float");
}
@Override
public double asDouble() {
throw new UnsupportedOperationException("Cannot cast an array to double");
}
@Override
public String asString() {
StringBuilder result = new StringBuilder();
result.append('[');
boolean first = true;
for (int value : data) {
if (first) {
first = false;
} else {
result.append(", ");
}
result.append(value);
}
result.append(']');
return result.toString();
}
@Override
public List<IData> asList() {
List<IData> result = new ArrayList<IData>();
for (int value : data) {
result.add(new DataInt(value));
}
return result;
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot convert list to map");
}
@Override
public byte[] asByteArray() {
byte[] result = new byte[data.length];
for (int i = 0; i < result.length; i++) {
result[i] = (byte) data[i];
}
return result;
}
@Override
public int[] asIntArray() {
return data;
}
@Override
public IData getAt(int i) {
return new DataInt(data[i]);
}
@Override
public void setAt(int i, IData value) {
if (immutable) {
throw new UnsupportedOperationException("Cannot modify this byte array");
} else {
data[i] = value.asInt();
}
}
@Override
public IData memberGet(String name) {
throw new UnsupportedOperationException("int[] doesn't have members");
}
@Override
public void memberSet(String name, IData data) {
throw new UnsupportedOperationException("cannot set int[] members");
}
@Override
public int length() {
return data.length;
}
@Override
public boolean contains(IData data) {
return equals(data);
}
@Override
public int compareTo(IData data) {
throw new UnsupportedOperationException("Cannot compare arrays");
}
@Override
public boolean equals(IData data) {
return Arrays.equals(this.data, data.asIntArray());
}
@Override
public IData immutable() {
if (immutable) {
return this;
} else {
return new DataIntArray(Arrays.copyOf(this.data, this.data.length), true);
}
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromIntArray(this.data);
}
}
@@ -0,0 +1,243 @@
/*
* 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.minecraft.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataList implements IData {
private final List<IData> values;
private final boolean immutable;
public DataList(List<IData> values, boolean immutable) {
this.values = values;
this.immutable = immutable;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot convert a list to a bool");
}
@Override
public byte asByte() {
throw new RuntimeException("Cannot convert a list to a byte");
}
@Override
public short asShort() {
throw new RuntimeException("Cannot convert a list to a short");
}
@Override
public int asInt() {
throw new RuntimeException("Cannot convert a list to an int");
}
@Override
public long asLong() {
throw new RuntimeException("Cannot convert a list to a long");
}
@Override
public float asFloat() {
throw new RuntimeException("Cannot convert a list to a float");
}
@Override
public double asDouble() {
throw new RuntimeException("Cannot convert a list to a double");
}
@Override
public List<IData> asList() {
if (immutable) {
return Collections.unmodifiableList(values);
} else {
return values;
}
}
@Override
public Map<String, IData> asMap() {
throw new RuntimeException("Cannot convert a list to a map");
}
@Override
public String asString() {
StringBuilder output = new StringBuilder();
output.append('[');
boolean first = true;
for (IData value : values) {
if (first) {
first = false;
} else {
output.append(", ");
}
output.append(value.asString());
}
output.append(']');
return output.toString();
}
@Override
public byte[] asByteArray() {
byte[] result = new byte[values.size()];
for (int i = 0; i < values.size(); i++) {
result[i] = values.get(i).asByte();
}
return result;
}
@Override
public int[] asIntArray() {
int[] result = new int[values.size()];
for (int i = 0; i < values.size(); i++) {
result[i] = values.get(i).asInt();
}
return result;
}
@Override
public IData getAt(int i) {
return values.get(i);
}
@Override
public void setAt(int i, IData value) {
if (immutable) {
throw new RuntimeException("this list is immutable");
} else {
values.set(i, value);
}
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("Lists don't have members");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("Lists don't have members");
}
@Override
public int length() {
return values.size();
}
@Override
public boolean contains(IData data) {
for (IData value : values) {
if (value.equals(data)) return true;
}
return false;
}
@Override
public boolean equals(IData data) {
List<IData> otherValues = data.asList();
if (otherValues.size() != values.size()) return false;
for (int i = 0; i < values.size(); i++) {
if (!values.get(i).equals(otherValues.get(i))) return false;
}
return true;
}
@Override
public int compareTo(IData data) {
throw new UnsupportedOperationException("Cannot compare with a list");
}
@Override
public IData immutable() {
if (immutable) {
return this;
} else {
List<IData> copy = new ArrayList<IData>();
for (IData value : values) {
copy.add(value.immutable());
}
return new DataList(copy, true);
}
}
@Override
public IData update(IData data) {
if (immutable) data = data.immutable();
List<IData> result = new ArrayList<IData>();
result.addAll(values);
result.addAll(data.asList());
return new DataList(result, immutable);
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromList(values);
}
@Override
public IData add(IData other) {
return update(other);
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract from a list");
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply a list");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide a list");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on a list");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Lists don't support bitwise operators");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Lists don't support bitwise operators");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Lists don't support bitwise operators");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate a list");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Lists don't support bitwise operators");
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataLong implements IData {
private final long value;
public DataLong(long value) {
this.value = value;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot cast a long to a bool");
}
@Override
public byte asByte() {
return (byte) value;
}
@Override
public short asShort() {
return (short) value;
}
@Override
public int asInt() {
return (int) value;
}
@Override
public long asLong() {
return value;
}
@Override
public float asFloat() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public String asString() {
return Long.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a long to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a long to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a long to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a long to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("A long is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("A long is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("A long is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("A long is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asLong() == value;
}
@Override
public boolean equals(IData data) {
return value == data.asLong();
}
@Override
public int compareTo(IData data) {
return Long.compare(value, data.asLong());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromLong(value);
}
@Override
public IData add(IData other) {
return new DataLong(value + other.asLong());
}
@Override
public IData sub(IData other) {
return new DataLong(value - other.asLong());
}
@Override
public IData mul(IData other) {
return new DataLong(value * other.asLong());
}
@Override
public IData div(IData other) {
return new DataLong(value / other.asLong());
}
@Override
public IData mod(IData other) {
return new DataLong(value % other.asLong());
}
@Override
public IData and(IData other) {
return new DataLong(value & other.asLong());
}
@Override
public IData or(IData other) {
return new DataLong(value | other.asLong());
}
@Override
public IData xor(IData other) {
return new DataLong(value ^ other.asLong());
}
@Override
public IData neg() {
return new DataLong(- value);
}
@Override
public IData not() {
return new DataLong(~ value);
}
}
@@ -0,0 +1,272 @@
/*
* 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.minecraft.data;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataMap implements IData {
private final Map<String, IData> data;
private final boolean immutable;
public DataMap(Map<String, IData> data, boolean immutable) {
this.data = data;
this.immutable = immutable;
}
@Override
public IData add(IData other) {
Map<String, IData> result = new HashMap<String, IData>();
Map<String, IData> otherMap = other.asMap();
for (Map.Entry<String, IData> entry : data.entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, IData> entry : otherMap.entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
return new DataMap(result, immutable);
}
@Override
public IData sub(IData other) {
Map<String, IData> result = new HashMap<String, IData>();
Map<String, IData> otherMap = other.asMap();
for (Map.Entry<String, IData> entry : data.entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
for (String key : otherMap.keySet()) {
result.remove(key);
}
return new DataMap(result, immutable);
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply maps");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide maps");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo with maps");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Maps do not support bitwise operations");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Maps do not support bitwise operations");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Maps do not support bitwise operations");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate maps.");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Maps do not support bitwise operations");
}
@Override
public boolean asBool() {
throw new UnsupportedOperationException("Cannot cast map to bool");
}
@Override
public byte asByte() {
throw new UnsupportedOperationException("Cannot cast map to byte");
}
@Override
public short asShort() {
throw new UnsupportedOperationException("Cannot cast map to short");
}
@Override
public int asInt() {
throw new UnsupportedOperationException("Cannot cast map to int");
}
@Override
public long asLong() {
throw new UnsupportedOperationException("Cannot cast map to long");
}
@Override
public float asFloat() {
throw new UnsupportedOperationException("Cannot cast map to float");
}
@Override
public double asDouble() {
throw new UnsupportedOperationException("Cannot cast map to double");
}
@Override
public String asString() {
StringBuilder result = new StringBuilder();
result.append('{');
boolean first = false;
for (Map.Entry<String, IData> entry : data.entrySet()) {
if (first) {
first = false;
} else {
result.append(", ");
}
result.append(entry.getKey());
result.append(": ");
result.append(entry.getValue().asString());
}
result.append('}');
return result.toString();
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast map to list");
}
@Override
public Map<String, IData> asMap() {
if (immutable) {
return Collections.unmodifiableMap(data);
} else {
return data;
}
}
@Override
public byte[] asByteArray() {
throw new UnsupportedOperationException("Cannot cast map to byte[]");
}
@Override
public int[] asIntArray() {
throw new UnsupportedOperationException("Cannot cast map to int[]");
}
@Override
public IData getAt(int i) {
throw new UnsupportedOperationException("Cannot index maps with integers");
}
@Override
public void setAt(int i, IData value) {
throw new UnsupportedOperationException("Cannot index maps with integers");
}
@Override
public IData memberGet(String name) {
return data.get(name);
}
@Override
public void memberSet(String name, IData data) {
if (immutable) {
throw new UnsupportedOperationException("this map is not modifiable");
} else {
this.data.put(name, data);
}
}
@Override
public int length() {
return data.size();
}
@Override
public boolean contains(IData data) {
Map<String, IData> dataMap = data.asMap();
for (Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
if (!this.data.containsKey(dataEntry.getKey())) {
return false;
} else if (!this.data.get(dataEntry.getKey()).contains(data)) {
return false;
}
}
return true;
}
@Override
public int compareTo(IData data) {
throw new UnsupportedOperationException("Cannot compare maps");
}
@Override
public boolean equals(IData data) {
if (this == data) return true;
Map<String, IData> dataMap = data.asMap();
if (dataMap.size() != this.data.size()) return false;
for (Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
if (!dataMap.containsKey(dataEntry.getKey())) {
return false;
} else if (!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
return false;
}
}
return true;
}
@Override
public IData immutable() {
if (immutable) {
return this;
} else {
Map<String, IData> result = new HashMap<String, IData>();
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
result.put(entry.getKey(), entry.getValue().immutable());
}
return new DataMap(result, true);
}
}
@Override
public IData update(IData data) {
if (immutable) data = data.immutable();
Map<String, IData> result = new HashMap<String, IData>();
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, IData> entry : data.asMap().entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
return new DataMap(result, immutable);
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromMap(data);
}
}
@@ -0,0 +1,187 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataShort implements IData {
private final short value;
public DataShort(short value) {
this.value = value;
}
@Override
public boolean asBool() {
throw new RuntimeException("Cannot cast a short to a bool");
}
@Override
public byte asByte() {
return (byte) value;
}
@Override
public short asShort() {
return value;
}
@Override
public int asInt() {
return value;
}
@Override
public long asLong() {
return value;
}
@Override
public float asFloat() {
return value;
}
@Override
public double asDouble() {
return value;
}
@Override
public String asString() {
return Short.toString(value);
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a short to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a short to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a short to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a short to an int array");
}
@Override
public IData getAt(int i) {
throw new RuntimeException("A short is not indexable");
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("A short is not indexable");
}
@Override
public IData memberGet(String name) {
throw new RuntimeException("A short is not indexable");
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("A short is not indexable");
}
@Override
public int length() {
return 0;
}
@Override
public boolean contains(IData data) {
return data.asShort() == value;
}
@Override
public boolean equals(IData data) {
return value == data.asShort();
}
@Override
public int compareTo(IData data) {
return Short.compare(value, data.asShort());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromShort(value);
}
@Override
public IData add(IData other) {
return new DataShort((short) (value + other.asShort()));
}
@Override
public IData sub(IData other) {
return new DataShort((short) (value - other.asShort()));
}
@Override
public IData mul(IData other) {
return new DataShort((short) (value * other.asShort()));
}
@Override
public IData div(IData other) {
return new DataShort((short) (value / other.asShort()));
}
@Override
public IData mod(IData other) {
return new DataShort((short) (value % other.asShort()));
}
@Override
public IData and(IData other) {
return new DataShort((short) (value & other.asShort()));
}
@Override
public IData or(IData other) {
return new DataShort((short) (value | other.asShort()));
}
@Override
public IData xor(IData other) {
return new DataShort((short) (value ^ other.asShort()));
}
@Override
public IData neg() {
return new DataShort((short) (- value));
}
@Override
public IData not() {
return new DataShort((short) (~ value));
}
}
@@ -0,0 +1,191 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
*/
public class DataString implements IData {
private final String value;
public DataString(String value) {
this.value = value;
}
@Override
public boolean asBool() {
return Boolean.parseBoolean(value);
}
@Override
public byte asByte() {
return Byte.parseByte(value);
}
@Override
public short asShort() {
return Short.parseShort(value);
}
@Override
public int asInt() {
return Integer.parseInt(value);
}
@Override
public long asLong() {
return Long.parseLong(value);
}
@Override
public float asFloat() {
return Float.parseFloat(value);
}
@Override
public double asDouble() {
return Double.parseDouble(value);
}
@Override
public String asString() {
return value;
}
@Override
public List<IData> asList() {
throw new UnsupportedOperationException("Cannot cast a string to a list");
}
@Override
public Map<String, IData> asMap() {
throw new UnsupportedOperationException("Cannot cast a string to a map");
}
@Override
public byte[] asByteArray() {
throw new RuntimeException("Cannot cast a string to a byte array");
}
@Override
public int[] asIntArray() {
throw new RuntimeException("Cannot cast a string to an int array");
}
@Override
public IData getAt(int i) {
return new DataString(value.substring(i, i + 1));
}
@Override
public void setAt(int i, IData value) {
throw new RuntimeException("Strings are immutable");
}
@Override
public IData memberGet(String name) {
if (name.equals("length")) {
return new DataInt(value.length());
} else {
throw new RuntimeException("no such member: " + name);
}
}
@Override
public void memberSet(String name, IData data) {
throw new RuntimeException("Strings are immutable");
}
@Override
public int length() {
return value.length();
}
@Override
public boolean contains(IData data) {
return data.asString().equals(value);
}
@Override
public boolean equals(IData data) {
return value.equals(data.asString());
}
@Override
public int compareTo(IData data) {
return value.compareTo(data.asString());
}
@Override
public IData immutable() {
return this;
}
@Override
public IData update(IData data) {
return data;
}
@Override
public <T> T convert(IDataConverter<T> converter) {
return converter.fromString(value);
}
@Override
public IData add(IData other) {
return new DataString(value + other.asString());
}
@Override
public IData sub(IData other) {
throw new UnsupportedOperationException("Cannot subtract from a string");
}
@Override
public IData mul(IData other) {
throw new UnsupportedOperationException("Cannot multiply a string");
}
@Override
public IData div(IData other) {
throw new UnsupportedOperationException("Cannot divide a string");
}
@Override
public IData mod(IData other) {
throw new UnsupportedOperationException("Cannot perform modulo on a string");
}
@Override
public IData and(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
}
@Override
public IData or(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
}
@Override
public IData xor(IData other) {
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
}
@Override
public IData neg() {
throw new UnsupportedOperationException("Cannot negate a string");
}
@Override
public IData not() {
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
}
}
@@ -0,0 +1,123 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMemberGetter;
import stanhebben.zenscript.annotations.ZenMemberSetter;
import stanhebben.zenscript.annotations.ZenOperator;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
@ZenClass("minecraft.data.IData")
public interface IData {
@ZenOperator(OperatorType.ADD)
public IData add(IData other);
@ZenOperator(OperatorType.SUB)
public IData sub(IData other);
@ZenOperator(OperatorType.MUL)
public IData mul(IData other);
@ZenOperator(OperatorType.DIV)
public IData div(IData other);
@ZenOperator(OperatorType.MOD)
public IData mod(IData other);
@ZenOperator(OperatorType.AND)
public IData and(IData other);
@ZenOperator(OperatorType.OR)
public IData or(IData other);
@ZenOperator(OperatorType.XOR)
public IData xor(IData other);
@ZenOperator(OperatorType.NEG)
public IData neg();
@ZenOperator(OperatorType.NOT)
public IData not();
@ZenCaster
public boolean asBool();
@ZenCaster
public byte asByte();
@ZenCaster
public short asShort();
@ZenCaster
public int asInt();
@ZenCaster
public long asLong();
@ZenCaster
public float asFloat();
@ZenCaster
public double asDouble();
@ZenCaster
public String asString();
@ZenCaster
public List<IData> asList();
@ZenCaster
public Map<String, IData> asMap();
@ZenCaster
public byte[] asByteArray();
@ZenCaster
public int[] asIntArray();
@ZenOperator(OperatorType.INDEXGET)
public IData getAt(int i);
@ZenOperator(OperatorType.INDEXSET)
public void setAt(int i, IData value);
@ZenMemberGetter
public IData memberGet(String name);
@ZenMemberSetter
public void memberSet(String name, IData data);
@ZenGetter
public int length();
@ZenOperator(OperatorType.CONTAINS)
public boolean contains(IData data);
@ZenOperator(OperatorType.COMPARE)
public int compareTo(IData data);
@ZenOperator(OperatorType.EQUALS)
public boolean equals(IData data);
@ZenGetter
public IData immutable();
@ZenMethod
public IData update(IData data);
public <T> T convert(IDataConverter<T> converter);
}
@@ -0,0 +1,41 @@
/*
* 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.minecraft.data;
import java.util.List;
import java.util.Map;
/**
*
* @author Stan
* @param <T> output type
*/
public interface IDataConverter<T> {
public T fromBool(boolean value);
public T fromByte(byte value);
public T fromShort(short value);
public T fromInt(int value);
public T fromLong(long value);
public T fromFloat(float value);
public T fromDouble(double value);
public T fromString(String value);
public T fromList(List<IData> values);
public T fromMap(Map<String, IData> values);
public T fromByteArray(byte[] value);
public T fromIntArray(int[] value);
}
@@ -0,0 +1,121 @@
/*
* 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.minecraft.item;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* Conditions can be used to set requirements for matching items. They can be
* used to require specific NBT tags or damage values, requiring changed items
* or as complement to damage-consuming or stack-consuming recipes.
*
* @author Stan Hebben
*/
@ZenClass("minecraft.item.Condition")
public class Condition {
/**
* Requires the item to be damaged. A damage value of 1 is enough.
*
* @return damaged condition
*/
@ZenGetter
public static IItemCondition damaged() {
return new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getDamage() > 0;
}
};
}
/**
* Requires the item to be damaged with at least a specified amount.
*
* @param minDamage minimum damage
* @return damage condition
*/
@ZenMethod
public static IItemCondition damageAtLeast(final int minDamage) {
return new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getDamage() >= minDamage;
}
};
}
/**
* Requires the item to be damaged with at most a specified amount. An
* undamaged item is accepted.
*
* @param maxDamage maximum damage
* @return damage condition
*/
@ZenMethod
public static IItemCondition damageAtMost(final int maxDamage) {
return new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getDamage() <= maxDamage;
}
};
}
/**
* Requires the item damage value to be between two values.
*
* @param minDamage minimum damage
* @param maxDamage maximum damage
* @return damage condition
*/
@ZenMethod
public static IItemCondition damageBetween(final int minDamage, final int maxDamage) {
return new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage;
}
};
}
/**
* Requires the item to contain at least the given tags. It is OK for the
* item to contain more data, as remaining data is ignored.
*
* @param data required data
* @return data condition
*/
@ZenMethod
public static IItemCondition data(final IData data) {
return new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getTag() != null && stack.getTag().contains(data);
}
};
}
/**
* Requires the input stack to contain at least the given number of items.
* Used in combination with stack consuming recipes.
*
* @param amount required stack size
* @return stack size condition
*/
@ZenMethod
public static IItemCondition stack(final int amount) {
return new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getAmount() >= amount;
}
};
}
}
@@ -0,0 +1,121 @@
package minetweaker.minecraft.item;
import java.util.List;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenOperator;
/**
* Represents a recipe ingredient. An ingredient can be an item, an ore
* dictionary entry, an item stack, an ore dictionary entry multiplied with
* an amount, or other kinds of ingredients as offered by the API.
*
* There is no guarantee that every mod will respect the conditions or
* transformations, or that every mod will support every kind of ingredient.
*
* @author Stan Hebben
*/
@ZenClass("minecraft.item.IIngredient")
public interface IIngredient {
/**
* Gets the mark of the ingredient. Ingredients can be marked so they can
* be used in crafting functions.
*
* @return ingredient mark
*/
@ZenGetter("mark")
public String getMark();
/**
* Gets the amount. Should return -1 if no amount is available and 1 for
* a single item. Stacks return the stack size.
*
* @return stack size
*/
@ZenGetter("amount")
public int getAmount();
/**
* Gets all possible items for this ingredient. If there is no item list
* (for example, it is the &lt;*&gt; wildcard item) null should be returned.
*
* @return the items for this ingredient, or null
*/
@ZenGetter("items")
public List<IItemStack> getItems();
/**
* Returns a new ingredient with the given stack size.
*
* @param amount new stack size
* @return modified ingredient
*/
@ZenOperator(OperatorType.MUL)
@ZenMethod
public IIngredient amount(int amount);
/**
* Returns a new ingredient with the given transform added to it.
*
* @param transformer transformer to add
* @return modified ingredient
*/
@ZenMethod
public IIngredient transform(IItemTransformer transformer);
/**
* Returns a new ingredient with the given condition added to it.
*
* @param condition condition to add
* @return modified ingredient
*/
@ZenMethod
public IIngredient only(IItemCondition condition);
/**
* Returns a new ingredient marked with the given name.
*
* @param mark mark to apply
* @return modified ingredient
*/
@ZenMethod
public IIngredient marked(String mark);
/**
* Checks if this ingredient matches the given item.
*
* @param item item to check
* @return true if the item matches
*/
@ZenMethod
public boolean matches(IItemStack item);
/**
* Check if this ingredient contains all possible values for the given
* ingredient.
*
* @param ingredient ingredient to check
* @return true if the ingredient contains the given one
*/
@ZenOperator(OperatorType.CONTAINS)
public boolean contains(IIngredient ingredient);
/**
* Applies transformations, if any, to the given item.
*
* @param item item to transform
* @return transformed item
*/
@ZenMethod
public IItemStack applyTransform(IItemStack item);
/**
* Gets the internal item backing this ingredient. The value is
* implementation-dependent.
*
* @return internal item
*/
public Object getInternal();
}
@@ -0,0 +1,18 @@
/*
* 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.minecraft.item;
import stanhebben.zenscript.annotations.ZenClass;
/**
*
* @author Stan
*/
@ZenClass("minecraft.item.IItemCondition")
public interface IItemCondition {
public boolean matches(IItemStack stack);
}
@@ -0,0 +1,15 @@
/*
* 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.minecraft.item;
/**
*
* @author Stan
*/
public interface IItemDefinition {
}
@@ -0,0 +1,56 @@
/*
* 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.minecraft.item;
import minetweaker.minecraft.data.IData;
import minetweaker.minecraft.liquid.ILiquidStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
@ZenClass("minecraft.item.IItemStack")
public interface IItemStack extends IIngredient {
@ZenGetter("definition")
public IItemDefinition getDefinition();
@ZenGetter("name")
public String getName();
@ZenGetter("displayName")
public String getDisplayName();
@ZenGetter("damage")
public int getDamage();
@ZenGetter("tag")
public IData getTag();
@ZenGetter("maxDamage")
public int getMaxDamage();
@ZenGetter("liquid")
public ILiquidStack getLiquid();
@ZenMethod
public IIngredient anyDamage();
@ZenMethod
public IItemStack withDamage(int damage);
@ZenMethod
public IItemStack withAmount(int amount);
@ZenMethod
public IItemStack withTag(IData tag);
@ZenMethod
public IItemStack updateTag(IData tagUpdate);
}
@@ -0,0 +1,30 @@
/*
* 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.minecraft.item;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* An item transformer modifies an item stack. Used to apply damage, grab multiple
* items, change NBT tags, replace the item with something else - or whatever
* else you'd want to happen to the input stack.
*
* @author Stan Hebben
*/
@ZenClass("minetweaker.IItemTransformer")
public interface IItemTransformer {
/**
* Transforms the specified item. May modify this item (and return it)
* or return an entirely new one.
*
* @param item input item
* @return output item
*/
@ZenMethod
public IItemStack transform(IItemStack item);
}
@@ -0,0 +1,75 @@
/*
* 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.minecraft.item;
import java.util.List;
/**
*
* @author Stan
*/
public class IngredientAny implements IIngredient {
public static IngredientAny INSTANCE = new IngredientAny();
public static Object INTERNAL_ANY = null; // platforms supporting an "any" item should fill it here
private IngredientAny() {}
@Override
public String getMark() {
return null;
}
@Override
public int getAmount() {
return -1;
}
@Override
public List<IItemStack> getItems() {
return null;
}
@Override
public IIngredient amount(int amount) {
return new IngredientStack(this, amount);
}
@Override
public IIngredient transform(IItemTransformer transformer) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public IIngredient only(IItemCondition condition) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public IIngredient marked(String mark) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean matches(IItemStack item) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean contains(IIngredient ingredient) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public IItemStack applyTransform(IItemStack item) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Object getInternal() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
@@ -0,0 +1,102 @@
/*
* 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.minecraft.item;
import java.util.Collections;
import java.util.List;
import minetweaker.minecraft.util.ArrayUtil;
/**
*
* @author Stan
*/
public class IngredientItem implements IIngredient {
private final IItemStack item;
private final String mark;
private final IItemCondition[] conditions;
private final IItemTransformer[] transformers;
private final List<IItemStack> items;
public IngredientItem(IItemStack item, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
this.item = item;
this.mark = mark;
this.conditions = conditions;
this.transformers = transformers;
items = Collections.singletonList(item);
}
@Override
public String getMark() {
return mark;
}
@Override
public int getAmount() {
return item.getAmount();
}
@Override
public List<IItemStack> getItems() {
return items;
}
@Override
public IIngredient amount(int amount) {
return new IngredientStack(this, amount);
}
@Override
public IIngredient transform(IItemTransformer transformer) {
return new IngredientItem(item, mark, conditions, ArrayUtil.append(transformers, transformer));
}
@Override
public IIngredient only(IItemCondition condition) {
return new IngredientItem(item, mark, ArrayUtil.append(conditions, condition), transformers);
}
@Override
public IIngredient marked(String mark) {
return new IngredientItem(item, mark, conditions, transformers);
}
@Override
public boolean matches(IItemStack item) {
if (!item.matches(item)) return false;
for (IItemCondition condition : conditions) {
if (!condition.matches(item)) return false;
}
return true;
}
@Override
public boolean contains(IIngredient ingredient) {
List<IItemStack> iitems = ingredient.getItems();
for (IItemStack iitem : iitems) {
if (!matches(iitem)) return false;
}
return true;
}
@Override
public IItemStack applyTransform(IItemStack item) {
for (IItemTransformer transform : transformers) {
item = transform.transform(item);
}
return item;
}
@Override
public Object getInternal() {
return item.getInternal();
}
}
@@ -0,0 +1,78 @@
/*
* 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.minecraft.item;
import java.util.List;
/**
*
* @author Stan
*/
public class IngredientStack implements IIngredient {
private final IIngredient ingredient;
private final int amount;
public IngredientStack(IIngredient ingredient, int amount) {
this.ingredient = ingredient;
this.amount = amount;
}
@Override
public String getMark() {
return null;
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<IItemStack> getItems() {
return ingredient.getItems();
}
@Override
public IIngredient amount(int amount) {
return new IngredientStack(ingredient, amount);
}
@Override
public IIngredient transform(IItemTransformer transformer) {
return new IngredientStack(ingredient.transform(transformer), amount);
}
@Override
public IIngredient only(IItemCondition condition) {
return new IngredientStack(ingredient.only(condition), amount);
}
@Override
public IIngredient marked(String mark) {
return new IngredientStack(ingredient.marked(mark), amount);
}
@Override
public boolean matches(IItemStack item) {
return item.getAmount() == amount && ingredient.matches(item);
}
@Override
public boolean contains(IIngredient ingredient) {
return this.ingredient.contains(ingredient);
}
@Override
public IItemStack applyTransform(IItemStack item) {
return ingredient.applyTransform(item);
}
@Override
public Object getInternal() {
return null;
}
}
@@ -0,0 +1,114 @@
/*
* 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.minecraft.item;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
@ZenClass("minecraft.item.Transform")
public class Transform {
/**
* Makes the item reusable. Prevents consumption of the item upon crafting.
*
* @return reuse transformer
*/
@ZenMethod
public IItemTransformer reuse() {
return new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
return item.withAmount(item.getAmount() + 1);
}
};
}
/**
* Damages the item. Also makes the item reusable. Will damage the item
* for 1 point upon crafting and consume it when broken.
*
* @return damage transformer
*/
@ZenMethod
public IItemTransformer damage() {
return new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
int newDamage = item.getDamage() + 1;
if (newDamage >= item.getMaxDamage()) {
return item.withAmount(item.getAmount() - 1).withDamage(0);
} else {
return item.withDamage(newDamage);
}
}
};
}
/**
* Damages the item for a specific amount. Also makes the item reusable.
* Upon reaching maximum damage, the item will be consumed. Take care to
* set the proper condition such that an almost-broken item becomes
* invalid for crafting.
*
* @param damage damage to be applied
* @return damage transformer
*/
@ZenMethod
public IItemTransformer damage(final int damage) {
return new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
int newDamage = item.getDamage() + damage;
if (newDamage >= item.getMaxDamage()) {
return item.withAmount(item.getAmount() - 1).withDamage(newDamage - item.getMaxDamage());
} else {
return item.withDamage(newDamage);
}
}
};
}
/**
* Causes the item to be replaced upon crafting. Can be used, for instance,
* to return empty bottles or buckets.
*
* @param withItem replacement item
* @return replacement transformer
*/
@ZenMethod
public IItemTransformer replaceWith(IItemStack withItem) {
final IItemStack result = withItem.withAmount(withItem.getAmount() + 1);
return new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
return result;
}
};
}
/**
* Causes multiple items to be consumed. Take care to set a condition for
* a minimum stack size too, as otherwise smaller stacks would still be
* accepted for input.
*
* @param amount consumption amount
* @return consuming transformer
*/
@ZenMethod
public IItemTransformer consume(final int amount) {
return new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
return item.withAmount(Math.max(item.getAmount() - amount, 0) + 1);
}
};
}
}
@@ -0,0 +1,53 @@
/*
* 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.minecraft.liquid;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenOperator;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenSetter;
/**
*
* @author Stanneke
*/
@ZenClass("minecraft.liquid.ILiquidDefinition")
public interface ILiquidDefinition {
@ZenOperator(OperatorType.MUL)
public ILiquidStack asStack(int millibuckets);
@ZenGetter("luminosity")
public int getLuminosity();
@ZenSetter("luminosity")
public void setLuminosity(int value);
@ZenGetter("density")
public int getDensity();
@ZenSetter("density")
public void setDensity(int density);
@ZenGetter("temperature")
public int getTemperature();
@ZenSetter("temperature")
public void setTemperature(int temperature);
@ZenGetter("viscosity")
public int getViscosity();
@ZenSetter("viscosity")
public void setViscosity(int viscosity);
@ZenGetter("gaseous")
public boolean isGaseous();
@ZenSetter("gaseous")
public void setGaseous(boolean gaseous);
}
@@ -0,0 +1,51 @@
/*
* 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.minecraft.liquid;
import minetweaker.minecraft.data.IData;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stanneke
*/
@ZenClass("minecraft.liquid.ILiquidStack")
public interface ILiquidStack {
@ZenGetter("definition")
public ILiquidDefinition getDefinition();
@ZenGetter("amount")
public int getAmount();
@ZenGetter("luminosity")
public int getLuminosity();
@ZenGetter("density")
public int getDensity();
@ZenGetter("temperature")
public int getTemperature();
@ZenGetter("viscosity")
public int getViscosity();
@ZenGetter("gaseous")
public boolean isGaseous();
@ZenGetter("tag")
public IData getTag();
@ZenMethod
public ILiquidStack withTag(IData data);
@ZenMethod
public ILiquidStack withAmount(int amount);
public Object getInternal();
}
@@ -0,0 +1,20 @@
/*
* 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.minecraft.oredict;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMemberGetter;
/**
*
* @author Stan
*/
@ZenClass("minecraft.oredict.IOreDict")
public interface IOreDict {
@ZenMemberGetter
public IOreDictEntry get(String name);
}
@@ -0,0 +1,34 @@
/*
* 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.minecraft.oredict;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
@ZenClass("minecraft.oreDict.IOreDictEntry")
public interface IOreDictEntry extends IIngredient {
@ZenMethod
public void add(IItemStack item);
@ZenMethod
public void addAll(IOreDictEntry entry);
@ZenMethod
public void remove(IItemStack item);
@ZenMethod
public boolean contains(IItemStack item);
@ZenMethod
public void mirror(IOreDictEntry other);
}
@@ -0,0 +1,102 @@
/*
* 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.minecraft.oredict;
import java.util.List;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemCondition;
import minetweaker.minecraft.item.IItemStack;
import minetweaker.minecraft.item.IItemTransformer;
import minetweaker.minecraft.item.IngredientStack;
import minetweaker.minecraft.util.ArrayUtil;
/**
*
* @author Stan Hebben
*/
public class IngredientOreDict implements IIngredient {
private final IOreDictEntry entry;
private final String mark;
private final IItemCondition[] conditions;
private final IItemTransformer[] transformers;
public IngredientOreDict(
IOreDictEntry entry,
String mark,
IItemCondition[] conditions,
IItemTransformer[] transformers) {
this.entry = entry;
this.mark = mark;
this.conditions = conditions;
this.transformers = transformers;
}
@Override
public String getMark() {
return mark;
}
@Override
public int getAmount() {
return 1;
}
@Override
public List<IItemStack> getItems() {
return entry.getItems();
}
@Override
public IIngredient amount(int amount) {
return new IngredientStack(this, amount);
}
@Override
public IIngredient transform(IItemTransformer transformer) {
return new IngredientOreDict(entry, mark, conditions, ArrayUtil.append(transformers, transformer));
}
@Override
public IIngredient only(IItemCondition condition) {
return new IngredientOreDict(entry, mark, ArrayUtil.append(conditions, condition), transformers);
}
@Override
public IIngredient marked(String mark) {
return new IngredientOreDict(entry, mark, conditions, transformers);
}
@Override
public boolean matches(IItemStack item) {
if (!entry.matches(item)) return false;
for (IItemCondition condition : conditions) {
if (!condition.matches(item)) return false;
}
return true;
}
@Override
public boolean contains(IIngredient ingredient) {
return entry.contains(ingredient);
}
@Override
public IItemStack applyTransform(IItemStack item) {
for (IItemTransformer transformer : transformers) {
item = transformer.transform(item);
}
return item;
}
@Override
public Object getInternal() {
return entry.getInternal();
}
}
@@ -0,0 +1,29 @@
/*
* 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.minecraft.recipes;
import minetweaker.minecraft.item.IItemStack;
/**
*
* @author Stan
*/
public interface ICraftingInventory {
public int getSize();
public int getWidth();
public int getHeight();
public IItemStack getStack(int i);
public IItemStack getStack(int x, int y);
public void setStack(int x, int y, IItemStack stack);
public void setStack(int i, IItemStack stack);
}
@@ -0,0 +1,30 @@
/*
* 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.minecraft.recipes;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
public interface IFurnaceManager {
@ZenMethod
public void remove(IIngredient ingredient);
@ZenMethod
public void addRecipe(IIngredient output, IIngredient input, @Optional double xp);
@ZenMethod
public void setFuel(IIngredient item, int fuel);
@ZenMethod
public int getFuel(IItemStack item);
}
@@ -0,0 +1,18 @@
/*
* 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.minecraft.recipes;
import java.util.Map;
import minetweaker.minecraft.item.IItemStack;
/**
*
* @author Stan
*/
public interface IRecipeFunction {
public IItemStack process(IItemStack output, Map<String, IItemStack> inputs);
}
@@ -0,0 +1,89 @@
package minetweaker.minecraft.recipes;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* The RecipeManager adds and removes crafting recipes. The IRecipeManager
* instance is available throug the recipes global variable.
*
* @author Stan Hebben
*/
@ZenClass("minetweaker.recipes.IRecipeManager")
public interface IRecipeManager {
/**
* Removes all crafting recipes crafting the specified item.
*
* @param output recipe output pattern
* @return number of removed recipes
*/
@ZenMethod
public int remove(IIngredient output);
/**
* Adds a shaped recipe.
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param function recipe function (optional)
* @param mirrored indicates if the mirrored recipe should be valid too (optional)
*/
@ZenMethod
public void addShaped(
IItemStack output,
IIngredient[][] ingredients,
@Optional IRecipeFunction function,
@Optional boolean mirrored);
/**
* Adds a shapeless recipe.
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param function recipe function (optional)
*/
@ZenMethod
public void addShapeless(
IItemStack output,
IIngredient[] ingredients,
@Optional IRecipeFunction function);
/**
* Removes shaped recipes.
*
* @param output recipe output
* @param ingredients recipe ingredients
* @return number of removed recipes
*/
@ZenMethod
public int removeShaped(
IIngredient output,
@Optional IIngredient[][] ingredients);
/**
* Removes shapeless recipes.
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param wildcard if the recipe may contain other ingredients too, besides the ones specified
* @return number of removed recipes
*/
@ZenMethod
public int removeShapeless(
IIngredient output,
@Optional IIngredient[] ingredients,
@Optional boolean wildcard);
/**
* Performs a crafting with the specified ingredients. Returns null if no
* crafting recipe exists.
*
* @param contents crafting inventory contents
* @return crafting result, or null
*/
@ZenMethod
public IItemStack craft(IItemStack[][] contents);
}
@@ -0,0 +1,217 @@
/*
* 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.minecraft.recipes;
import java.util.HashMap;
import java.util.Map;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
/**
*
* @author Stan
*/
public class ShapedRecipe {
private final int width;
private final int height;
private final byte[] posx;
private final byte[] posy;
private final boolean mirrored;
private final IRecipeFunction function;
private final IItemStack output;
private final IIngredient[] ingredients;
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
int numIngredients = 0;
for (IIngredient[] row : ingredients) {
for (IIngredient ingredient : row) {
if (ingredient != null) {
numIngredients++;
}
}
}
this.posx = new byte[numIngredients];
this.posy = new byte[numIngredients];
this.output = output;
this.ingredients = new IIngredient[numIngredients];
this.function = function;
int width1 = 0;
int height1 = ingredients.length;
int ix = 0;
for (int j = 0; j < ingredients.length; j++) {
IIngredient[] row = ingredients[j];
width1 = Math.max(width1, row.length);
for (int i = 0; i < row.length; i++) {
if (row[i] != null) {
this.posx[ix] = (byte) i;
this.posy[ix] = (byte) j;
this.ingredients[ix] = row[i];
ix++;
}
}
}
this.width = width1;
this.height = height1;
this.mirrored = mirrored;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public boolean isMirrored() {
return mirrored;
}
public IIngredient[] getIngredients() {
return ingredients;
}
public byte[] getIngredientsX() {
return posx;
}
public byte[] getIngredientsY() {
return posy;
}
public IItemStack getOutput() {
return output;
}
public boolean matches(ICraftingInventory inventory) {
int numItems = 0;
for (int i = 0; i < inventory.getSize(); i++) {
if (inventory.getStack(i) != null) {
numItems++;
}
}
if (numItems != ingredients.length) {
return false;
}
for (int i = 0; i < inventory.getWidth() - width; i++) {
out: for (int j = 0; j < inventory.getHeight() - height; j++) {
for (int k = 0; k < ingredients.length; k++) {
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
if (item == null) continue out;
if (!ingredients[k].matches(item)) continue out;
}
return true;
}
}
if (mirrored) {
for (int i = 0; i < inventory.getWidth() - width; i++) {
out: for (int j = 0; j < inventory.getHeight() - height; j++) {
for (int k = 0; k < ingredients.length; k++) {
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i), posy[k] + j);
if (item == null) continue out;
if (!ingredients[k].matches(item)) continue out;
}
return true;
}
}
}
return false;
}
public IItemStack getCraftingResult(ICraftingInventory inventory) {
IItemStack[] stacks = new IItemStack[ingredients.length];
for (int i = 0; i < inventory.getWidth() - width; i++) {
out: for (int j = 0; j < inventory.getHeight() - height; j++) {
for (int k = 0; k < ingredients.length; k++) {
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
if (item == null) continue out;
if (!ingredients[k].matches(item)) continue out;
stacks[k] = item;
}
return doRecipe(inventory, stacks, i, j, output, false);
}
}
if (mirrored) {
for (int i = 0; i < inventory.getWidth() - width; i++) {
out: for (int j = 0; j < inventory.getHeight() - height; j++) {
for (int k = 0; k < ingredients.length; k++) {
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i), posy[k] + j);
if (item == null) continue out;
if (!ingredients[k].matches(item)) continue out;
stacks[k] = item;
}
return doRecipe(inventory, stacks, i, j, output, true);
}
}
}
return null;
}
private IItemStack doRecipe(
ICraftingInventory inventory,
IItemStack[] stacks,
int offx, int offy,
IItemStack output,
boolean mirrored) {
// determine output and apply transformations
if (function != null) {
Map<String, IItemStack> tagged = new HashMap<String, IItemStack>();
for (int k = 0; k < ingredients.length; k++) {
if (ingredients[k].getMark() != null) {
tagged.put(ingredients[k].getMark(), stacks[k]);
}
}
output = function.process(output, tagged);
}
if (output == null) {
return null;
}
for (int i = 0; i < ingredients.length; i++) {
IItemStack transformed = ingredients[i].applyTransform(stacks[i]);
if (transformed != stacks[i]) {
if (mirrored) {
inventory.setStack(
inventory.getWidth() - (offx + posx[i]),
offy + posy[i],
transformed);
} else {
inventory.setStack(
offx + posx[i],
offy + posy[i],
transformed);
}
}
}
return output;
}
}
@@ -0,0 +1,128 @@
/*
* 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.minecraft.recipes;
import java.util.HashMap;
import java.util.Map;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
/**
*
* @author Stan
*/
public class ShapelessRecipe {
private final IItemStack output;
private final IRecipeFunction function;
private final IIngredient[] ingredients;
public ShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function) {
this.output = output;
this.function = function;
this.ingredients = ingredients;
}
public int getSize() {
return ingredients.length;
}
public IIngredient[] getIngredients() {
return ingredients;
}
public IItemStack getOutput() {
return output;
}
public boolean matches(ICraftingInventory inventory) {
return matchShapeless(ingredients, inventory) != null;
}
public IItemStack getCraftingResult(ICraftingInventory inventory) {
RecipeMatching matching = matchShapeless(ingredients, inventory);
IItemStack actualOutput = output;
if (function != null) {
Map<String, IItemStack> map = new HashMap<String, IItemStack>();
for (int i = 0; i < ingredients.length; i++) {
if (ingredients[i].getMark() != null) {
map.put(ingredients[i].getMark(), matching.inputs[i]);
}
}
actualOutput = function.process(actualOutput, map);
}
if (actualOutput == null) {
return null;
}
for (int i = 0; i < ingredients.length; i++) {
IIngredient ingredient = ingredients[i];
IItemStack transformed = ingredient.applyTransform(matching.inputs[i]);
if (transformed != matching.inputs[i]) {
inventory.setStack(matching.indices[i], transformed);
}
}
return actualOutput;
}
/**
* Reorders ingredients to match the given shapeless recipe.
*
* @param recipe shapeless recipe
* @param ingredients crafting input
* @return reordered inputs, or null if no match was found
*/
private static RecipeMatching matchShapeless(
IIngredient[] recipe,
ICraftingInventory ingredients) {
int numItems = 0;
for (int i = 0; i < ingredients.getSize(); i++) {
if (ingredients.getStack(i) != null) {
numItems++;
}
}
if (numItems != recipe.length) {
return null;
}
IItemStack[] matched = new IItemStack[recipe.length];
int[] indices = new int[recipe.length];
outer: for (int i = 0; i < ingredients.getSize(); i++) {
IItemStack ingredient = ingredients.getStack(i);
if (ingredient == null) continue;
for (int j = 0; j < recipe.length; j++) {
if (matched[j] != null) continue;
if (recipe[j].matches(ingredient)) {
matched[j] = ingredient;
indices[j] = i;
continue outer;
}
}
return null;
}
return new RecipeMatching(matched, indices);
}
private static class RecipeMatching {
public final IItemStack[] inputs;
public final int[] indices;
public RecipeMatching(IItemStack[] inputs, int[] indices) {
this.inputs = inputs;
this.indices = indices;
}
}
}
@@ -0,0 +1,32 @@
/*
* 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.minecraft.util;
import java.util.Arrays;
import minetweaker.minecraft.item.IItemCondition;
import minetweaker.minecraft.item.IItemTransformer;
/**
*
* @author Stan
*/
public class ArrayUtil {
public static final IItemCondition[] EMPTY_CONDITIONS = new IItemCondition[0];
public static final IItemTransformer[] EMPTY_TRANSFORMERS = new IItemTransformer[0];
public static IItemCondition[] append(IItemCondition[] values, IItemCondition value) {
IItemCondition[] result = Arrays.copyOf(values, values.length + 1);
result[values.length] = value;
return result;
}
public static IItemTransformer[] append(IItemTransformer[] values, IItemTransformer value) {
IItemTransformer[] result = Arrays.copyOf(values, values.length + 1);
result[values.length] = value;
return result;
}
}
+28
View File
@@ -0,0 +1,28 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
apply plugin: 'forge'
minecraft{version = "1.7.2-10.12.1.1112"}
version = "1.0"
archivesBaseName = project.projectDir.name
dependencies {
dependencies {
compile project(':ZenScript')
compile project(':MineTweaker3-API')
}
}
@@ -0,0 +1,264 @@
package minetweaker.mc172;
import java.util.Arrays;
import java.util.List;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
import stanhebben.zenscript.util.StringUtil;
/**
* Implements the /minetweaker command set.
*
* @author Stan Hebben
*/
public class MineTweakerCommand implements ICommand {
// ###########################
// ## Public static methods ##
// ###########################
public static void sendChatMessage(ICommandSender sender, String message) {
sender.addChatMessage(new ChatComponentText(message));
}
private static final List<String> aliases = Arrays.asList("mt");
// #######################################
// ## ICommand interface implementation ##
// #######################################
@Override
public int compareTo(Object arg0) {
return 0;
}
@Override
public String getCommandName() {
return "minetweaker";
}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
return StringUtil.join(new String[] {
"",
"minetweaker name <id>[:<meta>]",
" Prints the unlocalized name of the specified item," +
" can be used as item or block name",
"minetweaker liquid <id>[:<meta>]",
" Prints the unlocalized liquid name in the specified container," +
" con be used as liquid name",
"minetweaker oredict",
" Prints a list of all ore dictionary entries",
"minetweaker oredict <id>[:<meta>]",
" Prints the ore dictionary name(s) for the specified item",
"minetweaker oredict <name>",
" Prints all items for the specified ore dictionary name",
"minetweaker recipes <id>[:<meta>]",
" Prints all recipes for the specified item",
"minetweaker fuel <id>[:<meta>]",
" Retrieves the fuel value for the specified item",
"minetweaker reload",
" Reloads the server-side script (experimental)",
"minetweaker logdamage=on",
" Enables damage logging",
"minetweaker logdamage=off",
" Disables damage logging",
"minetweaker reload",
" Reloads the server script"
}, "\n");
}
@Override
public List<String> getCommandAliases() {
return aliases;
}
@Override
public void processCommand(ICommandSender icommandsender, String[] arguments) {
if (arguments.length == 0) {
sendChatMessage(icommandsender, "Please provide a command. Use /help minetweaker for more info.");
return;
}
if (arguments[0].equals("reload")) {
MineTweakerMod.instance.reloadScripts();
}
/*if (arguments[0].equals("name")) {
if (arguments.length < 2) {
sendChatMessage(icommandsender, "Please provide an item id");
} else {
try {
ITweakerItem item = TweakerItem.parse(arguments[1]);
sendChatMessage(icommandsender, "Name for " + item.toIdString() + ": " + MineTweakerUtil.formatItemName(item.getName()));
} catch (TweakerExecuteException ex) {
sendChatMessage(icommandsender, ex.getMessage());
} catch (TweakerException ex) {
sendChatMessage(icommandsender, ex.getExplanation());
}
}
} else if (arguments[0].equals("liquid")) {
if (arguments.length < 2) {
sendChatMessage(icommandsender, "Please provide a liquid container item id");
} else {
try {
TweakerItem item = TweakerItem.parse(arguments[1]);
//#ifdef MC152
//+if (LiquidContainerRegistry.isLiquid(item.make(1))) {
//+sendChatMessage(icommandsender, "Liquid name: " + item.getName());
//+} else if (LiquidContainerRegistry.isFilledContainer(item.make(1))) {
//+sendChatMessage(icommandsender, "Liquid name: " + LiquidContainerRegistry.getLiquidForFilledItem(item.make(1)).asItemStack().getItemName());
//+} else {
//+sendChatMessage(icommandsender, "This item is not a liquid or liquid container");
//+}
//#else
if (item.getItemId() == 9) {
sendChatMessage(icommandsender, "Liquid name: fluid.tile.water");
} else if (item.getItemId() == 11) {
sendChatMessage(icommandsender, "Liquid name: fluid.tile.lava");
} else if (Block.blocksList[item.getItemId()] != null && Block.blocksList[item.getItemId()] instanceof IFluidBlock) {
sendChatMessage(icommandsender, "Liquid name: " + ((IFluidBlock)(Block.blocksList[item.getItemId()])).getFluid().getUnlocalizedName());
} else if (FluidContainerRegistry.isFilledContainer(item.make(1))) {
sendChatMessage(icommandsender, "Liquid name: " + FluidContainerRegistry.getFluidForFilledItem(item.make(1)).getFluid().getUnlocalizedName());
} else {
sendChatMessage(icommandsender, "This item is not a liquid or liquid container");
}
//#endif
} catch (TweakerExecuteException ex) {
sendChatMessage(icommandsender, ex.getMessage());
} catch (TweakerException ex) {
sendChatMessage(icommandsender, ex.getExplanation());
}
}
} else if (arguments[0].equals("oredict")) {
if (arguments.length == 1) {
String[] names = OreDictionary.getOreNames();
Arrays.sort(names);
for (String name : names) {
sendChatMessage(icommandsender, "[" + name + "]");
ArrayList<ItemStack> entries = OreDictionary.getOres(name);
for (ItemStack stack : entries) {
//#ifdef MC152
//+sendChatMessage(icommandsender,
//+" " + MineTweakerUtil.getItemString(stack) + " - " +
//+MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItemName()));
//#else
sendChatMessage(icommandsender,
" " + MineTweakerUtil.getItemString(stack) + " - " +
MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getUnlocalizedName()));
//#endif
}
}
} else {
try {
if (Character.isDigit(arguments[1].charAt(0))) {
TweakerItemPattern item = TweakerItem.parse(arguments[1]).asItemPattern();
for (String name : OreDictionary.getOreNames()) {
for (ItemStack stack : OreDictionary.getOres(name)) {
if (item.matches(stack)) {
sendChatMessage(icommandsender, " " + name);
break;
}
}
}
} else {
for (ItemStack stack : OreDictionary.getOres(arguments[1])) {
//#ifdef MC152
//+sendChatMessage(icommandsender,
//+" " + MineTweakerUtil.getItemString(stack) + " - " +
//+MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItemName()));
//#else
sendChatMessage(icommandsender,
" " + MineTweakerUtil.getItemString(stack) + " - " +
MineTweakerUtil.formatItemName(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getUnlocalizedName()));
//#endif
}
}
} catch (TweakerExecuteException ex) {
sendChatMessage(icommandsender, "Invalid item id or ore dictionary entry");
} catch (TweakerException ex) {
sendChatMessage(icommandsender, "Invalid item id or ore dictionary entry");
}
}
} else if (arguments[0].equals("recipes")) {
if (arguments.length < 2) {
sendChatMessage(icommandsender, "Please provide an item id");
return;
}
try {
TweakerItem item = TweakerItem.parse(arguments[1]);
sendChatMessage(icommandsender, "Recipes for item " + item.toIdString());
TweakerItemPattern pattern = item.asItemPattern();
@SuppressWarnings("unchecked")
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe recipe : recipes) {
if (pattern.matches(recipe.getRecipeOutput())) {
sendChatMessage(icommandsender, " " + MineTweakerUtil.getRecipeString(recipe));
}
}
} catch (TweakerExecuteException ex) {
sendChatMessage(icommandsender, "Invalid item id");
} catch (TweakerException ex) {
sendChatMessage(icommandsender, "Invalid item id");
}
} else if (arguments[0].equals("fuel")) {
if (arguments.length < 2) {
sendChatMessage(icommandsender, "Please provide an item id");
return;
}
try {
TweakerItem item = TweakerItem.parse(arguments[1]);
ItemStack stack = item.make(1);
int value = TileEntityFurnace.getItemBurnTime(stack);
int regValue = GameRegistry.getFuelValue(stack);
sendChatMessage(icommandsender, "Fuel for " + item.toIdString() + " = " + value);
if (value != regValue) {
sendChatMessage(icommandsender, "The value is hardcoded and cannot be altered.");
}
} catch (TweakerExecuteException ex) {
sendChatMessage(icommandsender, "Invalid item id");
} catch (TweakerException ex) {
sendChatMessage(icommandsender, "Invalid item id");
}
} else if (arguments[0].equals("reload")) {
if (!MineTweaker.instance.canRollback()) {
sendChatMessage(icommandsender, "Previous server script contained permanent actions, cannot reload. A restart is required to reload scripts.");
} else {
MineTweaker.instance.reloadScripts();
sendChatMessage(icommandsender, "Script reloaded, updating all players");
}
} else if (arguments[0].equals("logdamage=on")) {
DamageTweaker.logDamage = true;
sendChatMessage(icommandsender, "Damage logging turned on");
sendChatMessage(icommandsender, "Info: logging is sent to the development console");
} else if (arguments[0].equals("logdamage=off")) {
DamageTweaker.logDamage = false;
sendChatMessage(icommandsender, "Damage logging turned off");
} else {
sendChatMessage(icommandsender, "Unrecognized minetweaker command");
}*/
//MineCraftCompat.sendChatMessage(icommandsender, "[" + Arrays2.join(arguments, ", ") + "]");
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender icommandsender) {
return true;
}
@Override
public List<?> addTabCompletionOptions(ICommandSender icommandsender,
String[] astring) {
return null;
}
@Override
public boolean isUsernameIndex(String[] astring, int i) {
return false;
}
}
@@ -0,0 +1,35 @@
/*
* 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;
import cpw.mods.fml.common.Mod;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.data.NBTConverter;
import minetweaker.mc172.oredict.OreDict;
import minetweaker.mc172.recipes.MTRecipeManager;
/**
*
* @author Stanneke
*/
@Mod(modid = MineTweakerMod.MODID, version = MineTweakerMod.MCVERSION + "-3.0.0")
public class MineTweakerMod {
public static final String MODID = "MineTweaker";
public static final String MCVERSION = "1.7.2";
@Mod.Instance(MODID)
public static MineTweakerMod instance;
public MineTweakerMod() {
MineTweakerAPI.oreDict = new OreDict();
MineTweakerAPI.recipes = new MTRecipeManager();
}
public void reloadScripts() {
// TODO: implements
}
}
@@ -0,0 +1,19 @@
/*
* 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;
import java.util.List;
/**
*
* @author Stan
*/
public class MineTweakerRegistry {
public static void getClasses(List<Class> classes) {
// method stub, actual content is generated by build process
}
}
@@ -0,0 +1,164 @@
/*
* 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.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import minetweaker.mc172.util.MineTweakerHacks;
import minetweaker.minecraft.data.DataByte;
import minetweaker.minecraft.data.DataByteArray;
import minetweaker.minecraft.data.DataDouble;
import minetweaker.minecraft.data.DataFloat;
import minetweaker.minecraft.data.DataInt;
import minetweaker.minecraft.data.DataIntArray;
import minetweaker.minecraft.data.DataList;
import minetweaker.minecraft.data.DataLong;
import minetweaker.minecraft.data.DataMap;
import minetweaker.minecraft.data.DataShort;
import minetweaker.minecraft.data.DataString;
import minetweaker.minecraft.data.IData;
import minetweaker.minecraft.data.IDataConverter;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
/**
*
* @author Stan
*/
public class NBTConverter implements IDataConverter<NBTBase> {
private static final NBTConverter INSTANCE = new NBTConverter();
public static NBTBase from(IData data) {
return data.convert(INSTANCE);
}
public static IData from(NBTBase nbt, boolean immutable) {
if (nbt == null) return null;
switch (nbt.getId()) {
case 1: // byte
return new DataByte(((NBTBase.NBTPrimitive) nbt).func_150290_f());
case 2: // short
return new DataShort(((NBTBase.NBTPrimitive) nbt).func_150289_e());
case 3: // int
return new DataInt(((NBTBase.NBTPrimitive) nbt).func_150287_d());
case 4: // long
return new DataLong(((NBTBase.NBTPrimitive) nbt).func_150291_c());
case 5: // float
return new DataFloat(((NBTBase.NBTPrimitive) nbt).func_150288_h());
case 6: // double
return new DataDouble(((NBTBase.NBTPrimitive) nbt).func_150286_g());
case 7: // byte[]
return new DataByteArray(((NBTTagByteArray) nbt).func_150292_c(), immutable);
case 8: // string
return new DataString(((NBTTagString) nbt).func_150285_a_());
case 9: { // list
List<IData> values = new ArrayList<IData>();
List<NBTBase> original = MineTweakerHacks.getTagList((NBTTagList) nbt);
for (NBTBase value : original) {
values.add(from(value, immutable));
}
return new DataList(values, immutable);
}
case 10: { // compound
Map<String, IData> values = new HashMap<String, IData>();
NBTTagCompound original = (NBTTagCompound) nbt;
for (String key : (Set<String>)original.func_150296_c()) {
values.put(key, from(original.getTag(key), immutable));
}
return new DataMap(values, immutable);
}
case 11: // int[]
return new DataIntArray(((NBTTagIntArray) nbt).func_150302_c(), immutable);
default:
throw new RuntimeException("Unknown tag type: " + nbt.getId());
}
}
private NBTConverter() {}
@Override
public NBTBase fromBool(boolean value) {
return new NBTTagInt(value ? 1 : 0);
}
@Override
public NBTBase fromByte(byte value) {
return new NBTTagByte(value);
}
@Override
public NBTBase fromShort(short value) {
return new NBTTagShort(value);
}
@Override
public NBTBase fromInt(int value) {
return new NBTTagInt(value);
}
@Override
public NBTBase fromLong(long value) {
return new NBTTagLong(value);
}
@Override
public NBTBase fromFloat(float value) {
return new NBTTagFloat(value);
}
@Override
public NBTBase fromDouble(double value) {
return new NBTTagDouble(value);
}
@Override
public NBTBase fromString(String value) {
return new NBTTagString(value);
}
@Override
public NBTBase fromList(List<IData> values) {
NBTTagList result = new NBTTagList();
for (IData value : values) {
result.appendTag(from(value));
}
return result;
}
@Override
public NBTBase fromMap(Map<String, IData> values) {
NBTTagCompound result = new NBTTagCompound();
for (Map.Entry<String, IData> entry : values.entrySet()) {
result.setTag(entry.getKey(), from(entry.getValue()));
}
return result;
}
@Override
public NBTBase fromByteArray(byte[] value) {
return new NBTTagByteArray(value);
}
@Override
public NBTBase fromIntArray(int[] value) {
return new NBTTagIntArray(value);
}
}
@@ -0,0 +1,22 @@
/*
* 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.item;
import minetweaker.minecraft.item.IItemDefinition;
import net.minecraft.item.Item;
/**
*
* @author Stan
*/
public class TweakerItemDefinition implements IItemDefinition {
private final Item item;
public TweakerItemDefinition(Item item) {
this.item = item;
}
}
@@ -0,0 +1,203 @@
/*
* 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.item;
import java.util.Collections;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.data.NBTConverter;
import minetweaker.mc172.liquid.TweakerLiquidStack;
import minetweaker.minecraft.data.IData;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemCondition;
import minetweaker.minecraft.item.IItemDefinition;
import minetweaker.minecraft.item.IItemStack;
import minetweaker.minecraft.item.IItemTransformer;
import minetweaker.minecraft.item.IngredientItem;
import minetweaker.minecraft.liquid.ILiquidStack;
import minetweaker.minecraft.util.ArrayUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
/**
*
* @author Stan
*/
public class TweakerItemStack implements IItemStack {
private final ItemStack stack;
private final List<IItemStack> items;
private IData tag = null;
public TweakerItemStack(ItemStack itemStack) {
stack = itemStack;
items = Collections.<IItemStack>singletonList(this);
}
private TweakerItemStack(ItemStack itemStack, IData tag) {
stack = itemStack;
items = Collections.<IItemStack>singletonList(this);
this.tag = tag;
}
@Override
public IItemDefinition getDefinition() {
return new TweakerItemDefinition(stack.getItem());
}
@Override
public String getName() {
return stack.getUnlocalizedName();
}
@Override
public String getDisplayName() {
return stack.getDisplayName();
}
@Override
public int getDamage() {
return stack.getItemDamage();
}
@Override
public IData getTag() {
if (tag == null) {
if (stack.stackTagCompound == null) {
return null;
}
tag = NBTConverter.from(stack.stackTagCompound, true);
}
return tag;
}
@Override
public int getMaxDamage() {
return stack.getMaxDamage();
}
@Override
public ILiquidStack getLiquid() {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
return liquid == null ? null : new TweakerLiquidStack(liquid);
}
@Override
public IIngredient anyDamage() {
if (stack.getItem().getHasSubtypes()) {
MineTweakerAPI.logger.logWarning("subitems don't have damaged states");
return this;
} else {
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, OreDictionary.WILDCARD_VALUE);
result.stackTagCompound = stack.stackTagCompound;
return new TweakerItemStack(result, tag);
}
}
@Override
public IItemStack withDamage(int damage) {
if (stack.getItem().getHasSubtypes()) {
MineTweakerAPI.logger.logWarning("subitems don't have damaged states");
return this;
} else {
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, damage);
result.stackTagCompound = stack.stackTagCompound;
return new TweakerItemStack(result, tag);
}
}
@Override
public IItemStack withAmount(int amount) {
ItemStack result = new ItemStack(stack.getItem(), amount, stack.getItemDamage());
result.stackTagCompound = stack.stackTagCompound;
return new TweakerItemStack(result, tag);
}
@Override
public IItemStack withTag(IData tag) {
ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage());
result.stackTagCompound = (NBTTagCompound) NBTConverter.from(tag);
return new TweakerItemStack(result, tag);
}
@Override
public IItemStack updateTag(IData tagUpdate) {
if (tag == null) {
if (stack.stackTagCompound == null) {
return withTag(tagUpdate);
}
tag = NBTConverter.from(stack.stackTagCompound, true);
}
IData updated = tag.update(tagUpdate);
return withTag(updated);
}
@Override
public String getMark() {
return null;
}
@Override
public int getAmount() {
return stack.stackSize;
}
@Override
public List<IItemStack> getItems() {
return items;
}
@Override
public IIngredient amount(int amount) {
return withAmount(amount);
}
@Override
public IIngredient transform(IItemTransformer transformer) {
return new IngredientItem(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
}
@Override
public IIngredient only(IItemCondition condition) {
return new IngredientItem(this, null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
}
@Override
public IIngredient marked(String mark) {
return new IngredientItem(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
}
@Override
public boolean matches(IItemStack item) {
ItemStack internal = (ItemStack) item.getInternal();
return internal.getItem() == stack.getItem()
&& internal.stackSize == stack.stackSize
&& (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack.getItemDamage() == internal.getItemDamage());
}
@Override
public boolean contains(IIngredient ingredient) {
List<IItemStack> iitems = ingredient.getItems();
if (iitems == null || iitems.size() != 1) return false;
return matches(iitems.get(0));
}
@Override
public IItemStack applyTransform(IItemStack item) {
return item;
}
@Override
public Object getInternal() {
return stack;
}
}
@@ -0,0 +1,260 @@
/*
* 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.liquid;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.minecraft.liquid.ILiquidDefinition;
import minetweaker.minecraft.liquid.ILiquidStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
/**
*
* @author Stan
*/
public class TweakerLiquidDefinition implements ILiquidDefinition {
private final Fluid fluid;
public TweakerLiquidDefinition(Fluid fluid) {
this.fluid = fluid;
}
@Override
public ILiquidStack asStack(int millibuckets) {
return new TweakerLiquidStack(new FluidStack(fluid, millibuckets));
}
@Override
public int getLuminosity() {
return fluid.getLuminosity();
}
@Override
public void setLuminosity(int value) {
MineTweakerAPI.tweaker.apply(new ActionSetLuminosity(value));
}
@Override
public int getDensity() {
return fluid.getDensity();
}
@Override
public void setDensity(int density) {
MineTweakerAPI.tweaker.apply(new ActionSetDensity(density));
}
@Override
public int getTemperature() {
return fluid.getTemperature();
}
@Override
public void setTemperature(int temperature) {
MineTweakerAPI.tweaker.apply(new ActionSetTemperature(temperature));
}
@Override
public int getViscosity() {
return fluid.getViscosity();
}
@Override
public void setViscosity(int viscosity) {
MineTweakerAPI.tweaker.apply(new ActionSetViscosity(viscosity));
}
@Override
public boolean isGaseous() {
return fluid.isGaseous();
}
@Override
public void setGaseous(boolean gaseous) {
MineTweakerAPI.tweaker.apply(new ActionSetGaseous(gaseous));
}
// ######################
// ### Action classes ###
// ######################
private class ActionSetLuminosity implements IUndoableAction {
private final int oldValue;
private final int newValue;
public ActionSetLuminosity(int newValue) {
oldValue = getLuminosity();
this.newValue = newValue;
}
@Override
public void apply() {
fluid.setLuminosity(newValue);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
fluid.setLuminosity(oldValue);
}
@Override
public String describe() {
return "Setting " + fluid.getName() + " luminosity to " + newValue;
}
@Override
public String describeUndo() {
return "Restoring " + fluid.getName() + " luminosity to " + oldValue;
}
}
private class ActionSetDensity implements IUndoableAction {
private final int oldValue;
private final int newValue;
public ActionSetDensity(int newValue) {
oldValue = getDensity();
this.newValue = newValue;
}
@Override
public void apply() {
fluid.setDensity(newValue);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
fluid.setDensity(oldValue);
}
@Override
public String describe() {
return "Setting " + fluid.getName() + " density to " + newValue;
}
@Override
public String describeUndo() {
return "Restoring " + fluid.getName() + " density to " + oldValue;
}
}
private class ActionSetTemperature implements IUndoableAction {
private final int oldValue;
private final int newValue;
public ActionSetTemperature(int newValue) {
oldValue = getTemperature();
this.newValue = newValue;
}
@Override
public void apply() {
fluid.setTemperature(newValue);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
fluid.setTemperature(oldValue);
}
@Override
public String describe() {
return "Setting " + fluid.getName() + " temperature to " + newValue;
}
@Override
public String describeUndo() {
return "Restoring " + fluid.getName() + " temperature to " + oldValue;
}
}
private class ActionSetViscosity implements IUndoableAction {
private final int oldValue;
private final int newValue;
public ActionSetViscosity(int newValue) {
oldValue = getViscosity();
this.newValue = newValue;
}
@Override
public void apply() {
fluid.setViscosity(newValue);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
fluid.setViscosity(oldValue);
}
@Override
public String describe() {
return "Setting " + fluid.getName() + " viscosity to " + newValue;
}
@Override
public String describeUndo() {
return "Restoring " + fluid.getName() + " viscosity to " + oldValue;
}
}
private class ActionSetGaseous implements IUndoableAction {
private final boolean oldValue;
private final boolean newValue;
public ActionSetGaseous(boolean newValue) {
oldValue = isGaseous();
this.newValue = newValue;
}
@Override
public void apply() {
fluid.setGaseous(newValue);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
fluid.setGaseous(oldValue);
}
@Override
public String describe() {
return "Setting " + fluid.getName() + " gaseous to " + newValue;
}
@Override
public String describeUndo() {
return "Restoring " + fluid.getName() + " gaseous to " + oldValue;
}
}
}
@@ -0,0 +1,99 @@
/*
* 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.liquid;
import minetweaker.mc172.data.NBTConverter;
import minetweaker.minecraft.data.IData;
import minetweaker.minecraft.liquid.ILiquidDefinition;
import minetweaker.minecraft.liquid.ILiquidStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
/**
*
* @author Stan
*/
public class TweakerLiquidStack implements ILiquidStack {
private final FluidStack stack;
private IData tag = null;
public TweakerLiquidStack(FluidStack stack) {
this.stack = stack;
}
private TweakerLiquidStack(FluidStack stack, IData tag) {
this.stack = stack;
this.tag = tag;
}
@Override
public ILiquidDefinition getDefinition() {
return new TweakerLiquidDefinition(stack.getFluid());
}
@Override
public int getAmount() {
return stack.amount;
}
@Override
public IData getTag() {
if (tag == null) {
if (stack.tag == null) {
return null;
}
tag = NBTConverter.from(stack.tag, true);
}
return tag;
}
@Override
public ILiquidStack withTag(IData data) {
FluidStack result = new FluidStack(stack.fluidID, stack.amount);
result.tag = (NBTTagCompound) NBTConverter.from(data);
return new TweakerLiquidStack(result, data.immutable());
}
@Override
public ILiquidStack withAmount(int amount) {
FluidStack result = new FluidStack(stack.fluidID, amount);
result.tag = stack.tag;
return new TweakerLiquidStack(result, tag);
}
@Override
public int getLuminosity() {
return stack.getFluid().getLuminosity(stack);
}
@Override
public int getDensity() {
return stack.getFluid().getDensity(stack);
}
@Override
public int getTemperature() {
return stack.getFluid().getTemperature(stack);
}
@Override
public int getViscosity() {
return stack.getFluid().getViscosity(stack);
}
@Override
public boolean isGaseous() {
return stack.getFluid().isGaseous(stack);
}
@Override
public Object getInternal() {
return stack;
}
}
@@ -0,0 +1,22 @@
/*
* 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.oredict;
import minetweaker.minecraft.oredict.IOreDict;
import minetweaker.minecraft.oredict.IOreDictEntry;
import net.minecraftforge.oredict.OreDictionary;
/**
*
* @author Stan
*/
public class OreDict implements IOreDict {
@Override
public IOreDictEntry get(String name) {
return new OreDictEntry(OreDictionary.getOreID(name));
}
}
@@ -0,0 +1,312 @@
/*
* 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.oredict;
import java.util.ArrayList;
import java.util.List;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.mc172.util.MineTweakerHacks;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemCondition;
import minetweaker.minecraft.item.IItemStack;
import minetweaker.minecraft.item.IItemTransformer;
import minetweaker.minecraft.item.IngredientStack;
import minetweaker.minecraft.oredict.IOreDictEntry;
import minetweaker.minecraft.oredict.IngredientOreDict;
import minetweaker.minecraft.util.ArrayUtil;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
*
* @author Stan
*/
public class OreDictEntry implements IOreDictEntry {
private final Integer id;
public OreDictEntry(Integer id) {
this.id = id;
}
// ####################################
// ### IOreDictEntry implementation ###
// ####################################
@Override
public void add(IItemStack item) {
ItemStack stack = (ItemStack) item.getInternal();
if (stack == null) {
MineTweakerAPI.logger.logError("not a valid item");
} else {
MineTweakerAPI.tweaker.apply(new ActionAddItem(id, stack));
}
}
@Override
public void addAll(IOreDictEntry entry) {
if (entry instanceof OreDictEntry) {
MineTweakerAPI.tweaker.apply(new ActionAddAll(id, ((OreDictEntry) entry).id));
} else {
MineTweakerAPI.logger.logError("not a valid entry");
}
}
@Override
public void remove(IItemStack item) {
ItemStack result = null;
for (ItemStack itemStack : OreDictionary.getOres(id)) {
if (item.matches(new TweakerItemStack(itemStack))) {
result = itemStack;
break;
}
}
if (result != null) {
MineTweakerAPI.tweaker.apply(new ActionRemoveItem(id, result));
}
}
@Override
public boolean contains(IItemStack item) {
for (ItemStack itemStack : OreDictionary.getOres(id)) {
if (item.matches(new TweakerItemStack(itemStack))) {
return true;
}
}
return false;
}
@Override
public void mirror(IOreDictEntry other) {
if (other instanceof OreDictEntry) {
MineTweakerAPI.tweaker.apply(new ActionMirror(id, ((OreDictEntry) other).id));
} else {
MineTweakerAPI.logger.logError("not a valid oredict entry");
}
}
@Override
public String getMark() {
return null;
}
@Override
public int getAmount() {
return 1;
}
@Override
public List<IItemStack> getItems() {
List<IItemStack> result = new ArrayList<IItemStack>();
for (ItemStack item : OreDictionary.getOres(id)) {
result.add(new TweakerItemStack(item));
}
return result;
}
@Override
public IIngredient amount(int amount) {
return new IngredientStack(this, amount);
}
@Override
public IIngredient transform(IItemTransformer transformer) {
return new IngredientOreDict(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
}
@Override
public IIngredient only(IItemCondition condition) {
return new IngredientOreDict(this, null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
}
@Override
public IIngredient marked(String mark) {
return new IngredientOreDict(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
}
@Override
public boolean matches(IItemStack item) {
return contains(item);
}
@Override
public boolean contains(IIngredient ingredient) {
List<IItemStack> items = ingredient.getItems();
for (IItemStack item : items) {
if (!matches(item)) return false;
}
return true;
}
@Override
public IItemStack applyTransform(IItemStack item) {
return item;
}
@Override
public Object getInternal() {
return OreDictionary.getOreName(id);
}
// ######################
// ### Action classes ###
// ######################
private static class ActionAddItem implements IUndoableAction {
private final Integer id;
private final ItemStack item;
public ActionAddItem(Integer id, ItemStack item) {
this.id = id;
this.item = item;
}
@Override
public void apply() {
OreDictionary.registerOre(id, item);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
OreDictionary.getOres(id).remove(item);
}
@Override
public String describe() {
return "Adding " + item.getDisplayName() + " to ore dictionary entry " + OreDictionary.getOreName(id);
}
@Override
public String describeUndo() {
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + OreDictionary.getOreName(id);
}
}
private static class ActionMirror implements IUndoableAction {
private final Integer idTarget;
private final Integer idSource;
private final ArrayList<ItemStack> targetCopy;
public ActionMirror(Integer idTarget, Integer idSource) {
this.idTarget = idTarget;
this.idSource = idSource;
targetCopy = OreDictionary.getOres(idTarget);
}
@Override
public void apply() {
MineTweakerHacks.getOreStacks().put(idTarget, OreDictionary.getOres(idSource));
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
MineTweakerHacks.getOreStacks().put(idTarget, targetCopy);
}
@Override
public String describe() {
return "Mirroring " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
}
@Override
public String describeUndo() {
return "Undoing mirror of " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
}
}
private static class ActionRemoveItem implements IUndoableAction {
private final Integer id;
private final ItemStack item;
public ActionRemoveItem(Integer id, ItemStack item) {
this.id = id;
this.item = item;
}
@Override
public void apply() {
OreDictionary.getOres(id).add(item);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
OreDictionary.getOres(id).remove(item);
}
@Override
public String describe() {
return "Adding " + item.getDisplayName() + " to ore dictionary entry " + OreDictionary.getOreName(id);
}
@Override
public String describeUndo() {
return "Removing " + item.getDisplayName() + " from ore dictionary entry " + OreDictionary.getOreName(id);
}
}
private static class ActionAddAll implements IUndoableAction {
private final Integer idTarget;
private final Integer idSource;
public ActionAddAll(Integer idTarget, Integer idSource) {
this.idTarget = idTarget;
this.idSource = idSource;
}
@Override
public void apply() {
List<ItemStack> ores = OreDictionary.getOres(idTarget);
for (ItemStack stack : OreDictionary.getOres(idSource)) {
ores.add(stack);
}
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
List<ItemStack> ores = OreDictionary.getOres(idTarget);
for (ItemStack stack : OreDictionary.getOres(idSource)) {
ores.remove(stack);
}
}
@Override
public String describe() {
return "Copying contents of ore dictionary entry " + OreDictionary.getOreName(idSource) + " to " + OreDictionary.getOreName(idTarget);
}
@Override
public String describeUndo() {
return "Removing contents of ore dictionary entry " + OreDictionary.getOreName(idSource) + " from " + OreDictionary.getOreName(idTarget);
}
}
}
@@ -0,0 +1,221 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapedRecipe;
import minetweaker.minecraft.recipes.ShapelessRecipe;
import java.util.ArrayList;
import java.util.List;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.mc172.util.MineTweakerHacks;import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
;
import minetweaker.minecraft.recipes.IRecipeFunction;
import minetweaker.minecraft.recipes.IRecipeManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
/**
*
* @author Stan
*/
public class MTRecipeManager implements IRecipeManager {
private final List<IRecipe> recipes;
public MTRecipeManager() {
recipes = MineTweakerHacks.getRecipes();
}
@Override
public int remove(IIngredient output) {
List<IRecipe> toRemove = new ArrayList<IRecipe>();
List<Integer> removeIndex = new ArrayList<Integer>();
for (int i = 0; i < recipes.size(); i++) {
IRecipe recipe = recipes.get(i);
if (output.matches(new TweakerItemStack(recipe.getRecipeOutput()))) {
toRemove.add(recipe);
removeIndex.add(i);
}
}
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
return toRemove.size();
}
@Override
public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
if (output.getInternal() == null) {
MineTweakerAPI.logger.logError("invalid output item");
return;
}
ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.tweaker.apply(new ActionAddRecipe(irecipe));
}
@Override
public void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function) {
if (output.getInternal() == null) {
MineTweakerAPI.logger.logError("invalid output item");
return;
}
ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function);
IRecipe irecipe = RecipeConverter.convert(recipe);
MineTweakerAPI.tweaker.apply(new ActionAddRecipe(irecipe));
}
@Override
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
List<IRecipe> toRemove = new ArrayList<IRecipe>();
List<Integer> removeIndex = new ArrayList<Integer>();
for (int i = 0; i < recipes.size(); i++) {
IRecipe recipe = recipes.get(i);
if (!output.matches(new TweakerItemStack(recipe.getRecipeOutput()))) {
continue;
}
if (recipe instanceof ShapedRecipes) {
ShapedRecipes srecipe = (ShapedRecipes) recipe;
// TODO: check contents
} else if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
// TODO: check contents
}
toRemove.add(recipe);
removeIndex.add(i);
}
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
return toRemove.size();
}
@Override
public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) {
List<IRecipe> toRemove = new ArrayList<IRecipe>();
List<Integer> removeIndex = new ArrayList<Integer>();
for (int i = 0; i < recipes.size(); i++) {
IRecipe recipe = recipes.get(i);
if (!output.matches(new TweakerItemStack(recipe.getRecipeOutput()))) {
continue;
}
if (recipe instanceof ShapelessRecipes) {
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
// TODO: check contents
} else if (recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe;
ArrayList<Object> inputs = srecipe.getInput();
if (inputs.size() < ingredients.length) {
continue;
} if (!wildcard && inputs.size() > ingredients.length) {
continue;
}
boolean[] tag = new boolean[ingredients.length];
for (Object object : inputs) {
}
// TODO: check contents
}
toRemove.add(recipe);
removeIndex.add(i);
}
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
return toRemove.size();
}
@Override
public IItemStack craft(IItemStack[][] contents) {
return null; // TODO: implement
}
private class ActionRemoveRecipes implements IUndoableAction {
private final List<Integer> removingIndices;
private final List<IRecipe> removingRecipes;
public ActionRemoveRecipes(List<IRecipe> recipes, List<Integer> indices) {
this.removingIndices = indices;
this.removingRecipes = recipes;
}
@Override
public void apply() {
for (int i = removingIndices.size() - 1; i >= 0; i--) {
recipes.remove((int) removingIndices.get(i));
}
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
for (int i = 0; i < removingIndices.size(); i++) {
recipes.add(removingIndices.get(i), removingRecipes.get(i));
}
}
@Override
public String describe() {
return "Removing " + removingIndices.size() + " recipes";
}
@Override
public String describeUndo() {
return "Restoring " + removingIndices.size() + " recipes";
}
}
private class ActionAddRecipe implements IUndoableAction {
private final IRecipe recipe;
public ActionAddRecipe(IRecipe recipe) {
this.recipe = recipe;
}
@Override
public void apply() {
recipes.add(recipe);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
recipes.remove(recipe);
}
@Override
public String describe() {
return "Adding recipe for " + recipe.getRecipeOutput().getDisplayName();
}
@Override
public String describeUndo() {
return "Removing recipe for " + recipe.getRecipeOutput().getDisplayName();
}
}
}
@@ -0,0 +1,119 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapedRecipe;
import minetweaker.minecraft.recipes.ShapelessRecipe;
import java.util.ArrayList;
import java.util.Arrays;
import minetweaker.minecraft.item.IIngredient;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
/**
*
* @author Stan
*/
public class RecipeConverter {
private RecipeConverter() {}
public static final int TYPE_ADVANCED = 0;
public static final int TYPE_ORE = 1;
public static final int TYPE_BASIC = 2;
private static int getIngredientType(IIngredient pattern) {
Object internal = pattern.getInternal();
if (internal == null) {
return TYPE_ADVANCED;
} else if (internal instanceof ItemStack) {
return TYPE_BASIC;
} else {
return TYPE_ORE;
}
}
private static int getRecipeType(IIngredient[] ingredients) {
int type = TYPE_BASIC;
for (IIngredient ingredient : ingredients) {
type = Math.min(type, getIngredientType(ingredient));
}
return type;
}
public static IRecipe convert(ShapelessRecipe recipe) {
IIngredient[] ingredients = recipe.getIngredients();
int type = getRecipeType(ingredients);
if (type == TYPE_BASIC) {
ItemStack[] items = new ItemStack[ingredients.length];
for (int i = 0; i < ingredients.length; i++) {
items[i] = (ItemStack) ingredients[i].getInternal();
}
return new ShapelessRecipeBasic(items, recipe);
} else if (type == TYPE_ORE) {
Object[] items = new Object[ingredients.length];
for (int i = 0; i < ingredients.length; i++) {
items[i] = ingredients[i].getInternal();
}
return new ShapelessRecipeOre(items, recipe);
} else {
return new ShapelessRecipeAdvanced(recipe);
}
}
public static IRecipe convert(ShapedRecipe recipe) {
IIngredient[] ingredients = recipe.getIngredients();
byte[] posx = recipe.getIngredientsX();
byte[] posy = recipe.getIngredientsY();
// determine recipe type
int type = getRecipeType(ingredients);
// construct recipe
if (type == TYPE_BASIC) {
ItemStack[] basicIngredients = new ItemStack[recipe.getHeight() * recipe.getWidth()];
for (int i = 0; i < ingredients.length; i++) {
basicIngredients[posx[i] + posy[i] * recipe.getWidth()] = (ItemStack) ingredients[i].getInternal();
}
return new ShapedRecipeBasic(basicIngredients, recipe);
} else if (type == TYPE_ORE) {
Object[] converted = new Object[recipe.getHeight() * recipe.getWidth()];
for (int i = 0; i < ingredients.length; i++) {
converted[posx[i] + posy[i] * recipe.getWidth()] = ingredients[i].getInternal();
}
// arguments contents:
// 1) recipe patterns
// 2) characters + ingredients
int counter = 0;
String[] parts = new String[recipe.getHeight()];
ArrayList rarguments = new ArrayList();
for (int i = 0; i < recipe.getHeight(); i++) {
char[] pattern = new char[recipe.getWidth()];
for (int j = 0; j < recipe.getWidth(); j++) {
int off = i * recipe.getWidth() + j;
if (converted[off] == null) {
pattern[j] = ' ';
} else {
pattern[j] = (char) ('A' + counter);
rarguments.add(pattern[j]);
rarguments.add(converted[off]);
}
}
parts[i] = new String(pattern);
}
rarguments.addAll(0, Arrays.asList(parts));
return new ShapedRecipeOre(rarguments.toArray(), recipe);
} else {
return new ShapedRecipeAdvanced(recipe);
}
}
}
@@ -0,0 +1,46 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapedRecipe;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
/**
* TODO: NEI integration for this kind of recipes.
*
* @author Stan
*/
public class ShapedRecipeAdvanced implements IRecipe {
private final ShapedRecipe recipe;
public ShapedRecipeAdvanced(ShapedRecipe recipe) {
this.recipe = recipe;
}
@Override
public boolean matches(InventoryCrafting inventory, World world) {
return recipe.matches(TweakerCraftingInventory.get(inventory));
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
}
@Override
public int getRecipeSize() {
return recipe.getWidth() * recipe.getHeight();
}
@Override
public ItemStack getRecipeOutput() {
return (ItemStack) recipe.getOutput().getInternal();
}
}
@@ -0,0 +1,37 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapedRecipe;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World;
/**
*
* @author Stan
*/
public class ShapedRecipeBasic extends ShapedRecipes {
private final ShapedRecipe recipe;
public ShapedRecipeBasic(ItemStack[] basicInputs, ShapedRecipe recipe) {
super(recipe.getWidth(), recipe.getHeight(), basicInputs, (ItemStack) recipe.getOutput().getInternal());
this.recipe = recipe;
}
@Override
public boolean matches(InventoryCrafting inventory, World world) {
return recipe.matches(TweakerCraftingInventory.get(inventory));
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
}
}
@@ -0,0 +1,37 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapedRecipe;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
/**
*
* @author Stan
*/
public class ShapedRecipeOre extends ShapedOreRecipe {
private final ShapedRecipe recipe;
public ShapedRecipeOre(Object[] contents, ShapedRecipe recipe) {
super((ItemStack) recipe.getOutput().getInternal(), contents);
this.recipe = recipe;
}
@Override
public boolean matches(InventoryCrafting inventory, World world) {
return recipe.matches(TweakerCraftingInventory.get(inventory));
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
}
}
@@ -0,0 +1,45 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapelessRecipe;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
/**
*
* @author Stan
*/
public class ShapelessRecipeAdvanced implements IRecipe {
private final ShapelessRecipe recipe;
public ShapelessRecipeAdvanced(ShapelessRecipe recipe) {
this.recipe = recipe;
}
@Override
public boolean matches(InventoryCrafting inventory, World world) {
return recipe.matches(TweakerCraftingInventory.get(inventory));
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
}
@Override
public int getRecipeSize() {
return recipe.getSize();
}
@Override
public ItemStack getRecipeOutput() {
return (ItemStack) recipe.getOutput().getInternal();
}
}
@@ -0,0 +1,38 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapelessRecipe;
import java.util.Arrays;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
/**
*
* @author Stan
*/
public class ShapelessRecipeBasic extends ShapelessRecipes {
private final ShapelessRecipe recipe;
public ShapelessRecipeBasic(ItemStack[] ingredients, ShapelessRecipe recipe) {
super((ItemStack) recipe.getOutput().getInternal(), Arrays.asList(ingredients));
this.recipe = recipe;
}
@Override
public boolean matches(InventoryCrafting inventory, World world) {
return recipe.matches(TweakerCraftingInventory.get(inventory));
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
}
}
@@ -0,0 +1,37 @@
/*
* 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.recipes;
import minetweaker.minecraft.recipes.ShapelessRecipe;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapelessOreRecipe;
/**
*
* @author Stan
*/
public class ShapelessRecipeOre extends ShapelessOreRecipe {
private final ShapelessRecipe recipe;
public ShapelessRecipeOre(Object[] ingredients, ShapelessRecipe recipe) {
super((ItemStack) recipe.getOutput().getInternal(), ingredients);
this.recipe = recipe;
}
@Override
public boolean matches(InventoryCrafting inventory, World world) {
return recipe.matches(TweakerCraftingInventory.get(inventory));
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
}
}
@@ -0,0 +1,84 @@
/*
* 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.recipes;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.minecraft.item.IItemStack;
import minetweaker.minecraft.recipes.ICraftingInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
/**
*
* @author Stan
*/
public class TweakerCraftingInventory implements ICraftingInventory {
private static final ThreadLocal<TweakerCraftingInventory> cache = new ThreadLocal<TweakerCraftingInventory>();
public static TweakerCraftingInventory get(InventoryCrafting inventory) {
if (cache.get() == null || cache.get().inventory != inventory) {
TweakerCraftingInventory result = new TweakerCraftingInventory(inventory);
cache.set(result);
return result;
} else {
return cache.get();
}
}
private final int width;
private final int height;
private final InventoryCrafting inventory;
private final IItemStack[] stacks;
private TweakerCraftingInventory(InventoryCrafting inventory) {
this.inventory = inventory;
width = height = (int) Math.sqrt(inventory.getSizeInventory());
stacks = new IItemStack[width * height];
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (inventory.getStackInSlot(i) != null) {
stacks[i] = new TweakerItemStack(inventory.getStackInSlot(i));
}
}
}
@Override
public int getSize() {
return width * height;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public IItemStack getStack(int i) {
return stacks[i];
}
@Override
public IItemStack getStack(int x, int y) {
return stacks[y * width + x];
}
@Override
public void setStack(int x, int y, IItemStack stack) {
stacks[y * width + x] = stack;
inventory.setInventorySlotContents(y * width + x, (ItemStack) stack.getInternal());
}
@Override
public void setStack(int i, IItemStack stack) {
stacks[i] = stack;
inventory.setInventorySlotContents(i, (ItemStack) stack.getInternal());
}
}
@@ -0,0 +1,42 @@
/*
* 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.transformer;
import java.util.List;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
/**
*
* @author Stanneke
*/
public class MineTweakerASM implements IClassTransformer {
@Override
public byte[] transform(String name, String newName, byte[] bytecode) {
ClassVisitor visitor = new AnnotationDetector();
ClassReader reader = new ClassReader(bytecode);
reader.accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return bytecode;
}
private class AnnotationDetector extends ClassVisitor {
public AnnotationDetector() {
super(Opcodes.ASM4);
}
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
System.out.println("Annotation: " + desc);
return super.visitAnnotation(desc, visible);
}
}
}
@@ -0,0 +1,48 @@
/*
* 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.transformer;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
import java.util.Map;
import minetweaker.mc172.MineTweakerMod;
/**
*
* @author Stanneke
*/
@MCVersion(MineTweakerMod.MCVERSION)
@IFMLLoadingPlugin.TransformerExclusions("minetweaker.mc172.transformer")
public class MineTweakerTransformer implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
System.out.println("MineTweakerASM transformer class loading");
return new String[] { MineTweakerASM.class.getName() };
}
@Override
public String getModContainerClass() {
//return MineTweaker.class.getName();
return null;
}
@Override
public String getSetupClass() {
return null;
}
@Override
public void injectData(Map<String, Object> data) {
}
@Override
public String getAccessTransformerClass() {
return null;
}
}
@@ -0,0 +1,84 @@
/*
* 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.util;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import minetweaker.MineTweakerAPI;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.oredict.OreDictionary;
/**
* Common class for all runtime hacks (stuff requiring reflection). It is not
* unexpected to have it break with new minecraft versions and may need regular
* adjustment - as such, those have been collected here.
*
* @author Stan Hebben
*/
public class MineTweakerHacks {
private static final Field NBTTAGLIST_TAGLIST;
private static final Field OREDICTIONARY_ORESTACKS;
static {
NBTTAGLIST_TAGLIST = getField(NBTTagList.class, MineTweakerObfuscation.NBTTAGLIST_TAGLIST);
OREDICTIONARY_ORESTACKS = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_ORESTACKS);
}
private MineTweakerHacks() {}
public static List<NBTBase> getTagList(NBTTagList list) {
if (NBTTAGLIST_TAGLIST == null) {
return null;
}
try {
return (List) NBTTAGLIST_TAGLIST.get(list);
} catch (IllegalArgumentException ex) {
return null;
} catch (IllegalAccessException ex) {
return null;
}
}
public static List<IRecipe> getRecipes() {
Field field = getField(CraftingManager.class, MineTweakerObfuscation.CRAFTINGMANAGER_RECIPES);
try {
return (List<IRecipe>) field.get(CraftingManager.getInstance());
} catch (IllegalAccessException ex) {
MineTweakerAPI.logger.logError("EPIC ERROR - could not load recipe list!");
return null;
}
}
public static HashMap<Integer, ArrayList<ItemStack>> getOreStacks() {
try {
return (HashMap<Integer, ArrayList<ItemStack>>) OREDICTIONARY_ORESTACKS.get(null);
} catch (IllegalAccessException ex) {
MineTweakerAPI.logger.logError("ERROR - could not load ore dictionary stacks!");
return null;
}
}
private static Field getField(Class cls, String[] names) {
for (String name : names) {
try {
Field field = cls.getField(name);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException ex) {
} catch (SecurityException ex) {
}
}
return null;
}
}
@@ -0,0 +1,19 @@
/*
* 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.util;
/**
*
* @author Stanneke
*/
public class MineTweakerObfuscation {
private MineTweakerObfuscation() {}
public static final String[] NBTTAGLIST_TAGLIST = {"tagList", "field_74747_a"};
public static final String[] CRAFTINGMANAGER_RECIPES = {"recipes", "field_77597_b"};
public static final String[] OREDICTIONARY_ORESTACKS = {"oreStacks"};
}
+28
View File
@@ -0,0 +1,28 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
apply plugin: 'forge'
minecraft{version = "1.7.2-10.12.1.1112"}
version = "1.0"
archivesBaseName = project.projectDir.name
dependencies {
compile project(':ZenScript')
compile project(':MineTweaker3-API')
compile project(':MineTweaker3-MC17-Main')
compile files('libs/industrialcraft-2-2.1.476-experimental-api.jar')
}
@@ -0,0 +1,58 @@
package stanhebben.minetweaker.mods.ic2;
import ic2.api.recipe.Recipes;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.NotNull;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* Provides access to the IC2 compressor recipes. Recipes can be added but not
* removed, due to IC2 API restrictions.
*
* @author Stan Hebben
*/
@ZenClass("mods.ic2.Centrifuge")
public class Centrifuge {
/**
* Adds a new recipe to the centrifuge.
*
* The recipe input can be any pattern, as long as the stack size is determined.
* The output can be any item stack.
*
* @param output recipe output
* @param ingredient recipe input
*/
@ZenMethod
public static void addRecipe(
@NotNull IItemStack output,
@NotNull IIngredient ingredient) {
if (ingredient.getAmount() < 0) {
MineTweakerAPI.logger.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
} else {
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
"compressor",
Recipes.compressor,
(ItemStack) output.getInternal(),
null,
new IC2RecipeInput(ingredient)));
}
}
/**
* Determines the recipe output for the given input. Will return the output
* of a single item, even if the stack contains multiple items.
*
* @param input recipe input
* @return recipe output
*/
@ZenMethod
public static IItemStack getOutput(
@NotNull IItemStack input) {
return new TweakerItemStack(Recipes.compressor.getOutputFor((ItemStack) input.getInternal(), false).items.get(0));
}
}
@@ -0,0 +1,58 @@
package stanhebben.minetweaker.mods.ic2;
import ic2.api.recipe.Recipes;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.NotNull;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* Provides access to the IC2 compressor recipes. Recipes can be added but not
* removed, due to IC2 API restrictions.
*
* @author Stan Hebben
*/
@ZenClass("mods.ic2.Compressor")
public class Compressor {
/**
* Adds a new recipe to the compressor.
*
* The recipe input can be any pattern, as long as the stack size is determined.
* The output can be any item stack.
*
* @param output recipe output
* @param ingredient recipe input
*/
@ZenMethod
public static void addRecipe(
@NotNull IItemStack output,
@NotNull IIngredient ingredient) {
if (ingredient.getAmount() < 0) {
MineTweakerAPI.logger.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
} else {
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
"compressor",
Recipes.compressor,
(ItemStack) output.getInternal(),
null,
new IC2RecipeInput(ingredient)));
}
}
/**
* Determines the recipe output for the given input. Will return the output
* of a single item, even if the stack contains multiple items.
*
* @param input recipe input
* @return recipe output
*/
@ZenMethod
public static IItemStack getOutput(
@NotNull IItemStack input) {
return new TweakerItemStack(Recipes.compressor.getOutputFor((ItemStack) input.getInternal(), false).items.get(0));
}
}
@@ -0,0 +1,63 @@
/*
* 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 stanhebben.minetweaker.mods.ic2;
import ic2.api.recipe.Recipes;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.NotNull;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* Provides access to the IC2 Extractor recipes.
*
* @author Stan Hebben
*/
@ZenClass("mods.ic2.Extractor")
public class Extractor {
/**
* Adds a new recipe to the extractor.
*
* The recipe input can be any pattern, as long as the stack size is determined.
* The output can be any item stack.
*
* @param output recipe output
* @param ingredient recipe input
*/
@ZenMethod
public static void addRecipe(
@NotNull IItemStack output,
@NotNull IIngredient ingredient) {
if (ingredient.getAmount() < 0) {
MineTweakerAPI.logger.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
} else {
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
"extractor",
Recipes.extractor,
(ItemStack) output.getInternal(),
null,
new IC2RecipeInput(ingredient)));
}
}
/**
* Determines the recipe output for the given input. Will return the output
* of a single item, even if the stack contains multiple items.
*
* @param input recipe input
* @return recipe output
*/
@ZenMethod
public static IItemStack getOutput(
@NotNull IItemStack input) {
return new TweakerItemStack(Recipes.extractor.getOutputFor((ItemStack) input.getInternal(), false).items.get(0));
}
}
@@ -0,0 +1,47 @@
/*
* 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 stanhebben.minetweaker.mods.ic2;
import ic2.api.recipe.IRecipeInput;
import java.util.ArrayList;
import java.util.List;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import net.minecraft.item.ItemStack;
/**
* Wrapper class for ITweakerItemStackPatterns to IC2 recipe inputs.
*
* @author Stan Hebben
*/
public class IC2RecipeInput implements IRecipeInput {
private final IIngredient ingredient;
public IC2RecipeInput(IIngredient ingredient) {
this.ingredient = ingredient;
}
@Override
public boolean matches(ItemStack subject) {
return ingredient.matches(new TweakerItemStack(subject));
}
@Override
public int getAmount() {
return ingredient.getAmount();
}
@Override
public List<ItemStack> getInputs() {
List<ItemStack> items = new ArrayList<ItemStack>();
for (IItemStack item : ingredient.getItems()) {
items.add((ItemStack) item.getInternal());
}
return items;
}
}
@@ -0,0 +1,58 @@
package stanhebben.minetweaker.mods.ic2;
import ic2.api.recipe.Recipes;
import minetweaker.MineTweakerAPI;
import minetweaker.mc172.item.TweakerItemStack;
import minetweaker.minecraft.item.IIngredient;
import minetweaker.minecraft.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.NotNull;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
/**
* Provides access to the IC2 macerator recipes. Recipes can be added but not
* removed, due to IC2 API restrictions.
*
* @author Stan Hebben
*/
@ZenClass("mods.ic2.Macerator")
public class Macerator {
/**
* Adds a new recipe to the macerator.
*
* The recipe input can be any pattern, as long as the stack size is determined.
* The output can be any item stack.
*
* @param output recipe output
* @param ingredient recipe input
*/
@ZenMethod
public static void addRecipe(
@NotNull IItemStack output,
@NotNull IIngredient ingredient) {
if (ingredient.getAmount() < 0) {
MineTweakerAPI.logger.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
} else {
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
"macerator",
Recipes.macerator,
(ItemStack) output.getInternal(),
null,
new IC2RecipeInput(ingredient)));
}
}
/**
* Determines the recipe output for the given input. Will return the output
* of a single item, even if the stack contains multiple items.
*
* @param input recipe input
* @return recipe output
*/
@ZenMethod
public static IItemStack getOutput(
@NotNull IItemStack input) {
return new TweakerItemStack(Recipes.macerator.getOutputFor((ItemStack) input.getInternal(), false).items.get(0));
}
}
@@ -0,0 +1,42 @@
/*
* 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 stanhebben.minetweaker.mods.ic2;
import ic2.api.recipe.IMachineRecipeManager;
import minetweaker.OneWayAction;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
*
* @author Stan
*/
public class MachineAddRecipeAction extends OneWayAction {
private final String name;
private final IMachineRecipeManager machine;
private final ItemStack output;
private final IC2RecipeInput input;
private final NBTTagCompound tag;
public MachineAddRecipeAction(String name, IMachineRecipeManager machine, ItemStack output, NBTTagCompound tag, IC2RecipeInput input) {
this.name = name;
this.machine = machine;
this.output = output;
this.input = input;
this.tag = tag;
}
@Override
public void apply() {
machine.addRecipe(input, tag, output);
}
@Override
public String describe() {
return "Adding " + name + " recipe for " + output.getDisplayName();
}
}
+28
View File
@@ -0,0 +1,28 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
apply plugin: 'forge'
minecraft{version = "1.7.2-10.12.1.1112"}
version = "1.0"
archivesBaseName = project.projectDir.name
dependencies {
compile project(':ZenScript')
compile project(':MineTweaker3-API')
compile project(':MineTweaker3-MC17-Main')
compile files('libs/NotEnoughItems-1.7.2-1.0.1-dev.jar')
}
@@ -0,0 +1,147 @@
package stanhebben.minetweaker.mods.nei;
import codechicken.nei.api.API;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.NotNull;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.OneWayAction;
import minetweaker.minecraft.item.IItemStack;
/**
* MineTweaker NEI support.
*
* Enables hiding NEI items as well as adding new item stacks. These item stacks
* can then show a custom message or contain NBT data. Can be used to show
* a custom message or lore with certain items, or to provide spawnable items
* with specific NBT tags.
*
* @author Stan Hebben
*/
@ZenClass("mods.nei.NEI")
public class NEI {
/**
* Hides a specific item in NEI. Will take into account metadata values, if
* any.
*
* @param item item to be hidden
*/
@ZenMethod
public static void hide(@NotNull IItemStack item) {
MineTweakerAPI.tweaker.apply(new NEIHideItemAction((ItemStack) item.getInternal()));
}
/**
* Adds a NEI entry. The item stack can contain damage values and NBT tags.
*
* @param stack item stack to be added
*/
@ZenMethod
public static void addEntry(@NotNull IItemStack stack) {
MineTweakerAPI.tweaker.apply(new NEIAddEntryAction((ItemStack) stack.getInternal()));
}
/**
* Overrides a name in NEI. Note that this will not change the original
* display name, but it will change the way it is displayed in NEI.
*
* @param item item
* @param name item name
*/
@ZenMethod
public static void overrideName(@NotNull IItemStack item, @NotNull String name) {
MineTweakerAPI.tweaker.apply(new NEIOverrideNameAction((ItemStack) item.getInternal(), name));
}
// #############################
// ### Private inner classes ###
// #############################
private static class NEIAddEntryAction implements IUndoableAction {
private final ItemStack item;
public NEIAddEntryAction(ItemStack item) {
this.item = item;
}
@Override
public void apply() {
API.addItemListEntry(item);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
API.hideItem(item);
}
@Override
public String describe() {
return "Adding " + item.getDisplayName() + " as NEI entry";
}
@Override
public String describeUndo() {
return "Removing " + item.getDisplayName() + " as NEI entry";
}
}
private static class NEIHideItemAction implements IUndoableAction {
private final ItemStack stack;
public NEIHideItemAction(ItemStack stack) {
this.stack = stack;
}
@Override
public void apply() {
API.hideItem(stack);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
API.addItemListEntry(stack);
}
@Override
public String describe() {
return "Hiding " + stack.getUnlocalizedName() + " in NEI";
}
@Override
public String describeUndo() {
return "Displaying " + stack.getUnlocalizedName() + " in NEI";
}
}
private static class NEIOverrideNameAction extends OneWayAction {
private final ItemStack item;
private final String name;
public NEIOverrideNameAction(ItemStack item, String name) {
this.item = item;
this.name = name;
}
@Override
public void apply() {
API.setOverrideName(item, name);
}
@Override
public String describe() {
return "Overriding NEI item name of " + item.getUnlocalizedName() + " to " + name;
}
}
}
+6
View File
@@ -0,0 +1,6 @@
apply plugin: 'java'
dependencies {
compile group: 'org.ow2.asm', name: 'asm', version:'4.2'
compile group: 'org.ow2.asm', name: 'asm-commons', version:'4.2'
}
@@ -0,0 +1,19 @@
/*
* 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 stanhebben.zenscript;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stanneke
*/
public interface IZenErrorLogger {
public void error(ZenPosition position, String message);
public void warning(ZenPosition position, String message);
}
@@ -0,0 +1,218 @@
/*
* 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 stanhebben.zenscript;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenMethodStatic;
import stanhebben.zenscript.annotations.ZenOperator;
import stanhebben.zenscript.annotations.ZenSetter;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.ITypeRegistry;
import stanhebben.zenscript.expression.Expression;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.expand.ZenExpandCaster;
import stanhebben.zenscript.type.expand.ZenExpandMember;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.ZenNativeOperator;
import stanhebben.zenscript.util.ZenPosition;
/**
*
* @author Stanneke
*/
public class TypeExpansion {
private final Map<String, ZenExpandMember> members;
private final Map<String, ZenExpandMember> staticMembers;
private final List<ZenExpandCaster> casters;
private final List<ZenNativeOperator> trinaryOperators;
private final List<ZenNativeOperator> binaryOperators;
private final List<ZenNativeOperator> unaryOperators;
public TypeExpansion() {
members = new HashMap<String, ZenExpandMember>();
staticMembers = new HashMap<String, ZenExpandMember>();
casters = new ArrayList<ZenExpandCaster>();
trinaryOperators = new ArrayList<ZenNativeOperator>();
binaryOperators = new ArrayList<ZenNativeOperator>();
unaryOperators = new ArrayList<ZenNativeOperator>();
}
public void expand(Class cls, ITypeRegistry types) {
for (Method method : cls.getMethods()) {
String methodName = method.getName();
for (Annotation annotation : method.getAnnotations()) {
if (annotation instanceof ZenCaster) {
checkStatic(method);
casters.add(new ZenExpandCaster(new JavaMethod(cls, method, types)));
} else if (annotation instanceof ZenGetter) {
checkStatic(method);
ZenGetter getterAnnotation = (ZenGetter) annotation;
String name = getterAnnotation.value().length() == 0 ? method.getName() : getterAnnotation.value();
if (!members.containsKey(name)) {
members.put(name, new ZenExpandMember());
}
members.get(name).setGetter(new JavaMethod(cls, method, types));
} else if (annotation instanceof ZenSetter) {
checkStatic(method);
ZenSetter setterAnnotation = (ZenSetter) annotation;
String name = setterAnnotation.value().length() == 0 ? method.getName() : setterAnnotation.value();
if (!members.containsKey(name)) {
members.put(name, new ZenExpandMember());
}
members.get(name).setSetter(new JavaMethod(cls, method, types));
} else if (annotation instanceof ZenOperator) {
checkStatic(method);
ZenOperator operatorAnnotation = (ZenOperator) annotation;
switch (operatorAnnotation.value()) {
case NEG:
case NOT:
if (method.getParameterTypes().length != 0) {
// TODO: error
} else {
unaryOperators.add(new ZenNativeOperator(
operatorAnnotation.value(),
new JavaMethod(cls, method, types)));
}
break;
case ADD:
case SUB:
case CAT:
case MUL:
case DIV:
case MOD:
case AND:
case OR:
case XOR:
case INDEXGET:
case RANGE:
case CONTAINS:
case COMPARE:
if (method.getParameterTypes().length != 1) {
// TODO: error
} else {
binaryOperators.add(new ZenNativeOperator(
operatorAnnotation.value(),
new JavaMethod(cls, method, types)));
}
break;
case INDEXSET:
if (method.getParameterTypes().length != 2) {
// TODO: error
} else {
trinaryOperators.add(new ZenNativeOperator(
operatorAnnotation.value(),
new JavaMethod(cls, method, types)));
}
break;
}
} else if (annotation instanceof ZenMethod) {
checkStatic(method);
ZenMethod methodAnnotation = (ZenMethod) annotation;
if (methodAnnotation.value().length() > 0) {
methodName = methodAnnotation.value();
}
if (!members.containsKey(methodName)) {
members.put(methodName, new ZenExpandMember());
}
members.get(methodName).addMethod(new JavaMethod(cls, method, types));
} else if (annotation instanceof ZenMethodStatic) {
checkStatic(method);
ZenMethodStatic methodAnnotation = (ZenMethodStatic) annotation;
if (methodAnnotation.value().length() > 0) {
methodName = methodAnnotation.value();
}
if (!staticMembers.containsKey(methodName)) {
staticMembers.put(methodName, new ZenExpandMember());
}
staticMembers.get(methodName).addMethod(new JavaMethod(cls, method, types));
}
}
}
}
public ZenExpandCaster getCaster(ZenType type, IEnvironmentGlobal environment) {
for (ZenExpandCaster caster : casters) {
if (caster.getTarget().equals(type)) {
return caster;
}
}
for (ZenExpandCaster caster : casters) {
if (caster.getTarget().canCastImplicit(type, environment)) {
return caster;
}
}
return null;
}
public Expression unary(ZenPosition position, IEnvironmentGlobal environment, Expression value, OperatorType operator) {
for (ZenNativeOperator op : unaryOperators) {
if (op.getOperator() == operator) {
return op.getMethod().callStatic(position, environment, value);
}
}
return null;
}
public Expression binary(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, OperatorType operator) {
for (ZenNativeOperator op : binaryOperators) {
if (op.getOperator() == operator) {
return op.getMethod().callStatic(position, environment, left, right);
}
}
return null;
}
public Expression trinary(ZenPosition position, IEnvironmentGlobal environment, Expression first, Expression second, Expression third, OperatorType operator) {
for (ZenNativeOperator op : trinaryOperators) {
if (op.getOperator() == operator) {
return op.getMethod().callStatic(position, environment, first, second, third);
}
}
return null;
}
public IPartialExpression member(ZenPosition position, IEnvironmentGlobal environment, Expression value, String member) {
if (members.containsKey(member)) {
return members.get(member).instance(position, environment, value);
}
return null;
}
public IPartialExpression staticMember(ZenPosition position, IEnvironmentGlobal environment, String member) {
if (staticMembers.containsKey(member)) {
return staticMembers.get(member).instance(position, environment);
}
return null;
}
private void checkStatic(Method method) {
if ((method.getModifiers() & Modifier.STATIC) == 0) {
throw new RuntimeException("Expansion method " + method.getName() + " must be static");
}
}
}
Loaded 100 of 281 files, more files were not shown because too many files have changed in this diff. Show more