mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-27 15:23:03 +00:00
- Continued writing on the IC2 integration code
- Implemented advanced recipes on <*> values - Removed unused ZenScript classes - Continued work on any values - Moved documentation generation to buildSrc - Started work on a jar merging task - Added toString implementation to ingredients - Added stack count to ICraftingInventory - Fixed imports - Added logCommand to the logger to log command output - Implemented memory script provider to load scripts received from the server - Added exception handling for script execution - First attempt at creating a transformer to generate a list of ZenClass and ZenExpansion classes - Added console commands (reload, names, liquids, inventory, hand, oredict) - Added general logic - Fixed item ingredients for wildcard sizes - Implemented selective recipe removal - Fixed null recipe results - Started implementation of player-specific recipes - Removed redundant IC2 mod copy - Other minor fixes
This commit is contained in:
1 parent
f3ea7f7831
commit
489347558f
124 files changed
+3942
-419
No files matched your search
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<gradle-project-properties>
|
||||
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
|
||||
<built-in-tasks>
|
||||
<task>
|
||||
<display-name>debug</display-name>
|
||||
<non-blocking>no</non-blocking>
|
||||
<task-names>
|
||||
<name must-exist="no">runClient</name>
|
||||
</task-names>
|
||||
<task-args/>
|
||||
<task-jvm-args/>
|
||||
</task>
|
||||
<task>
|
||||
<display-name>run</display-name>
|
||||
<non-blocking>no</non-blocking>
|
||||
<task-names>
|
||||
<name must-exist="no">runClient</name>
|
||||
</task-names>
|
||||
<task-args/>
|
||||
<task-jvm-args>
|
||||
<arg>-Dfml.coreMods.load=minetweaker.mc172.transformer.MineTweakerTransformer</arg>
|
||||
</task-jvm-args>
|
||||
</task>
|
||||
</built-in-tasks>
|
||||
</gradle-project-properties>
|
||||
@@ -1,6 +1,6 @@
|
||||
package minetweaker;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import minetweaker.runtime.IMineTweaker;
|
||||
import minetweaker.runtime.ILogger;
|
||||
import minetweaker.runtime.Tweaker;
|
||||
@@ -11,6 +11,10 @@ import minetweaker.runtime.GlobalRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticField;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticGetter;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the MineTweaker API.
|
||||
@@ -67,12 +71,12 @@ public class MineTweakerAPI {
|
||||
* @param annotatedClass
|
||||
*/
|
||||
public static void registerClass(Class annotatedClass) {
|
||||
for (Annotation annotation : annotatedClass.getAnnotations()) {
|
||||
if (annotation instanceof ZenExpansion) {
|
||||
GlobalRegistry.registerExpansion(annotatedClass);
|
||||
} else if (annotation instanceof ZenClass) {
|
||||
GlobalRegistry.registerNativeClass(annotatedClass);
|
||||
}
|
||||
if (annotatedClass.isAnnotationPresent(ZenExpansion.class)) {
|
||||
GlobalRegistry.registerExpansion(annotatedClass);
|
||||
}
|
||||
|
||||
if (annotatedClass.isAnnotationPresent(ZenClass.class)) {
|
||||
GlobalRegistry.registerNativeClass(annotatedClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,4 +111,63 @@ public class MineTweakerAPI {
|
||||
public static void registerBracketHandler(IBracketHandler handler) {
|
||||
GlobalRegistry.registerBracketHandler(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a symbol that refers to a java method.
|
||||
*
|
||||
* @param cls class that contains the method
|
||||
* @param name method name
|
||||
* @param arguments method argument types
|
||||
* @return corresponding symbol
|
||||
*/
|
||||
public static IZenSymbol getJavaStaticMethodSymbol(Class cls, String name, Class... arguments) {
|
||||
JavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
|
||||
return new SymbolJavaStaticMethod(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a symbol that refers to a java getter. The getter must be a method
|
||||
* with no arguments. The given symbol will act as a variable of which the
|
||||
* value can be retrieved but not set.
|
||||
*
|
||||
* @param cls class that contains the getter method
|
||||
* @param name name of the method
|
||||
* @return corresponding symbol
|
||||
*/
|
||||
public static IZenSymbol getJavaStaticGetterSymbol(Class cls, String name) {
|
||||
JavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name);
|
||||
return new SymbolJavaStaticGetter(method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a symbol that refers to a static field. The field must be an
|
||||
* existing public field in the given class. The field will act as a
|
||||
* variable that can be retrieved but not set.
|
||||
*
|
||||
* @param cls class that contains the field
|
||||
* @param name field name (must be public)
|
||||
* @return corresponding symbol
|
||||
*/
|
||||
public static IZenSymbol getJavaStaticFieldSymbol(Class cls, String name) {
|
||||
try {
|
||||
Field field = cls.getField(name);
|
||||
return new SymbolJavaStaticField(cls, field, GlobalRegistry.getTypeRegistry());
|
||||
} catch (NoSuchFieldException ex) {
|
||||
return null;
|
||||
} catch (SecurityException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a Java method from an existing class.
|
||||
*
|
||||
* @param cls method class
|
||||
* @param name method name
|
||||
* @param arguments argument types
|
||||
* @return java method
|
||||
*/
|
||||
public static JavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
|
||||
return JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package minetweaker.annotations;
|
||||
|
||||
/**
|
||||
* Marks a bracket handler. Bracket handlers are automatically registered.
|
||||
* The marked class should have an empty constructor.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public @interface BracketHandler {
|
||||
/**
|
||||
* Indicates priority. A lower value means a higher priority. Only change
|
||||
* if you have issues, default value is 10. Internal minetweaker handlers
|
||||
* have priorities up to 100.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int priority() default 10;
|
||||
}
|
||||
@@ -8,9 +8,11 @@ package minetweaker.minecraft.item;
|
||||
|
||||
import minetweaker.minecraft.data.IData;
|
||||
import minetweaker.minecraft.liquid.ILiquidStack;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -39,6 +41,10 @@ public interface IItemStack extends IIngredient {
|
||||
@ZenGetter("liquid")
|
||||
public ILiquidStack getLiquid();
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public IItemStack amount(int amount);
|
||||
|
||||
@ZenMethod
|
||||
public IIngredient anyDamage();
|
||||
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
package minetweaker.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.minecraft.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientAny implements IIngredient {
|
||||
public static IngredientAny INSTANCE = new IngredientAny();
|
||||
public static final IngredientAny INSTANCE = new IngredientAny();
|
||||
|
||||
public static Object INTERNAL_ANY = null; // platforms supporting an "any" item should fill it here
|
||||
|
||||
private IngredientAny() {}
|
||||
@@ -40,36 +42,36 @@ public class IngredientAny implements IIngredient {
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return new IngredientAnyAdvanced(null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[] { transformer });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return new IngredientAnyAdvanced(null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
return INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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;
|
||||
import minetweaker.minecraft.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientAnyAdvanced implements IIngredient {
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientAnyAdvanced(String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
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 null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientAnyAdvanced(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 IngredientAny.INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -99,4 +99,13 @@ public class IngredientItem implements IIngredient {
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(Ingredient) " + item.toString();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,12 @@ public interface ILiquidDefinition {
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
public ILiquidStack asStack(int millibuckets);
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
public int getLuminosity();
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ public interface ILiquidStack {
|
||||
@ZenGetter("definition")
|
||||
public ILiquidDefinition getDefinition();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
@ZenGetter("amount")
|
||||
public int getAmount();
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.player;
|
||||
|
||||
import minetweaker.minecraft.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minecraft.player.IPlayer")
|
||||
public interface IPlayer {
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("data")
|
||||
public IData getData();
|
||||
|
||||
@ZenMethod
|
||||
public void update(IData data);
|
||||
}
|
||||
@@ -26,6 +26,9 @@ public interface ICraftingInventory {
|
||||
@ZenGetter("height")
|
||||
public int getHeight();
|
||||
|
||||
@ZenGetter("stackCount")
|
||||
public int getStackCount();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getStack(int i);
|
||||
|
||||
|
||||
@@ -63,6 +63,12 @@ public class ShapedRecipe {
|
||||
this.width = width1;
|
||||
this.height = height1;
|
||||
this.mirrored = mirrored;
|
||||
|
||||
System.out.println("ShapedRecipe width=" + width + ", height=" + height);
|
||||
System.out.println("Ingredients: ");
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
System.out.println("(" + posx[i] + ", " + posy[i] + "): " + this.ingredients[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
@@ -94,19 +100,12 @@ public class ShapedRecipe {
|
||||
}
|
||||
|
||||
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) {
|
||||
if (inventory.getStackCount() != 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 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;
|
||||
@@ -119,8 +118,8 @@ public class ShapedRecipe {
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i < inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j < inventory.getHeight() - height; j++) {
|
||||
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;
|
||||
@@ -139,8 +138,8 @@ public class ShapedRecipe {
|
||||
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 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;
|
||||
@@ -154,8 +153,8 @@ public class ShapedRecipe {
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i < inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j < inventory.getHeight() - height; j++) {
|
||||
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;
|
||||
|
||||
@@ -18,7 +18,21 @@ import java.util.logging.Logger;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.IRecipeRemover;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.minecraft.data.IData;
|
||||
import minetweaker.minecraft.item.Condition;
|
||||
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.Transform;
|
||||
import minetweaker.minecraft.liquid.ILiquidDefinition;
|
||||
import minetweaker.minecraft.liquid.ILiquidStack;
|
||||
import minetweaker.minecraft.oredict.IOreDict;
|
||||
import minetweaker.minecraft.oredict.IOreDictEntry;
|
||||
import minetweaker.minecraft.recipes.ICraftingInventory;
|
||||
import minetweaker.minecraft.recipes.IFurnaceManager;
|
||||
import minetweaker.minecraft.recipes.IRecipeFunction;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
@@ -27,11 +41,12 @@ import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.TypeRegistry;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticField;
|
||||
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
|
||||
import stanhebben.zenscript.symbols.SymbolPackage;
|
||||
import stanhebben.zenscript.symbols.SymbolType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeNative;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
@@ -46,7 +61,7 @@ public class GlobalRegistry {
|
||||
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 SymbolPackage root = new SymbolPackage("<root>");
|
||||
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>();
|
||||
@@ -73,7 +88,7 @@ public class GlobalRegistry {
|
||||
registerExpansion(ExpandShort.class);
|
||||
registerExpansion(ExpandString.class);*/
|
||||
|
||||
/*registerNativeClass(IData.class);
|
||||
registerNativeClass(IData.class);
|
||||
|
||||
registerNativeClass(IIngredient.class);
|
||||
registerNativeClass(IItemCondition.class);
|
||||
@@ -91,7 +106,7 @@ public class GlobalRegistry {
|
||||
|
||||
registerNativeClass(ICraftingInventory.class);
|
||||
registerNativeClass(IFurnaceManager.class);
|
||||
registerNativeClass(IRecipeFunction.class);*/
|
||||
registerNativeClass(IRecipeFunction.class);
|
||||
}
|
||||
|
||||
private GlobalRegistry() {}
|
||||
@@ -126,7 +141,7 @@ public class GlobalRegistry {
|
||||
ZenTypeNative type = new ZenTypeNative(cls);
|
||||
type.complete(types);
|
||||
|
||||
root.put(type.getName(), root, errors);
|
||||
root.put(type.getName(), new SymbolType(type), errors);
|
||||
}
|
||||
|
||||
public static TypeRegistry getTypeRegistry() {
|
||||
@@ -285,12 +300,12 @@ public class GlobalRegistry {
|
||||
|
||||
@Override
|
||||
public void error(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logError("[" + position.getFile() + ":" + position.getLine() + "] Error: " + message);
|
||||
MineTweakerAPI.logger.logError(position.toString() + " > " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(ZenPosition position, String message) {
|
||||
MineTweakerAPI.logger.logWarning("[" + position.getFile() + ":" + position.getLine() + "] Warning: " + message);
|
||||
MineTweakerAPI.logger.logWarning(position.toString() + " > " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
* @author Stan
|
||||
*/
|
||||
public interface ILogger {
|
||||
@ZenMethod
|
||||
public void logCommand(String message);
|
||||
|
||||
@ZenMethod
|
||||
public void logInfo(String message);
|
||||
|
||||
|
||||
@@ -45,12 +45,22 @@ public interface IMineTweaker {
|
||||
public List<IUndoableAction> rollback();
|
||||
|
||||
/**
|
||||
* Registers a script provider.
|
||||
* Sets the script provider.
|
||||
*
|
||||
* @param provider
|
||||
* @return
|
||||
*/
|
||||
public Closeable registerScriptProvider(IScriptProvider provider);
|
||||
public void setScriptProvider(IScriptProvider provider);
|
||||
|
||||
/**
|
||||
* Executes all scripts provided by the script provider.
|
||||
*/
|
||||
public void load();
|
||||
|
||||
/**
|
||||
* Retrieves the data from the scripts that were loaded last.
|
||||
*
|
||||
* @return scripts data
|
||||
*/
|
||||
public byte[] getScriptData();
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
package minetweaker.runtime;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
@@ -21,13 +20,14 @@ import java.util.Set;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.util.CloseablePriorityList;
|
||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
import stanhebben.zenscript.ZenModule;
|
||||
import static stanhebben.zenscript.ZenModule.compileScripts;
|
||||
import static stanhebben.zenscript.ZenModule.extractClassName;
|
||||
import stanhebben.zenscript.ZenParsedFile;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.parser.ParseException;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -35,14 +35,17 @@ import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class Tweaker implements IMineTweaker {
|
||||
private final CloseablePriorityList<IScriptProvider> scriptProviders = new CloseablePriorityList<IScriptProvider>();
|
||||
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
|
||||
private final Set<IUndoableAction> wereStuck = new HashSet<IUndoableAction>();
|
||||
|
||||
private IScriptProvider scriptProvider;
|
||||
private byte[] scriptData;
|
||||
|
||||
@Override
|
||||
public void apply(IUndoableAction action) {
|
||||
MineTweakerAPI.logger.logInfo(action.describe());
|
||||
action.apply();
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,49 +71,65 @@ public class Tweaker implements IMineTweaker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Closeable registerScriptProvider(IScriptProvider provider) {
|
||||
return scriptProviders.add(provider);
|
||||
public void setScriptProvider(IScriptProvider provider) {
|
||||
scriptProvider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
scriptData = ScriptProviderMemory.collect(scriptProvider);
|
||||
Set<String> executed = new HashSet<String>();
|
||||
|
||||
for (IScriptProvider provider : scriptProviders) {
|
||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||
|
||||
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
|
||||
|
||||
while (script.next()) {
|
||||
try {
|
||||
String filename = script.getName();
|
||||
|
||||
String className = extractClassName(filename);
|
||||
|
||||
Reader reader = new InputStreamReader(new BufferedInputStream(script.open()));
|
||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment());
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
reader.close();
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
}
|
||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
IEnvironmentGlobal environmentGlobal = GlobalRegistry.makeGlobalEnvironment(classes);
|
||||
|
||||
List<ZenParsedFile> files = new ArrayList<ZenParsedFile>();
|
||||
|
||||
while (script.next()) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new InputStreamReader(new BufferedInputStream(script.open()));
|
||||
|
||||
String filename = script.getName();
|
||||
String className = extractClassName(filename);
|
||||
|
||||
ZenTokener parser = new ZenTokener(reader, environmentGlobal.getEnvironment());
|
||||
ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal);
|
||||
files.add(pfile);
|
||||
} catch (IOException ex) {
|
||||
MineTweakerAPI.logger.logError("Could not load script " + script.getName() + ": " + ex.getMessage());
|
||||
} catch (ParseException ex) {
|
||||
MineTweakerAPI.logger.logError("Error parsing " + ex.getFile() + ":" + ex.getLine() + " -- " + ex.getExplanation());
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logger.logError("Error loading " + script.getName() + ": " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String filename = script.getGroupName();
|
||||
System.out.println("MineTweaker: Loading " + filename);
|
||||
compileScripts(filename, files, environmentGlobal);
|
||||
|
||||
|
||||
// execute scripts
|
||||
ZenModule module = new ZenModule(classes);
|
||||
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());
|
||||
module.getMain().run();
|
||||
} catch (Exception ex) {
|
||||
MineTweakerAPI.logger.logError("Error executing " + script.getGroupName() + ": " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,4 +141,9 @@ public class Tweaker implements IMineTweaker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getScriptData() {
|
||||
return scriptData;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.runtime.providers;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import minetweaker.runtime.IScriptIterator;
|
||||
import minetweaker.runtime.IScriptProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class ScriptProviderCascade implements IScriptProvider {
|
||||
private final IScriptProvider[] providers;
|
||||
|
||||
public ScriptProviderCascade(IScriptProvider... providers) {
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IScriptIterator> getScripts() {
|
||||
return new MyScripterator();
|
||||
}
|
||||
|
||||
private class MyScripterator implements Iterator<IScriptIterator> {
|
||||
private final Set<String> executed = new HashSet<String>();
|
||||
|
||||
private int currentIndex = providers.length - 1;
|
||||
private Iterator<IScriptIterator> current;
|
||||
private IScriptIterator currentValue;
|
||||
|
||||
public MyScripterator() {
|
||||
currentIndex = providers.length - 1;
|
||||
current = providers[currentIndex].getScripts();
|
||||
|
||||
advance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptIterator next() {
|
||||
IScriptIterator result = currentValue;
|
||||
executed.add(result.getGroupName());
|
||||
|
||||
advance();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void advance() {
|
||||
do {
|
||||
while (!current.hasNext()) {
|
||||
currentIndex--;
|
||||
if (currentIndex < 0) return;
|
||||
|
||||
current = providers[currentIndex].getScripts();
|
||||
}
|
||||
if (currentIndex < 0) break;
|
||||
|
||||
currentValue = current.next();
|
||||
} while (executed.contains(currentValue.getGroupName()) && hasNext());
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-20
@@ -31,33 +31,31 @@ import minetweaker.runtime.IScriptProvider;
|
||||
* @author Stan
|
||||
*/
|
||||
public class ScriptProviderMemory implements IScriptProvider {
|
||||
public static byte[] collect(Iterable<IScriptProvider> providers) {
|
||||
public static byte[] collect(IScriptProvider provider) {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
try {
|
||||
DeflaterOutputStream deflater = new DeflaterOutputStream(output);
|
||||
DataOutputStream deflaterData = new DataOutputStream(deflater);
|
||||
Set<String> executed = new HashSet<String>();
|
||||
|
||||
for (IScriptProvider provider : providers) {
|
||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
deflaterData.writeUTF(script.getGroupName());
|
||||
|
||||
while (script.next()) {
|
||||
String name = script.getName();
|
||||
byte[] data = FileUtil.read(script.open());
|
||||
deflaterData.writeUTF(name);
|
||||
deflaterData.writeInt(data.length);
|
||||
deflaterData.write(data);
|
||||
}
|
||||
|
||||
deflaterData.writeUTF("");
|
||||
Iterator<IScriptIterator> scripts = provider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator script = scripts.next();
|
||||
|
||||
if (!executed.contains(script.getGroupName())) {
|
||||
executed.add(script.getGroupName());
|
||||
|
||||
deflaterData.writeUTF(script.getGroupName());
|
||||
|
||||
while (script.next()) {
|
||||
String name = script.getName();
|
||||
byte[] data = FileUtil.read(script.open());
|
||||
deflaterData.writeUTF(name);
|
||||
deflaterData.writeInt(data.length);
|
||||
deflaterData.write(data);
|
||||
}
|
||||
|
||||
deflaterData.writeUTF("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,3 +26,9 @@ dependencies {
|
||||
compile project(':MineTweaker3-API')
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'FMLCorePlugin': 'minetweaker.mc172.transformer.MineTweakerTransformer'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package minetweaker.mc172;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.network.MineTweakerLoadScriptsPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class FMLEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev) {
|
||||
if (ev.player instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) ev.player;
|
||||
MineTweakerMod.NETWORK.sendTo(
|
||||
new MineTweakerLoadScriptsPacket(MineTweakerAPI.tweaker.getScriptData()),
|
||||
player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ForgeEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onCrafted(PlayerEvent.ItemCraftedEvent ev) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,20 @@ package minetweaker.mc172;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.util.StringUtil;
|
||||
|
||||
/**
|
||||
@@ -43,7 +52,21 @@ public class MineTweakerCommand implements ICommand {
|
||||
public String getCommandUsage(ICommandSender icommandsender) {
|
||||
return StringUtil.join(new String[] {
|
||||
"",
|
||||
"minetweaker name <id>[:<meta>]",
|
||||
"minetweaker reload",
|
||||
" Reloads all scripts",
|
||||
"minetweaker names",
|
||||
" Outputs a list of all item names in the game to the minetweaker log",
|
||||
"minetweaker liquids",
|
||||
" Outputs a list of all liquid names in the game to the minetweaker log",
|
||||
"minetweaker inventory",
|
||||
" Lists all items in your inventory",
|
||||
"minetweaker hand",
|
||||
" Outputs the name of the item in your hand",
|
||||
"minetweaker oredict",
|
||||
" Outputs all ore dictionary entries in the game to the minetweaker log",
|
||||
"minetweaker oredict <name>",
|
||||
" Outputs all items in the given ore dictionary entry to the minetweaker log"
|
||||
/* "minetweaker name <id>[:<meta>]",
|
||||
" Prints the unlocalized name of the specified item," +
|
||||
" can be used as item or block name",
|
||||
"minetweaker liquid <id>[:<meta>]",
|
||||
@@ -66,7 +89,7 @@ public class MineTweakerCommand implements ICommand {
|
||||
"minetweaker logdamage=off",
|
||||
" Disables damage logging",
|
||||
"minetweaker reload",
|
||||
" Reloads the server script"
|
||||
" Reloads the server script"*/
|
||||
}, "\n");
|
||||
}
|
||||
|
||||
@@ -84,6 +107,94 @@ public class MineTweakerCommand implements ICommand {
|
||||
|
||||
if (arguments[0].equals("reload")) {
|
||||
MineTweakerAPI.tweaker.load();
|
||||
|
||||
String message = "Scripts have been reloaded";
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
sendChatMessage(icommandsender, message);
|
||||
} else if (arguments[0].equals("names")) {
|
||||
for (Object okey : Item.itemRegistry.getKeys()) {
|
||||
String key = (String) okey;
|
||||
Item item = (Item) Item.itemRegistry.getObject(key);
|
||||
|
||||
String message = "<" + key + "> -- " + new ItemStack(item, 1, 0).getDisplayName();
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
}
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
} else if (arguments[0].equals("liquids")) {
|
||||
for (Map.Entry<String, Fluid> entry : FluidRegistry.getRegisteredFluids().entrySet()) {
|
||||
String message = "<liquid:" + entry.getKey() + "> -- " + entry.getValue().getLocalizedName();
|
||||
MineTweakerAPI.logger.logCommand(message);
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else if (arguments[0].equals("inventory")) {
|
||||
if (icommandsender instanceof EntityPlayer) {
|
||||
InventoryPlayer inventory = ((EntityPlayer) icommandsender).inventory;
|
||||
for(int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
if (stack.getItemDamage() > 0) {
|
||||
description.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
description.append('>');
|
||||
|
||||
if (stack.stackSize != 1) {
|
||||
description.append('*').append(stack.stackSize);
|
||||
}
|
||||
|
||||
sendChatMessage(icommandsender, new TweakerItemStack(stack).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Inventory command can only be executed by players");
|
||||
}
|
||||
} else if (arguments[0].equals("hand")) {
|
||||
if (icommandsender instanceof EntityPlayer) {
|
||||
InventoryPlayer inventory = ((EntityPlayer) icommandsender).inventory;
|
||||
ItemStack stack = inventory.getCurrentItem();
|
||||
if (stack != null) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
if (stack.getItemDamage() > 0) {
|
||||
description.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
description.append('>');
|
||||
|
||||
if (stack.stackSize != 1) {
|
||||
description.append('*').append(stack.stackSize);
|
||||
}
|
||||
|
||||
sendChatMessage(icommandsender, new TweakerItemStack(stack).toString());
|
||||
}
|
||||
} else {
|
||||
sendChatMessage(icommandsender, "Hand command can only be executed by players");
|
||||
}
|
||||
} else if (arguments[0].equals("oredict")) {
|
||||
if (arguments.length > 2) {
|
||||
String entryName = arguments[2];
|
||||
List<ItemStack> ores = OreDictionary.getOres(entryName);
|
||||
if (ores.isEmpty()) {
|
||||
sendChatMessage(icommandsender, "Entry doesn't exist");
|
||||
return;
|
||||
} else {
|
||||
MineTweakerAPI.logger.logCommand("Ore entries for " + entryName + ":");
|
||||
for (ItemStack ore : ores) {
|
||||
MineTweakerAPI.logger.logCommand(" " + new TweakerItemStack(ore).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String entryName : OreDictionary.getOreNames()) {
|
||||
MineTweakerAPI.logger.logCommand("Ore entries for " + entryName + ":");
|
||||
List<ItemStack> ores = OreDictionary.getOres(entryName);
|
||||
for (ItemStack ore : ores) {
|
||||
MineTweakerAPI.logger.logCommand(" " + new TweakerItemStack(ore).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
sendChatMessage(icommandsender, "List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
|
||||
/*if (arguments[0].equals("name")) {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLogger implements ILogger {
|
||||
private Writer writer;
|
||||
|
||||
public MineTweakerLogger() {
|
||||
File logFile = new File("minetweaker.log");
|
||||
if (logFile.exists()) logFile.delete();
|
||||
|
||||
try {
|
||||
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(logFile)));
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.append("COMMAND: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("COMMAND: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.append("INFO: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("INFO: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.append("WARNING: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("WARNING: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
try {
|
||||
writer.append("ERROR: ");
|
||||
writer.append(message);
|
||||
writer.append('\n');
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
|
||||
System.out.println("ERROR: " + message);
|
||||
}
|
||||
}
|
||||
@@ -6,31 +6,63 @@
|
||||
|
||||
package minetweaker.mc172;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.mc172.brackets.ItemBracketHandler;
|
||||
import minetweaker.mc172.brackets.LiquidBracketHandler;
|
||||
import minetweaker.mc172.network.MineTweakerLoadScriptsHandler;
|
||||
import minetweaker.mc172.network.MineTweakerLoadScriptsPacket;
|
||||
import minetweaker.mc172.oredict.OreDict;
|
||||
import minetweaker.mc172.recipes.MTRecipeManager;
|
||||
import minetweaker.mc172.util.MineTweakerHacks;
|
||||
import minetweaker.runtime.IScriptProvider;
|
||||
import minetweaker.runtime.providers.ScriptProviderCascade;
|
||||
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
* Main mod class. Performs some general logic, initialization of the API and
|
||||
* FML event handling.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@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";
|
||||
|
||||
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
|
||||
|
||||
static {
|
||||
NETWORK.registerMessage(MineTweakerLoadScriptsHandler.class, MineTweakerLoadScriptsPacket.class, 0, Side.CLIENT);
|
||||
}
|
||||
|
||||
@Mod.Instance(MODID)
|
||||
public static MineTweakerMod instance;
|
||||
public static MineTweakerMod INSTANCE;
|
||||
|
||||
private final IScriptProvider scriptsGlobal;
|
||||
|
||||
private boolean iAmServer = false;
|
||||
|
||||
public MineTweakerMod() {
|
||||
MineTweakerAPI.oreDict = new OreDict();
|
||||
MineTweakerAPI.recipes = new MTRecipeManager();
|
||||
MineTweakerAPI.logger = new MineTweakerLogger();
|
||||
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
MineTweakerRegistry.getClasses(classes);
|
||||
@@ -47,5 +79,64 @@ public class MineTweakerMod {
|
||||
|
||||
MineTweakerAPI.registerClass(cls);
|
||||
}
|
||||
|
||||
File globalDir = new File("scripts");
|
||||
if (!globalDir.exists()) {
|
||||
globalDir.mkdirs();
|
||||
}
|
||||
|
||||
scriptsGlobal = new ScriptProviderDirectory(globalDir);
|
||||
MineTweakerAPI.tweaker.setScriptProvider(scriptsGlobal);
|
||||
}
|
||||
|
||||
public boolean iAmServer() {
|
||||
return iAmServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all scripts.
|
||||
*/
|
||||
public void reload() {
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
MineTweakerAPI.tweaker.load();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### FML Event Handlers ###
|
||||
// ##########################
|
||||
|
||||
@EventHandler
|
||||
public void onLoad(FMLPreInitializationEvent ev) {
|
||||
MinecraftForge.EVENT_BUS.register(new FMLEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(new FMLEventHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPostInit(FMLPostInitializationEvent ev) {
|
||||
MineTweakerAPI.registerBracketHandler(new ItemBracketHandler());
|
||||
MineTweakerAPI.registerBracketHandler(new LiquidBracketHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent ev) {
|
||||
// starts before loading worlds
|
||||
// perfect place to start MineTweaker!
|
||||
|
||||
File scriptsDir = new File(MineTweakerHacks.getWorldDirectory(ev.getServer()), "scripts");
|
||||
if (!scriptsDir.exists()) {
|
||||
scriptsDir.mkdir();
|
||||
}
|
||||
|
||||
iAmServer = true;
|
||||
|
||||
IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir);
|
||||
IScriptProvider cascaded = new ScriptProviderCascade(scriptsGlobal, scriptsLocal);
|
||||
MineTweakerAPI.tweaker.setScriptProvider(cascaded);
|
||||
reload();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent ev) {
|
||||
ev.registerServerCommand(new MineTweakerCommand());
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import minetweaker.minecraft.item.IngredientAny;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.expression.ExpressionInt;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler(priority=100)
|
||||
public class ItemBracketHandler implements IBracketHandler {
|
||||
public static IItemStack getItem(String name, int meta) {
|
||||
Item item = (Item) Item.itemRegistry.getObject(name);
|
||||
if (item != null) {
|
||||
return new TweakerItemStack(new ItemStack(item, 1, meta), true);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final IZenSymbol symbolAny;
|
||||
private final JavaMethod method;
|
||||
|
||||
public ItemBracketHandler() {
|
||||
symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE");
|
||||
method = MineTweakerAPI.getJavaMethod(
|
||||
ItemBracketHandler.class,
|
||||
"getItem",
|
||||
String.class, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
// any symbol
|
||||
if (tokens.size() == 1 && tokens.get(0).getValue().equals("*")) {
|
||||
return symbolAny;
|
||||
}
|
||||
|
||||
// detect special cases:
|
||||
// item: at the start means item-specific syntax
|
||||
// :xxx with xxx an integer means sub-item syntax
|
||||
// :* means any-subitem-syntax
|
||||
int fromIndex = 0;
|
||||
int toIndex = tokens.size();
|
||||
int meta = 0;
|
||||
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("item") && tokens.get(1).getValue().equals(":")) {
|
||||
fromIndex = 2;
|
||||
}
|
||||
if (tokens.get(tokens.size() - 1).getType() == ZenTokener.T_INTVALUE
|
||||
&& tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
||||
toIndex = tokens.size() - 2;
|
||||
meta = Integer.parseInt(tokens.get(tokens.size() - 1).getValue());
|
||||
} else if (tokens.get(tokens.size() - 1).getValue().equals("*")
|
||||
&& tokens.get(tokens.size() - 2).getValue().equals(":")) {
|
||||
toIndex = tokens.size() - 2;
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return find(tokens, fromIndex, toIndex, meta);
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex, int meta) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
Item item = (Item) Item.itemRegistry.getObject(valueBuilder.toString());
|
||||
if (item != null) {
|
||||
return new ItemReferenceSymbol(valueBuilder.toString(), meta);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ItemReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
private final int meta;
|
||||
|
||||
public ItemReferenceSymbol(String name, int meta) {
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name),
|
||||
new ExpressionInt(position, meta, ZenType.INT));
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package minetweaker.mc172.brackets;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc172.liquid.TweakerLiquidStack;
|
||||
import minetweaker.minecraft.liquid.ILiquidStack;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@BracketHandler
|
||||
public class LiquidBracketHandler implements IBracketHandler {
|
||||
public static ILiquidStack getLiquid(String name) {
|
||||
Fluid fluid = FluidRegistry.getFluid(name);
|
||||
if (fluid != null) {
|
||||
return new TweakerLiquidStack(new FluidStack(fluid, 1));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
if (tokens.size() > 2) {
|
||||
if (tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) {
|
||||
return find(tokens, 2, tokens.size());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IZenSymbol find(List<Token> tokens, int startIndex, int endIndex) {
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
Token token = tokens.get(i);
|
||||
valueBuilder.append(token.getValue());
|
||||
}
|
||||
|
||||
Fluid fluid = FluidRegistry.getFluid(valueBuilder.toString());
|
||||
if (fluid != null) {
|
||||
return new LiquidReferenceSymbol(valueBuilder.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class LiquidReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
|
||||
public LiquidReferenceSymbol(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
JavaMethod method = JavaMethod.get(
|
||||
GlobalRegistry.getTypeRegistry(),
|
||||
LiquidBracketHandler.class,
|
||||
"getLiquid",
|
||||
String.class);
|
||||
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,12 @@ public class NBTConverter implements IDataConverter<NBTBase> {
|
||||
}
|
||||
}
|
||||
|
||||
private NBTConverter() {}
|
||||
public static void updateMap(NBTTagCompound nbt, IData data) {
|
||||
NBTUpdater updater = new NBTUpdater(nbt);
|
||||
data.convert(updater);
|
||||
}
|
||||
|
||||
public NBTConverter() {}
|
||||
|
||||
@Override
|
||||
public NBTBase fromBool(boolean value) {
|
||||
|
||||
@@ -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 minetweaker.mc172.data;
|
||||
|
||||
import java.util.Map;
|
||||
import minetweaker.minecraft.data.IData;
|
||||
import minetweaker.minecraft.data.IDataConverter;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class NBTUpdater extends NBTConverter implements IDataConverter<NBTBase> {
|
||||
private final NBTTagCompound nbt;
|
||||
|
||||
public NBTUpdater(NBTTagCompound compound) {
|
||||
this.nbt = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> map) {
|
||||
for (Map.Entry<String, IData> entry : map.entrySet()) {
|
||||
if (nbt.hasKey(entry.getKey())) {
|
||||
if (entry.getValue() == null) {
|
||||
nbt.removeTag(entry.getKey());
|
||||
} else {
|
||||
if (nbt.getTag(entry.getKey()).getId() == 10) {
|
||||
NBTTagCompound tag = (NBTTagCompound) nbt.getTag(entry.getKey());
|
||||
nbt.setTag(entry.getKey(), entry.getValue().convert(new NBTUpdater(nbt)));
|
||||
} else {
|
||||
nbt.setTag(entry.getKey(), NBTConverter.from(entry.getValue()));
|
||||
}
|
||||
}
|
||||
} else if (entry.getValue() != null) {
|
||||
nbt.setTag(entry.getKey(), from(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import minetweaker.minecraft.item.IItemTransformer;
|
||||
import minetweaker.minecraft.item.IngredientItem;
|
||||
import minetweaker.minecraft.liquid.ILiquidStack;
|
||||
import minetweaker.minecraft.util.ArrayUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
@@ -34,13 +35,24 @@ public class TweakerItemStack implements IItemStack {
|
||||
private final ItemStack stack;
|
||||
private final List<IItemStack> items;
|
||||
private IData tag = null;
|
||||
private boolean wildcardSize;
|
||||
|
||||
public TweakerItemStack(ItemStack itemStack) {
|
||||
stack = itemStack;
|
||||
if (itemStack == null) throw new IllegalArgumentException("stack cannot be null");
|
||||
|
||||
stack = itemStack.copy();
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
}
|
||||
|
||||
public TweakerItemStack(ItemStack itemStack, boolean wildcardSize) {
|
||||
this(itemStack);
|
||||
|
||||
this.wildcardSize = wildcardSize;
|
||||
}
|
||||
|
||||
private TweakerItemStack(ItemStack itemStack, IData tag) {
|
||||
if (itemStack == null) throw new IllegalArgumentException("stack cannot be null");
|
||||
|
||||
stack = itemStack;
|
||||
items = Collections.<IItemStack>singletonList(this);
|
||||
this.tag = tag;
|
||||
@@ -157,7 +169,7 @@ public class TweakerItemStack implements IItemStack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
public IItemStack amount(int amount) {
|
||||
return withAmount(amount);
|
||||
}
|
||||
|
||||
@@ -179,8 +191,11 @@ public class TweakerItemStack implements IItemStack {
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
ItemStack internal = (ItemStack) item.getInternal();
|
||||
if (internal == null) {
|
||||
throw new RuntimeException("Invalid item: " + item);
|
||||
}
|
||||
return internal.getItem() == stack.getItem()
|
||||
&& internal.stackSize == stack.stackSize
|
||||
&& (wildcardSize || internal.stackSize == stack.stackSize)
|
||||
&& (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack.getItemDamage() == internal.getItemDamage());
|
||||
}
|
||||
|
||||
@@ -200,4 +215,32 @@ public class TweakerItemStack implements IItemStack {
|
||||
public Object getInternal() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('<');
|
||||
result.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
|
||||
if (stack.getItemDamage() > 0) {
|
||||
result.append(':').append(stack.getItemDamage());
|
||||
}
|
||||
result.append('>');
|
||||
|
||||
if (stack.getTagCompound() != null) {
|
||||
result.append(".withData(");
|
||||
result.append(stack.stackTagCompound.toString());
|
||||
result.append(")");
|
||||
}
|
||||
|
||||
if (!wildcardSize) {
|
||||
result.append(" * ").append(stack.stackSize);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
+10
@@ -23,6 +23,16 @@ public class TweakerLiquidDefinition implements ILiquidDefinition {
|
||||
public TweakerLiquidDefinition(Fluid fluid) {
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return fluid.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return fluid.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidStack asStack(int millibuckets) {
|
||||
|
||||
@@ -34,6 +34,16 @@ public class TweakerLiquidStack implements ILiquidStack {
|
||||
public ILiquidDefinition getDefinition() {
|
||||
return new TweakerLiquidDefinition(stack.getFluid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return stack.getFluid().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return stack.getFluid().getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
|
||||
+41
@@ -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.mc172.network;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.MineTweakerMod;
|
||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLoadScriptsHandler implements IMessageHandler<MineTweakerLoadScriptsPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MineTweakerLoadScriptsPacket message, MessageContext ctx) {
|
||||
if (!MineTweakerMod.INSTANCE.iAmServer()) {
|
||||
/*IScriptProvider scriptProvider = new ScriptProviderMemory(message.getData());
|
||||
Iterator<IScriptIterator> scripts = scriptProvider.getScripts();
|
||||
while (scripts.hasNext()) {
|
||||
IScriptIterator myGroup = scripts.next();
|
||||
System.out.println("Scripts: " + myGroup.getGroupName());
|
||||
|
||||
while (myGroup.next()) {
|
||||
System.out.println("Script name: " + myGroup.getName());
|
||||
}
|
||||
}*/
|
||||
MineTweakerAPI.tweaker.setScriptProvider(new ScriptProviderMemory(message.getData()));
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
MineTweakerAPI.tweaker.load();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.network;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerLoadScriptsPacket implements IMessage {
|
||||
private byte[] data;
|
||||
|
||||
public MineTweakerLoadScriptsPacket() {
|
||||
// used for deserialization
|
||||
}
|
||||
|
||||
public MineTweakerLoadScriptsPacket(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
data = new byte[size];
|
||||
buf.readBytes(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(data.length);
|
||||
buf.writeBytes(data);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,10 @@ public class OreDictEntry implements IOreDictEntry {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public OreDictEntry(String id) {
|
||||
this.id = OreDictionary.getOreID(id);
|
||||
}
|
||||
|
||||
// ####################################
|
||||
// ### IOreDictEntry implementation ###
|
||||
// ####################################
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.player;
|
||||
|
||||
import minetweaker.mc172.data.NBTConverter;
|
||||
import minetweaker.minecraft.data.IData;
|
||||
import minetweaker.minecraft.player.IPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class TweakerPlayer implements IPlayer {
|
||||
private final EntityPlayer player;
|
||||
|
||||
public TweakerPlayer(EntityPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return player.getCommandSenderName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getData() {
|
||||
return NBTConverter.from(player.getEntityData(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IData data) {
|
||||
NBTConverter.updateMap(player.getEntityData(), data);
|
||||
}
|
||||
}
|
||||
+176
-38
@@ -1,9 +1,3 @@
|
||||
/*
|
||||
* 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;
|
||||
@@ -13,11 +7,17 @@ import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.mc172.oredict.OreDictEntry;
|
||||
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.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
@@ -32,7 +32,7 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
private final List<IRecipe> recipes;
|
||||
|
||||
public MTRecipeManager() {
|
||||
recipes = MineTweakerHacks.getRecipes();
|
||||
recipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,13 +41,17 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
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);
|
||||
|
||||
// certain special recipes have no predefined output. ignore those
|
||||
// since these cannot be removed with MineTweaker scripts
|
||||
if (recipe.getRecipeOutput() != null) {
|
||||
if (output.matches(new TweakerItemStack(recipe.getRecipeOutput()))) {
|
||||
toRemove.add(recipe);
|
||||
removeIndex.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MineTweakerAPI.tweaker.apply(new ActionRemoveRecipes(toRemove, removeIndex));
|
||||
return toRemove.size();
|
||||
}
|
||||
@@ -78,21 +82,71 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
|
||||
@Override
|
||||
public int removeShaped(IIngredient output, IIngredient[][] ingredients) {
|
||||
int ingredientsWidth = 0;
|
||||
int ingredientsHeight = 0;
|
||||
|
||||
if (ingredients != null) {
|
||||
ingredientsHeight = ingredients.length;
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length);
|
||||
}
|
||||
}
|
||||
|
||||
List<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
for (int i = 0; i < recipes.size(); i++) {
|
||||
outer: 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
|
||||
if (ingredients != null) {
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes srecipe = (ShapedRecipes) recipe;
|
||||
if (ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredientsHeight; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
for (int k = 0; k < ingredientsWidth; k++) {
|
||||
IIngredient ingredient = k > row.length ? null : row[k];
|
||||
ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k];
|
||||
|
||||
if (!matches(recipeIngredient, ingredient)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe srecipe = (ShapedOreRecipe) recipe;
|
||||
int recipeWidth = MineTweakerHacks.getShapedOreRecipeWidth(srecipe);
|
||||
int recipeHeight = srecipe.getRecipeSize() / recipeWidth;
|
||||
if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < ingredientsHeight; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
for (int k = 0; k < ingredientsWidth; k++) {
|
||||
IIngredient ingredient = k > row.length ? null : row[k];
|
||||
Object input = srecipe.getInput()[j * recipeWidth + k];
|
||||
if (!matches(input, ingredient)) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (recipe instanceof ShapedRecipe) {
|
||||
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
@@ -107,31 +161,60 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
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++) {
|
||||
outer: 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) {
|
||||
if (ingredients != null) {
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes srecipe = (ShapelessRecipes) recipe;
|
||||
|
||||
if (ingredients.length > srecipe.getRecipeSize()) {
|
||||
continue;
|
||||
} else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checkIngredient: for (int j = 0; j < ingredients.length; j++) {
|
||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||
if (matches(srecipe.recipeItems.get(k), ingredients[j])) {
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
continue outer;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
checkIngredient: for (int j = 0; j < ingredients.length; j++) {
|
||||
for (int k = 0; k < srecipe.getRecipeSize(); k++) {
|
||||
if (matches(inputs.get(k), ingredients[j])) {
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (recipe instanceof ShapelessRecipes) {
|
||||
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: check contents
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
@@ -144,7 +227,43 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
|
||||
@Override
|
||||
public IItemStack craft(IItemStack[][] contents) {
|
||||
return null; // TODO: implement
|
||||
Container container = new ContainerVirtual();
|
||||
|
||||
int width = 0;
|
||||
int height = contents.length;
|
||||
for (IItemStack[] row : contents) {
|
||||
width = Math.max(width, row.length);
|
||||
}
|
||||
|
||||
ItemStack[] iContents = new ItemStack[width * height];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < contents[i].length; j++) {
|
||||
if (contents[i][j] != null) {
|
||||
Object internal = contents[i][j].getInternal();
|
||||
if (internal != null && (internal instanceof ItemStack)) {
|
||||
iContents[i * width + j] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
InventoryCrafting inventory = new InventoryCrafting(container, width, height);
|
||||
for (int i = 0; i < iContents.length; i++) {
|
||||
inventory.setInventorySlotContents(i, iContents[i]);
|
||||
}
|
||||
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(inventory, Minecraft.getMinecraft().theWorld);
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new TweakerItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
private class ContainerVirtual extends Container {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer var1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionRemoveRecipes implements IUndoableAction {
|
||||
@@ -195,6 +314,7 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
CraftingManager.getInstance().getRecipeList().add(recipe);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@@ -218,4 +338,22 @@ public class MTRecipeManager implements IRecipeManager {
|
||||
return "Removing recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean matches(Object input, IIngredient ingredient) {
|
||||
if ((input == null) != (ingredient == null)) {
|
||||
return false;
|
||||
} else if (ingredient != null) {
|
||||
if (input instanceof ItemStack) {
|
||||
if (!ingredient.matches(new TweakerItemStack((ItemStack) input))) {
|
||||
return false;
|
||||
}
|
||||
} else if (input instanceof String) {
|
||||
if (!ingredient.contains(new OreDictEntry((String) input))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,7 @@ public class RecipeConverter {
|
||||
|
||||
// construct recipe
|
||||
if (type == TYPE_BASIC) {
|
||||
System.out.println("Converted to basic recipe");
|
||||
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();
|
||||
@@ -82,6 +83,7 @@ public class RecipeConverter {
|
||||
|
||||
return new ShapedRecipeBasic(basicIngredients, recipe);
|
||||
} else if (type == TYPE_ORE) {
|
||||
System.out.println("Converted to ore recipe");
|
||||
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();
|
||||
@@ -113,6 +115,7 @@ public class RecipeConverter {
|
||||
|
||||
return new ShapedRecipeOre(rarguments.toArray(), recipe);
|
||||
} else {
|
||||
System.out.println("Converted to advanced recipe");
|
||||
return new ShapedRecipeAdvanced(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class ShapedRecipeAdvanced implements IRecipe {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
|
||||
return ((ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
package minetweaker.mc172.recipes;
|
||||
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import minetweaker.minecraft.recipes.ShapedRecipe;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -32,6 +33,11 @@ public class ShapedRecipeBasic extends ShapedRecipes {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
|
||||
IItemStack result = recipe.getCraftingResult(TweakerCraftingInventory.get(inventory));
|
||||
if (result == null) {
|
||||
return null;
|
||||
} else {
|
||||
return ((ItemStack) result.getInternal()).copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,6 @@ public class ShapedRecipeOre extends ShapedOreRecipe {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
|
||||
return ((ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class ShapelessRecipeAdvanced implements IRecipe {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
|
||||
return ((ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -33,6 +33,6 @@ public class ShapelessRecipeBasic extends ShapelessRecipes {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
|
||||
return ((ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -32,6 +32,6 @@ public class ShapelessRecipeOre extends ShapelessOreRecipe {
|
||||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventory) {
|
||||
return (ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal();
|
||||
return ((ItemStack) recipe.getCraftingResult(TweakerCraftingInventory.get(inventory)).getInternal()).copy();
|
||||
}
|
||||
}
|
||||
+91
-10
@@ -6,10 +6,16 @@
|
||||
|
||||
package minetweaker.mc172.recipes;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.mc172.util.MineTweakerHacks;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import minetweaker.minecraft.recipes.ICraftingInventory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
@@ -25,24 +31,60 @@ public class TweakerCraftingInventory implements ICraftingInventory {
|
||||
cache.set(result);
|
||||
return result;
|
||||
} else {
|
||||
return cache.get();
|
||||
TweakerCraftingInventory result = cache.get();
|
||||
result.update();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
private int width;
|
||||
private int height;
|
||||
private final InventoryCrafting inventory;
|
||||
private final IItemStack[] stacks;
|
||||
private IItemStack[] stacks;
|
||||
private ItemStack[] original;
|
||||
private int stackCount;
|
||||
|
||||
private TweakerCraftingInventory(InventoryCrafting inventory) {
|
||||
this.inventory = inventory;
|
||||
width = height = (int) Math.sqrt(inventory.getSizeInventory());
|
||||
stacks = new IItemStack[width * height];
|
||||
original = new ItemStack[stacks.length];
|
||||
stackCount = 0;
|
||||
update();
|
||||
|
||||
Container container = MineTweakerHacks.getCraftingContainer(inventory);
|
||||
List<Slot> slots = container.inventorySlots;
|
||||
if (!slots.isEmpty() && slots.get(0) instanceof SlotCrafting) {
|
||||
SlotCrafting slotCrafting = (SlotCrafting) slots.get(0);
|
||||
EntityPlayer player = MineTweakerHacks.getCraftingSlotPlayer(slotCrafting);
|
||||
System.out.println("Crafting slot for " + player.getCommandSenderName());
|
||||
}
|
||||
|
||||
System.out.println("Container: " + MineTweakerHacks.getCraftingContainer(inventory));
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (inventory.getSizeInventory() != original.length) {
|
||||
width = height = (int) Math.sqrt(inventory.getSizeInventory());
|
||||
stacks = new IItemStack[inventory.getSizeInventory()];
|
||||
original = new ItemStack[stacks.length];
|
||||
stackCount = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
stacks[i] = new TweakerItemStack(inventory.getStackInSlot(i));
|
||||
if (changed(i)) {
|
||||
System.out.println("Slot " + i + " changed");
|
||||
original[i] = inventory.getStackInSlot(i);
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
if (stacks[i] == null) stackCount++;
|
||||
stacks[i] = new TweakerItemStack(original[i]);
|
||||
} else {
|
||||
if (stacks[i] != null) stackCount--;
|
||||
stacks[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println("Num stack count: " + stackCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,6 +101,11 @@ public class TweakerCraftingInventory implements ICraftingInventory {
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStackCount() {
|
||||
return stackCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getStack(int i) {
|
||||
@@ -72,13 +119,47 @@ public class TweakerCraftingInventory implements ICraftingInventory {
|
||||
|
||||
@Override
|
||||
public void setStack(int x, int y, IItemStack stack) {
|
||||
stacks[y * width + x] = stack;
|
||||
inventory.setInventorySlotContents(y * width + x, (ItemStack) stack.getInternal());
|
||||
System.out.println("SetStack(" + x + ", " + y + ") " + stack);
|
||||
|
||||
int ix = y * width + x;
|
||||
if (stack != stacks[ix]) {
|
||||
if (stack == null) {
|
||||
stackCount--;
|
||||
inventory.setInventorySlotContents(ix, null);
|
||||
} else {
|
||||
inventory.setInventorySlotContents(ix, (ItemStack) stack.getInternal());
|
||||
|
||||
if (stacks[ix] == null) {
|
||||
stackCount++;
|
||||
}
|
||||
}
|
||||
stacks[ix] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int i, IItemStack stack) {
|
||||
stacks[i] = stack;
|
||||
inventory.setInventorySlotContents(i, (ItemStack) stack.getInternal());
|
||||
System.out.println("SetStack(" + i + ") " + stack);
|
||||
|
||||
if (stack != stacks[i]) {
|
||||
if (stack == null) {
|
||||
stackCount--;
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
} else {
|
||||
inventory.setInventorySlotContents(i, (ItemStack) stack.getInternal());
|
||||
|
||||
if (stacks[i] == null) {
|
||||
stackCount++;
|
||||
}
|
||||
}
|
||||
stacks[i] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean changed(int i) {
|
||||
if (original[i] != inventory.getStackInSlot(i)) return true;
|
||||
if (original[i] != null && stacks[i].getAmount() != original[i].stackSize) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.objectweb.asm.Opcodes;
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class MineTweakerASM implements IClassTransformer {
|
||||
public MineTweakerASM() {}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String newName, byte[] bytecode) {
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ import minetweaker.mc172.MineTweakerMod;
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
@MCVersion(MineTweakerMod.MCVERSION)
|
||||
@IFMLLoadingPlugin.TransformerExclusions("minetweaker.mc172.transformer")
|
||||
//@MCVersion(MineTweakerMod.MCVERSION)
|
||||
//@IFMLLoadingPlugin.TransformerExclusions("minetweaker.mc172.transformer")
|
||||
public class MineTweakerTransformer implements IFMLLoadingPlugin {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,17 +6,21 @@
|
||||
|
||||
package minetweaker.mc172.util;
|
||||
|
||||
import java.io.File;
|
||||
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.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.SlotCrafting;import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
/**
|
||||
* Common class for all runtime hacks (stuff requiring reflection). It is not
|
||||
@@ -28,10 +32,18 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
public class MineTweakerHacks {
|
||||
private static final Field NBTTAGLIST_TAGLIST;
|
||||
private static final Field OREDICTIONARY_ORESTACKS;
|
||||
private static final Field MINECRAFTSERVER_ANVILFILE;
|
||||
private static final Field SHAPEDORERECIPE_WIDTH;
|
||||
private static final Field INVENTORYCRAFTING_EVENTHANDLER;
|
||||
private static final Field SLOTCRAFTING_PLAYER;
|
||||
|
||||
static {
|
||||
NBTTAGLIST_TAGLIST = getField(NBTTagList.class, MineTweakerObfuscation.NBTTAGLIST_TAGLIST);
|
||||
OREDICTIONARY_ORESTACKS = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_ORESTACKS);
|
||||
MINECRAFTSERVER_ANVILFILE = getField(MinecraftServer.class, MineTweakerObfuscation.MINECRAFTSERVER_ANVILFILE);
|
||||
SHAPEDORERECIPE_WIDTH = getField(ShapedOreRecipe.class, new String[] {"width"});
|
||||
INVENTORYCRAFTING_EVENTHANDLER = getField(InventoryCrafting.class, MineTweakerObfuscation.INVENTORYCRAFTING_EVENTHANDLER);
|
||||
SLOTCRAFTING_PLAYER = getField(SlotCrafting.class, MineTweakerObfuscation.SLOTCRAFTING_PLAYER);
|
||||
}
|
||||
|
||||
private MineTweakerHacks() {}
|
||||
@@ -49,16 +61,6 @@ public class MineTweakerHacks {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -68,10 +70,61 @@ public class MineTweakerHacks {
|
||||
}
|
||||
}
|
||||
|
||||
public static File getAnvilFile(MinecraftServer server) {
|
||||
try {
|
||||
return (File) MINECRAFTSERVER_ANVILFILE.get(server);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not load anvil file!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static File getWorldDirectory(MinecraftServer server) {
|
||||
if (server.isDedicatedServer()) {
|
||||
return server.getFile("world");
|
||||
} else {
|
||||
File worldsDir = getAnvilFile(server);
|
||||
if (worldsDir == null) return null;
|
||||
|
||||
return new File(worldsDir, server.getFolderName());
|
||||
}
|
||||
}
|
||||
|
||||
public static int getShapedOreRecipeWidth(ShapedOreRecipe recipe) {
|
||||
try {
|
||||
return SHAPEDORERECIPE_WIDTH.getInt(recipe);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not load anvil file!");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
public static Container getCraftingContainer(InventoryCrafting inventory) {
|
||||
try {
|
||||
return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get inventory eventhandler");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
|
||||
try {
|
||||
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
|
||||
} catch (IllegalAccessException ex) {
|
||||
MineTweakerAPI.logger.logError("could not get inventory eventhandler");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
private static Field getField(Class cls, String[] names) {
|
||||
for (String name : names) {
|
||||
try {
|
||||
Field field = cls.getField(name);
|
||||
Field field = cls.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (NoSuchFieldException ex) {
|
||||
|
||||
+3
@@ -16,4 +16,7 @@ public class 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"};
|
||||
public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"};
|
||||
public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"};
|
||||
public static final String[] SLOTCRAFTING_PLAYER = {"thePlayer", "field_75238_b"};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerUtil {
|
||||
public static ItemStack[] fromArray(IItemStack[] items) {
|
||||
ItemStack[] output = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Object internal = items[i].getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
+97
@@ -0,0 +1,97 @@
|
||||
package stanhebben.minetweaker.mods.ic2;
|
||||
|
||||
import ic2.api.item.IC2Items;
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.expression.ExpressionInt;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
* Makes a ic2-item specific item syntax available in the form <item-ic2:name[:meta]>.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@BracketHandler
|
||||
public class IC2BracketHandler implements IBracketHandler {
|
||||
public static IItemStack getItem(String name, int meta) {
|
||||
ItemStack stack = IC2Items.getItem(name);
|
||||
stack.setItemDamage(meta);
|
||||
return new TweakerItemStack(stack);
|
||||
}
|
||||
|
||||
private final JavaMethod method;
|
||||
|
||||
public IC2BracketHandler() {
|
||||
method = MineTweakerAPI.getJavaMethod(IC2BracketHandler.class, "getItem", String.class, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(List<Token> tokens) {
|
||||
if (tokens.size() >= 5) {
|
||||
if (tokens.get(2).getValue().equals("ic2")
|
||||
&& tokens.get(0).getValue().equals("item")
|
||||
&& tokens.get(1).getValue().equals("-")
|
||||
&& tokens.get(3).getValue().equals(":")) {
|
||||
String name = tokens.get(4).getValue();
|
||||
int meta = 0;
|
||||
if (tokens.size() > 6 && tokens.get(5).getValue().equals(":")) {
|
||||
if (tokens.get(6).getType() == ZenTokener.T_INTVALUE) {
|
||||
meta = Integer.parseInt(tokens.get(6).getValue());
|
||||
} else if (tokens.get(6).getValue().equals("*")) {
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
} else {
|
||||
MineTweakerAPI.logger.logError("Not a valid meta value: " + tokens.get(6).getValue());
|
||||
}
|
||||
}
|
||||
ItemStack item = IC2Items.getItem(name);
|
||||
if (item == null) {
|
||||
MineTweakerAPI.logger.logError("Not a valid IC2 item: " + name);
|
||||
return null;
|
||||
} else {
|
||||
return new ItemReferenceSymbol(name, meta);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Private inner classes ###
|
||||
// #############################
|
||||
|
||||
private class ItemReferenceSymbol implements IZenSymbol {
|
||||
private final String name;
|
||||
private final int meta;
|
||||
|
||||
public ItemReferenceSymbol(String name, int meta) {
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new ExpressionJavaCallStatic(
|
||||
position,
|
||||
method,
|
||||
new ExpressionString(position, name),
|
||||
new ExpressionInt(position, meta, ZenType.INT));
|
||||
}
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
package stanhebben.minetweaker.mods.ic2;
|
||||
|
||||
import ic2.api.tile.ExplosionWhitelist;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Manages the explosion whitelist in IC2. Blocks on this whitelist will not resist
|
||||
* an explosion but won't be destroyed.
|
||||
*
|
||||
* The explosion code by default ignores blocks which absorb more than 1000 explosion power to
|
||||
* prevent abusing personal safes, Trade-O-Mats and other blocks to serve as a cheap and
|
||||
* invulnerable reactor chambers. Said blocks will not shield the explosion and won't get
|
||||
* destroyed.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.ExplosionWhitelist")
|
||||
public class IC2ExplosionWhitelist {
|
||||
/**
|
||||
* Adds a block to the explosion whitelist.
|
||||
*
|
||||
* @param item item to add
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void add(IItemStack item) {
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
Block block = Block.getBlockFromItem(iStack.getItem());
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logger.logError("This item is not a block");
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new AddAction(block));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a block from the explosion whitelist.
|
||||
*
|
||||
* @param item item to remove
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void remove(IItemStack item) {
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
Block block = Block.getBlockFromItem(iStack.getItem());
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logger.logError("This item is not a block");
|
||||
} else {
|
||||
if (ExplosionWhitelist.isBlockWhitelisted(block)) {
|
||||
MineTweakerAPI.logger.logWarning("This block is not in the whitelist");
|
||||
} else {
|
||||
MineTweakerAPI.tweaker.apply(new RemoveAction(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given item is already whitelisted.
|
||||
*
|
||||
* @param item item to check
|
||||
* @return true if whitelisted
|
||||
*/
|
||||
@ZenMethod
|
||||
public static boolean isWhitelisted(IItemStack item) {
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
Block block = Block.getBlockFromItem(iStack.getItem());
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logger.logWarning("This item is not a block");
|
||||
return false;
|
||||
} else {
|
||||
return ExplosionWhitelist.isBlockWhitelisted(block);
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddAction implements IUndoableAction {
|
||||
private final Block block;
|
||||
|
||||
public AddAction(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
ExplosionWhitelist.addWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
ExplosionWhitelist.removeWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveAction implements IUndoableAction {
|
||||
private final Block block;
|
||||
|
||||
public RemoveAction(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
ExplosionWhitelist.removeWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
ExplosionWhitelist.addWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -13,16 +13,16 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MachineAddRecipeAction extends OneWayAction {
|
||||
private final String name;
|
||||
private final IMachineRecipeManager machine;
|
||||
private final ItemStack output;
|
||||
private final ItemStack[] output;
|
||||
private final IC2RecipeInput input;
|
||||
private final NBTTagCompound tag;
|
||||
|
||||
public MachineAddRecipeAction(String name, IMachineRecipeManager machine, ItemStack output, NBTTagCompound tag, IC2RecipeInput input) {
|
||||
public MachineAddRecipeAction(String name, IMachineRecipeManager machine, ItemStack[] output, NBTTagCompound tag, IC2RecipeInput input) {
|
||||
this.name = name;
|
||||
this.machine = machine;
|
||||
this.output = output;
|
||||
@@ -37,6 +37,21 @@ public class MachineAddRecipeAction extends OneWayAction {
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding " + name + " recipe for " + output.getDisplayName();
|
||||
if (output.length == 1) {
|
||||
return "Adding " + name + " recipe for " + output[0].getDisplayName();
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("Adding ").append(name).append(" recipe for ");
|
||||
result.append("[");
|
||||
for (int i = 0; i < output.length; i++) {
|
||||
if (i == 0) {
|
||||
result.append(", ");
|
||||
} else {
|
||||
result.append(output[i].getDisplayName());
|
||||
}
|
||||
}
|
||||
result.append("]");
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
package stanhebben.minetweaker.mods.ic2.expand;
|
||||
|
||||
import ic2.api.item.ElectricItem;
|
||||
import ic2.api.item.IElectricItem;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenExpansion("minecraft.item.IItemStack")
|
||||
public class ItemExpansion {
|
||||
/**
|
||||
* Gets the charge level of this item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return charge level
|
||||
*/
|
||||
@ZenGetter("ic2getCharge")
|
||||
public static int getIC2Charge(IItemStack stack) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ElectricItem.manager.getCharge((ItemStack) internal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tier level of this item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return tier level
|
||||
*/
|
||||
@ZenGetter("ic2tier")
|
||||
public static int getIC2Tier(IItemStack stack) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
return ((IElectricItem) iStack.getItem()).getTier(iStack);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transfer limit of the specified stack.
|
||||
*
|
||||
* @param stack target
|
||||
* @return
|
||||
*/
|
||||
@ZenGetter("ic2transferLimit")
|
||||
public static int getIC2TransferLimit(IItemStack stack) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
return ((IElectricItem) iStack.getItem()).getTransferLimit(iStack);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully charged IC2 item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return charged item
|
||||
*/
|
||||
@ZenGetter("ic2charged")
|
||||
public static IItemStack getIC2Charged(IItemStack stack) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
IElectricItem eItem = (IElectricItem) iStack.getItem();
|
||||
Item item = eItem.getChargedItem(iStack);
|
||||
ItemStack stack2 = new ItemStack(item, 1, 0);
|
||||
ElectricItem.manager.charge(stack2, eItem.getMaxCharge(stack2), eItem.getTier(stack2), true, false);
|
||||
return new TweakerItemStack(stack2);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully discharged IC2 item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return discharged item
|
||||
*/
|
||||
@ZenGetter("ic2discharged")
|
||||
public static IItemStack getIC2Discharged(IItemStack stack) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack iStack = (ItemStack) internal;
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
IElectricItem eItem = (IElectricItem) iStack.getItem();
|
||||
Item item = eItem.getEmptyItem(iStack);
|
||||
return new TweakerItemStack(new ItemStack(item, 1, 0));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges the item with the specified amount and returns the charged item.
|
||||
*
|
||||
* @param stack target
|
||||
* @param amount charge amount
|
||||
* @param tier charge tier
|
||||
* @return charged item
|
||||
*/
|
||||
@ZenMethod("ic2charge")
|
||||
public static IItemStack ic2Charge(IItemStack stack, int amount, @Optional int tier) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (tier == 0) {
|
||||
tier = getIC2Tier(stack);
|
||||
}
|
||||
|
||||
ItemStack iStack = ((ItemStack) internal).copy();
|
||||
ElectricItem.manager.charge(iStack, amount, tier, true, false);
|
||||
return new TweakerItemStack(iStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharges the item with the specified amount and returns the discharged item.
|
||||
*
|
||||
* @param stack target
|
||||
* @param amount discharge amount
|
||||
* @param tier charge tier
|
||||
* @return discharged item
|
||||
*/
|
||||
@ZenMethod("ic2discharge")
|
||||
public static IItemStack ic2Discharge(IItemStack stack, int amount, @Optional int tier) {
|
||||
Object internal = stack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (tier == 0) {
|
||||
tier = getIC2Tier(stack);
|
||||
}
|
||||
|
||||
ItemStack iStack = ((ItemStack) internal).copy();
|
||||
ElectricItem.manager.discharge(iStack, amount, tier, true, false);
|
||||
return new TweakerItemStack(iStack);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
package stanhebben.minetweaker.mods.ic2;
|
||||
package stanhebben.minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
@@ -6,6 +6,8 @@ import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import stanhebben.minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -37,7 +39,7 @@ public class Compressor {
|
||||
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
|
||||
"compressor",
|
||||
Recipes.compressor,
|
||||
(ItemStack) output.getInternal(),
|
||||
new ItemStack[] {(ItemStack) output.getInternal()},
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
+4
-2
@@ -4,7 +4,7 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.minetweaker.mods.ic2;
|
||||
package stanhebben.minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
@@ -12,6 +12,8 @@ import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import stanhebben.minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -42,7 +44,7 @@ public class Extractor {
|
||||
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
|
||||
"extractor",
|
||||
Recipes.extractor,
|
||||
(ItemStack) output.getInternal(),
|
||||
new ItemStack[] {(ItemStack) output.getInternal()},
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
package stanhebben.minetweaker.mods.ic2;
|
||||
package stanhebben.minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
@@ -6,6 +6,8 @@ import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import stanhebben.minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -37,7 +39,7 @@ public class Macerator {
|
||||
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
|
||||
"macerator",
|
||||
Recipes.macerator,
|
||||
(ItemStack) output.getInternal(),
|
||||
new ItemStack[] {(ItemStack) output.getInternal()},
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
+39
-21
@@ -1,12 +1,15 @@
|
||||
package stanhebben.minetweaker.mods.ic2;
|
||||
package stanhebben.minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.mc172.item.TweakerItemStack;
|
||||
import minetweaker.mc172.util.MineTweakerUtil;
|
||||
import minetweaker.minecraft.item.IIngredient;
|
||||
import minetweaker.minecraft.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import stanhebben.minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import stanhebben.minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
@@ -16,31 +19,47 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.Centrifuge")
|
||||
public class Centrifuge {
|
||||
@ZenClass("mods.ic2.ThermalCentrifuge")
|
||||
public class ThermalCentrifuge {
|
||||
/**
|
||||
* Adds a new recipe to the centrifuge.
|
||||
*
|
||||
* The recipe input can be any pattern, as long as the stack size is determined.
|
||||
* The recipe input can be any ingredient, as long as the stack size is determined.
|
||||
* The output is an array of item stacks.
|
||||
*
|
||||
* @param output recipe outputs
|
||||
* @param ingredient recipe input
|
||||
* @param minHeat minimum centrifuge heat level
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack[] output, IIngredient ingredient, int minHeat) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logger.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("minHeat", minHeat);
|
||||
MineTweakerAPI.tweaker.apply(new MachineAddRecipeAction(
|
||||
"compressor",
|
||||
Recipes.compressor,
|
||||
MineTweakerUtil.fromArray(output),
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new recipe to the centrifuge.
|
||||
*
|
||||
* The recipe input can be any ingredient, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
* @param minHeat minimum centrifuge heat level
|
||||
*/
|
||||
@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)));
|
||||
}
|
||||
public static void addRecipe(IItemStack output, IIngredient ingredient, int minHeat) {
|
||||
addRecipe(new IItemStack[] { output }, ingredient, minHeat);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,8 +70,7 @@ public class Centrifuge {
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
return new TweakerItemStack(Recipes.compressor.getOutputFor((ItemStack) input.getInternal(), false).items.get(0));
|
||||
public static IItemStack getOutput(IItemStack input) {
|
||||
return new TweakerItemStack(Recipes.centrifuge.getOutputFor((ItemStack) input.getInternal(), false).items.get(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
# MineTweaker Roadmap
|
||||
|
||||
## Version 3.0: 1.7.2 and crafting upgrade
|
||||
|
||||
Goal: Make a 1.7.2 version available
|
||||
ETA: 22 june
|
||||
|
||||
- Support for 1.7.2 and 1.7.3
|
||||
- Add and remove shaped and shapeless recipes
|
||||
- Add and remove furnace recipes
|
||||
- Allow modification of fuel values
|
||||
- Allow modification of ore dictionary
|
||||
- Liquid support
|
||||
- Allow conditional ingredients, transforming ingredients and improved function recipes
|
||||
- Mod support for NEI, IC2, Forestry
|
||||
- Improved scripting engine and better documentation
|
||||
|
||||
## Version 3.1: 1.6.4 upgrade
|
||||
|
||||
Goal: Make a 1.6.4 version available
|
||||
ETA: 29 june
|
||||
|
||||
- Support for 1.6.4
|
||||
|
||||
## Version 3.2: Mods upgrade
|
||||
|
||||
Goal: support more mods and port the remaining mods from MineTweaker 2, such that all functionality from MineTweaker 2 is now present in MineTweaker 3
|
||||
ETA: 13 july
|
||||
|
||||
- Ability to make scripts adjust themselves to the mods available
|
||||
- Ability to share functions between modules
|
||||
- Ability to make functions private inside a specific scripts
|
||||
- Mod support for BuildCraft, GregTech, MFR
|
||||
- Mod support for Thaumcraft
|
||||
- (Hopefully) Mod support for Thermal Expansion
|
||||
|
||||
## Version 3.3: World & Scripting upgrade
|
||||
|
||||
Goal: enable scripted sequences and behavior, make servers more interactive and customized, enable creation of advanced maps and puzzles
|
||||
|
||||
- Event-based actions, scripted sequences and world interaction
|
||||
- Ability to add worldgen, including ores, plants, trees and other terrain features
|
||||
- Maybe even entirely new biomes
|
||||
- Ability to send messages between clients & server
|
||||
- Can store data with world, dimensions and players
|
||||
- Can read settings from minetweaker-specific settings files
|
||||
|
||||
## Version 3.4: Assets upgrade
|
||||
|
||||
Goal: make it possible to load images, audio and data from assets inside the zip files (which are then distributed automatically) and enable creation of new items and blocks as well as modifying existing ones.
|
||||
|
||||
- Ability to define new items and blocks with preprogrammed behavior
|
||||
- Ability to redefine behavior of existing blocks and items, using assets from zipped modules
|
||||
- Ability to play sounds and music packaged with the zipped modules
|
||||
- Caching of files so they don't have to be sent again
|
||||
- (Hopefully) a way to see the progress of downloading new files, as these may grow significantly
|
||||
|
||||
## Version 3.5: Classes upgrade
|
||||
|
||||
Goal: expand the scripting engine's capability (massively) and turn it into a full object-oriented language. Makes it possible to define blocks with custom behavior (more so than in the assets upgrade).
|
||||
|
||||
- Major scripting engine upgrade
|
||||
- Can define new classes and interfaces
|
||||
- Can define enumeration values (enums)
|
||||
- Can implement completely custom blocks and items, same API across all Minecraft versions
|
||||
- Possible to write entire mods in MineTweaker
|
||||
|
||||
## Version 3.6: Integration upgrade
|
||||
|
||||
Goal: integrate with systems present in existing mods, such as microblocks, cutted blocks, piping systems and energy nets.
|
||||
|
||||
- Support for microblocks and microblock implementations, supporting existing Mineblock libraries
|
||||
- Integration with IC2, Buildcraft and Thermal Expansion energy nets
|
||||
- Integration with BuildCraft and Thermal Expansion pipe systems
|
||||
@@ -6,5 +6,6 @@ targetCompatibility = '1.6'
|
||||
dependencies {
|
||||
compile group: 'org.ow2.asm', name: 'asm', version:'4.2'
|
||||
compile group: 'org.ow2.asm', name: 'asm-commons', version:'4.2'
|
||||
compile files("${System.properties['java.home']}/../lib/tools.jar")
|
||||
//compile files("${System.properties['java.home']}/../lib/tools.jar")
|
||||
//compile files("libs/tools.jar")
|
||||
}
|
||||
+2
-1
@@ -4,13 +4,14 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package stanhebben.zenscript.symbols;
|
||||
package stanhebben.zenscript;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.compiler.TypeRegistry;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -29,7 +29,6 @@ import stanhebben.zenscript.definitions.ParsedFunctionArgument;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.statements.Statement;
|
||||
import stanhebben.zenscript.statements.StatementReturn;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolArgument;
|
||||
import stanhebben.zenscript.symbols.SymbolZenStaticMethod;
|
||||
@@ -79,30 +78,9 @@ public class ZenModule {
|
||||
for (ZenParsedFile script : scripts) {
|
||||
ClassWriter clsScript = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
clsScript.visitSource(script.getFileName(), null);
|
||||
EnvironmentClass environmentScript = new EnvironmentClass(clsScript, environmentGlobal);
|
||||
EnvironmentClass environmentScript = new EnvironmentClass(clsScript, script.getEnvironment());
|
||||
|
||||
clsScript.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, script.getClassName(), null, internal(Object.class), new String[] {internal(Runnable.class)});
|
||||
for (Import imprt : script.getImports()) {
|
||||
List<String> name = imprt.getName();
|
||||
IPartialExpression value = environmentGlobal.getValue(name.get(0), imprt.getPosition());
|
||||
for (int i = 1; i < name.size(); i++) {
|
||||
IPartialExpression member = value.getMember(imprt.getPosition(), environmentGlobal, name.get(i));
|
||||
if (member == null) {
|
||||
environmentGlobal.error(imprt.getPosition(), StringUtil.join(name, ".") + " not found");
|
||||
break;
|
||||
}
|
||||
value = member;
|
||||
}
|
||||
IZenSymbol symbol = value.toSymbol();
|
||||
if (symbol == null) {
|
||||
environmentGlobal.error(imprt.getPosition(), StringUtil.join(name, ".") + " is not a valid import");
|
||||
} else {
|
||||
environmentScript.putValue(
|
||||
imprt.getRename() == null
|
||||
? name.get(name.size() - 1)
|
||||
: imprt.getRename(), value.toSymbol());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, ParsedFunction> function : script.getFunctions().entrySet()) {
|
||||
ParsedFunction fn = function.getValue();
|
||||
@@ -180,7 +158,7 @@ public class ZenModule {
|
||||
* @return compiled module
|
||||
* @throws IOException if the file could not be read
|
||||
*/
|
||||
public static ZenModule compileScriptFile(File single, IZenCompileEnvironment environment) throws IOException {
|
||||
public static ZenModule compileScriptFile(File single, IZenCompileEnvironment environment, ClassLoader baseClassLoader) throws IOException {
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
ClassNameGenerator nameGen = new ClassNameGenerator();
|
||||
EnvironmentGlobal environmentGlobal = new EnvironmentGlobal(
|
||||
@@ -214,7 +192,7 @@ public class ZenModule {
|
||||
output.close();
|
||||
}
|
||||
|
||||
return new ZenModule(classes);
|
||||
return new ZenModule(classes, baseClassLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +205,11 @@ public class ZenModule {
|
||||
* @return compiled module
|
||||
* @throws IOException if the file could not be read properly
|
||||
*/
|
||||
public static ZenModule compileZip(File file, String subdir, IZenCompileEnvironment environment) throws IOException {
|
||||
public static ZenModule compileZip(
|
||||
File file,
|
||||
String subdir,
|
||||
IZenCompileEnvironment environment,
|
||||
ClassLoader baseClassLoader) throws IOException {
|
||||
Map<String, byte[]> classes = new HashMap<String, byte[]>();
|
||||
ClassNameGenerator nameGen = new ClassNameGenerator();
|
||||
EnvironmentGlobal environmentGlobal = new EnvironmentGlobal(
|
||||
@@ -269,7 +251,7 @@ public class ZenModule {
|
||||
output.close();
|
||||
}
|
||||
|
||||
return new ZenModule(classes);
|
||||
return new ZenModule(classes, baseClassLoader);
|
||||
}
|
||||
|
||||
private final Map<String, byte[]> classes;
|
||||
@@ -281,9 +263,9 @@ public class ZenModule {
|
||||
*
|
||||
* @param classes
|
||||
*/
|
||||
public ZenModule(Map<String, byte[]> classes) {
|
||||
public ZenModule(Map<String, byte[]> classes, ClassLoader baseClassLoader) {
|
||||
this.classes = classes;
|
||||
classLoader = new MyClassLoader();
|
||||
classLoader = new MyClassLoader(baseClassLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,10 +323,14 @@ public class ZenModule {
|
||||
* Custom class loader. Loads classes from this module.
|
||||
*/
|
||||
private class MyClassLoader extends ClassLoader {
|
||||
private MyClassLoader(ClassLoader baseClassLoader) {
|
||||
super(baseClassLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
if (classes.containsKey(name)) {
|
||||
return this.defineClass(name, classes.get(name), 0, classes.get(name).length);
|
||||
return defineClass(name, classes.get(name), 0, classes.get(name).length);
|
||||
}
|
||||
|
||||
return super.findClass(name);
|
||||
|
||||
@@ -5,11 +5,15 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static stanhebben.zenscript.ZenTokener.*;
|
||||
import stanhebben.zenscript.compiler.EnvironmentScript;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.definitions.Import;
|
||||
import stanhebben.zenscript.definitions.ParsedFunction;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.statements.Statement;
|
||||
import stanhebben.zenscript.symbols.SymbolType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
|
||||
/**
|
||||
* Contains a parsed file.
|
||||
@@ -32,6 +36,7 @@ public class ZenParsedFile {
|
||||
private final List<Import> imports;
|
||||
private final Map<String, ParsedFunction> functions;
|
||||
private final List<Statement> statements;
|
||||
private final IEnvironmentGlobal environmentScript;
|
||||
|
||||
/**
|
||||
* Constructs and parses a given file.
|
||||
@@ -48,6 +53,7 @@ public class ZenParsedFile {
|
||||
imports = new ArrayList<Import>();
|
||||
functions = new HashMap<String, ParsedFunction>();
|
||||
statements = new ArrayList<Statement>();
|
||||
environmentScript = new EnvironmentScript(environment);
|
||||
|
||||
tokener.setFile(this);
|
||||
|
||||
@@ -74,20 +80,55 @@ public class ZenParsedFile {
|
||||
imports.add(new Import(start.getPosition(), importName, rename));
|
||||
}
|
||||
|
||||
for (Import imprt : imports) {
|
||||
List<String> name = imprt.getName();
|
||||
IPartialExpression type = null;
|
||||
|
||||
StringBuilder nameSoFar = new StringBuilder();
|
||||
|
||||
for (String part : name) {
|
||||
if (type == null) {
|
||||
nameSoFar.append(part);
|
||||
type = environment.getValue(part, imprt.getPosition());
|
||||
if (type == null) {
|
||||
environment.error(imprt.getPosition(), "could not find package " + type);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
nameSoFar.append('.').append(part);
|
||||
type = type.getMember(imprt.getPosition(), environment, part);
|
||||
if (type == null) {
|
||||
environment.error(imprt.getPosition(), "could not find type or package " + nameSoFar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
environmentScript.putValue(imprt.getRename(), type.toSymbol());
|
||||
} else {
|
||||
environmentScript.putValue(imprt.getRename(), new SymbolType(ZenType.ANY));
|
||||
}
|
||||
}
|
||||
|
||||
while (tokener.hasNext()) {
|
||||
Token next = tokener.peek();
|
||||
if (next.getType() == T_FUNCTION) {
|
||||
ParsedFunction function = ParsedFunction.parse(tokener, environment);
|
||||
ParsedFunction function = ParsedFunction.parse(tokener, environmentScript);
|
||||
if (functions.containsKey(function.getName())) {
|
||||
environment.error(function.getPosition(), "function " + function.getName() + " already exists");
|
||||
}
|
||||
functions.put(function.getName(), function);
|
||||
} else {
|
||||
statements.add(Statement.read(tokener, environment));
|
||||
statements.add(Statement.read(tokener, environmentScript));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnvironmentGlobal getEnvironment() {
|
||||
return environmentScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output classname for this file.
|
||||
*
|
||||
|
||||
@@ -8,7 +8,6 @@ import stanhebben.zenscript.parser.CompiledDFA;
|
||||
import stanhebben.zenscript.parser.NFA;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.parser.TokenStream;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
|
||||
/**
|
||||
* A tokener is capable of splitting a single file into tokens. It's intended
|
||||
@@ -96,6 +95,7 @@ public class ZenTokener extends TokenStream {
|
||||
private static final String[] REGEXPS = {
|
||||
"#[^\n]*\n",
|
||||
"//[^\n]*\n",
|
||||
"/\\*[^\\*]*(\\*^/[^\\*]*)*\\*/",
|
||||
"[ \t\r\n]*",
|
||||
"[a-zA-Z_][a-zA-Z_0-9]*",
|
||||
"\\-?(0|[1-9][0-9]*)\\.[0-9]+([eE][\\+\\-]?[0-9]+)?",
|
||||
@@ -147,6 +147,7 @@ public class ZenTokener extends TokenStream {
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
T_ID,
|
||||
T_FLOATVALUE,
|
||||
T_INTVALUE,
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolLocal;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolLocal;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.compiler;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class EnvironmentScript implements IEnvironmentGlobal {
|
||||
private final IEnvironmentGlobal parent;
|
||||
private final Map<String, IZenSymbol> imports;
|
||||
|
||||
public EnvironmentScript(IEnvironmentGlobal parent) {
|
||||
this.parent = parent;
|
||||
imports = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenCompileEnvironment getEnvironment() {
|
||||
return parent.getEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeExpansion getExpansion(String name) {
|
||||
return parent.getExpansion(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String makeClassName() {
|
||||
return parent.makeClassName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsClass(String name) {
|
||||
return parent.containsClass(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putClass(String name, byte[] data) {
|
||||
parent.putClass(name, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
||||
if (imports.containsKey(name)) {
|
||||
return imports.get(name).instance(position);
|
||||
} else {
|
||||
return parent.getValue(name, position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, IZenSymbol value) {
|
||||
imports.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType(Type type) {
|
||||
return parent.getType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(ZenPosition position, String message) {
|
||||
parent.error(position, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(ZenPosition position, String message) {
|
||||
parent.warning(position, message);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ package stanhebben.zenscript.compiler;
|
||||
import stanhebben.zenscript.IZenErrorLogger;
|
||||
import stanhebben.zenscript.TypeExpansion;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.IZenCompileEnvironment;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
|
||||
@@ -33,6 +33,6 @@ public class Import {
|
||||
}
|
||||
|
||||
public String getRename() {
|
||||
return rename;
|
||||
return rename == null ? name.get(name.size() - 1) : rename;
|
||||
}
|
||||
}
|
||||
@@ -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.zenscript.expression.partial;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.expression.ExpressionInvalid;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.symbols.SymbolType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class PartialType implements IPartialExpression {
|
||||
private final ZenPosition position;
|
||||
private final ZenType type;
|
||||
|
||||
public PartialType(ZenPosition position, ZenType type) {
|
||||
this.position = position;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression eval(IEnvironmentGlobal environment) {
|
||||
environment.error(position, "cannot use type as expression");
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression assign(ZenPosition position, IEnvironmentGlobal environment, Expression other) {
|
||||
environment.error(position, "cannot assign to a type");
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
||||
return type.getStaticMember(position, environment, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
environment.error(position, "cannot call a type");
|
||||
return new ExpressionInvalid(position, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol toSymbol() {
|
||||
return new SymbolType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType toType(IEnvironmentGlobal environment) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
+2
@@ -20,6 +20,8 @@ public class ParsedExpressionValue extends ParsedExpression {
|
||||
public ParsedExpressionValue(ZenPosition position, IPartialExpression value) {
|
||||
super(position);
|
||||
|
||||
if (value == null) throw new IllegalArgumentException("value cannot be null");
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeBool;
|
||||
import stanhebben.zenscript.symbols.IZenNamespace;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* 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.symbols;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public interface IZenEnvironment {
|
||||
public Object getValue(byte[] key);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* 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.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public interface IZenNamespace {
|
||||
public IZenCompileEnvironment getEnvironment();
|
||||
|
||||
public IPartialExpression getValue(String name, ZenPosition position);
|
||||
|
||||
public void putValue(String name, IZenSymbol value);
|
||||
}
|
||||
@@ -22,10 +22,17 @@ import stanhebben.zenscript.util.ZenPosition;
|
||||
public class SymbolPackage implements IZenSymbol {
|
||||
private final HashMap<String, IZenSymbol> members;
|
||||
|
||||
public SymbolPackage() {
|
||||
private final String name;
|
||||
|
||||
public SymbolPackage(String name) {
|
||||
this.name = name;
|
||||
members = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Map<String, IZenSymbol> getPackages() {
|
||||
return members;
|
||||
}
|
||||
@@ -38,7 +45,14 @@ public class SymbolPackage implements IZenSymbol {
|
||||
String[] parts = StringUtil.split(name, '.');
|
||||
String[] pkgParts = Arrays.copyOf(parts, parts.length - 1);
|
||||
SymbolPackage pkgCurrent = this;
|
||||
String pkgName = null;
|
||||
for (String part : pkgParts) {
|
||||
if (pkgName == null) {
|
||||
pkgName = part;
|
||||
} else {
|
||||
pkgName = pkgName + '.' + part;
|
||||
}
|
||||
|
||||
if (pkgCurrent.members.containsKey(part)) {
|
||||
IZenSymbol member = pkgCurrent.members.get(part);
|
||||
if (member instanceof SymbolPackage) {
|
||||
@@ -48,12 +62,13 @@ public class SymbolPackage implements IZenSymbol {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
SymbolPackage child = new SymbolPackage();
|
||||
SymbolPackage child = new SymbolPackage(pkgName);
|
||||
pkgCurrent.members.put(part, child);
|
||||
pkgCurrent = child;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Adding " + parts[parts.length - 1] + " to package " + pkgCurrent.getName() + "(" + symbol + ")");
|
||||
if (pkgCurrent.members.containsKey(parts[parts.length - 1])) {
|
||||
errors.error(null, parts[parts.length - 1] + " is already defined in that package");
|
||||
} else {
|
||||
|
||||
@@ -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 stanhebben.zenscript.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.expression.partial.PartialType;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class SymbolType implements IZenSymbol {
|
||||
private final ZenType type;
|
||||
|
||||
public SymbolType(ZenType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new PartialType(position, type);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class ZenNamespaceLocal implements IZenNamespace {
|
||||
private final IZenNamespace parent;
|
||||
private final Map<String, IZenSymbol> values;
|
||||
|
||||
public ZenNamespaceLocal(IZenNamespace parent) {
|
||||
this.parent = parent;
|
||||
this.values = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenCompileEnvironment getEnvironment() {
|
||||
return parent.getEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
||||
if (values.containsKey(name)) {
|
||||
return values.get(name).instance(position);
|
||||
} else {
|
||||
return parent.getValue(name, position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, IZenSymbol value) {
|
||||
values.put(name, value);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.symbols;
|
||||
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class ZenNamespaceScript implements IZenNamespace {
|
||||
private final IZenCompileEnvironment environment;
|
||||
private final Map<String, IZenSymbol> values;
|
||||
|
||||
public ZenNamespaceScript(IZenCompileEnvironment environment) {
|
||||
this.environment = environment;
|
||||
this.values = new HashMap<String, IZenSymbol>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenCompileEnvironment getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getValue(String name, ZenPosition position) {
|
||||
if (values.containsKey(name)) {
|
||||
return values.get(name).instance(position);
|
||||
} else {
|
||||
IZenSymbol symbol = environment.getGlobal(name);
|
||||
if (symbol == null) {
|
||||
return null;
|
||||
} else {
|
||||
return symbol.instance(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, IZenSymbol value) {
|
||||
values.put(name, value);
|
||||
}
|
||||
}
|
||||
@@ -80,12 +80,27 @@ public abstract class ZenType {
|
||||
base = STRING;
|
||||
break;
|
||||
case ZenTokener.T_ID:
|
||||
base = ANY;
|
||||
|
||||
StringBuilder typeName = new StringBuilder();
|
||||
typeName.append(next.getValue());
|
||||
IPartialExpression partial = environment.getValue(next.getValue(), next.getPosition());
|
||||
while (parser.optional(ZenTokener.T_DOT) != null) {
|
||||
typeName.append('.');
|
||||
|
||||
Token member = parser.required(ZenTokener.T_ID, "identifier expected");
|
||||
typeName.append(member.getValue());
|
||||
partial = partial.getMember(member.getPosition(), environment, member.getValue());
|
||||
|
||||
if (partial == null) {
|
||||
environment.error(member.getPosition(), "could not find type " + typeName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (partial != null) {
|
||||
base = partial.toType(environment);
|
||||
System.out.println("Parsed type " + base.getName());
|
||||
}
|
||||
base = partial.toType(environment);
|
||||
break;
|
||||
default:
|
||||
throw new ParseException(next, "Unknown type: " + next.getValue());
|
||||
|
||||
@@ -140,12 +140,14 @@ public class ZenTypeAny extends ZenType {
|
||||
|
||||
@Override
|
||||
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value, String name) {
|
||||
return null;
|
||||
environment.error(position, "any values not yet supported");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getStaticMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
||||
return null;
|
||||
environment.error(position, "any values not yet supported");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,7 +157,7 @@ public class ZenTypeAny extends ZenType {
|
||||
|
||||
@Override
|
||||
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return true; // true or not?
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,15 @@ public abstract class ZenTypeArray extends ZenType {
|
||||
|
||||
@Override
|
||||
public final boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return equals(type) || canCastExpansion(environment, type);
|
||||
if (equals(type) || canCastExpansion(environment, type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type instanceof ZenTypeArray) {
|
||||
return base.canCastImplicit(((ZenTypeArray) type).base, environment);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* 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.type;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.annotations.CompareType;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.compiler.ITypeRegistry;
|
||||
import stanhebben.zenscript.compiler.TypeRegistry;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.expression.ExpressionInvalid;
|
||||
import stanhebben.zenscript.expression.ExpressionJavaCallVirtual;
|
||||
import stanhebben.zenscript.expression.ExpressionNull;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
import static stanhebben.zenscript.util.ZenTypeUtil.signature;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ZenTypeIntRange extends ZenType {
|
||||
public static final ZenTypeIntRange INSTANCE = new ZenTypeIntRange();
|
||||
|
||||
private final JavaMethod methodFrom;
|
||||
private final JavaMethod methodTo;
|
||||
|
||||
private ZenTypeIntRange() {
|
||||
ITypeRegistry dummy = new TypeRegistry();
|
||||
methodFrom = JavaMethod.get(dummy, IntRange.class, "getFrom");
|
||||
methodTo = JavaMethod.get(dummy, IntRange.class, "getTo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression unary(ZenPosition position, IEnvironmentGlobal environment, Expression value, OperatorType operator) {
|
||||
environment.error(position, "cannot apply unary operators on int ranges");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression binary(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, OperatorType operator) {
|
||||
environment.error(position, "cannot apply binary operators on int ranges");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression trinary(ZenPosition position, IEnvironmentGlobal environment, Expression first, Expression second, Expression third, OperatorType operator) {
|
||||
environment.error(position, "cannot apply ternary operators on int ranges");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression compare(ZenPosition position, IEnvironmentGlobal environment, Expression left, Expression right, CompareType type) {
|
||||
environment.error(position, "cannot compare int ranges");
|
||||
return new ExpressionInvalid(position, BOOL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, IPartialExpression value, String name) {
|
||||
if (name.equals("from")) {
|
||||
return new ExpressionJavaCallVirtual(position, methodFrom, value.eval(environment));
|
||||
} else if (name.equals("to")) {
|
||||
return new ExpressionJavaCallVirtual(position, methodTo, value.eval(environment));
|
||||
} else {
|
||||
environment.error(position, "no such member " + name + " in int range");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression getStaticMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
||||
environment.error(position, "int ranges don't have static members");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression call(ZenPosition position, IEnvironmentGlobal environment, Expression receiver, Expression... arguments) {
|
||||
environment.error(position, "int ranges cannot be called");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, Expression value, ZenType type) {
|
||||
if (type == this) {
|
||||
return value;
|
||||
}
|
||||
|
||||
environment.error(position, "cannot cast int ranges to any other type");
|
||||
return new ExpressionInvalid(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenIterator makeIterator(int numValues, IEnvironmentMethod methodOutput) {
|
||||
if (numValues == 1) {
|
||||
return new IntRangeIterator(methodOutput);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCastImplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return type == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCastExplicit(ZenType type, IEnvironmentGlobal environment) {
|
||||
return type == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class toJavaClass() {
|
||||
return IntRange.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type toASMType() {
|
||||
return Type.getType(IntRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return signature(IntRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPointer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileCast(ZenPosition position, IEnvironmentMethod environment, ZenType type) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "int..";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression defaultValue(ZenPosition position) {
|
||||
return new ExpressionNull(position);
|
||||
}
|
||||
|
||||
private class IntRangeIterator implements IZenIterator {
|
||||
private final IEnvironmentMethod method;
|
||||
|
||||
public IntRangeIterator(IEnvironmentMethod methodOutput) {
|
||||
this.method = methodOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileStart(int[] locals) {
|
||||
MethodOutput output = method.getOutput();
|
||||
|
||||
output.dup(); // copy IntRange reference
|
||||
output.invoke(methodFrom);
|
||||
output.storeInt(locals[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compilePreIterate(int[] locals, Label exit) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compilePostIterate(int[] locals, Label exit, Label repeat) {
|
||||
MethodOutput output = method.getOutput();
|
||||
|
||||
output.dup(); // copy IntRange reference
|
||||
output.invoke(methodTo);
|
||||
|
||||
output.loadInt(locals[0]);
|
||||
output.iinc(locals[0]);
|
||||
output.dup();
|
||||
output.storeInt(locals[0]);
|
||||
|
||||
output.ifICmpGT(repeat);
|
||||
output.goTo(exit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compileEnd() {
|
||||
method.getOutput().pop(); // remove IntRange reference
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZenType getType(int i) {
|
||||
return INT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,7 +412,7 @@ public class ZenTypeNative extends ZenType {
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return cls.getName();
|
||||
return signature(cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,7 +429,9 @@ public class ZenTypeNative extends ZenType {
|
||||
*/
|
||||
private static boolean canCastImplicit(Class cls, ZenType type) {
|
||||
if (isEqual(cls, type)) return true;
|
||||
if (canCastImplicit(cls.getSuperclass(), type)) return true;
|
||||
if (cls.getSuperclass() != null) {
|
||||
if (canCastImplicit(cls.getSuperclass(), type)) return true;
|
||||
}
|
||||
for (Class iface : cls.getInterfaces()) {
|
||||
if (canCastImplicit(iface, type)) return true;
|
||||
}
|
||||
@@ -458,7 +460,7 @@ public class ZenTypeNative extends ZenType {
|
||||
}
|
||||
|
||||
private static String getSignature(Class cls) {
|
||||
String signature = cls.getName();
|
||||
String signature = signature(cls);
|
||||
if (Number.class.isAssignableFrom(cls)) {
|
||||
if (cls == Byte.class) {
|
||||
signature = "B";
|
||||
|
||||
@@ -16,6 +16,7 @@ import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
import static stanhebben.zenscript.util.StringUtil.methodMatchingError;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,7 @@ public class ZenExpandMember {
|
||||
System.arraycopy(values, 0, newValues, 1, values.length);
|
||||
JavaMethod method = JavaMethod.select(true, methods, environment, newValues);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callStatic(position, environment, newValues);
|
||||
@@ -133,7 +134,7 @@ public class ZenExpandMember {
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
JavaMethod method = JavaMethod.select(true, methods, environment, values);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callStatic(position, environment, values);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class JavaMethod {
|
||||
Method method = cls.getMethod(name, parameterTypes);
|
||||
return new JavaMethod(cls, method, types);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new RuntimeException("method not found", ex);
|
||||
throw new RuntimeException("method " + name + " not found in class " + cls.getName(), ex);
|
||||
} catch (SecurityException ex) {
|
||||
throw new RuntimeException("method retrieval not permitted", ex);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import stanhebben.zenscript.expression.ExpressionInvalid;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import static stanhebben.zenscript.util.StringUtil.methodMatchingError;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
@@ -91,7 +92,7 @@ public class ZenNativeMember {
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
JavaMethod method = JavaMethod.select(false, methods, environment, values);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callVirtual(position, environment, value.eval(environment), values);
|
||||
@@ -137,7 +138,7 @@ public class ZenNativeMember {
|
||||
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
||||
JavaMethod method = JavaMethod.select(true, methods, environment, values);
|
||||
if (method == null) {
|
||||
environment.error(position, "no matching method found");
|
||||
environment.error(position, methodMatchingError(methods, values));
|
||||
return new ExpressionInvalid(position);
|
||||
} else {
|
||||
return method.callStatic(position, environment, values);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class MethodOutput {
|
||||
private final LocalVariablesSorter visitor;
|
||||
|
||||
public MethodOutput(ClassVisitor cls, int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
System.out.println("Method output: " + name + descriptor);
|
||||
MethodVisitor methodVisitor = cls.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
visitor = new LocalVariablesSorter(access, descriptor, methodVisitor);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
package stanhebben.zenscript.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -42,6 +45,39 @@ public class StringUtil {
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* If a set of methods is available and none matches, this method creates
|
||||
* a suitable message.
|
||||
*
|
||||
* @param methods matching methods
|
||||
* @param arguments calling arguments
|
||||
* @return return value
|
||||
*/
|
||||
public static String methodMatchingError(List<JavaMethod> methods, Expression... arguments) {
|
||||
if (methods.isEmpty()) {
|
||||
return "no method with that name available";
|
||||
} else {
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (methods.size() == 1) {
|
||||
message.append("a method ");
|
||||
} else {
|
||||
message.append(methods.size()).append(" methods ");
|
||||
}
|
||||
message.append("available but none matches the parameters (");
|
||||
boolean first = true;
|
||||
for (Expression value : arguments) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
message.append(", ");
|
||||
}
|
||||
message.append(value.getType().toString());
|
||||
}
|
||||
message.append(")");
|
||||
return message.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string in parts, given a specified delimiter.
|
||||
|
||||
@@ -37,6 +37,6 @@ public class ZenPosition {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(line) + ":" + offset;
|
||||
return (file == null ? "?" : file.getFileName()) + " - " + Integer.toString(line) + ":" + offset;
|
||||
}
|
||||
}
|
||||
@@ -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 stanhebben.zenscript.value;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IntRange {
|
||||
private final int from;
|
||||
private final int to;
|
||||
|
||||
public IntRange(int from, int to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public int getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public int getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package stanhebben.zenscript.value.builtin;
|
||||
import java.util.Iterator;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -82,8 +83,7 @@ public class AnyByte implements IAny {
|
||||
|
||||
@Override
|
||||
public IAny range(IAny value) {
|
||||
//return new AnyIntRange(this.value, value.asInt());
|
||||
return null; // TODO
|
||||
return new AnyIntRange(new IntRange(this.value, value.asInt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,7 +117,7 @@ public class AnyByte implements IAny {
|
||||
|
||||
@Override
|
||||
public IAny call(IAny... values) {
|
||||
throw new ZenRuntimeException("cannot index a byte value");
|
||||
throw new ZenRuntimeException("cannot call a byte value");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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.value.builtin;
|
||||
|
||||
import java.util.Iterator;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class AnyInt implements IAny {
|
||||
public static AnyInt valueOf(byte value) {
|
||||
return new AnyInt(value);
|
||||
}
|
||||
|
||||
private final int value;
|
||||
|
||||
public AnyInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny not() {
|
||||
return new AnyInt(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny neg() {
|
||||
return new AnyInt(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny add(IAny value) {
|
||||
return new AnyInt(this.value + value.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny sub(IAny value) {
|
||||
return new AnyInt(this.value - value.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny cat(IAny value) {
|
||||
return new AnyString(Integer.toString(this.value) + value.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mul(IAny value) {
|
||||
return new AnyInt(this.value * value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny div(IAny value) {
|
||||
return new AnyInt(this.value / value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mod(IAny value) {
|
||||
return new AnyInt(this.value % value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny and(IAny value) {
|
||||
return new AnyInt(this.value & value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny or(IAny value) {
|
||||
return new AnyInt(this.value | value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny xor(IAny value) {
|
||||
return new AnyInt(this.value ^ value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny range(IAny value) {
|
||||
return new AnyIntRange(new IntRange(this.value, value.asInt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IAny value) {
|
||||
return Integer.compare(this.value, value.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IAny value) {
|
||||
throw new ZenRuntimeException("int has no in operator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny member(String value) {
|
||||
if (value.equals("abs")) {
|
||||
return new AnyInt(Math.abs(this.value));
|
||||
} else {
|
||||
throw new ZenRuntimeException("no such member in int: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny indexGet(IAny key) {
|
||||
throw new ZenRuntimeException("cannot index an int value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexSet(IAny key, IAny value) {
|
||||
throw new ZenRuntimeException("cannot index an int value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny call(IAny... values) {
|
||||
throw new ZenRuntimeException("cannot call an int value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new ZenRuntimeException("cannot convert 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 <T> T as(Class<T> cls) {
|
||||
throw new ZenRuntimeException("cannot convert a byte to an object");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAny> iteratorSingle() {
|
||||
throw new ZenRuntimeException("cannot iterate over a byte value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAny[]> iteratorMulti(int n) {
|
||||
throw new ZenRuntimeException("cannot iterate over a byte value");
|
||||
}
|
||||
}
|
||||
@@ -7,107 +7,126 @@
|
||||
package stanhebben.zenscript.value.builtin;
|
||||
|
||||
import java.util.Iterator;
|
||||
import stanhebben.zenscript.ZenRuntimeException;
|
||||
import stanhebben.zenscript.value.IAny;
|
||||
import stanhebben.zenscript.value.IntRange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class AnyIntRange implements IAny {
|
||||
private IntRange value;
|
||||
|
||||
public AnyIntRange(IntRange value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny not() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot invert an int range");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny neg() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot negate an int range");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny add(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot add int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny sub(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot subtract int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny cat(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot concatenate int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mul(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot multiply int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny div(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot divide int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny mod(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform modulo on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny and(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform and on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny or(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform or on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny xor(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot perform xor on int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny range(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Already a range!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot compare ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
int ivalue = value.asInt();
|
||||
return ivalue >= this.value.getFrom() && ivalue < this.value.getTo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny member(String value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
if (value.equals("from")) {
|
||||
return new AnyInt(this.value.getFrom());
|
||||
} else if (value.equals("to")) {
|
||||
return new AnyInt(this.value.getTo());
|
||||
} else {
|
||||
throw new ZenRuntimeException("No member " + value + " in int range");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny indexGet(IAny key) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
int ivalue = key.asInt();
|
||||
if (ivalue < value.getTo() - value.getFrom()) {
|
||||
return new AnyInt(this.value.getFrom() + ivalue);
|
||||
} else {
|
||||
throw new ArrayIndexOutOfBoundsException("int range index out of bounds: " + ivalue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexSet(IAny key, IAny value) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot modify int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAny call(IAny... values) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot call int ranges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
throw new ZenRuntimeException("Cannot cast int range to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,5 +178,4 @@ public class AnyIntRange implements IAny {
|
||||
public Iterator<IAny[]> iteratorMulti(int n) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,4 +7,5 @@ repositories {
|
||||
dependencies {
|
||||
compile gradleApi()
|
||||
compile 'org.ow2.asm:asm-debug-all:4.1'
|
||||
compile files("libs/tools.jar")
|
||||
}
|
||||
@@ -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.tasks;
|
||||
|
||||
import java.io.File;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MergeJarsTask extends DefaultTask {
|
||||
@InputFile
|
||||
public File mainInput;
|
||||
|
||||
@InputFile
|
||||
public File[] inputs;
|
||||
|
||||
@OutputFile
|
||||
public File output;
|
||||
|
||||
@TaskAction
|
||||
public void doTask() {
|
||||
System.out.println("Main: " + mainInput.toString());
|
||||
System.out.println("Inputs: " + inputs.length);
|
||||
System.out.println("Output: " + output.toString());
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class RegisterZenClassesTask extends DefaultTask {
|
||||
}
|
||||
|
||||
String fullClassName = classPackage.replace('.', '/') + '/' + className;
|
||||
System.out.println("Full classname: " + fullClassName);
|
||||
//System.out.println("Full classname: " + fullClassName);
|
||||
|
||||
// generate class
|
||||
ClassWriter output = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package stanhebben.zenscript.annotations;
|
||||
|
||||
/**
|
||||
* Used to indicate comparison types.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public enum CompareType {
|
||||
LT,
|
||||
GT,
|
||||
EQ,
|
||||
NE,
|
||||
LE,
|
||||
GE
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package stanhebben.zenscript.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Makes a class implementing List expose itself as iterable over keys and values.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface IterableList {
|
||||
String value();
|
||||
}
|
||||
Loaded 100 of 124 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user