- Rewrote the whole damn typecasting system. Now uses a more flexible and more structure casting rule system.

- Improved function literals. Function recipes are a thing!
- Added mirrored shaped recipes
- Fixed a few "any" type - related errors
- Added environment to the bracket handlers. Breaks existing bracket handlers!!
- Turned JavaMethod into an interface. Can now be used both for existing methods and generated ones. Makes a few things simpler :)
- Added creative and adventure getters to player info
This commit is contained in:
Stan Hebben committed 2014-08-20 11:59:49 +02:00
1 parent c67ad22270
commit 154c2242f9
172 files changed
+5400 -2134

No files matched your search

@@ -1,6 +1,7 @@
package minetweaker;
import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.parser.Token;
import stanhebben.zenscript.symbols.IZenSymbol;
@@ -23,8 +24,9 @@ public interface IBracketHandler {
*
* If the series of tokens is unrecognized, this method should return null.
*
* @param environment global compilation environment
* @param tokens token stream to be detected
* @return the resolved symbol, or null
*/
public IZenSymbol resolve(List<Token> tokens);
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens);
}
@@ -29,6 +29,7 @@ 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.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
/**
@@ -333,7 +334,7 @@ public class MineTweakerAPI {
* @return corresponding symbol
*/
public static IZenSymbol getJavaStaticMethodSymbol(Class cls, String name, Class... arguments) {
JavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
return new SymbolJavaStaticMethod(method);
}
@@ -347,7 +348,7 @@ public class MineTweakerAPI {
* @return corresponding symbol
*/
public static IZenSymbol getJavaStaticGetterSymbol(Class cls, String name) {
JavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name);
IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name);
return new SymbolJavaStaticGetter(method);
}
@@ -379,7 +380,7 @@ public class MineTweakerAPI {
* @param arguments argument types
* @return java method
*/
public static JavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
public static IJavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
return JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
}
}
@@ -6,7 +6,6 @@
package minetweaker.api.player;
import java.util.List;
import minetweaker.api.chat.IChatMessage;
import minetweaker.api.data.IData;
import minetweaker.api.item.IItemStack;
@@ -53,5 +52,12 @@ public interface IPlayer {
@ZenGetter("currentItem")
public IItemStack getCurrentItem();
@ZenGetter("creative")
public boolean isCreative();
@ZenGetter("adventure")
public boolean isAdventure();
// not an exposed method. risks abuse
public void openBrowser(String url);
}
@@ -28,28 +28,26 @@ public interface IRecipeManager {
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param mirrored indicates if the mirrored recipe should be valid too (optional)
* @param function recipe function (optional)
*/
@ZenMethod
public void addShaped(
IItemStack output,
IIngredient[][] ingredients,
@Optional boolean mirrored);
@Optional IRecipeFunction function);
/**
* Adds a shaped recipe.
* Adds a mirrored shaped recipe.
*
* @param output recipe output
* @param ingredients recipe ingredients
* @param function recipe function (optional)
* @param mirrored indicates if the mirrored recipe should be valid too (optional)
*/
@ZenMethod
public void addShaped(
public void addShapedMirrored(
IItemStack output,
IIngredient[][] ingredients,
IRecipeFunction function,
@Optional boolean mirrored);
@Optional IRecipeFunction function);
/**
* Adds a shapeless recipe.
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import minetweaker.IBracketHandler;
@@ -35,6 +36,7 @@ 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.IJavaMethod;
import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.util.ZenPosition;
@@ -105,9 +107,9 @@ public class GlobalRegistry {
}
}
public static IZenSymbol resolveBracket(List<Token> tokens) {
public static IZenSymbol resolveBracket(IEnvironmentGlobal environment, List<Token> tokens) {
for (IBracketHandler handler : bracketHandlers) {
IZenSymbol symbol = handler.resolve(tokens);
IZenSymbol symbol = handler.resolve(environment, tokens);
if (symbol != null) {
return symbol;
}
@@ -117,7 +119,7 @@ public class GlobalRegistry {
}
public static IZenSymbol getStaticFunction(Class cls, String name, Class... arguments) {
JavaMethod method = JavaMethod.get(types, cls, name, arguments);
IJavaMethod method = JavaMethod.get(types, cls, name, arguments);
if (method == null) return null;
return new SymbolJavaStaticMethod(method);
}
@@ -180,8 +182,8 @@ public class GlobalRegistry {
}
@Override
public IZenSymbol getBracketed(List<Token> tokens) {
return resolveBracket(tokens);
public IZenSymbol getBracketed(IEnvironmentGlobal environment, List<Token> tokens) {
return resolveBracket(environment, tokens);
}
@Override
@@ -266,5 +268,15 @@ public class GlobalRegistry {
public void warning(ZenPosition position, String message) {
MineTweakerAPI.logWarning(position.toString() + " > " + message);
}
@Override
public Set<String> getClassNames() {
return classes.keySet();
}
@Override
public byte[] getClass(String name) {
return classes.get(name);
}
}
}
@@ -36,6 +36,8 @@ import stanhebben.zenscript.parser.ParseException;
* @author Stan Hebben
*/
public class MTTweaker implements ITweaker {
private static final boolean DEBUG = true;
private final List<IUndoableAction> actions = new ArrayList<IUndoableAction>();
private final Set<IUndoableAction> wereStuck = new LinkedHashSet<IUndoableAction>();
private final Map<Object, IUndoableAction> stuckOverridable = new HashMap<Object, IUndoableAction>();
@@ -61,8 +63,9 @@ public class MTTweaker implements ITweaker {
}
action.apply();
actions.add(action);
}
actions.add(action);
}
@Override
@@ -148,7 +151,7 @@ public class MTTweaker implements ITweaker {
try {
String filename = script.getGroupName();
System.out.println("MineTweaker: Loading " + filename);
compileScripts(filename, files, environmentGlobal);
compileScripts(filename, files, environmentGlobal, DEBUG);
// execute scripts
ZenModule module = new ZenModule(classes, MineTweakerAPI.class.getClassLoader());