mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-25 06:14:25 +00:00
migrate to new buildscript
Class Registries are merged together into one. All subprojects are also merged into one. It's probably possible to split stuff into multiple source sets and not merging the registries, but I'm just too lazy for that.
This commit is contained in:
341 files changed
+1027
-11951
No files matched your search
@@ -0,0 +1,16 @@
|
||||
package minetweaker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The class registry provides the list of annotated classes to the scripting
|
||||
* system.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class ClassRegistry {
|
||||
public static void getClasses(List<Class> output) {
|
||||
// no longer needed. kept to not break anyone who reference this
|
||||
// seriously though, why would anyone want to look at this registry anyway
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package minetweaker;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
|
||||
/**
|
||||
* Bracket handlers enable processing of the bracket syntax.
|
||||
*
|
||||
* Inside brackets, any kind of token is acceptable except the closing bracket.
|
||||
* (>) Bracket handlers (multiple handlers can be registered) will resolve
|
||||
* these tokens into actual values. Values have to be ZenScript symbols and will
|
||||
* resolve at compile-time.
|
||||
*
|
||||
* These may of course return an expression that are executed on run-time, but
|
||||
* the type of the resulting value must be known compile-time.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IBracketHandler {
|
||||
/**
|
||||
* Resolves a set of tokens.
|
||||
*
|
||||
* 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(IEnvironmentGlobal environment, List<Token> tokens);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package minetweaker;
|
||||
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
|
||||
/**
|
||||
* Platform functions are a set of internal functions implemented by the
|
||||
* platform intended to communicate between API and implementation.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IPlatformFunctions {
|
||||
/**
|
||||
* Converts a string into a chat message.
|
||||
*
|
||||
* @param message message string
|
||||
* @return chat message
|
||||
*/
|
||||
public IChatMessage getMessage(String message);
|
||||
|
||||
/**
|
||||
* Distributes the given script data to all connected clients. Automatically
|
||||
* reloads the scripts from this data.
|
||||
*
|
||||
* @param data data to be distributed
|
||||
*/
|
||||
public void distributeScripts(byte[] data);
|
||||
|
||||
/**
|
||||
* Finds the item definition with the given ID.
|
||||
*
|
||||
* @param id item ID
|
||||
* @return resulting item definition
|
||||
*/
|
||||
public IItemDefinition getItemDefinition(int id);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package minetweaker;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
/**
|
||||
* Used to register removable mod recipes for mod machines. Once registered, it
|
||||
* will be called when minetweaker.remove() is called.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IRecipeRemover {
|
||||
/**
|
||||
* Removes all the items matching the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient
|
||||
*/
|
||||
public void remove(IIngredient ingredient);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package minetweaker;
|
||||
|
||||
/**
|
||||
* Defines a (possibly) undoable action.
|
||||
*
|
||||
* Every modification made by a command must be registered to the Tweaker with
|
||||
* the Tweaker.apply method. This enables MineTweaker to keep track of actions
|
||||
* that have been performed, and enables them to be rolled back later on.
|
||||
*
|
||||
* Actions exist in two flavors: undoable and permanent. If an action returns
|
||||
* canUndo(), the action is undoable, otherwise it is permanent. Permanent
|
||||
* actions cannot be used in server scripts.
|
||||
*
|
||||
* There also exist semi-permanent actions. Those actions can return an override
|
||||
* key; if a newer action has the same override key as an old action, the new
|
||||
* action is considered to override the old one.
|
||||
*
|
||||
* Likewise, actions can implement hashCode and equals methods to indicate that
|
||||
* they are equal. If an action is equal to a non-undoable stuck action, it will
|
||||
* be omitted from execution.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IUndoableAction {
|
||||
/**
|
||||
* Executes what the action is supposed to do. This method can be called
|
||||
* again if undo() has been called in between.
|
||||
*/
|
||||
public void apply();
|
||||
|
||||
/**
|
||||
* Checks if this action can be undone. If this method returns true, it must
|
||||
* implement undo() properly. If this method returns false, the action is
|
||||
* considered permanent, undo() will never be called, and the action cannot
|
||||
* be executed as part of a server script. Additionally, the
|
||||
* minetweaker.clear() function will not work and minetweaker.canClear will
|
||||
* return false.
|
||||
*
|
||||
* @return undoable status
|
||||
*/
|
||||
public boolean canUndo();
|
||||
|
||||
/**
|
||||
* Undoes the action. Will only be called after apply() has been executed.
|
||||
* After an undo, apply may be called again. They could be done multiple
|
||||
* times in certain scenarios.
|
||||
*/
|
||||
public void undo();
|
||||
|
||||
/**
|
||||
* Describes, in a single human-readable sentence, what this specific action
|
||||
* is doing. Used in logging messages, lists, ...
|
||||
*
|
||||
* Try to be as descriptive as possible without being too verbose.
|
||||
*
|
||||
* Examples: - Adding Peach planks to the woodPlanks ore dictionary entry -
|
||||
* Removing a recipe for Iron Ore
|
||||
*
|
||||
* @return the description of this action
|
||||
*/
|
||||
public String describe();
|
||||
|
||||
/**
|
||||
* Describes what this action does if it is undone. Similar to the
|
||||
* describe() method. No implementation is needed if the action cannot be
|
||||
* undone.
|
||||
*
|
||||
* @return the description of this action, when undone
|
||||
*/
|
||||
public String describeUndo();
|
||||
|
||||
/**
|
||||
* Returns the override key. Two actions are considered to override each
|
||||
* other if their override key is equal. You can return null to indicate
|
||||
* that an action can never be overridden.
|
||||
*
|
||||
* This value only makes sense for recipes that are not undoable. For
|
||||
* undoable recipes, you should return null.
|
||||
*
|
||||
* @return override key (null for actions that are undoable or which can
|
||||
* never be overridden by another action)
|
||||
*/
|
||||
public Object getOverrideKey();
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
package minetweaker;
|
||||
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.client.IClient;
|
||||
import minetweaker.api.compat.*;
|
||||
import minetweaker.api.event.IEventManager;
|
||||
import minetweaker.api.formatting.IFormatter;
|
||||
import minetweaker.api.game.IGame;
|
||||
import minetweaker.api.mods.ILoadedMods;
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import minetweaker.api.server.IServer;
|
||||
import minetweaker.api.vanilla.IVanilla;
|
||||
import minetweaker.runtime.GlobalRegistry;
|
||||
import minetweaker.runtime.ILogger;
|
||||
import minetweaker.runtime.ITweaker;
|
||||
import minetweaker.runtime.MTTweaker;
|
||||
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.IJavaMethod;
|
||||
import stanhebben.zenscript.type.natives.JavaMethod;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Provides access to the MineTweaker API.
|
||||
*
|
||||
* An implementing platform needs to do the following: - Set a logger - Set the
|
||||
* ore dictionary - Set the recipe manager - Set the furnace manager - Set event
|
||||
* manager - Set resource manager
|
||||
*
|
||||
* - Register additional global symbols to the GlobalRegistry (recipes,
|
||||
* minetweaker, oreDict, logger, as well as the official set of functions) -
|
||||
* Register native classes using the GlobalRegistry - Register bracket handlers
|
||||
* to resolve block/item/... references using the bracket syntax
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerAPI {
|
||||
public static final String[] COLOR_NAMES = {
|
||||
"White",
|
||||
"Orange",
|
||||
"Magenta",
|
||||
"Light Blue",
|
||||
"Yellow",
|
||||
"Lime",
|
||||
"Pink",
|
||||
"Gray",
|
||||
"Light Gray",
|
||||
"Cyan",
|
||||
"Purple",
|
||||
"Blue",
|
||||
"Brown",
|
||||
"Green",
|
||||
"Red",
|
||||
"Black"
|
||||
};
|
||||
private static IJEIRecipeRegistry ijeiRecipeRegistry = new DummyJEIRecipeRegistry();
|
||||
|
||||
static {
|
||||
registerClassRegistry(ClassRegistry.class, "MT-API");
|
||||
|
||||
registerGlobalSymbol("logger", getJavaStaticGetterSymbol(MineTweakerAPI.class, "getLogger"));
|
||||
registerGlobalSymbol("recipes", getJavaStaticFieldSymbol(MineTweakerAPI.class, "recipes"));
|
||||
// registerGlobalSymbol("brewing", getJavaStaticFieldSymbol(MineTweakerAPI.class, "brewing"));
|
||||
registerGlobalSymbol("furnace", getJavaStaticFieldSymbol(MineTweakerAPI.class, "furnace"));
|
||||
registerGlobalSymbol("oreDict", getJavaStaticFieldSymbol(MineTweakerAPI.class, "oreDict"));
|
||||
registerGlobalSymbol("events", getJavaStaticFieldSymbol(MineTweakerAPI.class, "events"));
|
||||
registerGlobalSymbol("server", getJavaStaticFieldSymbol(MineTweakerAPI.class, "server"));
|
||||
registerGlobalSymbol("client", getJavaStaticFieldSymbol(MineTweakerAPI.class, "client"));
|
||||
registerGlobalSymbol("game", getJavaStaticFieldSymbol(MineTweakerAPI.class, "game"));
|
||||
registerGlobalSymbol("loadedMods", getJavaStaticFieldSymbol(MineTweakerAPI.class, "loadedMods"));
|
||||
registerGlobalSymbol("format", getJavaStaticFieldSymbol(MineTweakerAPI.class, "format"));
|
||||
registerGlobalSymbol("vanilla", getJavaStaticFieldSymbol(MineTweakerAPI.class, "vanilla"));
|
||||
}
|
||||
|
||||
private MineTweakerAPI() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Tweaker is where you apply undoable actions. Any kind of action that
|
||||
* reloads with the scripts should always be submitted to the tweaker.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final ITweaker tweaker = new MTTweaker();
|
||||
|
||||
/**
|
||||
* The logger can be used to write logging messages to the client. Error and
|
||||
* warning messages should be relayed to admins for further handling.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static final ILogger getLogger() {
|
||||
return MineTweakerImplementationAPI.logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access point to the ore dictionary.
|
||||
*/
|
||||
public static IOreDict oreDict = null;
|
||||
|
||||
/**
|
||||
* Access point to the recipe manager.
|
||||
*/
|
||||
public static IRecipeManager recipes = null;
|
||||
|
||||
// /**
|
||||
// * Access point to the brewing manager.
|
||||
// */
|
||||
// public static IBrewingManager brewing = null;
|
||||
|
||||
/**
|
||||
* Access point to the furnace manager.
|
||||
*/
|
||||
public static IFurnaceManager furnace = null;
|
||||
|
||||
/**
|
||||
* Access point to the events manager.
|
||||
*/
|
||||
public static final IEventManager events = MineTweakerImplementationAPI.events;
|
||||
|
||||
/**
|
||||
* Access point to the server, if any.
|
||||
*/
|
||||
public static IServer server = null;
|
||||
|
||||
/**
|
||||
* Access point to the client, if any.
|
||||
*/
|
||||
public static IClient client = null;
|
||||
|
||||
/**
|
||||
* Access point to general game data, such as items.
|
||||
*/
|
||||
public static IGame game = null;
|
||||
|
||||
/**
|
||||
* Access point to mods list.
|
||||
*/
|
||||
public static ILoadedMods loadedMods = null;
|
||||
|
||||
/**
|
||||
* Access point to the text formatter.
|
||||
*/
|
||||
public static IFormatter format = null;
|
||||
|
||||
/**
|
||||
* Access point to the vanilla functions and data.
|
||||
*/
|
||||
public static IVanilla vanilla = null;
|
||||
|
||||
/**
|
||||
* Applies this given action.
|
||||
*
|
||||
* @param action action object
|
||||
*/
|
||||
public static void apply(IUndoableAction action) {
|
||||
tweaker.apply(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a command message. Commands messages are those generated as output
|
||||
* in response to a command.
|
||||
*
|
||||
* @param message command message
|
||||
*/
|
||||
public static void logCommand(String message) {
|
||||
getLogger().logCommand(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an info message. Info messages have low priority and will only be
|
||||
* displayed in the log files, but not directly to players in-game.
|
||||
*
|
||||
* @param message info message
|
||||
*/
|
||||
public static void logInfo(String message) {
|
||||
getLogger().logInfo(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a warning message. Warning messages are displayed to admins and
|
||||
* indicate that there is an issue. However, the issue is not a large
|
||||
* problem, and everything should run fine - besides perhaps a few things
|
||||
* not entirely working as expected.
|
||||
*
|
||||
* @param message warning message
|
||||
*/
|
||||
public static void logWarning(String message) {
|
||||
getLogger().logWarning(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message. Error messages indicate a real problem and
|
||||
* indicate that things won't run properly. The scripting system will still
|
||||
* make a best-effort attempt at executing the rest of the scripts, but that
|
||||
* might cause additional errors and issues.
|
||||
*
|
||||
* @param message error message
|
||||
*/
|
||||
public static void logError(String message) {
|
||||
getLogger().logError(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error message. Error messages indicate a real problem and
|
||||
* indicate that things won't run properly. The scripting system will still
|
||||
* make a best-effort attempt at executing the rest of the scripts, but that
|
||||
* might cause additional errors and issues.
|
||||
*
|
||||
* @param message error message
|
||||
* @param exception exception that was caught related to the error
|
||||
*/
|
||||
public static void logError(String message, Throwable exception) {
|
||||
getLogger().logError(message, exception);
|
||||
}
|
||||
|
||||
// ###################################
|
||||
// ### Plugin registration methods ###
|
||||
// ###################################
|
||||
|
||||
/**
|
||||
* Register a class registry class. Such class must have (at least) a public
|
||||
* static method called "getClasses" with accepts a List of classes and
|
||||
* which stores its classes into that list.
|
||||
*
|
||||
* @param registryClass
|
||||
*/
|
||||
public static void registerClassRegistry(Class registryClass) {
|
||||
registerClassRegistry(registryClass, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a class registry class. Such class must have (at least) a public
|
||||
* static method called "getClasses" with accepts a List of classes and
|
||||
* which stores its classes into that list.
|
||||
*
|
||||
* @param registryClass
|
||||
* @param description
|
||||
*/
|
||||
public static void registerClassRegistry(Class registryClass, String description) {
|
||||
try {
|
||||
Method method = registryClass.getMethod("getClasses", List.class);
|
||||
if ((method.getModifiers() & Modifier.STATIC) == 0) {
|
||||
logError("ERROR: getClasses method in " + registryClass.getName() + " isn't static");
|
||||
} else {
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
method.invoke(null, classes);
|
||||
|
||||
outer: for (Class cls : classes) {
|
||||
for (Annotation annotation : cls.getAnnotations()) {
|
||||
if (annotation instanceof ModOnly) {
|
||||
String[] value = ((ModOnly) annotation).value();
|
||||
String version = ((ModOnly) annotation).version();
|
||||
|
||||
for (String mod : value) {
|
||||
if (!loadedMods.contains(mod))
|
||||
continue outer;
|
||||
|
||||
if (!loadedMods.get(mod).getVersion().startsWith(version))
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.registerClass(cls);
|
||||
}
|
||||
|
||||
if (description != null)
|
||||
logInfo("Loaded class registry: " + description);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
|
||||
if(ex.getCause() instanceof NoClassDefFoundError) {
|
||||
logInfo("Classes for registry " + registryClass + " not found, skipping");
|
||||
} else {
|
||||
logError("Error registering class registry", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class registry. Will attempt to resolve the given class name.
|
||||
* Does nothing if the class could not be loaded.
|
||||
*
|
||||
* @param className class name to be loaded
|
||||
* @return true if registration was successful
|
||||
*/
|
||||
public static boolean registerClassRegistry(String className) {
|
||||
return registerClassRegistry(className, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class registry. Will attempt to resolve the given class name.
|
||||
* Does nothing if the class could not be loaded.
|
||||
*
|
||||
* @param className class name to be loaded
|
||||
* @param description
|
||||
* @return true if registration was successful
|
||||
*/
|
||||
public static boolean registerClassRegistry(String className, String description) {
|
||||
try {
|
||||
registerClassRegistry(Class.forName(className), description);
|
||||
return true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an annotated class. A class is annotated with either @ZenClass
|
||||
* or @ZenExpansion. Classes not annotated with either of these will be
|
||||
* ignored.
|
||||
*
|
||||
* @param annotatedClass
|
||||
*/
|
||||
public static void registerClass(Class annotatedClass) {
|
||||
// System.out.println("Registering " + annotatedClass.getName());
|
||||
|
||||
for (Annotation annotation : annotatedClass.getAnnotations()) {
|
||||
if (annotation instanceof ZenExpansion) {
|
||||
GlobalRegistry.registerExpansion(annotatedClass);
|
||||
}
|
||||
|
||||
if (annotation instanceof ZenClass) {
|
||||
GlobalRegistry.registerNativeClass(annotatedClass);
|
||||
}
|
||||
if ((annotation instanceof BracketHandler) && IBracketHandler.class.isAssignableFrom(annotatedClass)) {
|
||||
try {
|
||||
IBracketHandler bracketHandler = (IBracketHandler) annotatedClass.newInstance();
|
||||
registerBracketHandler(bracketHandler);
|
||||
} catch (InstantiationException ex) {
|
||||
Logger.getLogger(MineTweakerAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Logger.getLogger(MineTweakerAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a global symbol. Global symbols are immediately accessible from
|
||||
* anywhere in the scripts.
|
||||
*
|
||||
* @param name symbol name
|
||||
* @param symbol symbol
|
||||
*/
|
||||
public static void registerGlobalSymbol(String name, IZenSymbol symbol) {
|
||||
GlobalRegistry.registerGlobal(name, symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a recipe remover. Removers are called when the global
|
||||
* minetweaker.remove() function is called.
|
||||
*
|
||||
* @param remover recipe remover
|
||||
*/
|
||||
public static void registerRemover(IRecipeRemover remover) {
|
||||
GlobalRegistry.registerRemover(remover);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a bracket handler. Is capable of converting the bracket syntax
|
||||
* to an actual value. This new handler will be added last - it can thus not
|
||||
* intercept values that are already handled by the system.
|
||||
*
|
||||
* @param handler bracket handler to be added
|
||||
*/
|
||||
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) {
|
||||
IJavaMethod 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) {
|
||||
IJavaMethod 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 IJavaMethod getJavaMethod(Class cls, String name, Class... arguments) {
|
||||
return JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments);
|
||||
}
|
||||
|
||||
public static IJEIRecipeRegistry getIjeiRecipeRegistry() {
|
||||
return ijeiRecipeRegistry;
|
||||
}
|
||||
|
||||
public static void setIjeiRecipeRegistry(IJEIRecipeRegistry ijeiRecipeRegistry) {
|
||||
MineTweakerAPI.ijeiRecipeRegistry = ijeiRecipeRegistry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerImplementation {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,830 @@
|
||||
package minetweaker;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.entity.IEntityDefinition;
|
||||
import minetweaker.api.event.*;
|
||||
import minetweaker.api.formatting.IFormatter;
|
||||
import minetweaker.api.game.IGame;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.logger.MTLogger;
|
||||
import minetweaker.api.mods.ILoadedMods;
|
||||
import minetweaker.api.mods.IMod;
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.*;
|
||||
import minetweaker.api.server.ICommandFunction;
|
||||
import minetweaker.api.server.ICommandValidator;
|
||||
import minetweaker.api.server.IServer;
|
||||
import minetweaker.api.vanilla.IVanilla;
|
||||
import minetweaker.api.vanilla.LootEntry;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import minetweaker.runtime.IScriptProvider;
|
||||
import minetweaker.util.EventList;
|
||||
import minetweaker.util.IEventHandler;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import static minetweaker.MineTweakerAPI.furnace;
|
||||
import static minetweaker.MineTweakerAPI.server;
|
||||
|
||||
/**
|
||||
* The implementation API is used by API implementations for internal
|
||||
* communication and initialization.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerImplementationAPI {
|
||||
private static Set<IPlayer> blockInfoPlayers = new HashSet<IPlayer>();
|
||||
private static IEventHandle blockEventHandler = null;
|
||||
|
||||
private static final Map<String, MineTweakerCommand> minetweakerCommands;
|
||||
|
||||
private static final Comparator<IItemDefinition> ITEM_COMPARATOR = new ItemComparator();
|
||||
private static final Comparator<ILiquidDefinition> LIQUID_COMPARATOR = new LiquidComparator();
|
||||
private static final Comparator<IBlockDefinition> BLOCK_COMPARATOR = new BlockComparator();
|
||||
private static final Comparator<IEntityDefinition> ENTITY_COMPARATOR = new EntityComparator();
|
||||
|
||||
private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn();
|
||||
private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut();
|
||||
private static final ListenBlockInfo LISTEN_BLOCK_INFO = new ListenBlockInfo();
|
||||
private static final EventList<ReloadEvent> ONROLLBACK = new EventList<>();
|
||||
private static final EventList<ReloadEvent> ONRELOAD = new EventList<>();
|
||||
private static final EventList<ReloadEvent> ONPOSTRELOAD = new EventList<>();
|
||||
|
||||
static {
|
||||
minetweakerCommands = new HashMap<String, MineTweakerCommand>();
|
||||
|
||||
minetweakerCommands.put("reload", new MineTweakerCommand(
|
||||
"reload",
|
||||
new String[]{
|
||||
"/minetweaker reload",
|
||||
" Reloads all scripts"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
reload();
|
||||
player.sendChat("Scripts reloaded");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("names", new MineTweakerCommand(
|
||||
"names",
|
||||
new String[]{
|
||||
"/minetweaker names",
|
||||
" Outputs a list of all item names in the game to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
List<IItemDefinition> items = MineTweakerAPI.game.getItems();
|
||||
Collections.sort(items, ITEM_COMPARATOR);
|
||||
for (IItemDefinition item : items) {
|
||||
String displayName;
|
||||
|
||||
try {
|
||||
displayName = ", " + item.makeStack(0).getDisplayName();
|
||||
} catch (Throwable ex) {
|
||||
// some mods (such as buildcraft) may throw
|
||||
// exceptions when calling
|
||||
// getDisplayName on an item stack that doesn't
|
||||
// contain valid NBT data
|
||||
// also seems to cause errors in some other
|
||||
// cases too
|
||||
displayName = " -- Name could not be retrieved due to an error: " + ex;
|
||||
}
|
||||
|
||||
MineTweakerAPI.logCommand("<" + item.getId() + ">" + displayName);
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("liquids", new MineTweakerCommand(
|
||||
"liquids",
|
||||
new String[]{
|
||||
"/minetweaker liquids",
|
||||
" Outputs a list of all liquid names in the game to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
List<ILiquidDefinition> liquids = MineTweakerAPI.game.getLiquids();
|
||||
Collections.sort(liquids, LIQUID_COMPARATOR);
|
||||
|
||||
MineTweakerAPI.logCommand("Liquids:");
|
||||
for (ILiquidDefinition liquid : liquids) {
|
||||
MineTweakerAPI.logCommand("<liquid:" + liquid.getName() + ">, " + liquid.getDisplayName());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("blocks", new MineTweakerCommand(
|
||||
"blocks",
|
||||
new String[]{
|
||||
"/minetweaker blocks",
|
||||
" Outputs a list of all blocks in the game to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
List<IBlockDefinition> blocks = MineTweakerAPI.game.getBlocks();
|
||||
Collections.sort(blocks, BLOCK_COMPARATOR);
|
||||
|
||||
MineTweakerAPI.logCommand("Blocks:");
|
||||
for (IBlockDefinition block : blocks) {
|
||||
MineTweakerAPI.logCommand("<block:" + block.getId() + ">, " + block.getDisplayName());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("entities", new MineTweakerCommand(
|
||||
"entities",
|
||||
new String[]{
|
||||
"/minetweaker entities",
|
||||
" Outputs a list of all entity definitions in the game to the minetweaker log"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
List<IEntityDefinition> entities = MineTweakerAPI.game.getEntities();
|
||||
Collections.sort(entities, ENTITY_COMPARATOR);
|
||||
|
||||
MineTweakerAPI.logCommand("Entities:");
|
||||
for (IEntityDefinition entity : entities) {
|
||||
MineTweakerAPI.logCommand(entity.getId() + " -- " + entity.getName());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("recipes", new MineTweakerCommand(
|
||||
"recipes",
|
||||
new String[]{
|
||||
"/minetweaker recipes",
|
||||
" Lists all crafting recipes in the game",
|
||||
"/minetweaker recipes hand",
|
||||
" Lists all crafting recipes for the item in your hand",
|
||||
" Also copies the recipes to clipboard",
|
||||
"/minetweaker recipes furnace",
|
||||
" lists all furnace recipes in the game"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
if (player != null) {
|
||||
player.sendChat("Generating recipe list, this could take a while...");
|
||||
}
|
||||
|
||||
MineTweakerAPI.logCommand("Recipes:");
|
||||
for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) {
|
||||
try {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
} catch (Throwable ex) {
|
||||
// Some recipes can result in an NPE :-(
|
||||
if (recipe instanceof ShapedRecipe) {
|
||||
ShapedRecipe shaped = (ShapedRecipe) recipe;
|
||||
IItemStack out = shaped.getOutput();
|
||||
MineTweakerAPI.logError("Could not dump recipe for " + out, ex);
|
||||
} else if (recipe instanceof ShapelessRecipe) {
|
||||
ShapelessRecipe shapeless = (ShapelessRecipe) recipe;
|
||||
IItemStack out = shapeless.getOutput();
|
||||
MineTweakerAPI.logError("Could not dump recipe for " + out, ex);
|
||||
} else {
|
||||
MineTweakerAPI.logError("Could not dump recipe", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else if (arguments[0].equals("hand") && player != null) {
|
||||
IItemStack item = player.getCurrentItem();
|
||||
if (item != null) {
|
||||
List<ICraftingRecipe> recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount());
|
||||
if (recipes.isEmpty()) {
|
||||
player.sendChat("No crafting recipes found for that item");
|
||||
} else {
|
||||
StringBuilder recipesString = new StringBuilder();
|
||||
|
||||
for (ICraftingRecipe recipe : recipes) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
player.sendChat(recipe.toCommandString());
|
||||
recipesString.append(recipe.toCommandString()).append("\n");
|
||||
}
|
||||
|
||||
copyToClipboard(recipesString.toString());
|
||||
}
|
||||
} else {
|
||||
player.sendChat("No item was found");
|
||||
}
|
||||
} else if (arguments[0].equals("furnace") && player != null) {
|
||||
if (player != null) {
|
||||
player.sendChat("Generating furnace list, this could take a while...");
|
||||
}
|
||||
|
||||
MineTweakerAPI.logCommand("Furnace Recipes:");
|
||||
for (IFurnaceRecipe recipe : furnace.getAll()) {
|
||||
try {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
} catch (Throwable ex) {
|
||||
MineTweakerAPI.logError("Could not dump furnace recipe", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("Furnace Recipe list generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendChat("Invalid arguments for recipes command");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("inventory", new MineTweakerCommand(
|
||||
"inventory",
|
||||
new String[]{
|
||||
"/minetweaker inventory",
|
||||
" Lists all items in your inventory"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
for (int i = 0; i < player.getInventorySize(); i++) {
|
||||
IItemStack stack = player.getInventoryStack(i);
|
||||
if (stack != null) {
|
||||
player.sendChat(stack.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("hand", new MineTweakerCommand(
|
||||
"hand",
|
||||
new String[]{
|
||||
"/minetweaker hand",
|
||||
" Outputs the name of the item in your hand",
|
||||
" Also copies the name to clipboard and prints",
|
||||
" oredict entries"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
IItemStack hand = player.getCurrentItem();
|
||||
if (hand != null) {
|
||||
String value = hand.toString();
|
||||
player.sendChat(value);
|
||||
copyToClipboard(value);
|
||||
|
||||
List<IOreDictEntry> entries = hand.getOres();
|
||||
for (IOreDictEntry entry : entries) {
|
||||
player.sendChat("Is in <ore:" + entry.getName() + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("oredict", new MineTweakerCommand(
|
||||
"oredict",
|
||||
new String[]{
|
||||
"/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"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length > 0) {
|
||||
String entryName = arguments[0];
|
||||
IOreDictEntry entry = MineTweakerAPI.oreDict.get(entryName);
|
||||
if (entry.isEmpty()) {
|
||||
player.sendChat("Entry doesn't exist");
|
||||
return;
|
||||
} else {
|
||||
MineTweakerAPI.logCommand("Ore entries for " + entryName + ":");
|
||||
for (IItemStack ore : entry.getItems()) {
|
||||
MineTweakerAPI.logCommand(" " + ore);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (IOreDictEntry entry : MineTweakerAPI.oreDict.getEntries()) {
|
||||
if (!entry.isEmpty()) {
|
||||
MineTweakerAPI.logCommand("Ore entries for <ore:" + entry.getName() + "> :");
|
||||
for (IItemStack ore : entry.getItems()) {
|
||||
MineTweakerAPI.logCommand(" " + ore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("mods", new MineTweakerCommand(
|
||||
"mods",
|
||||
new String[]{
|
||||
"/minetweaker mods",
|
||||
" Outputs all active mod IDs and versions in the game"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
MineTweakerAPI.logCommand("Mods list:");
|
||||
for (IMod mod : MineTweakerAPI.loadedMods) {
|
||||
String message = mod.getId() + " - " + mod.getName() + " - " + mod.getVersion();
|
||||
player.sendChat(message);
|
||||
MineTweakerAPI.logCommand("Mod: " + message);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("name", new MineTweakerCommand(
|
||||
"name",
|
||||
new String[]{
|
||||
"/minetweaker name <id>",
|
||||
" Outputs the name for the given item ID",
|
||||
},
|
||||
new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length < 1) {
|
||||
player.sendChat("missing id parameter");
|
||||
} else {
|
||||
try {
|
||||
int id = Integer.parseInt(arguments[0]);
|
||||
IItemDefinition definition = platform.getItemDefinition(id);
|
||||
if (definition == null) {
|
||||
player.sendChat("no such item");
|
||||
} else {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append('<');
|
||||
description.append(definition.getId());
|
||||
description.append('>');
|
||||
player.sendChat(description.toString());
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
MineTweakerAPI.logCommand("ID must be an integer");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("seeds", new MineTweakerCommand(
|
||||
"seeds",
|
||||
new String[]{
|
||||
"/minetweaker seeds",
|
||||
" Prints all seeds registered",
|
||||
" for tall grass"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
MineTweakerAPI.logCommand("Seeds:");
|
||||
for (WeightedItemStack seed : MineTweakerAPI.vanilla.getSeeds().getSeeds()) {
|
||||
String message = seed.getStack() + " - " + (int) seed.getChance();
|
||||
player.sendChat(message);
|
||||
MineTweakerAPI.logCommand("Seed: " + message);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("loot", new MineTweakerCommand(
|
||||
"seeds",
|
||||
new String[]{
|
||||
"/minetweaker seeds",
|
||||
" Prints all seeds registered",
|
||||
" for tall grass"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
MineTweakerAPI.logCommand("Loot chest contents:");
|
||||
List<String> types = MineTweakerAPI.vanilla.getLoot().getLootTypes();
|
||||
Collections.sort(types);
|
||||
for (String lootType : types) {
|
||||
MineTweakerAPI.logCommand("Loot type: " + lootType);
|
||||
|
||||
List<LootEntry> entries = MineTweakerAPI.vanilla.getLoot().getLoot(lootType);
|
||||
for (LootEntry entry : entries) {
|
||||
MineTweakerAPI.logCommand(" " + entry.toString());
|
||||
}
|
||||
}
|
||||
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
} else {
|
||||
MineTweakerAPI.logCommand("Loot for type: " + arguments[0]);
|
||||
|
||||
List<LootEntry> entries = MineTweakerAPI.vanilla.getLoot().getLoot(arguments[0]);
|
||||
for (LootEntry entry : entries) {
|
||||
MineTweakerAPI.logCommand(" " + entry.toString());
|
||||
}
|
||||
|
||||
player.sendChat("List generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("wiki", new MineTweakerCommand(
|
||||
"wiki",
|
||||
new String[]{
|
||||
"/minetweaker wiki",
|
||||
" Opens your browser with the wiki"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
player.openBrowser("http://minetweaker3.powerofbytes.com/wiki/");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("bugs", new MineTweakerCommand(
|
||||
"bugs",
|
||||
new String[]{
|
||||
"/minetweaker bugs",
|
||||
" Opens your browser with the GitHub bug tracker"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
player.openBrowser("https://github.com/stanhebben/MineTweaker3/issues");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("forum", new MineTweakerCommand(
|
||||
"forum",
|
||||
new String[]{
|
||||
"/minetweaker forum",
|
||||
" Opens your browser with the forum"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
player.openBrowser("http://minetweaker3.powerofbytes.com/forum");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("biomes", new MineTweakerCommand(
|
||||
"biomes",
|
||||
new String[]{
|
||||
"/minetweaker biomes",
|
||||
" Lists all the biomes in the game"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
MineTweakerAPI.logCommand("Biomes:");
|
||||
|
||||
for (IBiome biome : MineTweakerAPI.game.getBiomes()) {
|
||||
MineTweakerAPI.logCommand(" " + biome.getName());
|
||||
}
|
||||
|
||||
player.sendChat("Biome list generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("blockinfo", new MineTweakerCommand(
|
||||
"blockinfo",
|
||||
new String[]{
|
||||
"/minetweaker blockinfo",
|
||||
" Activates or deactivates block reader. In block info mode,",
|
||||
" right-click a block to see ID, meta and tile entity data"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (blockInfoPlayers.isEmpty()) {
|
||||
blockEventHandler = events.onPlayerInteract(LISTEN_BLOCK_INFO);
|
||||
}
|
||||
|
||||
if (blockInfoPlayers.contains(player)) {
|
||||
blockInfoPlayers.remove(player);
|
||||
player.sendChat("Block info mode deactivated.");
|
||||
} else {
|
||||
blockInfoPlayers.add(player);
|
||||
player.sendChat("Block info mode activated. Right-click a block to see its data.");
|
||||
}
|
||||
|
||||
if (blockInfoPlayers.isEmpty()) {
|
||||
blockEventHandler.close();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Access point to the event handler implementation.
|
||||
*/
|
||||
public static final MTEventManager events = new MTEventManager();
|
||||
|
||||
/**
|
||||
* Access point to the internal logger instance.
|
||||
*/
|
||||
public static final MTLogger logger = new MTLogger();
|
||||
|
||||
/**
|
||||
* Access point to general platform functions.
|
||||
*/
|
||||
public static IPlatformFunctions platform = null;
|
||||
|
||||
/**
|
||||
* Initializes the MineTweaker API.
|
||||
*
|
||||
* @param oreDict ore dictionary interface
|
||||
* @param recipes recipe manager interface
|
||||
* @param furnace furnace manager interface
|
||||
* @param game game interface
|
||||
* @param mods mods interface
|
||||
* @param formatter formatter interface
|
||||
* @param vanilla vanilla interface
|
||||
*/
|
||||
public static void init(
|
||||
IOreDict oreDict,
|
||||
IRecipeManager recipes,
|
||||
IFurnaceManager furnace,
|
||||
IGame game,
|
||||
ILoadedMods mods,
|
||||
IFormatter formatter,
|
||||
IVanilla vanilla) {
|
||||
MineTweakerAPI.oreDict = oreDict;
|
||||
MineTweakerAPI.recipes = recipes;
|
||||
MineTweakerAPI.furnace = furnace;
|
||||
MineTweakerAPI.game = game;
|
||||
MineTweakerAPI.loadedMods = mods;
|
||||
MineTweakerAPI.format = formatter;
|
||||
MineTweakerAPI.vanilla = vanilla;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event handler to be fired upon reload.
|
||||
*
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
public static IEventHandle onRollbackEvent(IEventHandler<ReloadEvent> handler) {
|
||||
return ONROLLBACK.add(handler);
|
||||
}
|
||||
public static IEventHandle onReloadEvent(IEventHandler<ReloadEvent> handler) {
|
||||
return ONRELOAD.add(handler);
|
||||
}
|
||||
|
||||
public static IEventHandle onPostReload(IEventHandler<ReloadEvent> handler) {
|
||||
return ONPOSTRELOAD.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called upon server start.
|
||||
*
|
||||
* @param server server interface
|
||||
*/
|
||||
public static void onServerStart(IServer server) {
|
||||
MineTweakerAPI.server = server;
|
||||
reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be called upon server stop.
|
||||
*/
|
||||
public static void onServerStop() {
|
||||
MineTweakerAPI.server = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the script provider.
|
||||
*
|
||||
* @param provider script provider
|
||||
*/
|
||||
public static void setScriptProvider(IScriptProvider provider) {
|
||||
MineTweakerAPI.tweaker.setScriptProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to reload scripts. Must be called after setting a new script
|
||||
* provider in order to reload scripts.
|
||||
*/
|
||||
public static void reload() {
|
||||
blockInfoPlayers.clear();
|
||||
|
||||
logger.clear();
|
||||
events.clear();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
events.onPlayerLoggedIn(LISTEN_LOGIN);
|
||||
events.onPlayerLoggedOut(LISTEN_LOGOUT);
|
||||
}
|
||||
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
ONROLLBACK.publish(new ReloadEvent());
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
if (!MineTweakerAPI.server.isCommandAdded("minetweaker")) {
|
||||
server.addCommand("minetweaker", "", new String[]{"mt", "crafttweaker", "ct"}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
player.sendChat("Please provide a command. Use /mt help for more info.");
|
||||
} else if (arguments[0].equals("help")) {
|
||||
String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]);
|
||||
Arrays.sort(keys);
|
||||
for (String key : keys) {
|
||||
for (String helpMessage : minetweakerCommands.get(key).description) {
|
||||
player.sendChat(helpMessage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MineTweakerCommand command = minetweakerCommands.get(arguments[0]);
|
||||
if (command == null) {
|
||||
player.sendChat("No such minetweaker command available");
|
||||
} else {
|
||||
command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, new ICommandValidator() {
|
||||
@Override
|
||||
public boolean canExecute(IPlayer player) {
|
||||
return server.isOp(player);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
ONRELOAD.publish(new ReloadEvent());
|
||||
|
||||
MineTweakerAPI.tweaker.load();
|
||||
|
||||
if (MineTweakerAPI.server != null) {
|
||||
platform.distributeScripts(MineTweakerAPI.tweaker.getScriptData());
|
||||
}
|
||||
|
||||
ONPOSTRELOAD.publish(new ReloadEvent());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new minetweaker command. Can be called with /mt <command&;gt;
|
||||
* <arguments>.
|
||||
*
|
||||
* @param name command name
|
||||
* @param description description strings
|
||||
* @param function command implementation
|
||||
*/
|
||||
public static void addMineTweakerCommand(String name, String[] description, ICommandFunction function) {
|
||||
MineTweakerAPI.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function)));
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### Private static methods ###
|
||||
// ##############################
|
||||
|
||||
private static void copyToClipboard(String value) {
|
||||
StringSelection stringSelection = new StringSelection(value);
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(stringSelection, null);
|
||||
}
|
||||
}
|
||||
|
||||
// ############################
|
||||
// ### Public inner classes ###
|
||||
// ############################
|
||||
|
||||
public static class ReloadEvent {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddMineTweakerCommandAction implements IUndoableAction {
|
||||
private final MineTweakerCommand command;
|
||||
|
||||
public AddMineTweakerCommandAction(MineTweakerCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!minetweakerCommands.containsKey(command.name)) {
|
||||
minetweakerCommands.put(command.name, command);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
if (!minetweakerCommands.containsKey(command.name)) {
|
||||
return "Adding minetweaker command " + command.name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "tried to remove command: " + command.name + " failed. THIS IS NOT AN ERROR!";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Private inner classes ###
|
||||
// #############################
|
||||
|
||||
private static class MineTweakerCommand {
|
||||
private final String name;
|
||||
private final String[] description;
|
||||
private final ICommandFunction function;
|
||||
|
||||
public MineTweakerCommand(String name, String[] description, ICommandFunction function) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.function = function;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ItemComparator implements Comparator<IItemDefinition> {
|
||||
@Override
|
||||
public int compare(IItemDefinition o1, IItemDefinition o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class LiquidComparator implements Comparator<ILiquidDefinition> {
|
||||
@Override
|
||||
public int compare(ILiquidDefinition o1, ILiquidDefinition o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockComparator implements Comparator<IBlockDefinition> {
|
||||
@Override
|
||||
public int compare(IBlockDefinition o1, IBlockDefinition o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class EntityComparator implements Comparator<IEntityDefinition> {
|
||||
@Override
|
||||
public int compare(IEntityDefinition o1, IEntityDefinition o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ListenPlayerLoggedIn implements IEventHandler<PlayerLoggedInEvent> {
|
||||
@Override
|
||||
public void handle(PlayerLoggedInEvent event) {
|
||||
if (MineTweakerAPI.server != null && MineTweakerAPI.server.isOp(event.getPlayer())) {
|
||||
logger.addPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ListenPlayerLoggedOut implements IEventHandler<PlayerLoggedOutEvent> {
|
||||
@Override
|
||||
public void handle(PlayerLoggedOutEvent event) {
|
||||
logger.removePlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ListenBlockInfo implements IEventHandler<PlayerInteractEvent> {
|
||||
@Override
|
||||
public void handle(PlayerInteractEvent event) {
|
||||
if (blockInfoPlayers.contains(event.getPlayer())) {
|
||||
IBlock block = event.getBlock();
|
||||
event.getPlayer().sendChat("Block ID: " + block.getDefinition().getId());
|
||||
event.getPlayer().sendChat("Meta value: " + block.getMeta());
|
||||
IData data = block.getTileData();
|
||||
if (data != null) {
|
||||
event.getPlayer().sendChat("Tile entity data: " + data.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker;
|
||||
|
||||
/**
|
||||
* Base implementation for a non-undoable action.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public abstract class OneWayAction implements IUndoableAction {
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "impossibru!";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package minetweaker.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks a bracket handler. Bracket handlers are automatically registered. The
|
||||
* marked class should have an empty constructor.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package minetweaker.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that a certain class is only available when a specific mod is
|
||||
* available. Multiple mods can be specified.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
public @interface ModOnly {
|
||||
public String[] value();
|
||||
|
||||
public String version() default "";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD })
|
||||
public @interface OnRegister {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class BlockPatternOr implements IBlockPattern {
|
||||
|
||||
private final IBlockPattern[] elements;
|
||||
|
||||
public BlockPatternOr(IBlockPattern[] elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public BlockPatternOr(IBlockPattern a, IBlockPattern b) {
|
||||
this.elements = new IBlockPattern[]{a, b};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
List<IBlock> blocks = new ArrayList<>();
|
||||
for(IBlockPattern pattern : elements) {
|
||||
blocks.addAll(pattern.getBlocks());
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(pattern.matches(block))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(" | ");
|
||||
}
|
||||
|
||||
result.append(pattern.getDisplayName());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(ArrayUtil.append(elements, pattern));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Block interface. Used to interact with blocks in the world.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlock")
|
||||
public interface IBlock extends IBlockPattern {
|
||||
|
||||
/**
|
||||
* Gets the block definition.
|
||||
*
|
||||
* @return block definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IBlockDefinition getDefinition();
|
||||
|
||||
@ZenGetter("meta")
|
||||
int getMeta();
|
||||
|
||||
@ZenGetter("data")
|
||||
IData getTileData();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Blocks definitions provide additional information about blocks.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockDefinition")
|
||||
public interface IBlockDefinition {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockPattern")
|
||||
public interface IBlockPattern {
|
||||
|
||||
@ZenMethod("blocks")
|
||||
List<IBlock> getBlocks();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean matches(IBlock block);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
IBlockPattern or(IBlockPattern pattern);
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package minetweaker.api.chat;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents a chat message. Strings can be converted into chat messages, and
|
||||
* chat messages can be colored and concatenated.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.chat.IChatMessage")
|
||||
public interface IChatMessage {
|
||||
|
||||
/**
|
||||
* Concatenates two chat messages.
|
||||
*
|
||||
* @param other other chat message
|
||||
*
|
||||
* @return concatenated chat message
|
||||
*/
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IChatMessage add(IChatMessage other);
|
||||
|
||||
/**
|
||||
* Retrieves the internal object backing this object. Must be generated by
|
||||
* the implementing platform.
|
||||
*
|
||||
* @return internal object
|
||||
*/
|
||||
Object getInternal();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package minetweaker.api.client;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Interface for client interaction. Only available on clients.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.api.IClient")
|
||||
public interface IClient {
|
||||
|
||||
/**
|
||||
* Gets the current player.
|
||||
*
|
||||
* @return current player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("language")
|
||||
String getLanguage();
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DummyJEIRecipeRegistry implements IJEIRecipeRegistry {
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object, String category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object output, String category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFurnace(List<Object> inputs, Object output) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFurnace(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFuel(Collection<Object> input, int burnTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFuel(Object object) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadItemList() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeItem(Object stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(Object stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateTooltips(IIngredient ingredient) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface IJEIRecipeRegistry {
|
||||
|
||||
void addRecipe(Object object);
|
||||
|
||||
void addRecipe(Object object, String category);
|
||||
|
||||
void removeRecipe(Object output);
|
||||
|
||||
void removeRecipe(Object output, String category);
|
||||
|
||||
|
||||
void addFurnace(List<Object> inputs, Object output);
|
||||
|
||||
void removeFurnace(Object output);
|
||||
|
||||
void addFuel(Collection<Object> input, int burnTime);
|
||||
|
||||
void removeFuel(Object object);
|
||||
|
||||
void invalidateTooltips(IIngredient ingredient);
|
||||
|
||||
//To update the items in 1.10.2
|
||||
void reloadItemList();
|
||||
|
||||
//To update the items in 1.11.2 both below are used
|
||||
void removeItem(Object stack);
|
||||
|
||||
void addItem(Object stack);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package minetweaker.api.container;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Container interface.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.container.IContainer")
|
||||
public interface IContainer extends Iterable<IItemStack> {
|
||||
|
||||
/**
|
||||
* Gets the container size.
|
||||
*
|
||||
* @return container size
|
||||
*/
|
||||
@ZenGetter("containerSize")
|
||||
int getContainerSize();
|
||||
|
||||
/**
|
||||
* Gets the item stack at the given position. Returns null if there is no
|
||||
* stack at that position.
|
||||
*
|
||||
* @param i stack position
|
||||
*
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Sets the item stack at the given position.
|
||||
*
|
||||
* @param i stack position
|
||||
* @param stack contents, or null to set an empty stack
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package minetweaker.api.damage;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IDamageSource {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a boolean value (true or false).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataBool implements IData {
|
||||
|
||||
private final boolean value;
|
||||
|
||||
public DataBool(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asBool() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asBool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot compare bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromBool(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot add bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataBool(value & other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataBool(value | other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataBool(value ^ other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a bool value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataBool(!value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a byte value (-128 .. 127)
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataByte implements IData {
|
||||
|
||||
private final byte value;
|
||||
|
||||
public DataByte(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a byte to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Byte.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asByte() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Byte.compare(value, data.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataByte((byte) (value + other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataByte((byte) (value - other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataByte((byte) (value * other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataByte((byte) (value / other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataByte((byte) (value % other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataByte((byte) (value & other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataByte((byte) (value | other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataByte((byte) (value ^ other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataByte((byte) (-value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataByte((byte) (~value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a byte array.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataByteArray implements IData {
|
||||
|
||||
private final byte[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataByteArray(byte[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
byte[] otherData = other.asByteArray();
|
||||
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataByteArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("[");
|
||||
boolean first = true;
|
||||
for(byte value : data) {
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
result.append(", ");
|
||||
|
||||
result.append(value);
|
||||
}
|
||||
result.append("] as byte[]");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for(byte value : data) {
|
||||
result.add(new DataByte(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataByte(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("byte[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set byte[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByteArray(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte[]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a double-precision value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataDouble implements IData {
|
||||
|
||||
private final double value;
|
||||
|
||||
public DataDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a double to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return (float) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Double.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asDouble() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
return Double.compare(value, other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataDouble(value + other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataDouble(value - other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataDouble(value * other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataDouble(value / other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataDouble(value % other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataDouble(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a single-precision floating point value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataFloat implements IData {
|
||||
|
||||
private final float value;
|
||||
|
||||
public DataFloat(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a float to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Float.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asFloat() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Float.compare(value, data.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataFloat(value + other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataFloat(value - other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataFloat(value * other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataFloat(value / other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataFloat(value % other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataFloat(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as float";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 32-bit integer value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataInt implements IData {
|
||||
|
||||
private final int value;
|
||||
|
||||
public DataInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast an int to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asInt() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Integer.compare(value, data.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataInt(value + other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataInt(value - other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataInt(value * other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataInt(value / other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataInt(value % other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataInt(value & other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataInt(value | other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataInt(value ^ other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataInt(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataInt(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an int array.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataIntArray implements IData {
|
||||
|
||||
private final int[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataIntArray(int[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
int[] otherData = other.asIntArray();
|
||||
int[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataIntArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('[');
|
||||
boolean first = true;
|
||||
for(int value : data) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(value);
|
||||
}
|
||||
result.append(']');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<>();
|
||||
for(int value : data) {
|
||||
result.add(new DataInt(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
byte[] result = new byte[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte) data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataInt(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("int[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set int[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asIntArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataIntArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromIntArray(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as int[]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a list.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataList implements IData {
|
||||
|
||||
private final List<IData> values;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataList(List<IData> values, boolean immutable) {
|
||||
this.values = values;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot convert a list to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot convert a list to a byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot convert a list to a short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot convert a list to an int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot convert a list to a long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot convert a list to a float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot convert a list to a double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
if(immutable) {
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append('[');
|
||||
boolean first = true;
|
||||
for(IData value : values) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
output.append(", ");
|
||||
}
|
||||
output.append(value.toString());
|
||||
}
|
||||
output.append(']');
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
byte[] result = new byte[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asByte();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
try {
|
||||
int[] result = new int[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asInt();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return values.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("this list is immutable");
|
||||
} else {
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
List<IData> dataValues = data.asList();
|
||||
if(dataValues != null && containsList(dataValues))
|
||||
return true;
|
||||
|
||||
for(IData value : values) {
|
||||
if(value.contains(data))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean containsList(List<IData> dataValues) {
|
||||
outer:
|
||||
for(IData dataValue : dataValues) {
|
||||
for(IData value : values) {
|
||||
if(value.contains(dataValue))
|
||||
continue outer;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
List<IData> otherValues = data.asList();
|
||||
if(otherValues.size() != values.size())
|
||||
return false;
|
||||
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if(!values.get(i).equals(otherValues.get(i)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare with a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
List<IData> copy = new ArrayList<>();
|
||||
for(IData value : values) {
|
||||
copy.add(value.immutable());
|
||||
}
|
||||
return new DataList(copy, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
|
||||
List<IData> result = new ArrayList<>();
|
||||
result.addAll(values);
|
||||
result.addAll(data.asList());
|
||||
return new DataList(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromList(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return update(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 64-bit long value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataLong implements IData {
|
||||
|
||||
private final long value;
|
||||
|
||||
public DataLong(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a long to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Long.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asLong() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Long.compare(value, data.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataLong(value + other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataLong(value - other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataLong(value * other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataLong(value / other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataLong(value % other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataLong(value & other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataLong(value | other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataLong(value ^ other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataLong(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataLong(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as long";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a map, mapping strings to data elements.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataMap implements IData {
|
||||
|
||||
public static final DataMap EMPTY = new DataMap(new HashMap<>(), true);
|
||||
|
||||
private final Map<String, IData> data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataMap(Map<String, IData> data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(String key : otherMap.keySet()) {
|
||||
result.remove(key);
|
||||
}
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo with maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate maps.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('{');
|
||||
boolean first = true;
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
if(isValidIdentifier(entry.getKey())) {
|
||||
result.append(entry.getKey());
|
||||
} else {
|
||||
result.append("\"").append(entry.getKey()).append("\"");
|
||||
}
|
||||
|
||||
result.append(": ");
|
||||
result.append(entry.getValue().toString());
|
||||
}
|
||||
result.append('}');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
if(immutable) {
|
||||
return Collections.unmodifiableMap(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
return data.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("this map is not modifiable");
|
||||
} else {
|
||||
this.data.put(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if(data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap == null)
|
||||
return false;
|
||||
|
||||
for(Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if(!this.data.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if(!this.data.get(dataEntry.getKey()).contains(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
if(this == data)
|
||||
return true;
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap.size() != this.data.size())
|
||||
return false;
|
||||
|
||||
for(Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
|
||||
if(!dataMap.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if(!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().immutable());
|
||||
}
|
||||
return new DataMap(result, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromMap(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
|
||||
private boolean isValidIdentifier(String str) {
|
||||
if(!Character.isJavaIdentifierStart(str.charAt(0)))
|
||||
return false;
|
||||
|
||||
for(int i = 1; i < str.length(); i++) {
|
||||
if(!Character.isJavaIdentifierPart(str.charAt(i)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 16-bit short value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataShort implements IData {
|
||||
|
||||
private final short value;
|
||||
|
||||
public DataShort(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a short to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Short.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asShort() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Short.compare(value, data.asShort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataShort((short) (value + other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataShort((short) (value - other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataShort((short) (value * other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataShort((short) (value / other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataShort((short) (value % other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataShort((short) (value & other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataShort((short) (value | other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataShort((short) (value ^ other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataShort((short) (-value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataShort((short) (~value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as short";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a string value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataString implements IData {
|
||||
|
||||
private final String value;
|
||||
|
||||
public DataString(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return Byte.parseByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return Short.parseShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataString(value.substring(i, i + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
if(name.equals("length")) {
|
||||
return new DataInt(value.length());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("no such member: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return value.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asString().equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value.equals(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return value.compareTo(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataString(value + other.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '\"' + value.replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Generic data interface. A data element may contain any kind of basic data
|
||||
* element (bool, byte, short, int, long, float, double, string, list, map, int
|
||||
* array or byte array). Used to store data with stacks, blocks, world, ...
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.data.IData")
|
||||
public interface IData {
|
||||
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IData add(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.SUB)
|
||||
IData sub(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
IData mul(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.DIV)
|
||||
IData div(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
IData mod(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.AND)
|
||||
IData and(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
IData or(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.XOR)
|
||||
IData xor(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.NEG)
|
||||
IData neg();
|
||||
|
||||
@ZenOperator(OperatorType.NOT)
|
||||
IData not();
|
||||
|
||||
@ZenCaster
|
||||
boolean asBool();
|
||||
|
||||
@ZenCaster
|
||||
byte asByte();
|
||||
|
||||
@ZenCaster
|
||||
short asShort();
|
||||
|
||||
@ZenCaster
|
||||
int asInt();
|
||||
|
||||
@ZenCaster
|
||||
long asLong();
|
||||
|
||||
@ZenCaster
|
||||
float asFloat();
|
||||
|
||||
@ZenCaster
|
||||
double asDouble();
|
||||
|
||||
@ZenCaster
|
||||
String asString();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a List. Returns null if this value
|
||||
* cannot be converted to a list.
|
||||
*
|
||||
* @return list data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
List<IData> asList();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a Map. Returns null if this value
|
||||
* cannot be converted to a map.
|
||||
*
|
||||
* @return map data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
Map<String, IData> asMap();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a byte array. Returns null if this
|
||||
* value cannot be converted to a byte array.
|
||||
*
|
||||
* @return byte array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
byte[] asByteArray();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to an int array. Returns null if this
|
||||
* value cannot be converted to an int array.
|
||||
*
|
||||
* @return int array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
int[] asIntArray();
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
IData getAt(int i);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXSET)
|
||||
void setAt(int i, IData value);
|
||||
|
||||
@ZenMemberGetter
|
||||
IData memberGet(String name);
|
||||
|
||||
@ZenMemberSetter
|
||||
void memberSet(String name, IData data);
|
||||
|
||||
@ZenGetter
|
||||
int length();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.COMPARE)
|
||||
int compareTo(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.EQUALS)
|
||||
boolean equals(IData data);
|
||||
|
||||
@ZenGetter
|
||||
IData immutable();
|
||||
|
||||
@ZenMethod
|
||||
IData update(IData data);
|
||||
|
||||
<T> T convert(IDataConverter<T> converter);
|
||||
|
||||
@Override
|
||||
String toString();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Data converter interface. Used to convert data elements to other types.
|
||||
*
|
||||
* @param <T> output type
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IDataConverter<T> {
|
||||
|
||||
T fromBool(boolean value);
|
||||
|
||||
T fromByte(byte value);
|
||||
|
||||
T fromShort(short value);
|
||||
|
||||
T fromInt(int value);
|
||||
|
||||
T fromLong(long value);
|
||||
|
||||
T fromFloat(float value);
|
||||
|
||||
T fromDouble(double value);
|
||||
|
||||
T fromString(String value);
|
||||
|
||||
T fromList(List<IData> values);
|
||||
|
||||
T fromMap(Map<String, IData> values);
|
||||
|
||||
T fromByteArray(byte[] value);
|
||||
|
||||
T fromIntArray(int[] value);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* This file is part of MineTweaker API, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2014 MineTweaker <http://minetweaker3.powerofbytes.com>
|
||||
*/
|
||||
package minetweaker.api.data;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class IllegalDataException extends RuntimeException {
|
||||
|
||||
public IllegalDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.util.Position3f;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Entity interface. Used to obtain information about entities, and modify their
|
||||
* data. Entities are any item that is freely movable in the world, such as
|
||||
* players, monsters, items on the ground, ...
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntity")
|
||||
public interface IEntity {
|
||||
|
||||
/**
|
||||
* Retrieves the dimension this entity is in.
|
||||
*
|
||||
* @return current dimension of this entity
|
||||
*/
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
|
||||
/**
|
||||
* Retrieves the x position of this entity.
|
||||
*
|
||||
* @return entity x position
|
||||
*/
|
||||
@ZenGetter("x")
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Retrieves the y position of this entity.
|
||||
*
|
||||
* @return entity y position
|
||||
*/
|
||||
@ZenGetter("y")
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Retrieves the z position of this entity.
|
||||
*
|
||||
* @return entity z position
|
||||
*/
|
||||
@ZenGetter("z")
|
||||
float getZ();
|
||||
|
||||
/**
|
||||
* Retrieves the position of this entity.
|
||||
*
|
||||
* @return entity position
|
||||
*/
|
||||
@ZenGetter("position")
|
||||
Position3f getPosition();
|
||||
|
||||
/**
|
||||
* Sets the position of this entity. Instantly moves (teleports) the entity
|
||||
* to that position.
|
||||
*
|
||||
* @param position entity position
|
||||
*/
|
||||
@ZenSetter("position")
|
||||
void setPosition(Position3f position);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
import stanhebben.zenscript.value.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntityDefinition")
|
||||
public interface IEntityDefinition {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenMethod
|
||||
void addDrop(IItemStack stack, @Optional int min, @Optional int max);
|
||||
|
||||
@ZenMethod
|
||||
void addPlayerOnlyDrop(IItemStack stack, @Optional int min, @Optional int max);
|
||||
|
||||
@ZenMethod
|
||||
void removeDrop(IItemStack stack);
|
||||
|
||||
Map<IItemStack, IntRange> getDropsToAdd();
|
||||
|
||||
Map<IItemStack, IntRange> getDropsToAddPlayerOnly();
|
||||
|
||||
List<IItemStack> getDropsToRemove();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* Represents an item entity. Item entities are entities representing an item
|
||||
* stack on the ground (or flying through the air).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IEntityItem extends IEntity {
|
||||
|
||||
/**
|
||||
* Gets the entity item.
|
||||
*
|
||||
* @return entity item
|
||||
*/
|
||||
@ZenGetter("item")
|
||||
IItemStack getItem();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents an xp orb.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntityXp")
|
||||
public interface IEntityXp extends IEntity {
|
||||
|
||||
/**
|
||||
* Gets the amount of xp in this orb.
|
||||
*
|
||||
* @return xp amount
|
||||
*/
|
||||
@ZenGetter("xp")
|
||||
float getXp();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
/**
|
||||
* Represents an event handle. Event handles are used to cancel event listeners.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IEventHandler")
|
||||
public interface IEventHandle extends Closeable {
|
||||
|
||||
/**
|
||||
* Closes the event listener (stops listening and unregisters the listener).
|
||||
*/
|
||||
@ZenMethod
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
|
||||
/**
|
||||
* 37 kinds of event handlers!
|
||||
* <p>
|
||||
* NOTE: not all of these are implemented yet, but will be later on.
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IEventManager {
|
||||
|
||||
// implemented
|
||||
IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev);
|
||||
|
||||
// implemented
|
||||
IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev);
|
||||
|
||||
IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev);
|
||||
|
||||
IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev);
|
||||
|
||||
IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev);
|
||||
|
||||
IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev);
|
||||
|
||||
IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev);
|
||||
|
||||
IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev);
|
||||
|
||||
IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev);
|
||||
|
||||
IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev);
|
||||
|
||||
IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev);
|
||||
|
||||
IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev);
|
||||
|
||||
IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev);
|
||||
|
||||
IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev);
|
||||
|
||||
IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev);
|
||||
|
||||
IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev);
|
||||
|
||||
IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev);
|
||||
|
||||
IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev);
|
||||
|
||||
/*
|
||||
* IEventHandle
|
||||
* onPlayerUseItemStop(IEventHandler<PlayerUseItemStopEvent> ev);
|
||||
*
|
||||
* IEventHandle
|
||||
* onPlayerUseItemFinish(IPlayerUserItemFinishEventHandler ev);
|
||||
*
|
||||
* IEventHandle onPlayerChat(IPlayerChatEventHandler ev);
|
||||
*
|
||||
* IEventHandle onTimerSingle(int millis, ITimerEventHandler ev);
|
||||
*
|
||||
* IEventHandle onTimerRepeat(int millis, ITimerEventHandler ev);
|
||||
*
|
||||
* IEventHandle onEntityJoinWorld(IEntityJoinWorldEventHandler ev);
|
||||
*
|
||||
* IEventHandle
|
||||
* onEntityStruckByLightning(IEntityStruckByLightningEventHandler ev);
|
||||
*
|
||||
* IEventHandle
|
||||
* onLivingEnderTeleport(ILivingEnderTeleportEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingAttackEvent(ILivingAttackEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingDeathEvent(ILivingDeathEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingJumpEvent(ILivingJumpEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingFallEvent(ILivingFallEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingHurtEvent(ILivingHurtEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingDeathDropsEvent(ILivingDeathDropsEventHandler
|
||||
* ev);
|
||||
*
|
||||
* IEventHandle onItemTossed(IItemTossedEventHandler ev);
|
||||
*
|
||||
* IEventHandle onItemExpired(IItemExpiredEventHandler ev);
|
||||
*
|
||||
* IEventHandle onMinecartCollision(IMinecartCollisionEventHandler
|
||||
* ev);
|
||||
*
|
||||
* IEventHandle onMinecartInteract(IMinecartInteractEventHandler ev);
|
||||
*
|
||||
* IEventHandle onCommand(ICommandEventHandler ev);
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTEventManager implements IEventManager {
|
||||
|
||||
private final EventList<PlayerCraftedEvent> elPlayerCrafted = new EventList<PlayerCraftedEvent>();
|
||||
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
private final EventList<PlayerSmeltedEvent> elPlayerSmelted = new EventList<PlayerSmeltedEvent>();
|
||||
private final EventList<PlayerChangedDimensionEvent> elPlayerChangedDimension = new EventList<PlayerChangedDimensionEvent>();
|
||||
private final EventList<PlayerLoggedInEvent> elPlayerLoggedIn = new EventList<PlayerLoggedInEvent>();
|
||||
private final EventList<PlayerLoggedOutEvent> elPlayerLoggedOut = new EventList<PlayerLoggedOutEvent>();
|
||||
|
||||
// ##########################
|
||||
// ### PlayerSmeltedEvent ###
|
||||
// ##########################
|
||||
private final EventList<PlayerRespawnEvent> elPlayerRespawn = new EventList<PlayerRespawnEvent>();
|
||||
private final EventList<PlayerAttackEntityEvent> elPlayerAttackEntity = new EventList<PlayerAttackEntityEvent>();
|
||||
private final EventList<PlayerBonemealEvent> elPlayerBonemeal = new EventList<PlayerBonemealEvent>();
|
||||
private final EventList<PlayerInteractEntityEvent> elPlayerInteractEntity = new EventList<PlayerInteractEntityEvent>();
|
||||
|
||||
// ###################################
|
||||
// ### PlayerChangedDimensionEvent ###
|
||||
// ###################################
|
||||
private final EventList<PlayerPickupEvent> elPlayerPickup = new EventList<PlayerPickupEvent>();
|
||||
private final EventList<PlayerPickupItemEvent> elPlayerPickupItem = new EventList<PlayerPickupItemEvent>();
|
||||
private final EventList<PlayerFillBucketEvent> elPlayerFillBucket = new EventList<PlayerFillBucketEvent>();
|
||||
private final EventList<PlayerDeathDropsEvent> elPlayerDeathDrops = new EventList<PlayerDeathDropsEvent>();
|
||||
|
||||
// ###########################
|
||||
// ### PlayerLoggedInEvent ###
|
||||
// ###########################
|
||||
private final EventList<PlayerInteractEvent> elPlayerInteract = new EventList<PlayerInteractEvent>();
|
||||
private final EventList<PlayerOpenContainerEvent> elPlayerOpenContainer = new EventList<PlayerOpenContainerEvent>();
|
||||
private final EventList<PlayerPickupXpEvent> elPlayerPickupXp = new EventList<PlayerPickupXpEvent>();
|
||||
private final EventList<PlayerSleepInBedEvent> elPlayerSleepInBed = new EventList<PlayerSleepInBedEvent>();
|
||||
|
||||
// ############################
|
||||
// ### PlayerLoggedOutEvent ###
|
||||
// ############################
|
||||
private final EventList<PlayerUseHoeEvent> elPlayerUseHoe = new EventList<PlayerUseHoeEvent>();
|
||||
private final EventList<PlayerUseItemStartEvent> elPlayerUseItemStart = new EventList<PlayerUseItemStartEvent>();
|
||||
private final EventList<PlayerUseItemTickEvent> elPlayerUseItemTick = new EventList<PlayerUseItemTickEvent>();
|
||||
|
||||
public void clear() {
|
||||
elPlayerCrafted.clear();
|
||||
elPlayerSmelted.clear();
|
||||
elPlayerChangedDimension.clear();
|
||||
elPlayerLoggedIn.clear();
|
||||
elPlayerLoggedOut.clear();
|
||||
elPlayerRespawn.clear();
|
||||
elPlayerAttackEntity.clear();
|
||||
elPlayerBonemeal.clear();
|
||||
elPlayerInteractEntity.clear();
|
||||
elPlayerPickup.clear();
|
||||
elPlayerPickupItem.clear();
|
||||
elPlayerFillBucket.clear();
|
||||
elPlayerDeathDrops.clear();
|
||||
elPlayerInteract.clear();
|
||||
elPlayerOpenContainer.clear();
|
||||
elPlayerPickupXp.clear();
|
||||
elPlayerSleepInBed.clear();
|
||||
elPlayerUseHoe.clear();
|
||||
elPlayerUseItemStart.clear();
|
||||
elPlayerUseItemTick.clear();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerRespawnEvent ###
|
||||
// ##########################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev) {
|
||||
return elPlayerCrafted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerCrafted() {
|
||||
return elPlayerCrafted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerCrafted(PlayerCraftedEvent event) {
|
||||
elPlayerCrafted.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev) {
|
||||
return elPlayerSmelted.add(ev);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerAttackEntityEvent ###
|
||||
// ###############################
|
||||
|
||||
public boolean hasPlayerSmelted() {
|
||||
return elPlayerSmelted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSmelted(PlayerSmeltedEvent event) {
|
||||
elPlayerSmelted.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev) {
|
||||
return elPlayerChangedDimension.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerChangedDimension() {
|
||||
return elPlayerChangedDimension.hasHandlers();
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerBonemealEvent ###
|
||||
// ###########################
|
||||
|
||||
public void publishPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
elPlayerChangedDimension.publish(event);
|
||||
}
|
||||
|
||||
public IEventHandle onPlayerLoggedIn(IEventHandler<PlayerLoggedInEvent> ev) {
|
||||
return elPlayerLoggedIn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedIn() {
|
||||
return elPlayerLoggedIn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedIn(PlayerLoggedInEvent event) {
|
||||
elPlayerLoggedIn.publish(event);
|
||||
}
|
||||
|
||||
// #################################
|
||||
// ### PlayerInteractEntityEvent ###
|
||||
// #################################
|
||||
|
||||
public IEventHandle onPlayerLoggedOut(IEventHandler<PlayerLoggedOutEvent> ev) {
|
||||
return elPlayerLoggedOut.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedOut() {
|
||||
return elPlayerLoggedOut.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedOut(PlayerLoggedOutEvent event) {
|
||||
elPlayerLoggedOut.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev) {
|
||||
return elPlayerRespawn.add(ev);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerPickupEvent ###
|
||||
// #########################
|
||||
|
||||
public boolean hasPlayerRespawn() {
|
||||
return elPlayerRespawn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerRespawn(PlayerRespawnEvent event) {
|
||||
elPlayerRespawn.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev) {
|
||||
return elPlayerAttackEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerAttackEntity() {
|
||||
return elPlayerAttackEntity.hasHandlers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerPickupItemEvent ###
|
||||
// #############################
|
||||
|
||||
public void publishPlayerAttackEntity(PlayerAttackEntityEvent event) {
|
||||
elPlayerAttackEntity.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev) {
|
||||
return elPlayerBonemeal.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerBonemeal() {
|
||||
return elPlayerBonemeal.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerBonemeal(PlayerBonemealEvent event) {
|
||||
elPlayerBonemeal.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerFillBucketEvent ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev) {
|
||||
return elPlayerInteractEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteractEntity() {
|
||||
return elPlayerInteractEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
elPlayerInteractEntity.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev) {
|
||||
return elPlayerPickup.add(ev);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerDeathDropsEvent ###
|
||||
// #############################
|
||||
|
||||
public boolean hasPlayerPickup() {
|
||||
return elPlayerPickup.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupEvent event) {
|
||||
elPlayerPickup.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev) {
|
||||
return elPlayerPickupItem.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupItem() {
|
||||
return elPlayerPickupItem.hasHandlers();
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerInteractEvent ###
|
||||
// ###########################
|
||||
|
||||
public void publishPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
elPlayerPickupItem.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev) {
|
||||
return elPlayerFillBucket.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerFillBucket() {
|
||||
return elPlayerFillBucket.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerFillBucket(PlayerFillBucketEvent event) {
|
||||
elPlayerFillBucket.publish(event);
|
||||
}
|
||||
|
||||
// ################################
|
||||
// ### PlayerOpenContainerEvent ###
|
||||
// ################################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev) {
|
||||
return elPlayerDeathDrops.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerDeathDrops() {
|
||||
return elPlayerDeathDrops.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerDeathDrops(PlayerDeathDropsEvent event) {
|
||||
elPlayerDeathDrops.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev) {
|
||||
return elPlayerInteract.add(ev);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerPickupXpEvent ###
|
||||
// ###########################
|
||||
|
||||
public boolean hasPlayerInteract() {
|
||||
return elPlayerInteract.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteract(PlayerInteractEvent event) {
|
||||
elPlayerInteract.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev) {
|
||||
return elPlayerOpenContainer.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerOpenContainer() {
|
||||
return elPlayerOpenContainer.hasHandlers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerSleepInBedEvent ###
|
||||
// #############################
|
||||
|
||||
public void publishPlayerOpenContainer(PlayerOpenContainerEvent event) {
|
||||
elPlayerOpenContainer.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev) {
|
||||
return elPlayerPickupXp.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupXp() {
|
||||
return elPlayerPickupXp.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupXpEvent event) {
|
||||
elPlayerPickupXp.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerUseHoeEvent ###
|
||||
// #########################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev) {
|
||||
return elPlayerSleepInBed.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSleepInBed() {
|
||||
return elPlayerSleepInBed.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSleepInBed(PlayerSleepInBedEvent event) {
|
||||
elPlayerSleepInBed.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev) {
|
||||
return elPlayerUseHoe.add(ev);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerUseItemStartEvent ###
|
||||
// ###############################
|
||||
|
||||
public boolean hasPlayerUseHoe() {
|
||||
return elPlayerUseHoe.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseHoe(PlayerUseHoeEvent event) {
|
||||
elPlayerUseHoe.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev) {
|
||||
return elPlayerUseItemStart.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemStart() {
|
||||
return elPlayerUseItemStart.hasHandlers();
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### PlayerUseItemTickEvent ###
|
||||
// ##############################
|
||||
|
||||
public void publishPlayerUseItemStart(PlayerUseItemStartEvent event) {
|
||||
elPlayerUseItemStart.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev) {
|
||||
return elPlayerUseItemTick.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemTick() {
|
||||
return elPlayerUseItemTick.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemTick(PlayerUseItemTickEvent event) {
|
||||
elPlayerUseItemTick.publish(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerAttackEntityEvent")
|
||||
public class PlayerAttackEntityEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerAttackEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerBonemealEvent")
|
||||
public class PlayerBonemealEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerBonemealEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerChangedDimensionEvent")
|
||||
public class PlayerChangedDimensionEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IDimension from;
|
||||
private final IDimension to;
|
||||
|
||||
public PlayerChangedDimensionEvent(IPlayer player, IDimension from, IDimension to) {
|
||||
this.player = player;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("from")
|
||||
public IDimension getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
@ZenGetter("to")
|
||||
public IDimension getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingInventory;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerCraftingEvent")
|
||||
public class PlayerCraftedEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
private final ICraftingInventory inventory;
|
||||
|
||||
public PlayerCraftedEvent(IPlayer player, IItemStack output, ICraftingInventory inventory) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.damage.IDamageSource;
|
||||
import minetweaker.api.entity.IEntityItem;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerDeathDropsEvent")
|
||||
public class PlayerDeathDropsEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final List<IEntityItem> items;
|
||||
private final IDamageSource damageSource;
|
||||
|
||||
public PlayerDeathDropsEvent(IPlayer player, List<IEntityItem> items, IDamageSource damageSource) {
|
||||
this.player = player;
|
||||
this.items = items;
|
||||
this.damageSource = damageSource;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("items")
|
||||
public List<IEntityItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@ZenGetter("damageSource")
|
||||
public IDamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerFillBucketEvent")
|
||||
public class PlayerFillBucketEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private IItemStack result;
|
||||
|
||||
public PlayerFillBucketEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
result = null;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("result")
|
||||
public IItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resulting item. Automatically processes the event, too.
|
||||
*
|
||||
* @param result resulting item
|
||||
*/
|
||||
@ZenSetter("result")
|
||||
public void setResult(IItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerInteractEntityEvent")
|
||||
public class PlayerInteractEntityEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerInteractEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerInteractEvent")
|
||||
public class PlayerInteractEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
private boolean canceled;
|
||||
private boolean useBlock;
|
||||
private boolean useItem;
|
||||
|
||||
public PlayerInteractEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
useBlock = false;
|
||||
useItem = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void useBlock() {
|
||||
useBlock = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void useItem() {
|
||||
useItem = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("usingBlock")
|
||||
public boolean isUsingBlock() {
|
||||
return useBlock;
|
||||
}
|
||||
|
||||
@ZenGetter("usingItem")
|
||||
public boolean isUsingItem() {
|
||||
return useItem;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerLoggedInEvent")
|
||||
public class PlayerLoggedInEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedInEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerLoggedOutEvent")
|
||||
public class PlayerLoggedOutEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedOutEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.container.IContainer;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerOpenContainerEvent")
|
||||
public class PlayerOpenContainerEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IContainer container;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerOpenContainerEvent(IPlayer player, IContainer container) {
|
||||
this.player = player;
|
||||
this.container = container;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("container")
|
||||
public IContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupEvent")
|
||||
public class PlayerPickupEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerPickupEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the event (picks up the entity).
|
||||
*/
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupItemEvent")
|
||||
public class PlayerPickupItemEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
|
||||
public PlayerPickupItemEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntityXp;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupXpEvent")
|
||||
public class PlayerPickupXpEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntityXp xp;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerPickupXpEvent(IPlayer player, IEntityXp xp) {
|
||||
this.player = player;
|
||||
this.xp = xp;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntityXp getEntity() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
@ZenGetter("xp")
|
||||
public float getXp() {
|
||||
return xp.getXp();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerRespawnEvent")
|
||||
public class PlayerRespawnEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerRespawnEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerSleepInBedEvent")
|
||||
public class PlayerSleepInBedEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public PlayerSleepInBedEvent(IPlayer player, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class PlayerSmeltedEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
|
||||
public PlayerSmeltedEvent(IPlayer player, IItemStack output) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseHoeEvent")
|
||||
public class PlayerUseHoeEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerUseHoeEvent(IPlayer player, IItemStack item, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemStartEvent")
|
||||
public class PlayerUseItemStartEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemStartEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemTickEvent")
|
||||
public class PlayerUseItemTickEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final int duration;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemTickEvent(IPlayer player, IItemStack item, int duration) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.duration = duration;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("duration")
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package minetweaker.api.formatting;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.formatting.IFormattedText")
|
||||
public interface IFormattedText {
|
||||
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IFormattedText add(IFormattedText other);
|
||||
|
||||
@ZenOperator(OperatorType.CAT)
|
||||
IFormattedText cat(IFormattedText other);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package minetweaker.api.formatting;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IFormatter {
|
||||
|
||||
IFormattedText string(String text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText black(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkBlue(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkGreen(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkAqua(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkRed(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkPurple(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText gold(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText gray(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkGray(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText blue(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText green(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText aqua(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText red(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText lightPurple(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText yellow(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText white(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText obfuscated(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText bold(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText strikethrough(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText underline(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText italic(IFormattedText text);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package minetweaker.api.game;
|
||||
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.entity.IEntityDefinition;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Game interface. Used to obtain general game information.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.game.IGame")
|
||||
public interface IGame {
|
||||
|
||||
/**
|
||||
* Retrieves the item definitions in this game.
|
||||
*
|
||||
* @return game items
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemDefinition> getItems();
|
||||
|
||||
/**
|
||||
* Retrieves the block definitions in this game.
|
||||
*
|
||||
* @return block definitions
|
||||
*/
|
||||
@ZenGetter("blocks")
|
||||
List<IBlockDefinition> getBlocks();
|
||||
|
||||
/**
|
||||
* Retrieves the liquids in this game.
|
||||
*
|
||||
* @return game liquids
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidDefinition> getLiquids();
|
||||
|
||||
/**
|
||||
* Retrieves the biomes in this game.
|
||||
*
|
||||
* @return game biomes
|
||||
*/
|
||||
@ZenGetter("biomes")
|
||||
List<IBiome> getBiomes();
|
||||
|
||||
/**
|
||||
* Retrieves the entities in this game.
|
||||
*
|
||||
* @return game entities
|
||||
*/
|
||||
@ZenGetter("entities")
|
||||
List<IEntityDefinition> getEntities();
|
||||
|
||||
@ZenMethod()
|
||||
IEntityDefinition getEntity(String entityName);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String key, String value);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param lang language
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String lang, String key, String value);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
*
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param lang language
|
||||
*
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key, String lang);
|
||||
|
||||
/**
|
||||
* Lock the game and disable reload. Recommended for distributed versions.
|
||||
* <p>
|
||||
* Once locked, reload cannot be unlocked - a game restart is required to
|
||||
* alter the scripts.
|
||||
*/
|
||||
@ZenMethod
|
||||
void lock();
|
||||
|
||||
/**
|
||||
* Returns the lock state. True if locked.
|
||||
*
|
||||
* @return lock state
|
||||
*/
|
||||
@ZenGetter("locked")
|
||||
boolean isLocked();
|
||||
|
||||
/**
|
||||
* Signals a modified script while in locked mode.
|
||||
*/
|
||||
void signalLockError();
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a recipe ingredient. An ingredient can be an item, an ore
|
||||
* dictionary entry, an item stack, an ore dictionary entry multiplied with an
|
||||
* amount, or other kinds of ingredients as offered by the API.
|
||||
* <p>
|
||||
* There is no guarantee that every mod will respect the conditions or
|
||||
* transformations, or that every mod will support every kind of ingredient.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IIngredient")
|
||||
public interface IIngredient {
|
||||
|
||||
/**
|
||||
* Gets the mark of the ingredient. Ingredients can be marked so they can be
|
||||
* used in crafting functions.
|
||||
*
|
||||
* @return ingredient mark
|
||||
*/
|
||||
@ZenGetter("mark")
|
||||
String getMark();
|
||||
|
||||
/**
|
||||
* Gets the amount.
|
||||
* <p>
|
||||
* Should return -1 if no amount is available and 1 for a single item.
|
||||
* Stacks return the stack size.
|
||||
*
|
||||
* @return stack size
|
||||
*/
|
||||
@ZenGetter("amount")
|
||||
int getAmount();
|
||||
|
||||
/**
|
||||
* Gets all possible items for this ingredient.
|
||||
* <p>
|
||||
* If there is no item list (for example, it is the <*> wildcard item)
|
||||
* null should be returned.
|
||||
*
|
||||
* @return the items for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemStack> getItems();
|
||||
|
||||
/**
|
||||
* Gets all possible liquids for this ingredient.
|
||||
* <p>
|
||||
* If there is no liquid list (for example, it is the <*&ft; wildcard
|
||||
* item) null should be returned.
|
||||
*
|
||||
* @return the liquids for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidStack> getLiquids();
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given stack size.
|
||||
*
|
||||
* @param amount new stack size
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
IIngredient amount(int amount);
|
||||
|
||||
/**
|
||||
* Combines multiple ingredients into a single one. Note that ore dictionary
|
||||
* entries are preferred to or statements.
|
||||
*
|
||||
* @param ingredient ingredient to combine with
|
||||
*
|
||||
* @return or-ed ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.OR)
|
||||
@ZenMethod
|
||||
IIngredient or(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
* @param transformer transformer to add
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient transform(IItemTransformer transformer);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given condition added to it.
|
||||
*
|
||||
* @param condition condition to add
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient only(IItemCondition condition);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient marked with the given name.
|
||||
*
|
||||
* @param mark mark to apply
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient marked(String mark);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
*
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matches(IItemStack item);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
*
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matchesExact(IItemStack item);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given liquid.
|
||||
*
|
||||
* @param liquid liquid to check
|
||||
*
|
||||
* @return true if the liquid matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matches(ILiquidStack liquid);
|
||||
|
||||
/**
|
||||
* Check if this ingredient contains all possible values for the given
|
||||
* ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to check
|
||||
*
|
||||
* @return true if the ingredient contains the given one
|
||||
*/
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Applies transformations after crafting, if any, to the given item.
|
||||
*
|
||||
* @param item item to transform
|
||||
* @param byPlayer player performing the crafting operation
|
||||
*
|
||||
* @return transformed item
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack applyTransform(IItemStack item, IPlayer byPlayer);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient has (or could have) any transformatiosns.
|
||||
*
|
||||
* @return true if there are (or could be) any transformations false
|
||||
* otherwise.
|
||||
*/
|
||||
@ZenGetter("hasTransformations")
|
||||
boolean hasTransformers();
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
* <p>
|
||||
* The value is implementation-dependent and should only be handled by the
|
||||
* internal code. Don't use this value - instead, use the version-specific
|
||||
* helper methods.
|
||||
*
|
||||
* @return internal item
|
||||
*/
|
||||
Object getInternal();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* Item conditions apply additional conditions on item stacks.
|
||||
* <p>
|
||||
* They may, for instance, require specific damage ranges or NBT tags. Custom
|
||||
* implementations of this functional interface may contain any kind of
|
||||
* condition.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemCondition")
|
||||
public interface IItemCondition {
|
||||
|
||||
/**
|
||||
* Returns true if the given stack matches the required conditions.
|
||||
*
|
||||
* @param stack item stack to check
|
||||
*
|
||||
* @return true if the condition applies to this stack
|
||||
*/
|
||||
boolean matches(IItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains an item definition. Item definitions provide general information
|
||||
* about an item, such as its name and ID.
|
||||
* <p>
|
||||
* Item definitions themselves have no localized name, as it could be different
|
||||
* for each subitem or even depend on NBT tags.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemDefinition")
|
||||
public interface IItemDefinition {
|
||||
|
||||
/**
|
||||
* Gets the item ID.
|
||||
*
|
||||
* @return item ID
|
||||
*/
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Makes an item stack from this definition.
|
||||
*
|
||||
* @param meta meta value
|
||||
*
|
||||
* @return item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack makeStack(@Optional int meta);
|
||||
|
||||
/**
|
||||
* Returns all ore entries containing this item. Also contains ore entries
|
||||
* that refer to a specific sub-item.
|
||||
*
|
||||
* @return all the ore entries containing this item.
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains an item stack. An item stack consists of an item definition, a meta
|
||||
* or damage value and NBT data.
|
||||
* <p>
|
||||
* Item stacks can be retrieved using its name (or ID, in 1.6.4) with the
|
||||
* bracket syntax. When using the bracket syntax, by default, the item stack
|
||||
* will match any size when used as ingredient. Item stacks can be multiplied
|
||||
* with an integer to create a stack of different size.
|
||||
* <p>
|
||||
* Item stacks are immutable. You can, however, easily create modified stacks
|
||||
* using the helper methods. Adding conditions and transformations will turn the
|
||||
* item stack into an ingredients.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemStack")
|
||||
public interface IItemStack extends IIngredient {
|
||||
|
||||
/**
|
||||
* Gets the item definition.
|
||||
*
|
||||
* @return item definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IItemDefinition getDefinition();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return unlocalized item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the display name. By default, it is the localized item name, but
|
||||
* could also be the display name from NBT data, or another item-specific
|
||||
* name.
|
||||
*
|
||||
* @return item display name
|
||||
*/
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* Sets the display name. Only works if the name is translatable. Does not
|
||||
* override names set by NBT data or using item-specific logic.
|
||||
*
|
||||
* @param name item display name
|
||||
*/
|
||||
@ZenSetter("displayName")
|
||||
void setDisplayName(String name);
|
||||
|
||||
/**
|
||||
* Gets the max stack size for an item
|
||||
*
|
||||
* @return int max stack size
|
||||
*/
|
||||
@ZenGetter("maxStackSize")
|
||||
int getMaxStackSize();
|
||||
|
||||
/**
|
||||
* Sets the ItemStack max stack size.
|
||||
*
|
||||
* @param size the new max size
|
||||
*/
|
||||
@ZenSetter("maxStackSize")
|
||||
void setMaxStackSize(int size);
|
||||
|
||||
/**
|
||||
* Gets the block hardness
|
||||
*/
|
||||
@ZenGetter("hardness")
|
||||
float getBlockHardness();
|
||||
|
||||
/**
|
||||
* Sets the block hardness
|
||||
*
|
||||
* @param hardness the new hardness
|
||||
*/
|
||||
@ZenSetter("hardness")
|
||||
void setBlockHardness(float hardness);
|
||||
|
||||
/**
|
||||
* Gets the item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return item damage
|
||||
*/
|
||||
@ZenGetter("damage")
|
||||
int getDamage();
|
||||
|
||||
/**
|
||||
* Gets the maximum item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return maximum item damage
|
||||
*/
|
||||
@ZenGetter("maxDamage")
|
||||
int getMaxDamage();
|
||||
|
||||
/**
|
||||
* Sets the max Itemstack damage
|
||||
*
|
||||
* @param damage the new max damage
|
||||
*/
|
||||
@ZenSetter("maxDamage")
|
||||
void setMaxDamage(int damage);
|
||||
|
||||
/**
|
||||
* Gets the item tag. (NBT data) The resulting data is immutable and can
|
||||
* only be changed with updateTag. Returns empty data if there is no data.
|
||||
* Never returns null.
|
||||
*
|
||||
* @return item tag
|
||||
*/
|
||||
@ZenGetter("tag")
|
||||
IData getTag();
|
||||
|
||||
/**
|
||||
* Gets the liquid contained in this item, if any. If this item stack is not
|
||||
* an item container, it returns null. Only returns the amount of liquid in
|
||||
* a single item and doesn't into account stack size.
|
||||
*
|
||||
* @return liquid data
|
||||
*/
|
||||
@ZenGetter("liquid")
|
||||
ILiquidStack getLiquid();
|
||||
|
||||
/**
|
||||
* Creates a new item stack with a different stack size.
|
||||
*
|
||||
* @param amount new item stack size
|
||||
*
|
||||
* @return new item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack amount(int amount);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given percentage chance. Does the
|
||||
* same as item.weight(p * 0.01).
|
||||
*
|
||||
* @param p probability, with percent
|
||||
*
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
WeightedItemStack percent(float p);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given weight.
|
||||
*
|
||||
* @param p item weight
|
||||
*
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
WeightedItemStack weight(float p);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the same item and stack size, but accepting
|
||||
* any damage value. Only useful for items used as ingredients.
|
||||
*
|
||||
* @return item stack with wildcard damage
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient anyDamage();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified damage.
|
||||
*
|
||||
* @param damage damage value
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withDamage(int damage);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified stack size.
|
||||
*
|
||||
* @param amount stack size
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
IItemStack withAmount(int amount);
|
||||
|
||||
/**
|
||||
* Creates an item stack with wildcard stack size.
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
|
||||
@ZenMethod
|
||||
IItemStack anyAmount();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the given nbt tag. Ignores existing tags.
|
||||
*
|
||||
* @param tag item tag to be assigned
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withTag(IData tag);
|
||||
|
||||
/**
|
||||
* Create an item stack with an empty nbt tag. Removes previous tag if any.
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withEmptyTag();
|
||||
|
||||
/**
|
||||
* Creates an item stack without the given nbt tag.
|
||||
*
|
||||
* @param tag item tag to be removed
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack removeTag(String tag);
|
||||
|
||||
/**
|
||||
* Creates an item stack with updated nbt tag. Updates existing tags.
|
||||
*
|
||||
* @param tagUpdate item tag updates
|
||||
*
|
||||
* @return updated item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack updateTag(IData tagUpdate);
|
||||
|
||||
/**
|
||||
* Converts this item stack into a block.
|
||||
*
|
||||
* @return block, or null if this item is not a block
|
||||
*/
|
||||
@ZenCaster
|
||||
IBlock asBlock();
|
||||
|
||||
/**
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore
|
||||
* entries.
|
||||
*
|
||||
* @return ore entries containing this item stack
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* An item transformer modifies an item stack after crafting. Used to apply
|
||||
* damage, grab multiple items, change NBT tags, replace the item with something
|
||||
* else - or whatever else you'd want to happen to the input stack.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemTransformer")
|
||||
public interface IItemTransformer {
|
||||
|
||||
/**
|
||||
* Transforms the specified item. May modify this item (and return it) or
|
||||
* return an entirely new one.
|
||||
*
|
||||
* @param item input item
|
||||
* @param byPlayer player that performs the crafting
|
||||
*
|
||||
* @return output item
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack transform(IItemStack item, IPlayer byPlayer);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the wildcard ingredient (<*>).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientAny implements IIngredient {
|
||||
|
||||
public static final IngredientAny INSTANCE = new IngredientAny();
|
||||
|
||||
public static Object INTERNAL_ANY = null; // platforms supporting an "any"
|
||||
// item should fill it here
|
||||
|
||||
private IngredientAny() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[]{transformer});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientAnyAdvanced(null, new IItemCondition[]{condition}, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return INTERNAL_ANY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<*>";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the wildcard ingredient, with conditions and/or transformers
|
||||
* applied to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
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 List<ILiquidStack> getLiquids() {
|
||||
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 IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
// TODO: conditions on liquids?
|
||||
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, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Conditions can be used to set requirements for matching items. They can be
|
||||
* used to require specific NBT tags or damage values, requiring changed items
|
||||
* or as complement to damage-consuming or stack-consuming recipes.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientCondition {
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged. A damage value of 1 is enough.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return damaged condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamaged(IIngredient ingredient) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() > 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at least a specified amount.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamageAtLeast(IIngredient ingredient, final int minDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at most a specified amount. An
|
||||
* undamaged item is accepted.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param maxDamage maximum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamageAtMost(IIngredient ingredient, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() <= maxDamage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item damage value to be between two values.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @param maxDamage maximum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamageBetween(IIngredient ingredient, final int minDamage, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to contain at least the given tags. It is OK for the
|
||||
* item to contain more data, as remaining data is ignored.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param data required data
|
||||
*
|
||||
* @return data condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyWithTag(IIngredient ingredient, final IData data) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getTag() != null && stack.getTag().contains(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the input stack to contain at least the given number of items.
|
||||
* Used in combination with stack consuming recipes.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount required stack size
|
||||
*
|
||||
* @return stack size condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyStack(IIngredient ingredient, final int amount) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getAmount() >= amount;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an item stack with modifiers applied to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientItem implements IIngredient {
|
||||
|
||||
private final IItemStack item;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
private final List<IItemStack> items;
|
||||
|
||||
public IngredientItem(IItemStack item, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.item = item;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
|
||||
items = Collections.singletonList(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientItem(item, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientItem(item, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(item, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!this.item.matches(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!this.item.matchesExact(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@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, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(Ingredient) " + item.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientOr implements IIngredient {
|
||||
|
||||
private final IIngredient[] elements;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOr(IIngredient[] elements) {
|
||||
this.elements = elements;
|
||||
mark = null;
|
||||
conditions = ArrayUtil.EMPTY_CONDITIONS;
|
||||
transformers = ArrayUtil.EMPTY_TRANSFORMERS;
|
||||
}
|
||||
|
||||
public IngredientOr(IIngredient a, IIngredient b) {
|
||||
this(new IIngredient[]{a, b});
|
||||
}
|
||||
|
||||
private IngredientOr(IIngredient[] elements, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.elements = elements;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return elements[0].getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
result.addAll(element.getItems());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
List<ILiquidStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
result.addAll(element.getLiquids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
IIngredient[] result = new IIngredient[elements.length];
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].amount(amount);
|
||||
}
|
||||
return new IngredientOr(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOr(elements, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOr(elements, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOr(elements, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(ArrayUtil.append(elements, ingredient));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matchesExact(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(liquid))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for(IItemStack item : items) {
|
||||
if(!matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an ingredient stack. Is an ingredient with a specific stack size
|
||||
* assigned to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientStack implements IIngredient {
|
||||
|
||||
private final IIngredient ingredient;
|
||||
private final int amount;
|
||||
|
||||
public IngredientStack(IIngredient ingredient, int amount) {
|
||||
this.ingredient = ingredient;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return ingredient.getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(ingredient, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientStack(ingredient.transform(transformer), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientStack(ingredient.only(condition), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientStack(ingredient.marked(mark), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matches(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matchesExact(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return this.ingredient.contains(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return ingredient.applyTransform(item, byPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return ingredient.hasTransformers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "(Ingredients) ";
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
for(IItemStack st : ingredient.getItems()) {
|
||||
names.add(st.getName());
|
||||
}
|
||||
s += String.join(",", names);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Transformations can be used to modify an ingredient after it is used in a
|
||||
* crafting recipe. It could reuse the item, damage it or consume multiple
|
||||
* items.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTransform {
|
||||
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient reuse(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> item.withAmount(item.getAmount() + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item for
|
||||
* 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item for a specific amount. Also makes the item reusable.
|
||||
* Upon reaching maximum damage, the item will be consumed. Take care to set
|
||||
* the proper condition such that an almost-broken item becomes invalid for
|
||||
* crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount()).withDamage(newDamage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
*
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(item.getAmount() > 1) {
|
||||
byPlayer.give(withItem);
|
||||
return item;
|
||||
} else {
|
||||
return withItem.withAmount(withItem.getAmount());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes multiple items to be consumed. Take care to set a condition for a
|
||||
* minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
*
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform((item, byPlayer) -> item.withAmount(Math.max(item.getAmount() - amount, 0) + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure there is no return value.
|
||||
*
|
||||
* @param ingredient
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient noReturn(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives an item back to the player. Also clears the inventory slot at that
|
||||
* position.
|
||||
*
|
||||
* @param ingredient
|
||||
* @param givenItem
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient giveBack(IIngredient ingredient, @Optional final IItemStack givenItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(givenItem == null) {
|
||||
byPlayer.give(item.withAmount(1));
|
||||
return item;
|
||||
} else {
|
||||
byPlayer.give(givenItem);
|
||||
return item;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientUnknown implements IIngredient {
|
||||
|
||||
public static final IngredientUnknown INSTANCE = new IngredientUnknown(1);
|
||||
|
||||
private final int size;
|
||||
|
||||
public IngredientUnknown(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientUnknown(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedItemStack {
|
||||
|
||||
private final IItemStack stack;
|
||||
private final float p;
|
||||
public WeightedItemStack(IItemStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static List<IItemStack> pickRandomDrops(Random random, WeightedItemStack[] items) {
|
||||
ArrayList<IItemStack> result = new ArrayList<>();
|
||||
|
||||
for(WeightedItemStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public IItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedItemStack other = (WeightedItemStack) obj;
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) && Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains a liquid definition. Liquid definitions provide additional
|
||||
* information about liquids.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.liquid.ILiquidDefinition")
|
||||
public interface ILiquidDefinition {
|
||||
|
||||
/**
|
||||
* Converts this liquid into a liquid stack.
|
||||
*
|
||||
* @param millibuckets item stack size
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
ILiquidStack asStack(int millibuckets);
|
||||
|
||||
/**
|
||||
* Gets the unlocalized name of this item.
|
||||
*
|
||||
* @return unlocalized name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
int getLuminosity();
|
||||
|
||||
@ZenSetter("luminosity")
|
||||
void setLuminosity(int value);
|
||||
|
||||
@ZenGetter("density")
|
||||
int getDensity();
|
||||
|
||||
@ZenSetter("density")
|
||||
void setDensity(int density);
|
||||
|
||||
@ZenGetter("temperature")
|
||||
int getTemperature();
|
||||
|
||||
@ZenSetter("temperature")
|
||||
void setTemperature(int temperature);
|
||||
|
||||
@ZenGetter("viscosity")
|
||||
int getViscosity();
|
||||
|
||||
@ZenSetter("viscosity")
|
||||
void setViscosity(int viscosity);
|
||||
|
||||
@ZenGetter("gaseous")
|
||||
boolean isGaseous();
|
||||
|
||||
@ZenSetter("gaseous")
|
||||
void setGaseous(boolean gaseous);
|
||||
|
||||
@ZenGetter("containers")
|
||||
List<IItemStack> getContainers();
|
||||
|
||||
@ZenMethod
|
||||
void addContainer(IItemStack filled, IItemStack empty, int amount);
|
||||
|
||||
@ZenMethod
|
||||
void removeContainer(IItemStack filled);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stanneke
|
||||
*/
|
||||
@ZenClass("minetweaker.liquid.ILiquidStack")
|
||||
public interface ILiquidStack extends IIngredient {
|
||||
|
||||
@ZenGetter("definition")
|
||||
ILiquidDefinition getDefinition();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
@ZenGetter("amount")
|
||||
int getAmount();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
int getLuminosity();
|
||||
|
||||
@ZenGetter("density")
|
||||
int getDensity();
|
||||
|
||||
@ZenGetter("temperature")
|
||||
int getTemperature();
|
||||
|
||||
@ZenGetter("viscosity")
|
||||
int getViscosity();
|
||||
|
||||
@ZenGetter("gaseous")
|
||||
boolean isGaseous();
|
||||
|
||||
@ZenGetter("tag")
|
||||
IData getTag();
|
||||
|
||||
@ZenMethod
|
||||
ILiquidStack withTag(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
ILiquidStack withAmount(int amount);
|
||||
|
||||
Object getInternal();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedLiquidStack {
|
||||
|
||||
private final ILiquidStack stack;
|
||||
private final float p;
|
||||
public WeightedLiquidStack(ILiquidStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static List<ILiquidStack> pickRandomDrops(Random random, WeightedLiquidStack[] items) {
|
||||
ArrayList<ILiquidStack> result = new ArrayList<>();
|
||||
|
||||
for(WeightedLiquidStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public ILiquidStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedLiquidStack other = (WeightedLiquidStack) obj;
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) && Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package minetweaker.api.logger;
|
||||
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class FileLogger implements ILogger {
|
||||
|
||||
private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
|
||||
private final Writer writer;
|
||||
private final PrintWriter printWriter;
|
||||
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
printWriter = new PrintWriter(writer);
|
||||
} catch(UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch(FileNotFoundException ex) {
|
||||
throw new RuntimeException("Could not open log file " + output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write(stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.write("INFO: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.write("WARNING: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
try {
|
||||
writer.write("ERROR: " + stripMessage(message) + "\n");
|
||||
if(exception != null) {
|
||||
exception.printStackTrace(printWriter);
|
||||
}
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the given string, with formatting codes stripped away.
|
||||
*/
|
||||
public String stripMessage(String message) {
|
||||
return message == null ? null : FORMATTING_CODE_PATTERN.matcher(message).replaceAll("");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package minetweaker.api.logger;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTLogger implements ILogger {
|
||||
|
||||
private final List<ILogger> loggers = new ArrayList<>();
|
||||
private final List<IPlayer> players = new ArrayList<>();
|
||||
private final List<String> unprocessed = new ArrayList<>();
|
||||
|
||||
public void addLogger(ILogger logger) {
|
||||
loggers.add(logger);
|
||||
}
|
||||
|
||||
public void removeLogger(ILogger logger) {
|
||||
loggers.remove(logger);
|
||||
}
|
||||
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
|
||||
if(!unprocessed.isEmpty()) {
|
||||
unprocessed.forEach(player::sendChat);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(IPlayer player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
unprocessed.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
|
||||
String message2 = "WARNING: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logError(message, exception);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,495 @@
|
||||
package minetweaker.api.minecraft;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IngredientUnknown;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import minetweaker.mc1710.block.MCBlockDefinition;
|
||||
import minetweaker.mc1710.block.MCSpecificBlock;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.oredict.MCOreDictEntry;
|
||||
import minetweaker.mc1710.player.MCPlayer;
|
||||
import minetweaker.mc1710.world.MCDimension;
|
||||
import minetweaker.mc1710.block.MCWorldBlock;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
import minetweaker.mc1710.world.MCBiome;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* MineTweaker - MineCraft API bridge.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerMC {
|
||||
private static final Map<Block, MCBlockDefinition> blockDefinitions = new HashMap<Block, MCBlockDefinition>();
|
||||
public static final IBiome[] biomes;
|
||||
|
||||
static {
|
||||
biomes = new IBiome[BiomeGenBase.getBiomeGenArray().length];
|
||||
for (int i = 0; i < BiomeGenBase.getBiomeGenArray().length; i++) {
|
||||
if (BiomeGenBase.getBiomeGenArray()[i] != null)
|
||||
biomes[i] = new MCBiome(BiomeGenBase.getBiomeGenArray()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private MineTweakerMC() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Minecraft item for this MineTweaker item.
|
||||
*
|
||||
* @param item minetweaker item stack
|
||||
* @return minecraft item stack
|
||||
*/
|
||||
public static ItemStack getItemStack(IItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.logError("Not a valid item stack: " + item);
|
||||
}
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Minecraft ingredient for this ingredient. This method is only
|
||||
* useful for ingredients that represent a single item stack.
|
||||
*
|
||||
* @param ingredient item ingredient
|
||||
* @return minecraft item stack
|
||||
*/
|
||||
public static ItemStack getItemStack(IIngredient ingredient) {
|
||||
if (ingredient == null)
|
||||
return null;
|
||||
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
if (items.size() != 1) {
|
||||
MineTweakerAPI.logError("Not an ingredient with a single item: " + ingredient);
|
||||
}
|
||||
return getItemStack(items.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MineTweaker item stack for this item.
|
||||
*
|
||||
* @param item minecraft item stack
|
||||
* @return minetweaker item stack
|
||||
*/
|
||||
public static IItemStack getIItemStack(ItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with wildcard size.
|
||||
*
|
||||
* @param item minecraft item stack
|
||||
* @return minetweaker stack
|
||||
*/
|
||||
public static IItemStack getIItemStackWildcardSize(ItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(item, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with wildcard size.
|
||||
*
|
||||
* @param item
|
||||
* @param meta
|
||||
* @return minetweaker stack
|
||||
*/
|
||||
public static IItemStack getIItemStackWildcardSize(Item item, int meta) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(new ItemStack(item, 1, meta), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with wildcard damage.
|
||||
*
|
||||
* @param item stack item
|
||||
* @param amount stack size
|
||||
* @return minetweaker item stack
|
||||
*/
|
||||
public static IItemStack getIItemStackWildcard(Item item, int amount) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public static ItemStack[] getExamples(IIngredient ingredient) {
|
||||
List<IItemStack> examples = ingredient.getItems();
|
||||
ItemStack[] result = new ItemStack[examples.size()];
|
||||
for (int i = 0; i < examples.size(); i++) {
|
||||
result[i] = MineTweakerMC.getItemStack(examples.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with given item, damage and amount.
|
||||
*
|
||||
* @param item stack item
|
||||
* @param damage stack damage
|
||||
* @param amount stack amount
|
||||
* @return minetweaker item stack
|
||||
*/
|
||||
public static IItemStack getItemStack(Item item, int amount, int damage) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(new ItemStack(item, amount, damage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of minetweaker item stacks into an array of minecraft
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minetweker item stacks
|
||||
* @return minecraft item stacks
|
||||
*/
|
||||
public static ItemStack[] getItemStacks(IItemStack... items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of minetweaker item stacks into an array of minecraft
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minetweaker items
|
||||
* @return minecraft items
|
||||
*/
|
||||
public static ItemStack[] getItemStacks(List<IItemStack> items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
ItemStack[] output = new ItemStack[items.size()];
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Object internal = items.get(i).getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
} else {
|
||||
MineTweakerAPI.logError("Invalid item stack: " + items.get(i));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of minecraft item stacks into an array of minetweaker
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minecraft item stacks
|
||||
* @return minetweaker item stacks
|
||||
*/
|
||||
public static IItemStack[] getIItemStacks(ItemStack... items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
IItemStack[] result = new IItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new MCItemStack(items[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of minecraft item stacks into an array of minetweaker
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minecraft item stacks
|
||||
* @return minetweaker item stacks
|
||||
*/
|
||||
public static IItemStack[] getIItemStacks(List<ItemStack> items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MCItemStack(items.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ore dictionary entry with the given name. If the entry didn't
|
||||
* exist yet, it will create it and return an empty entry.
|
||||
*
|
||||
* @param name ore entry name
|
||||
* @return ore dictionary entry
|
||||
*/
|
||||
public static IOreDictEntry getOreDict(String name) {
|
||||
return new MCOreDictEntry(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft player into a MineTweaker player.
|
||||
*
|
||||
* @param player minecraft player
|
||||
* @return minetweaker player
|
||||
*/
|
||||
public static IPlayer getIPlayer(EntityPlayer player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
|
||||
return new MCPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a MineTweaker player into a Minecraft player.
|
||||
*
|
||||
* @param player minetweaker player
|
||||
* @return minecraft player
|
||||
*/
|
||||
public static EntityPlayer getPlayer(IPlayer player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
|
||||
if (!(player instanceof MCPlayer)) {
|
||||
MineTweakerAPI.logError("Invalid player: " + player);
|
||||
}
|
||||
|
||||
return ((MCPlayer) player).getInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft NBT to an IData instance. The IData instance is
|
||||
* immutable (not modifyiable).
|
||||
*
|
||||
* @param nbt nbt data
|
||||
* @return IData value
|
||||
*/
|
||||
public static IData getIData(NBTBase nbt) {
|
||||
if (nbt == null)
|
||||
return null;
|
||||
|
||||
return NBTConverter.from(nbt, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft NBT to a modifyable IData instance.
|
||||
*
|
||||
* @param nbt nbt data
|
||||
* @return mutable IData value
|
||||
*/
|
||||
public static IData getIDataModifyable(NBTBase nbt) {
|
||||
if (nbt == null)
|
||||
return null;
|
||||
|
||||
return NBTConverter.from(nbt, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IData instance to an NBT value.
|
||||
*
|
||||
* @param data IData value
|
||||
* @return nbt data
|
||||
*/
|
||||
public static NBTBase getNBT(IData data) {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return NBTConverter.from(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IData instance to an NBT Tag compound.
|
||||
*
|
||||
* @param data IData value
|
||||
* @return nbt compound data
|
||||
*/
|
||||
public static NBTTagCompound getNBTCompound(IData data) {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return (NBTTagCompound) NBTConverter.from(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block at the given position.
|
||||
*
|
||||
* @param blocks block access
|
||||
* @param x block x position
|
||||
* @param y block y position
|
||||
* @param z block z position
|
||||
* @return block instance
|
||||
*/
|
||||
public static IBlock getBlock(IBlockAccess blocks, int x, int y, int z) {
|
||||
return new MCWorldBlock(blocks, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block definition for the given block.
|
||||
*
|
||||
* @param block block object
|
||||
* @return block definition
|
||||
*/
|
||||
public static IBlockDefinition getBlockDefinition(Block block) {
|
||||
if (!blockDefinitions.containsKey(block)) {
|
||||
blockDefinitions.put(block, new MCBlockDefinition(block));
|
||||
}
|
||||
return blockDefinitions.get(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the dimension instance for a given world.
|
||||
*
|
||||
* @param world world
|
||||
* @return dimension
|
||||
*/
|
||||
public static IDimension getDimension(World world) {
|
||||
if (world == null)
|
||||
return null;
|
||||
|
||||
return new MCDimension(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the given block.
|
||||
*
|
||||
* @param block MC block definition
|
||||
* @return MT block instance
|
||||
*/
|
||||
public static IBlock getBlockAnyMeta(Block block) {
|
||||
return new MCSpecificBlock(block, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the given block.
|
||||
*
|
||||
* @param block MC block definition
|
||||
* @param meta block meta value
|
||||
* @return MT block instance
|
||||
*/
|
||||
public static IBlock getBlock(Block block, int meta) {
|
||||
return new MCSpecificBlock(block, meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block from an item stack.
|
||||
*
|
||||
* @param itemStack
|
||||
* @return
|
||||
*/
|
||||
public static Block getBlock(IItemStack itemStack) {
|
||||
return ((MCBlockDefinition) itemStack.asBlock().getDefinition()).getInternalBlock();
|
||||
}
|
||||
|
||||
public static Block getBlock(IBlock block) {
|
||||
return ((MCBlockDefinition) block.getDefinition()).getInternalBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the internal fluid stack of the given stack.
|
||||
*
|
||||
* @param stack MT liquid stack
|
||||
* @return MCF fluid stack
|
||||
*/
|
||||
public static FluidStack getLiquidStack(ILiquidStack stack) {
|
||||
if (stack == null)
|
||||
return null;
|
||||
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of MT liquid stacks into an array of MCF fluid stacks
|
||||
*
|
||||
*/
|
||||
public static FluidStack[] getLiquidStacks(ILiquidStack[] stacks) {
|
||||
if (stacks == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack[] res = new FluidStack[stacks.length];
|
||||
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
ILiquidStack liquidStack = stacks[i];
|
||||
res[i] = getLiquidStack(liquidStack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
|
||||
public static IOreDictEntry getOreDictEntryFromArray(List array) {
|
||||
if (!oreDictArrays.containsKey(array)) {
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictionary.getOres(ore) == array) {
|
||||
oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
* @param ingredient minecraft ingredient
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient == null) {
|
||||
return null;
|
||||
} else if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else if (ingredient instanceof List) {
|
||||
IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient);
|
||||
|
||||
if (entry == null) {
|
||||
return IngredientUnknown.INSTANCE;
|
||||
}
|
||||
|
||||
return entry;
|
||||
} else if (ingredient instanceof FluidStack) {
|
||||
return new MCLiquidStack((FluidStack) ingredient);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package minetweaker.api.mods;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.mods.ILoadedMods")
|
||||
@IterableSimple("minetweaker.mods.IMod")
|
||||
public interface ILoadedMods extends Iterable<IMod> {
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(String name);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
IMod get(String name);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.mods;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IMod {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("version")
|
||||
String getVersion();
|
||||
|
||||
@ZenGetter("decription")
|
||||
String getDescription();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDict")
|
||||
public interface IOreDict {
|
||||
|
||||
@ZenMemberGetter
|
||||
IOreDictEntry get(String name);
|
||||
|
||||
@ZenGetter("entries")
|
||||
List<IOreDictEntry> getEntries();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDictEntry")
|
||||
public interface IOreDictEntry extends IIngredient {
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("empty")
|
||||
boolean isEmpty();
|
||||
|
||||
@ZenGetter("firstItem")
|
||||
IItemStack getFirstItem();
|
||||
|
||||
@ZenMethod
|
||||
void add(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void addItems(IItemStack[] items);
|
||||
|
||||
@ZenMethod
|
||||
void addAll(IOreDictEntry entry);
|
||||
|
||||
@ZenMethod
|
||||
void remove(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void removeItems(IItemStack[] items);
|
||||
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void mirror(IOreDictEntry other);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientOreDict implements IIngredient {
|
||||
|
||||
private final IOreDictEntry entry;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOreDict(IOreDictEntry entry, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.entry = entry;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return entry.getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOreDict(entry, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOreDict(entry, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(entry, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!entry.matches(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!entry.matchesExact(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return entry.contains(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return entry.getInternal();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package minetweaker.api.player;
|
||||
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.player.IPlayer")
|
||||
public interface IPlayer {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("data")
|
||||
IData getData();
|
||||
|
||||
@ZenGetter("xp")
|
||||
int getXP();
|
||||
|
||||
@ZenSetter("xp")
|
||||
void setXP(int xp);
|
||||
|
||||
@ZenMethod
|
||||
void removeXP(int xp);
|
||||
|
||||
@ZenMethod
|
||||
void update(IData data);
|
||||
|
||||
@ZenMethod
|
||||
void sendChat(IChatMessage message);
|
||||
|
||||
@ZenMethod
|
||||
void sendChat(String message);
|
||||
|
||||
@ZenGetter("hotbarSize")
|
||||
int getHotbarSize();
|
||||
|
||||
@ZenMethod
|
||||
IItemStack getHotbarStack(int i);
|
||||
|
||||
@ZenGetter("inventorySize")
|
||||
int getInventorySize();
|
||||
|
||||
@ZenMethod
|
||||
IItemStack getInventoryStack(int i);
|
||||
|
||||
@ZenGetter("currentItem")
|
||||
IItemStack getCurrentItem();
|
||||
|
||||
@ZenGetter("creative")
|
||||
boolean isCreative();
|
||||
|
||||
@ZenGetter("adventure")
|
||||
boolean isAdventure();
|
||||
|
||||
@ZenMethod
|
||||
void give(IItemStack stack);
|
||||
|
||||
// not an exposed method. risks abuse
|
||||
void openBrowser(String url);
|
||||
|
||||
// not an exposed method, so far. would it be useful?
|
||||
void copyToClipboard(String value);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
|
||||
public class BrewingRecipe implements IBrewingRecipe {
|
||||
|
||||
private final IItemStack output;
|
||||
private final IItemStack input;
|
||||
private final IIngredient ingredient;
|
||||
|
||||
public BrewingRecipe(IItemStack output, IItemStack input, IIngredient ingredient) {
|
||||
this.input = input;
|
||||
this.ingredient = ingredient;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return String.format("brewing.add(%s, %s, %s)", output, input, ingredient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class CraftingInfo implements ICraftingInfo {
|
||||
|
||||
private final ICraftingInventory inventory;
|
||||
private final IDimension dimension;
|
||||
|
||||
public CraftingInfo(ICraftingInventory inventory, IDimension dimension) {
|
||||
this.inventory = inventory;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return inventory.getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
||||
public class FurnaceRecipe implements IFurnaceRecipe {
|
||||
|
||||
private final IItemStack input;
|
||||
private final IItemStack output;
|
||||
private final float xp;
|
||||
|
||||
public FurnaceRecipe(IItemStack input, IItemStack output, float xp) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return String.format("furnace.addRecipe(%s, %s, %s)", output, input, xp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The BrewingManager adds and removes brewing recipes. The IBrewingManager
|
||||
* instance is available through the recipes global variable.
|
||||
*
|
||||
* @author Jared
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IBrewingManager")
|
||||
public interface IBrewingManager {
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<IBrewingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Removes a brewing recipe from the specified item.
|
||||
*
|
||||
* @param output recipe output pattern
|
||||
*/
|
||||
@ZenMethod
|
||||
void remove(IItemStack output);
|
||||
|
||||
/**
|
||||
* Adds a recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe ingredient
|
||||
* @param input recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
void add(IItemStack output, IItemStack ingredient, IItemStack input);
|
||||
|
||||
/**
|
||||
* Removes recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredient
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int remove(IItemStack output, IItemStack ingredients);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
@ZenClass("minetweaker.recipes.IBrewingRecipe")
|
||||
public interface IBrewingRecipe {
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInfo")
|
||||
public interface ICraftingInfo {
|
||||
|
||||
@ZenGetter("inventory")
|
||||
ICraftingInventory getInventory();
|
||||
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Crafting inventory interface. The crafting inventory is the 2x2 grid in the
|
||||
* player inventory or the 3x3 grid in the crafting bench.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInventory")
|
||||
public interface ICraftingInventory {
|
||||
|
||||
/**
|
||||
* Gets the player owning this inventory.
|
||||
*
|
||||
* @return inventory player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
/**
|
||||
* Gets the size of this inventory.
|
||||
*
|
||||
* @return inventory size
|
||||
*/
|
||||
@ZenGetter("size")
|
||||
int getSize();
|
||||
|
||||
/**
|
||||
* Gets the width of this inventory.
|
||||
*
|
||||
* @return inventory width
|
||||
*/
|
||||
@ZenGetter("width")
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of this inventory.
|
||||
*
|
||||
* @return inventory height
|
||||
*/
|
||||
@ZenGetter("height")
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* Gets the number of stacks that are actually filled in.
|
||||
*
|
||||
* @return effective stack count
|
||||
*/
|
||||
@ZenGetter("stackCount")
|
||||
int getStackCount();
|
||||
|
||||
/**
|
||||
* Gets the stack at the given location.
|
||||
*
|
||||
* @param i stack index
|
||||
*
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Gets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
*
|
||||
* @return item stack, or null if there is no item stack at that position
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int x, int y);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* position
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int x, int y, IItemStack stack);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given index.
|
||||
*
|
||||
* @param i stack index
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* index
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
}
|
||||
Loaded 100 of 341 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user