mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
[ci skip] spotlessApply with the new settings
This commit is contained in:
1 parent
6b208b98bc
commit
a309488cdf
214 files changed
+9283
-9265
No files matched your search
@@ -3,14 +3,14 @@ package minetweaker;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The class registry provides the list of annotated classes to the scripting
|
||||
* system.
|
||||
* 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
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package minetweaker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
@@ -8,25 +9,25 @@ 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.
|
||||
* 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.
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -4,33 +4,33 @@ 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.
|
||||
* 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);
|
||||
/**
|
||||
* Converts a string into a chat message.
|
||||
*
|
||||
* @param message message string
|
||||
* @return chat message
|
||||
*/
|
||||
public IChatMessage getMessage(String message);
|
||||
|
||||
/**
|
||||
* Finds the item definition with the given ID.
|
||||
*
|
||||
* @param id item ID
|
||||
* @return resulting item definition
|
||||
*/
|
||||
public IItemDefinition getItemDefinition(int id);
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -3,16 +3,17 @@ 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.
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Removes all the items matching the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient
|
||||
*/
|
||||
public void remove(IIngredient ingredient);
|
||||
}
|
||||
@@ -3,82 +3,70 @@ 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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();
|
||||
/**
|
||||
* Executes what the action is supposed to do. This method can be called again if undo() has been called in between.
|
||||
*/
|
||||
public void apply();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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 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();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
@@ -1,5 +1,15 @@
|
||||
package minetweaker;
|
||||
|
||||
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;
|
||||
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.client.IClient;
|
||||
@@ -26,427 +36,385 @@ 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
|
||||
* 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
|
||||
* - 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"
|
||||
};
|
||||
|
||||
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");
|
||||
registerClassRegistry(ClassRegistry.class, "MT-API");
|
||||
|
||||
registerGlobalSymbol("logger", getJavaStaticGetterSymbol(MineTweakerAPI.class, "getLogger"));
|
||||
registerGlobalSymbol("recipes", getJavaStaticFieldSymbol(MineTweakerAPI.class, "recipes"));
|
||||
// registerGlobalSymbol("brewing", getJavaStaticFieldSymbol(MineTweakerAPI.class, "brewing"));
|
||||
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"));
|
||||
}
|
||||
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() {
|
||||
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 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;
|
||||
}
|
||||
/**
|
||||
* 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 ore dictionary.
|
||||
*/
|
||||
public static IOreDict oreDict = null;
|
||||
|
||||
/**
|
||||
* Access point to the recipe manager.
|
||||
*/
|
||||
public static IRecipeManager recipes = 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 brewing manager.
|
||||
// */
|
||||
// public static IBrewingManager brewing = null;
|
||||
|
||||
/**
|
||||
* Access point to the furnace manager.
|
||||
*/
|
||||
public static IFurnaceManager furnace = 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 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 server, if any.
|
||||
*/
|
||||
public static IServer server = null;
|
||||
|
||||
/**
|
||||
* Access point to the client, if any.
|
||||
*/
|
||||
public static IClient client = 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 general game data, such as items.
|
||||
*/
|
||||
public static IGame game = null;
|
||||
|
||||
/**
|
||||
* Access point to mods list.
|
||||
*/
|
||||
public static ILoadedMods loadedMods = 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 text formatter.
|
||||
*/
|
||||
public static IFormatter format = null;
|
||||
|
||||
/**
|
||||
* Access point to the vanilla functions and data.
|
||||
*/
|
||||
public static IVanilla vanilla = 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);
|
||||
}
|
||||
/**
|
||||
* 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 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 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 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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 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 ###
|
||||
// ###################################
|
||||
// ###################################
|
||||
// ### 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
|
||||
*/
|
||||
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);
|
||||
/**
|
||||
* 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();
|
||||
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;
|
||||
for (String mod : value) {
|
||||
if (!loadedMods.contains(mod)) continue outer;
|
||||
|
||||
if (!loadedMods.get(mod).getVersion().startsWith(version))
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!loadedMods.get(mod).getVersion().startsWith(version)) continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.registerClass(cls);
|
||||
}
|
||||
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");
|
||||
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
|
||||
* @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 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());
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 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 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);
|
||||
}
|
||||
/**
|
||||
* 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 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 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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,17 +6,17 @@ package minetweaker;
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public abstract class OneWayAction implements IUndoableAction {
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
}
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "impossibru!";
|
||||
}
|
||||
@Override
|
||||
public void undo() {}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "impossibru!";
|
||||
}
|
||||
}
|
||||
@@ -6,20 +6,20 @@ 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.
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -6,15 +6,15 @@ 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.
|
||||
* 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 "";
|
||||
public String[] value();
|
||||
|
||||
public String version() default "";
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@@ -16,13 +16,13 @@ public class BlockPatternOr implements IBlockPattern {
|
||||
}
|
||||
|
||||
public BlockPatternOr(IBlockPattern a, IBlockPattern b) {
|
||||
this.elements = new IBlockPattern[]{a, b};
|
||||
this.elements = new IBlockPattern[] { a, b };
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
List<IBlock> blocks = new ArrayList<>();
|
||||
for(IBlockPattern pattern : elements) {
|
||||
for (IBlockPattern pattern : elements) {
|
||||
blocks.addAll(pattern.getBlocks());
|
||||
}
|
||||
return blocks;
|
||||
@@ -30,9 +30,8 @@ public class BlockPatternOr implements IBlockPattern {
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(pattern.matches(block))
|
||||
return true;
|
||||
for (IBlockPattern pattern : elements) {
|
||||
if (pattern.matches(block)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -42,8 +41,8 @@ public class BlockPatternOr implements IBlockPattern {
|
||||
public String getDisplayName() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(first) {
|
||||
for (IBlockPattern pattern : elements) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(" | ");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
|
||||
@@ -3,14 +3,14 @@ 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.
|
||||
* 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.
|
||||
*
|
||||
@@ -20,10 +20,9 @@ public interface IChatMessage {
|
||||
*/
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IChatMessage add(IChatMessage other);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the internal object backing this object. Must be generated by
|
||||
* the implementing platform.
|
||||
* Retrieves the internal object backing this object. Must be generated by the implementing platform.
|
||||
*
|
||||
* @return internal object
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@ZenClass("minetweaker.api.IClient")
|
||||
public interface IClient {
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current player.
|
||||
*
|
||||
@@ -18,7 +18,7 @@ public interface IClient {
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
|
||||
@ZenGetter("language")
|
||||
String getLanguage();
|
||||
}
|
||||
@@ -1,45 +1,41 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
public class DummyJEIRecipeRegistry implements IJEIRecipeRegistry {
|
||||
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object) {
|
||||
}
|
||||
|
||||
public void addRecipe(Object object) {}
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object, String category) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object object) {
|
||||
}
|
||||
|
||||
public void removeRecipe(Object object) {}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object output, String category) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addFurnace(List<Object> inputs, Object output) {
|
||||
}
|
||||
|
||||
public void addFurnace(List<Object> inputs, Object output) {}
|
||||
|
||||
@Override
|
||||
public void removeFurnace(Object object) {
|
||||
}
|
||||
|
||||
public void removeFurnace(Object object) {}
|
||||
|
||||
@Override
|
||||
public void addFuel(Collection<Object> input, int burnTime) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void removeFuel(Object object) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
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
|
||||
// To update the items in 1.10.2
|
||||
void reloadItemList();
|
||||
|
||||
//To update the items in 1.11.2 both below are used
|
||||
// To update the items in 1.11.2 both below are used
|
||||
void removeItem(Object stack);
|
||||
|
||||
void addItem(Object stack);
|
||||
|
||||
@@ -20,8 +20,7 @@ public interface IContainer extends Iterable<IItemStack> {
|
||||
int getContainerSize();
|
||||
|
||||
/**
|
||||
* Gets the item stack at the given position. Returns null if there is no
|
||||
* stack at that position.
|
||||
* Gets the item stack at the given position. Returns null if there is no stack at that position.
|
||||
*
|
||||
* @param i stack position
|
||||
*
|
||||
|
||||
@@ -110,11 +110,9 @@ public class DataByteArray implements IData {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("[");
|
||||
boolean first = true;
|
||||
for(byte value : data) {
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
result.append(", ");
|
||||
for (byte value : data) {
|
||||
if (first) first = false;
|
||||
else result.append(", ");
|
||||
|
||||
result.append(value);
|
||||
}
|
||||
@@ -125,7 +123,7 @@ public class DataByteArray implements IData {
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for(byte value : data) {
|
||||
for (byte value : data) {
|
||||
result.add(new DataByte(value));
|
||||
}
|
||||
return result;
|
||||
@@ -144,7 +142,7 @@ public class DataByteArray implements IData {
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
@@ -157,7 +155,7 @@ public class DataByteArray implements IData {
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asByte();
|
||||
@@ -196,7 +194,7 @@ public class DataByteArray implements IData {
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
|
||||
@@ -110,8 +110,8 @@ public class DataIntArray implements IData {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('[');
|
||||
boolean first = true;
|
||||
for(int value : data) {
|
||||
if(first) {
|
||||
for (int value : data) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
@@ -125,7 +125,7 @@ public class DataIntArray implements IData {
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<>();
|
||||
for(int value : data) {
|
||||
for (int value : data) {
|
||||
result.add(new DataInt(value));
|
||||
}
|
||||
return result;
|
||||
@@ -139,7 +139,7 @@ public class DataIntArray implements IData {
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
byte[] result = new byte[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte) data[i];
|
||||
}
|
||||
return result;
|
||||
@@ -157,7 +157,7 @@ public class DataIntArray implements IData {
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asInt();
|
||||
@@ -196,7 +196,7 @@ public class DataIntArray implements IData {
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataIntArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DataList implements IData {
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return values;
|
||||
@@ -71,8 +71,8 @@ public class DataList implements IData {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append('[');
|
||||
boolean first = true;
|
||||
for(IData value : values) {
|
||||
if(first) {
|
||||
for (IData value : values) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
output.append(", ");
|
||||
@@ -87,11 +87,11 @@ public class DataList implements IData {
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
byte[] result = new byte[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asByte();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
} catch (IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -100,11 +100,11 @@ public class DataList implements IData {
|
||||
public int[] asIntArray() {
|
||||
try {
|
||||
int[] result = new int[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asInt();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
} catch (IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class DataList implements IData {
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("this list is immutable");
|
||||
} else {
|
||||
values.set(i, value);
|
||||
@@ -141,23 +141,19 @@ public class DataList implements IData {
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
List<IData> dataValues = data.asList();
|
||||
if(dataValues != null && containsList(dataValues))
|
||||
return true;
|
||||
if (dataValues != null && containsList(dataValues)) return true;
|
||||
|
||||
for(IData value : values) {
|
||||
if(value.contains(data))
|
||||
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;
|
||||
outer: for (IData dataValue : dataValues) {
|
||||
for (IData value : values) {
|
||||
if (value.contains(dataValue)) continue outer;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -169,12 +165,10 @@ public class DataList implements IData {
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
List<IData> otherValues = data.asList();
|
||||
if(otherValues.size() != values.size())
|
||||
return false;
|
||||
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;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
if (!values.get(i).equals(otherValues.get(i))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -187,11 +181,11 @@ public class DataList implements IData {
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
List<IData> copy = new ArrayList<>();
|
||||
for(IData value : values) {
|
||||
for (IData value : values) {
|
||||
copy.add(value.immutable());
|
||||
}
|
||||
return new DataList(copy, true);
|
||||
@@ -200,8 +194,7 @@ public class DataList implements IData {
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
if (immutable) data = data.immutable();
|
||||
|
||||
List<IData> result = new ArrayList<>();
|
||||
result.addAll(values);
|
||||
|
||||
@@ -24,10 +24,10 @@ public class DataMap implements IData {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
for (Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ public class DataMap implements IData {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(String key : otherMap.keySet()) {
|
||||
for (String key : otherMap.keySet()) {
|
||||
result.remove(key);
|
||||
}
|
||||
|
||||
@@ -129,14 +129,14 @@ public class DataMap implements IData {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('{');
|
||||
boolean first = true;
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if(first) {
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
if(isValidIdentifier(entry.getKey())) {
|
||||
if (isValidIdentifier(entry.getKey())) {
|
||||
result.append(entry.getKey());
|
||||
} else {
|
||||
result.append("\"").append(entry.getKey()).append("\"");
|
||||
@@ -156,7 +156,7 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
return Collections.unmodifiableMap(data);
|
||||
} else {
|
||||
return data;
|
||||
@@ -190,7 +190,7 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("this map is not modifiable");
|
||||
} else {
|
||||
this.data.put(name, data);
|
||||
@@ -204,18 +204,17 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if(data instanceof DataString) {
|
||||
if (data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap == null)
|
||||
return false;
|
||||
if (dataMap == null) return false;
|
||||
|
||||
for(Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if(!this.data.containsKey(dataEntry.getKey())) {
|
||||
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())) {
|
||||
} else if (!this.data.get(dataEntry.getKey()).contains(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -230,17 +229,15 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
if(this == data)
|
||||
return true;
|
||||
if (this == data) return true;
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap.size() != this.data.size())
|
||||
return false;
|
||||
if (dataMap.size() != this.data.size()) return false;
|
||||
|
||||
for(Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
|
||||
if(!dataMap.containsKey(dataEntry.getKey())) {
|
||||
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())) {
|
||||
} else if (!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -250,11 +247,11 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().immutable());
|
||||
}
|
||||
return new DataMap(result, true);
|
||||
@@ -263,14 +260,13 @@ public class DataMap implements IData {
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
if (immutable) data = data.immutable();
|
||||
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
for (Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
@@ -287,12 +283,10 @@ public class DataMap implements IData {
|
||||
}
|
||||
|
||||
private boolean isValidIdentifier(String str) {
|
||||
if(!Character.isJavaIdentifierStart(str.charAt(0)))
|
||||
return false;
|
||||
if (!Character.isJavaIdentifierStart(str.charAt(0))) return false;
|
||||
|
||||
for(int i = 1; i < str.length(); i++) {
|
||||
if(!Character.isJavaIdentifierPart(str.charAt(i)))
|
||||
return false;
|
||||
for (int i = 1; i < str.length(); i++) {
|
||||
if (!Character.isJavaIdentifierPart(str.charAt(i))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class DataString implements IData {
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
if(name.equals("length")) {
|
||||
if (name.equals("length")) {
|
||||
return new DataInt(value.length());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("no such member: " + name);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* 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, ...
|
||||
* 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
|
||||
*/
|
||||
@@ -69,8 +68,7 @@ public interface IData {
|
||||
String asString();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a List. Returns null if this value
|
||||
* cannot be converted to a list.
|
||||
* 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
|
||||
*/
|
||||
@@ -78,8 +76,7 @@ public interface IData {
|
||||
List<IData> asList();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a Map. Returns null if this value
|
||||
* cannot be converted to a map.
|
||||
* 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
|
||||
*/
|
||||
@@ -87,8 +84,7 @@ public interface IData {
|
||||
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.
|
||||
* 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
|
||||
*/
|
||||
@@ -96,8 +92,7 @@ public interface IData {
|
||||
byte[] asByteArray();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to an int array. Returns null if this
|
||||
* value cannot be converted to an int array.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* This file is part of MineTweaker API, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2014 MineTweaker <http://minetweaker3.powerofbytes.com>
|
||||
* 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;
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ 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, ...
|
||||
* 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
|
||||
*/
|
||||
@@ -55,8 +54,7 @@ public interface IEntity {
|
||||
Position3f getPosition();
|
||||
|
||||
/**
|
||||
* Sets the position of this entity. Instantly moves (teleports) the entity
|
||||
* to that position.
|
||||
* Sets the position of this entity. Instantly moves (teleports) the entity to that position.
|
||||
*
|
||||
* @param position entity position
|
||||
*/
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
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.*;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.value.*;
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
|
||||
}
|
||||
@@ -4,8 +4,8 @@ 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).
|
||||
* Represents an item entity. Item entities are entities representing an item stack on the ground (or flying through the
|
||||
* air).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents an event handle. Event handles are used to cancel event listeners.
|
||||
*
|
||||
|
||||
@@ -10,88 +10,58 @@ import minetweaker.util.IEventHandler;
|
||||
* @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);
|
||||
*/
|
||||
/*
|
||||
* 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);
|
||||
*/
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -10,89 +10,89 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@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();
|
||||
|
||||
@@ -8,13 +8,13 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@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;
|
||||
|
||||
@@ -8,13 +8,13 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@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;
|
||||
|
||||
@@ -9,33 +9,33 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@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;
|
||||
|
||||
@@ -6,69 +6,69 @@ 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);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package minetweaker.api.game;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.entity.IEntityDefinition;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
@@ -7,8 +9,6 @@ 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.
|
||||
*
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
*/
|
||||
@ZenClass("minetweaker.game.IGame")
|
||||
public interface IGame {
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the item definitions in this game.
|
||||
*
|
||||
@@ -24,7 +24,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemDefinition> getItems();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the block definitions in this game.
|
||||
*
|
||||
@@ -32,7 +32,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenGetter("blocks")
|
||||
List<IBlockDefinition> getBlocks();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the liquids in this game.
|
||||
*
|
||||
@@ -40,7 +40,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidDefinition> getLiquids();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the biomes in this game.
|
||||
*
|
||||
@@ -48,7 +48,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenGetter("biomes")
|
||||
List<IBiome> getBiomes();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the entities in this game.
|
||||
*
|
||||
@@ -56,10 +56,10 @@ public interface IGame {
|
||||
*/
|
||||
@ZenGetter("entities")
|
||||
List<IEntityDefinition> getEntities();
|
||||
|
||||
|
||||
@ZenMethod()
|
||||
IEntityDefinition getEntity(String entityName);
|
||||
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
@@ -68,7 +68,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String key, String value);
|
||||
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
@@ -78,7 +78,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String lang, String key, String value);
|
||||
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
@@ -88,7 +88,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key);
|
||||
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
@@ -99,16 +99,15 @@ public interface IGame {
|
||||
*/
|
||||
@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.
|
||||
* 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.
|
||||
*
|
||||
@@ -116,7 +115,7 @@ public interface IGame {
|
||||
*/
|
||||
@ZenGetter("locked")
|
||||
boolean isLocked();
|
||||
|
||||
|
||||
/**
|
||||
* Signals a modified script while in locked mode.
|
||||
*/
|
||||
|
||||
@@ -1,66 +1,61 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
@@ -71,10 +66,9 @@ public interface IIngredient {
|
||||
@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.
|
||||
* Combines multiple ingredients into a single one. Note that ore dictionary entries are preferred to or statements.
|
||||
*
|
||||
* @param ingredient ingredient to combine with
|
||||
*
|
||||
@@ -83,7 +77,7 @@ public interface IIngredient {
|
||||
@ZenOperator(OperatorType.OR)
|
||||
@ZenMethod
|
||||
IIngredient or(IIngredient ingredient);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
@@ -93,7 +87,7 @@ public interface IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient transform(IItemTransformer transformer);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given condition added to it.
|
||||
*
|
||||
@@ -103,7 +97,7 @@ public interface IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient only(IItemCondition condition);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new ingredient marked with the given name.
|
||||
*
|
||||
@@ -113,10 +107,9 @@ public interface IIngredient {
|
||||
*/
|
||||
@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.
|
||||
* 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
|
||||
*
|
||||
@@ -124,10 +117,9 @@ public interface IIngredient {
|
||||
*/
|
||||
@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.
|
||||
* 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
|
||||
*
|
||||
@@ -135,8 +127,7 @@ public interface IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matchesExact(IItemStack item);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given liquid.
|
||||
*
|
||||
@@ -146,10 +137,9 @@ public interface IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matches(ILiquidStack liquid);
|
||||
|
||||
|
||||
/**
|
||||
* Check if this ingredient contains all possible values for the given
|
||||
* ingredient.
|
||||
* Check if this ingredient contains all possible values for the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to check
|
||||
*
|
||||
@@ -157,7 +147,7 @@ public interface IIngredient {
|
||||
*/
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IIngredient ingredient);
|
||||
|
||||
|
||||
/**
|
||||
* Applies transformations after crafting, if any, to the given item.
|
||||
*
|
||||
@@ -168,25 +158,23 @@ public interface IIngredient {
|
||||
*/
|
||||
@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.
|
||||
* @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.
|
||||
* 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();
|
||||
|
||||
|
||||
}
|
||||
@@ -5,9 +5,8 @@ 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.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
@@ -24,7 +23,7 @@ public interface IItemDefinition {
|
||||
*/
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
@@ -32,7 +31,7 @@ public interface IItemDefinition {
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
|
||||
/**
|
||||
* Makes an item stack from this definition.
|
||||
*
|
||||
@@ -42,10 +41,9 @@ public interface IItemDefinition {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack makeStack(@Optional int meta);
|
||||
|
||||
|
||||
/**
|
||||
* Returns all ore entries containing this item. Also contains ore entries
|
||||
* that refer to a specific sub-item.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
@@ -33,7 +30,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IItemDefinition getDefinition();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
@@ -41,26 +38,25 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@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.
|
||||
* 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.
|
||||
* 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
|
||||
*
|
||||
@@ -68,7 +64,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenGetter("maxStackSize")
|
||||
int getMaxStackSize();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the ItemStack max stack size.
|
||||
*
|
||||
@@ -76,13 +72,13 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenSetter("maxStackSize")
|
||||
void setMaxStackSize(int size);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the block hardness
|
||||
*/
|
||||
@ZenGetter("hardness")
|
||||
float getBlockHardness();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the block hardness
|
||||
*
|
||||
@@ -90,7 +86,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenSetter("hardness")
|
||||
void setBlockHardness(float hardness);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
@@ -98,7 +94,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenGetter("damage")
|
||||
int getDamage();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the maximum item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
@@ -106,7 +102,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenGetter("maxDamage")
|
||||
int getMaxDamage();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the max Itemstack damage
|
||||
*
|
||||
@@ -114,27 +110,25 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@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.
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
@@ -144,10 +138,9 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack amount(int amount);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given percentage chance. Does the
|
||||
* same as item.weight(p * 0.01).
|
||||
* Creates a weighted item stack with the given percentage chance. Does the same as item.weight(p * 0.01).
|
||||
*
|
||||
* @param p probability, with percent
|
||||
*
|
||||
@@ -155,7 +148,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
WeightedItemStack percent(float p);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given weight.
|
||||
*
|
||||
@@ -165,16 +158,16 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@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.
|
||||
* 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.
|
||||
*
|
||||
@@ -184,7 +177,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withDamage(int damage);
|
||||
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified stack size.
|
||||
*
|
||||
@@ -195,16 +188,16 @@ public interface IItemStack extends IIngredient {
|
||||
@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.
|
||||
*
|
||||
@@ -214,7 +207,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withTag(IData tag);
|
||||
|
||||
|
||||
/**
|
||||
* Create an item stack with an empty nbt tag. Removes previous tag if any.
|
||||
*
|
||||
@@ -222,7 +215,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withEmptyTag();
|
||||
|
||||
|
||||
/**
|
||||
* Creates an item stack without the given nbt tag.
|
||||
*
|
||||
@@ -232,7 +225,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack removeTag(String tag);
|
||||
|
||||
|
||||
/**
|
||||
* Creates an item stack with updated nbt tag. Updates existing tags.
|
||||
*
|
||||
@@ -242,7 +235,7 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack updateTag(IData tagUpdate);
|
||||
|
||||
|
||||
/**
|
||||
* Converts this item stack into a block.
|
||||
*
|
||||
@@ -250,10 +243,9 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenCaster
|
||||
IBlock asBlock();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore
|
||||
* entries.
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore entries.
|
||||
*
|
||||
* @return ore entries containing this item stack
|
||||
*/
|
||||
|
||||
@@ -4,9 +4,8 @@ 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.
|
||||
* 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
|
||||
*/
|
||||
@@ -14,8 +13,7 @@ import stanhebben.zenscript.annotations.*;
|
||||
public interface IItemTransformer {
|
||||
|
||||
/**
|
||||
* Transforms the specified item. May modify this item (and return it) or
|
||||
* return an entirely new one.
|
||||
* 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
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the wildcard ingredient (<*>).
|
||||
*
|
||||
@@ -18,8 +18,7 @@ public class IngredientAny implements IIngredient {
|
||||
public static Object INTERNAL_ANY = null; // platforms supporting an "any"
|
||||
// item should fill it here
|
||||
|
||||
private IngredientAny() {
|
||||
}
|
||||
private IngredientAny() {}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
@@ -48,12 +47,12 @@ public class IngredientAny implements IIngredient {
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(null, ArrayUtil.EMPTY_CONDITIONS, new 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);
|
||||
return new IngredientAnyAdvanced(null, new IItemCondition[] { condition }, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +75,6 @@ public class IngredientAny implements IIngredient {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return true;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
* Represents the wildcard ingredient, with conditions and/or transformers applied to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@@ -71,9 +70,8 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -81,9 +79,8 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -98,9 +95,8 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for(IItemStack iitem : iitems) {
|
||||
if(!matches(iitem))
|
||||
return false;
|
||||
for (IItemStack iitem : iitems) {
|
||||
if (!matches(iitem)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -108,7 +104,7 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
for (IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,8 @@ 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.
|
||||
* 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
|
||||
*/
|
||||
@@ -23,6 +22,7 @@ public class IngredientCondition {
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamaged(IIngredient ingredient) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() > 0;
|
||||
@@ -41,6 +41,7 @@ public class IngredientCondition {
|
||||
@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;
|
||||
@@ -49,8 +50,7 @@ public class IngredientCondition {
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at most a specified amount. An
|
||||
* undamaged item is accepted.
|
||||
* 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
|
||||
@@ -60,6 +60,7 @@ public class IngredientCondition {
|
||||
@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;
|
||||
@@ -79,6 +80,7 @@ public class IngredientCondition {
|
||||
@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;
|
||||
@@ -87,8 +89,8 @@ public class IngredientCondition {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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
|
||||
@@ -98,6 +100,7 @@ public class IngredientCondition {
|
||||
@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);
|
||||
@@ -106,8 +109,8 @@ public class IngredientCondition {
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the input stack to contain at least the given number of items.
|
||||
* Used in combination with stack consuming recipes.
|
||||
* 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
|
||||
@@ -117,6 +120,7 @@ public class IngredientCondition {
|
||||
@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;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
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.
|
||||
*
|
||||
@@ -75,12 +75,10 @@ public class IngredientItem implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!this.item.matches(item))
|
||||
return false;
|
||||
if (!this.item.matches(item)) return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -88,12 +86,10 @@ public class IngredientItem implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!this.item.matchesExact(item))
|
||||
return false;
|
||||
if (!this.item.matchesExact(item)) return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -107,9 +103,8 @@ public class IngredientItem implements IIngredient {
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for(IItemStack iitem : iitems) {
|
||||
if(!matches(iitem))
|
||||
return false;
|
||||
for (IItemStack iitem : iitems) {
|
||||
if (!matches(iitem)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -117,7 +112,7 @@ public class IngredientItem implements IIngredient {
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
for (IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@@ -24,10 +24,11 @@ public class IngredientOr implements IIngredient {
|
||||
}
|
||||
|
||||
public IngredientOr(IIngredient a, IIngredient b) {
|
||||
this(new IIngredient[]{a, b});
|
||||
this(new IIngredient[] { a, b });
|
||||
}
|
||||
|
||||
private IngredientOr(IIngredient[] elements, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
private IngredientOr(IIngredient[] elements, String mark, IItemCondition[] conditions,
|
||||
IItemTransformer[] transformers) {
|
||||
this.elements = elements;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
@@ -47,7 +48,7 @@ public class IngredientOr implements IIngredient {
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
for (IIngredient element : elements) {
|
||||
result.addAll(element.getItems());
|
||||
}
|
||||
return result;
|
||||
@@ -56,7 +57,7 @@ public class IngredientOr implements IIngredient {
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
List<ILiquidStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
for (IIngredient element : elements) {
|
||||
result.addAll(element.getLiquids());
|
||||
}
|
||||
return result;
|
||||
@@ -65,7 +66,7 @@ public class IngredientOr implements IIngredient {
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
IIngredient[] result = new IIngredient[elements.length];
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].amount(amount);
|
||||
}
|
||||
return new IngredientOr(result);
|
||||
@@ -93,9 +94,8 @@ public class IngredientOr implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(item))
|
||||
return true;
|
||||
for (IIngredient ingredient : elements) {
|
||||
if (ingredient.matches(item)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -103,9 +103,8 @@ public class IngredientOr implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matchesExact(item))
|
||||
return true;
|
||||
for (IIngredient ingredient : elements) {
|
||||
if (ingredient.matchesExact(item)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -113,9 +112,8 @@ public class IngredientOr implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(liquid))
|
||||
return true;
|
||||
for (IIngredient ingredient : elements) {
|
||||
if (ingredient.matches(liquid)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -124,9 +122,8 @@ public class IngredientOr implements IIngredient {
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for(IItemStack item : items) {
|
||||
if(!matches(item))
|
||||
return false;
|
||||
for (IItemStack item : items) {
|
||||
if (!matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -134,7 +131,7 @@ public class IngredientOr implements IIngredient {
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
for (IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
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.
|
||||
* Contains an ingredient stack. Is an ingredient with a specific stack size assigned to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@@ -110,7 +109,7 @@ public class IngredientStack implements IIngredient {
|
||||
String s = "(Ingredients) ";
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
for(IItemStack st : ingredient.getItems()) {
|
||||
for (IItemStack st : ingredient.getItems()) {
|
||||
names.add(st.getName());
|
||||
}
|
||||
s += String.join(",", names);
|
||||
|
||||
@@ -3,9 +3,8 @@ 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.
|
||||
* 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
|
||||
*/
|
||||
@@ -25,8 +24,8 @@ public class IngredientTransform {
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item for
|
||||
* 1 point upon crafting and consume it when broken.
|
||||
* 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
|
||||
*
|
||||
@@ -36,7 +35,7 @@ public class IngredientTransform {
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
@@ -45,10 +44,8 @@ public class IngredientTransform {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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
|
||||
@@ -59,7 +56,7 @@ public class IngredientTransform {
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount()).withDamage(newDamage);
|
||||
@@ -68,8 +65,7 @@ public class IngredientTransform {
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
* 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
|
||||
@@ -79,7 +75,7 @@ public class IngredientTransform {
|
||||
@ZenMethod
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(item.getAmount() > 1) {
|
||||
if (item.getAmount() > 1) {
|
||||
byPlayer.give(withItem);
|
||||
return item;
|
||||
} else {
|
||||
@@ -89,9 +85,8 @@ public class IngredientTransform {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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
|
||||
@@ -116,8 +111,7 @@ public class IngredientTransform {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives an item back to the player. Also clears the inventory slot at that
|
||||
* position.
|
||||
* Gives an item back to the player. Also clears the inventory slot at that position.
|
||||
*
|
||||
* @param ingredient
|
||||
* @param givenItem
|
||||
@@ -127,7 +121,7 @@ public class IngredientTransform {
|
||||
@ZenMethod
|
||||
public static IIngredient giveBack(IIngredient ingredient, @Optional final IItemStack givenItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(givenItem == null) {
|
||||
if (givenItem == null) {
|
||||
byPlayer.give(item.withAmount(1));
|
||||
return item;
|
||||
} else {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@@ -73,7 +73,6 @@ public class IngredientUnknown implements IIngredient {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
* 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()) {
|
||||
|
||||
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;
|
||||
@@ -58,16 +58,17 @@ public final class WeightedItemStack {
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
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);
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack)))
|
||||
&& Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains a liquid definition. Liquid definitions provide additional
|
||||
* information about liquids.
|
||||
* Contains a liquid definition. Liquid definitions provide additional information about liquids.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
|
||||
@@ -9,43 +9,43 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack and a weight.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@@ -15,6 +14,7 @@ public final class WeightedLiquidStack {
|
||||
|
||||
private final ILiquidStack stack;
|
||||
private final float p;
|
||||
|
||||
public WeightedLiquidStack(ILiquidStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
@@ -23,8 +23,8 @@ public final class WeightedLiquidStack {
|
||||
public static List<ILiquidStack> pickRandomDrops(Random random, WeightedLiquidStack[] items) {
|
||||
ArrayList<ILiquidStack> result = new ArrayList<>();
|
||||
|
||||
for(WeightedLiquidStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
for (WeightedLiquidStack item : items) {
|
||||
if (random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
@@ -61,13 +61,14 @@ public final class WeightedLiquidStack {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
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);
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack)))
|
||||
&& Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package minetweaker.api.logger;
|
||||
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
/**
|
||||
* @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 static final Pattern FORMATTING_CODE_PATTERN = Pattern
|
||||
.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
|
||||
private final Writer writer;
|
||||
private final PrintWriter printWriter;
|
||||
|
||||
@@ -19,9 +19,9 @@ public class FileLogger implements ILogger {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
printWriter = new PrintWriter(writer);
|
||||
} catch(UnsupportedEncodingException ex) {
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch(FileNotFoundException ex) {
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("Could not open log file " + output);
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class FileLogger implements ILogger {
|
||||
try {
|
||||
writer.write(stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class FileLogger implements ILogger {
|
||||
try {
|
||||
writer.write("INFO: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class FileLogger implements ILogger {
|
||||
try {
|
||||
writer.write("WARNING: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@@ -65,11 +65,11 @@ public class FileLogger implements ILogger {
|
||||
public void logError(String message, Throwable exception) {
|
||||
try {
|
||||
writer.write("ERROR: " + stripMessage(message) + "\n");
|
||||
if(exception != null) {
|
||||
if (exception != null) {
|
||||
exception.printStackTrace(printWriter);
|
||||
}
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package minetweaker.api.logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ public class MTLogger implements ILogger {
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
|
||||
if(!unprocessed.isEmpty()) {
|
||||
if (!unprocessed.isEmpty()) {
|
||||
unprocessed.forEach(player::sendChat);
|
||||
}
|
||||
}
|
||||
@@ -40,30 +40,30 @@ public class MTLogger implements ILogger {
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
|
||||
String message2 = "WARNING: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
@@ -76,16 +76,16 @@ public class MTLogger implements ILogger {
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
for(ILogger logger : loggers) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logError(message, exception);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -17,14 +18,15 @@ import minetweaker.api.world.IBiome;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import minetweaker.mc1710.block.MCBlockDefinition;
|
||||
import minetweaker.mc1710.block.MCSpecificBlock;
|
||||
import minetweaker.mc1710.block.MCWorldBlock;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
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 minetweaker.mc1710.world.MCDimension;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -43,453 +45,428 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
* @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 static final Map<Block, MCBlockDefinition> blockDefinitions = new HashMap<Block, MCBlockDefinition>();
|
||||
public static final IBiome[] biomes;
|
||||
|
||||
private MineTweakerMC() {
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private MineTweakerMC() {}
|
||||
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.logError("Not a valid item stack: " + item);
|
||||
}
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.logError("Not a valid item stack: " + item);
|
||||
}
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
if (items.size() != 1) {
|
||||
MineTweakerAPI.logError("Not an ingredient with a single item: " + ingredient);
|
||||
}
|
||||
return getItemStack(items.get(0));
|
||||
}
|
||||
|
||||
return new MCItemStack(item);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
return new MCItemStack(item, true);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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(item, true);
|
||||
}
|
||||
|
||||
return new MCItemStack(new ItemStack(item, 1, meta), 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;
|
||||
|
||||
/**
|
||||
* 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, meta), true);
|
||||
}
|
||||
|
||||
return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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;
|
||||
}
|
||||
return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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;
|
||||
}
|
||||
|
||||
return new MCItemStack(new ItemStack(item, amount, damage));
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return new MCItemStack(new ItemStack(item, amount, damage));
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* 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.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;
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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;
|
||||
}
|
||||
|
||||
IItemStack[] result = new IItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new MCItemStack(items[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new MCItemStack(items[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MCItemStack(items.get(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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MCItemStack(items.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
return new MCPlayer(player);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return new MCPlayer(player);
|
||||
}
|
||||
|
||||
if (!(player instanceof MCPlayer)) {
|
||||
MineTweakerAPI.logError("Invalid player: " + 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;
|
||||
|
||||
return ((MCPlayer) player).getInternal();
|
||||
}
|
||||
if (!(player instanceof MCPlayer)) {
|
||||
MineTweakerAPI.logError("Invalid player: " + player);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ((MCPlayer) player).getInternal();
|
||||
}
|
||||
|
||||
return NBTConverter.from(nbt, true);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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, true);
|
||||
}
|
||||
|
||||
return NBTConverter.from(nbt, false);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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(nbt, false);
|
||||
}
|
||||
|
||||
return NBTConverter.from(data);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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 NBTConverter.from(data);
|
||||
}
|
||||
|
||||
return (NBTTagCompound) 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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
return (NBTTagCompound) NBTConverter.from(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 dimension instance for a given world.
|
||||
*
|
||||
* @param world world
|
||||
* @return dimension
|
||||
*/
|
||||
public static IDimension getDimension(World world) {
|
||||
if (world == null)
|
||||
return null;
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
return new MCDimension(world);
|
||||
}
|
||||
/**
|
||||
* Retrieves the dimension instance for a given world.
|
||||
*
|
||||
* @param world world
|
||||
* @return dimension
|
||||
*/
|
||||
public static IDimension getDimension(World world) {
|
||||
if (world == null) return null;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
return new MCDimension(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block from an item stack.
|
||||
*
|
||||
* @param itemStack
|
||||
* @return
|
||||
*/
|
||||
public static Block getBlock(IItemStack itemStack) {
|
||||
return ((MCBlockDefinition) itemStack.asBlock().getDefinition()).getInternalBlock();
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public static Block getBlock(IBlock block) {
|
||||
return ((MCBlockDefinition) block.getDefinition()).getInternalBlock();
|
||||
}
|
||||
/**
|
||||
* Retrieves the block from an item stack.
|
||||
*
|
||||
* @param itemStack
|
||||
* @return
|
||||
*/
|
||||
public static Block getBlock(IItemStack itemStack) {
|
||||
return ((MCBlockDefinition) itemStack.asBlock().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;
|
||||
public static Block getBlock(IBlock block) {
|
||||
return ((MCBlockDefinition) block.getDefinition()).getInternalBlock();
|
||||
}
|
||||
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
|
||||
FluidStack[] res = new FluidStack[stacks.length];
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
ILiquidStack liquidStack = stacks[i];
|
||||
res[i] = getLiquidStack(liquidStack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
FluidStack[] res = new FluidStack[stacks.length];
|
||||
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
ILiquidStack liquidStack = stacks[i];
|
||||
res[i] = getLiquidStack(liquidStack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
|
||||
if (entry == null) {
|
||||
return IngredientUnknown.INSTANCE;
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
|
||||
return entry;
|
||||
} else if (ingredient instanceof FluidStack) {
|
||||
return new MCLiquidStack((FluidStack) ingredient);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ import stanhebben.zenscript.annotations.*;
|
||||
@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);
|
||||
}
|
||||
@@ -6,16 +6,16 @@ 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();
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDict")
|
||||
public interface IOreDict {
|
||||
|
||||
|
||||
@ZenMemberGetter
|
||||
IOreDictEntry get(String name);
|
||||
|
||||
|
||||
@ZenGetter("entries")
|
||||
List<IOreDictEntry> getEntries();
|
||||
}
|
||||
@@ -33,7 +33,6 @@ public interface IOreDictEntry extends IIngredient {
|
||||
@ZenMethod
|
||||
void removeItems(IItemStack[] items);
|
||||
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IItemStack item);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@@ -17,7 +17,8 @@ public class IngredientOreDict implements IIngredient {
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOreDict(IOreDictEntry entry, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
public IngredientOreDict(IOreDictEntry entry, String mark, IItemCondition[] conditions,
|
||||
IItemTransformer[] transformers) {
|
||||
this.entry = entry;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
@@ -71,12 +72,10 @@ public class IngredientOreDict implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!entry.matches(item))
|
||||
return false;
|
||||
if (!entry.matches(item)) return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -84,12 +83,10 @@ public class IngredientOreDict implements IIngredient {
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!entry.matchesExact(item))
|
||||
return false;
|
||||
if (!entry.matchesExact(item)) return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -107,7 +104,7 @@ public class IngredientOreDict implements IIngredient {
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
for (IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@ 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);
|
||||
|
||||
@@ -7,25 +7,25 @@ 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;
|
||||
|
||||
@@ -3,20 +3,20 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
* 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.
|
||||
*
|
||||
@@ -21,7 +21,7 @@ public interface IBrewingManager {
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<IBrewingRecipe> getAll();
|
||||
|
||||
|
||||
/**
|
||||
* Removes a brewing recipe from the specified item.
|
||||
*
|
||||
@@ -29,7 +29,7 @@ public interface IBrewingManager {
|
||||
*/
|
||||
@ZenMethod
|
||||
void remove(IItemStack output);
|
||||
|
||||
|
||||
/**
|
||||
* Adds a recipe.
|
||||
*
|
||||
@@ -39,7 +39,7 @@ public interface IBrewingManager {
|
||||
*/
|
||||
@ZenMethod
|
||||
void add(IItemStack output, IItemStack ingredient, IItemStack input);
|
||||
|
||||
|
||||
/**
|
||||
* Removes recipes.
|
||||
*
|
||||
@@ -50,5 +50,5 @@ public interface IBrewingManager {
|
||||
*/
|
||||
@ZenMethod
|
||||
int remove(IItemStack output, IItemStack ingredients);
|
||||
|
||||
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
@ZenClass("minetweaker.recipes.IBrewingRecipe")
|
||||
public interface IBrewingRecipe {
|
||||
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -9,13 +9,13 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInfo")
|
||||
public interface ICraftingInfo {
|
||||
|
||||
|
||||
@ZenGetter("inventory")
|
||||
ICraftingInventory getInventory();
|
||||
|
||||
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
}
|
||||
@@ -5,14 +5,14 @@ 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.
|
||||
* 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.
|
||||
*
|
||||
@@ -20,7 +20,7 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the size of this inventory.
|
||||
*
|
||||
@@ -28,7 +28,7 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenGetter("size")
|
||||
int getSize();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the width of this inventory.
|
||||
*
|
||||
@@ -36,7 +36,7 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenGetter("width")
|
||||
int getWidth();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the height of this inventory.
|
||||
*
|
||||
@@ -44,7 +44,7 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenGetter("height")
|
||||
int getHeight();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of stacks that are actually filled in.
|
||||
*
|
||||
@@ -52,7 +52,7 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenGetter("stackCount")
|
||||
int getStackCount();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the stack at the given location.
|
||||
*
|
||||
@@ -62,10 +62,9 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
* 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
|
||||
@@ -74,25 +73,22 @@ public interface ICraftingInventory {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int x, int y);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
* 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
|
||||
* @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
|
||||
* @param stack item stack to be set, or null to clear the stack at that index
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
|
||||
@@ -9,14 +9,14 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingRecipe")
|
||||
public interface ICraftingRecipe {
|
||||
|
||||
|
||||
boolean matches(ICraftingInventory inventory);
|
||||
|
||||
|
||||
IItemStack getCraftingResult(ICraftingInventory inventory);
|
||||
|
||||
|
||||
boolean hasTransformers();
|
||||
|
||||
|
||||
void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer);
|
||||
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IFurnaceManager")
|
||||
public interface IFurnaceManager {
|
||||
|
||||
|
||||
@ZenMethod
|
||||
void remove(IIngredient output, @Optional IIngredient input);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
void addRecipe(IItemStack output, IIngredient input, @Optional double xp);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
void setFuel(IIngredient item, int fuel);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
int getFuel(IItemStack item);
|
||||
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
|
||||
@@ -4,7 +4,6 @@ package minetweaker.api.recipes;
|
||||
* Created by Jared on 4/18/2016.
|
||||
*/
|
||||
public interface IFurnaceRecipe {
|
||||
|
||||
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
public interface IMTRecipe {
|
||||
|
||||
|
||||
|
||||
ICraftingRecipe getRecipe();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeAction")
|
||||
public interface IRecipeAction {
|
||||
|
||||
|
||||
void process(IItemStack output, ICraftingInfo craftingInfo, IPlayer player);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeFunction")
|
||||
public interface IRecipeFunction {
|
||||
|
||||
|
||||
IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInfo craftingInfo);
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The RecipeManager adds and removes crafting recipes. The IRecipeManager
|
||||
* instance is available through the recipes global variable.
|
||||
* The RecipeManager adds and removes crafting recipes. The IRecipeManager instance is available through the recipes
|
||||
* global variable.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeManager")
|
||||
public interface IRecipeManager {
|
||||
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
@@ -21,7 +21,7 @@ public interface IRecipeManager {
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<ICraftingRecipe> getAll();
|
||||
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes resulting in the given ingredient.
|
||||
*
|
||||
@@ -31,7 +31,7 @@ public interface IRecipeManager {
|
||||
*/
|
||||
@ZenMethod
|
||||
List<ICraftingRecipe> getRecipesFor(IIngredient ingredient);
|
||||
|
||||
|
||||
/**
|
||||
* Removes all crafting recipes crafting the specified item.
|
||||
*
|
||||
@@ -52,13 +52,15 @@ public interface IRecipeManager {
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function,
|
||||
@Optional IRecipeAction action);
|
||||
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function);
|
||||
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeAction action);
|
||||
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients);
|
||||
|
||||
/**
|
||||
* Adds a mirrored shaped recipe.
|
||||
*
|
||||
@@ -67,13 +69,15 @@ public interface IRecipeManager {
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function,
|
||||
@Optional IRecipeAction action);
|
||||
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function);
|
||||
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeAction action);
|
||||
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients);
|
||||
|
||||
/**
|
||||
* Adds a shapeless recipe.
|
||||
*
|
||||
@@ -82,7 +86,8 @@ public interface IRecipeManager {
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function,
|
||||
@Optional IRecipeAction action);
|
||||
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function);
|
||||
|
||||
@@ -102,13 +107,13 @@ public interface IRecipeManager {
|
||||
int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients);
|
||||
|
||||
int removeShaped(IIngredient output);
|
||||
|
||||
/**
|
||||
* Removes shapeless recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param wildcard if the recipe may contain other ingredients too, besides
|
||||
* the ones specified
|
||||
* @param wildcard if the recipe may contain other ingredients too, besides the ones specified
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@@ -122,8 +127,7 @@ public interface IRecipeManager {
|
||||
int removeShapeless(IIngredient output);
|
||||
|
||||
/**
|
||||
* Performs a crafting with the specified ingredients. Returns null if no
|
||||
* crafting recipe exists.
|
||||
* Performs a crafting with the specified ingredients. Returns null if no crafting recipe exists.
|
||||
*
|
||||
* @param contents crafting inventory contents
|
||||
*
|
||||
@@ -131,5 +135,5 @@ public interface IRecipeManager {
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack craft(IItemStack[][] contents);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipe implements ICraftingRecipe {
|
||||
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
@@ -17,16 +17,16 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
private final boolean mirrored;
|
||||
private final IRecipeFunction function;
|
||||
private final IRecipeAction action;
|
||||
|
||||
|
||||
|
||||
private final IItemStack output;
|
||||
private final IIngredient[] ingredients;
|
||||
|
||||
|
||||
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
|
||||
this(output, ingredients, function, null, mirrored);
|
||||
}
|
||||
|
||||
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) {
|
||||
|
||||
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action,
|
||||
boolean mirrored) {
|
||||
int numIngredients = 0;
|
||||
for (IIngredient[] ingredient : ingredients) {
|
||||
for (IIngredient iIngredient : ingredient) {
|
||||
@@ -42,17 +42,17 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
this.ingredients = new IIngredient[numIngredients];
|
||||
this.function = function;
|
||||
this.action = action;
|
||||
|
||||
|
||||
int width1 = 0;
|
||||
int height1 = ingredients.length;
|
||||
|
||||
|
||||
int ix = 0;
|
||||
for(int j = 0; j < ingredients.length; j++) {
|
||||
for (int j = 0; j < ingredients.length; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
width1 = Math.max(width1, row.length);
|
||||
|
||||
for(int i = 0; i < row.length; i++) {
|
||||
if(row[i] != null) {
|
||||
|
||||
for (int i = 0; i < row.length; i++) {
|
||||
if (row[i] != null) {
|
||||
this.posx[ix] = (byte) i;
|
||||
this.posy[ix] = (byte) j;
|
||||
this.ingredients[ix] = row[i];
|
||||
@@ -60,253 +60,234 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.width = width1;
|
||||
this.height = height1;
|
||||
this.mirrored = mirrored;
|
||||
}
|
||||
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMirrored() {
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
|
||||
public IIngredient[] getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getIngredientsX() {
|
||||
return posx;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getIngredientsY() {
|
||||
return posy;
|
||||
}
|
||||
|
||||
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
if(inventory.getStackCount() != ingredients.length) {
|
||||
if (inventory.getStackCount() != ingredients.length) {
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for(IIngredient ingredient : ingredients) {
|
||||
if(ingredient.hasTransformers()) {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, false, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
if (item == null) continue out;
|
||||
|
||||
if (!ingredients[k].matches(item)) continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, true, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("recipes.addShaped(");
|
||||
if(output != null) {
|
||||
if (output != null) {
|
||||
result.append(output);
|
||||
} else {
|
||||
result.append("null");
|
||||
}
|
||||
result.append(", [");
|
||||
|
||||
|
||||
IIngredient[][] ingredientsArray = new IIngredient[height][width];
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredientsArray[posy[i]][posx[i]] = ingredients[i];
|
||||
}
|
||||
|
||||
for(int i = 0; i < ingredientsArray.length; i++) {
|
||||
if(i > 0) {
|
||||
|
||||
for (int i = 0; i < ingredientsArray.length; i++) {
|
||||
if (i > 0) {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
|
||||
result.append("[");
|
||||
|
||||
for(int j = 0; j < ingredientsArray[i].length; j++) {
|
||||
if(j > 0)
|
||||
result.append(", ");
|
||||
|
||||
|
||||
for (int j = 0; j < ingredientsArray[i].length; j++) {
|
||||
if (j > 0) result.append(", ");
|
||||
|
||||
result.append(ingredientsArray[i][j]);
|
||||
}
|
||||
|
||||
|
||||
result.append("]");
|
||||
}
|
||||
|
||||
|
||||
result.append("]);");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private IItemStack doRecipe(ICraftingInventory inventory, IItemStack[] stacks, int offx, int offy, IItemStack output, boolean mirrored) {
|
||||
|
||||
private IItemStack doRecipe(ICraftingInventory inventory, IItemStack[] stacks, int offx, int offy,
|
||||
IItemStack output, boolean mirrored) {
|
||||
// determine output and apply transformations
|
||||
|
||||
if(function != null) {
|
||||
|
||||
if (function != null) {
|
||||
Map<String, IItemStack> tagged = new HashMap<>();
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
if(ingredients[k].getMark() != null) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
if (ingredients[k].getMark() != null) {
|
||||
tagged.put(ingredients[k].getMark(), stacks[k]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: supply dimension
|
||||
output = function.process(output, tagged, new CraftingInfo(inventory, null));
|
||||
System.out.println("Ouput: " + output);
|
||||
}
|
||||
|
||||
if(output == null) {
|
||||
|
||||
if (output == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* for (int i = 0; i < ingredients.length; i++) { IItemStack transformed
|
||||
* = ingredients[i].applyTransform(stacks[i]); if (transformed !=
|
||||
* stacks[i]) { if (mirrored) { inventory.setStack( inventory.getWidth()
|
||||
* - (offx + posx[i]) - 1, offy + posy[i], transformed); } else {
|
||||
* inventory.setStack( offx + posx[i], offy + posy[i], transformed); } }
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* for (int i = 0; i < ingredients.length; i++) { IItemStack transformed =
|
||||
* ingredients[i].applyTransform(stacks[i]); if (transformed != stacks[i]) { if (mirrored) { inventory.setStack(
|
||||
* inventory.getWidth() - (offx + posx[i]) - 1, offy + posy[i], transformed); } else { inventory.setStack( offx
|
||||
* + posx[i], offy + posy[i], transformed); } } }
|
||||
*/
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private void doRecipeTransformers(ICraftingInventory inventory, IItemStack[] stacks, int offx, int offy, boolean mirrored, IPlayer byPlayer) {
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
|
||||
private void doRecipeTransformers(ICraftingInventory inventory, IItemStack[] stacks, int offx, int offy,
|
||||
boolean mirrored, IPlayer byPlayer) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i], byPlayer);
|
||||
if(transformed != stacks[i]) {
|
||||
if(mirrored) {
|
||||
if (transformed != stacks[i]) {
|
||||
if (mirrored) {
|
||||
inventory.setStack(inventory.getWidth() - (offx + posx[i]) - 1, offy + posy[i], transformed);
|
||||
} else {
|
||||
inventory.setStack(offx + posx[i], offy + posy[i], transformed);
|
||||
@@ -314,7 +295,7 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IRecipeAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipe implements ICraftingRecipe {
|
||||
|
||||
|
||||
private final IItemStack output;
|
||||
private final IRecipeFunction function;
|
||||
private final IRecipeAction action;
|
||||
private final IIngredient[] ingredients;
|
||||
|
||||
public ShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||
|
||||
public ShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function,
|
||||
IRecipeAction action) {
|
||||
this.output = output;
|
||||
this.function = function;
|
||||
this.ingredients = ingredients;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reorders ingredients to match the given shapeless recipe.
|
||||
*
|
||||
@@ -32,138 +33,134 @@ public class ShapelessRecipe implements ICraftingRecipe {
|
||||
*/
|
||||
private static RecipeMatching matchShapeless(IIngredient[] recipe, ICraftingInventory ingredients) {
|
||||
int numItems = 0;
|
||||
for(int i = 0; i < ingredients.getSize(); i++) {
|
||||
if(ingredients.getStack(i) != null) {
|
||||
for (int i = 0; i < ingredients.getSize(); i++) {
|
||||
if (ingredients.getStack(i) != null) {
|
||||
numItems++;
|
||||
}
|
||||
}
|
||||
|
||||
if(numItems != recipe.length) {
|
||||
|
||||
if (numItems != recipe.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
IItemStack[] matched = new IItemStack[recipe.length];
|
||||
int[] indices = new int[recipe.length];
|
||||
|
||||
outer:
|
||||
for(int i = 0; i < ingredients.getSize(); i++) {
|
||||
|
||||
outer: for (int i = 0; i < ingredients.getSize(); i++) {
|
||||
IItemStack ingredient = ingredients.getStack(i);
|
||||
if(ingredient == null)
|
||||
continue;
|
||||
|
||||
for(int j = 0; j < recipe.length; j++) {
|
||||
if(matched[j] != null)
|
||||
continue;
|
||||
if(recipe[j].matches(ingredient)) {
|
||||
if (ingredient == null) continue;
|
||||
|
||||
for (int j = 0; j < recipe.length; j++) {
|
||||
if (matched[j] != null) continue;
|
||||
if (recipe[j].matches(ingredient)) {
|
||||
matched[j] = ingredient;
|
||||
indices[j] = i;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return new RecipeMatching(matched, indices);
|
||||
}
|
||||
|
||||
|
||||
public int getSize() {
|
||||
return ingredients.length;
|
||||
}
|
||||
|
||||
|
||||
public IIngredient[] getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
return matchShapeless(ingredients, inventory) != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
RecipeMatching matching = matchShapeless(ingredients, inventory);
|
||||
|
||||
|
||||
IItemStack actualOutput = output;
|
||||
if(function != null) {
|
||||
if (function != null) {
|
||||
Map<String, IItemStack> map = new HashMap<>();
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
if(ingredients[i].getMark() != null) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (ingredients[i].getMark() != null) {
|
||||
map.put(ingredients[i].getMark(), matching.inputs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
actualOutput = function.process(actualOutput, map, new CraftingInfo(inventory, null));
|
||||
}
|
||||
|
||||
if(actualOutput == null) {
|
||||
|
||||
if (actualOutput == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return actualOutput;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
RecipeMatching matching = matchShapeless(ingredients, inventory);
|
||||
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IIngredient ingredient = ingredients[i];
|
||||
IItemStack transformed = ingredient.applyTransform(matching.inputs[i], byPlayer);
|
||||
if(transformed != matching.inputs[i]) {
|
||||
if (transformed != matching.inputs[i]) {
|
||||
inventory.setStack(matching.indices[i], transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
|
||||
result.append("recipes.addShapeless(");
|
||||
if(output != null){
|
||||
if (output != null) {
|
||||
result.append(output);
|
||||
}else{
|
||||
} else {
|
||||
result.append("null");
|
||||
}
|
||||
result.append(", [");
|
||||
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
if(i > 0)
|
||||
result.append(", ");
|
||||
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (i > 0) result.append(", ");
|
||||
|
||||
result.append(ingredients[i]);
|
||||
}
|
||||
|
||||
|
||||
result.append("]);");
|
||||
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for(IIngredient ingredient : ingredients) {
|
||||
if(ingredient.hasTransformers()) {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public IRecipeAction getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
|
||||
private static class RecipeMatching {
|
||||
|
||||
|
||||
public final IItemStack[] inputs;
|
||||
public final int[] indices;
|
||||
|
||||
|
||||
public RecipeMatching(IItemStack[] inputs, int[] indices) {
|
||||
this.inputs = inputs;
|
||||
this.indices = indices;
|
||||
|
||||
@@ -7,33 +7,33 @@ import minetweaker.api.player.IPlayer;
|
||||
* @author Stan
|
||||
*/
|
||||
public class UnknownRecipe implements ICraftingRecipe {
|
||||
|
||||
|
||||
private final IItemStack output;
|
||||
|
||||
|
||||
public UnknownRecipe(IItemStack output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return "// unknown recipe type for " + output;
|
||||
|
||||
@@ -5,8 +5,7 @@ import minetweaker.api.event.*;
|
||||
import minetweaker.util.IEventHandler;
|
||||
|
||||
/**
|
||||
* Abstract server implementation. Implements call of which the implementation
|
||||
* is already fixed by the API.
|
||||
* Abstract server implementation. Implements call of which the implementation is already fixed by the API.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
|
||||
@@ -10,22 +10,23 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@ZenClass("minetweaker.server.IServer")
|
||||
public interface IServer {
|
||||
|
||||
|
||||
@ZenMethod
|
||||
void addCommand(String name, String usage, String[] aliases, ICommandFunction function, @Optional ICommandValidator validator, @Optional ICommandTabCompletion completion);
|
||||
|
||||
void addCommand(String name, String usage, String[] aliases, ICommandFunction function,
|
||||
@Optional ICommandValidator validator, @Optional ICommandTabCompletion completion);
|
||||
|
||||
@ZenMethod
|
||||
void addMineTweakerCommand(String name, String[] usage, ICommandFunction function);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
boolean isOp(IPlayer player);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
IEventHandle onPlayerLoggedIn(IEventHandler<PlayerLoggedInEvent> ev);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
IEventHandle onPlayerLoggedOut(IEventHandler<PlayerLoggedOutEvent> ev);
|
||||
|
||||
|
||||
@ZenMethod
|
||||
boolean isCommandAdded(String name);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package minetweaker.api.tooltip;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.*;
|
||||
import minetweaker.api.formatting.IFormattedText;
|
||||
import minetweaker.api.item.*;
|
||||
@@ -7,83 +9,81 @@ import minetweaker.api.util.IngredientMap;
|
||||
import minetweaker.api.util.IngredientMap.IngredientMapEntry;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTooltips {
|
||||
|
||||
|
||||
private static final IngredientMap<IFormattedText> TOOLTIPS = new IngredientMap<>();
|
||||
private static final IngredientMap<IFormattedText> SHIFT_TOOLTIPS = new IngredientMap<>();
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addTooltip(IIngredient ingredient, IFormattedText tooltip) {
|
||||
MineTweakerAPI.apply(new AddTooltipAction(ingredient, tooltip, false));
|
||||
}
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addShiftTooltip(IIngredient ingredient, IFormattedText tooltip) {
|
||||
MineTweakerAPI.apply(new AddTooltipAction(ingredient, tooltip, true));
|
||||
}
|
||||
|
||||
|
||||
public static List<IFormattedText> getTooltips(IItemStack item) {
|
||||
return TOOLTIPS.getEntries(item);
|
||||
}
|
||||
|
||||
|
||||
public static List<IFormattedText> getShiftTooltips(IItemStack item) {
|
||||
return SHIFT_TOOLTIPS.getEntries(item);
|
||||
}
|
||||
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
|
||||
private static class AddTooltipAction implements IUndoableAction {
|
||||
|
||||
|
||||
private final IIngredient ingredient;
|
||||
private final IFormattedText tooltip;
|
||||
private final boolean shift;
|
||||
private IngredientMapEntry<IFormattedText> entry;
|
||||
|
||||
|
||||
public AddTooltipAction(IIngredient ingredient, IFormattedText tooltip, boolean shift) {
|
||||
this.ingredient = ingredient;
|
||||
this.tooltip = tooltip;
|
||||
this.shift = shift;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
entry = (shift ? SHIFT_TOOLTIPS : TOOLTIPS).register(ingredient, tooltip);
|
||||
MineTweakerAPI.getIjeiRecipeRegistry().invalidateTooltips(ingredient);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if(shift) {
|
||||
if (shift) {
|
||||
SHIFT_TOOLTIPS.unregister(entry);
|
||||
} else {
|
||||
TOOLTIPS.unregister(entry);
|
||||
}
|
||||
MineTweakerAPI.getIjeiRecipeRegistry().invalidateTooltips(ingredient);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding tooltip for " + ingredient + ": " + tooltip;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing tooltip for " + ingredient + ": " + tooltip;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package minetweaker.api.util;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@@ -17,12 +17,13 @@ public class IngredientMap<T> {
|
||||
}
|
||||
|
||||
public IngredientMapEntry<T> register(IIngredient ingredient, T entry) {
|
||||
Set<IItemDefinition> items = ingredient.getItems().stream().map(IItemStack::getDefinition).collect(Collectors.toSet());
|
||||
Set<IItemDefinition> items = ingredient.getItems().stream().map(IItemStack::getDefinition)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
IngredientMapEntry<T> actualEntry = new IngredientMapEntry<>(ingredient, entry);
|
||||
|
||||
for(IItemDefinition item : items) {
|
||||
if(!entries.containsKey(item)) {
|
||||
for (IItemDefinition item : items) {
|
||||
if (!entries.containsKey(item)) {
|
||||
entries.put(item, new ArrayList<>());
|
||||
}
|
||||
|
||||
@@ -33,18 +34,19 @@ public class IngredientMap<T> {
|
||||
}
|
||||
|
||||
public void unregister(IngredientMapEntry<T> entry) {
|
||||
Set<IItemDefinition> items = entry.ingredient.getItems().stream().map(IItemStack::getDefinition).collect(Collectors.toSet());
|
||||
Set<IItemDefinition> items = entry.ingredient.getItems().stream().map(IItemStack::getDefinition)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
for(IItemDefinition item : items) {
|
||||
if(entries.containsKey(item)) {
|
||||
for (IItemDefinition item : items) {
|
||||
if (entries.containsKey(item)) {
|
||||
entries.get(item).remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T getFirstEntry(IItemStack item) {
|
||||
for(IngredientMapEntry<T> entry : entries.get(item.getDefinition())) {
|
||||
if(entry.ingredient.matches(item)) {
|
||||
for (IngredientMapEntry<T> entry : entries.get(item.getDefinition())) {
|
||||
if (entry.ingredient.matches(item)) {
|
||||
return entry.entry;
|
||||
}
|
||||
}
|
||||
@@ -53,12 +55,13 @@ public class IngredientMap<T> {
|
||||
}
|
||||
|
||||
public List<T> getEntries(IItemStack item) {
|
||||
if(item == null || item.getDefinition() == null){
|
||||
if (item == null || item.getDefinition() == null) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
List<IngredientMapEntry<T>> entries = this.entries.get(item.getDefinition());
|
||||
if(entries != null) {
|
||||
return entries.stream().filter(entry -> entry.ingredient.matches(item)).map(entry -> entry.entry).collect(Collectors.toCollection(ArrayList::new));
|
||||
if (entries != null) {
|
||||
return entries.stream().filter(entry -> entry.ingredient.matches(item)).map(entry -> entry.entry)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
} else {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package minetweaker.api.vanilla;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package minetweaker.api.vanilla;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,10 @@ import stanhebben.zenscript.annotations.*;
|
||||
*/
|
||||
@ZenClass("vanilla.IVanilla")
|
||||
public interface IVanilla {
|
||||
|
||||
|
||||
@ZenGetter("loot")
|
||||
ILootRegistry getLoot();
|
||||
|
||||
|
||||
@ZenGetter("seeds")
|
||||
ISeedRegistry getSeeds();
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package minetweaker.api.vanilla;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Jared on 5/9/2016.
|
||||
*/
|
||||
|
||||
@@ -40,7 +40,7 @@ public class LootEntry {
|
||||
message.append(getItem().getStack());
|
||||
message.append(" (weight ");
|
||||
message.append((int) getItem().getChance());
|
||||
if(getMinAmount() != 0 || getMaxAmount() != 1) {
|
||||
if (getMinAmount() != 0 || getMaxAmount() != 1) {
|
||||
message.append(", ");
|
||||
message.append(getMinAmount());
|
||||
message.append("-");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package minetweaker.expand;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import minetweaker.api.data.DataList;
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
@@ -13,8 +14,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("any[]")
|
||||
public class ExpandAnyArray {
|
||||
@ZenCaster
|
||||
public static IData asData(IData[] values) {
|
||||
return new DataList(Arrays.asList(values), true);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(IData[] values) {
|
||||
return new DataList(Arrays.asList(values), true);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import minetweaker.api.data.DataMap;
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
@@ -18,8 +18,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("any[any]")
|
||||
public class ExpandAnyDict {
|
||||
@ZenCaster
|
||||
public static IData asData(Map<String, IData> values) {
|
||||
return new DataMap(values, true);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(Map<String, IData> values) {
|
||||
return new DataMap(values, true);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("bool")
|
||||
public class ExpandBool {
|
||||
@ZenCaster
|
||||
public static IData asData(boolean value) {
|
||||
return new DataBool(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(boolean value) {
|
||||
return new DataBool(value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("byte")
|
||||
public class ExpandByte {
|
||||
@ZenCaster
|
||||
public static IData asData(byte value) {
|
||||
return new DataByte(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(byte value) {
|
||||
return new DataByte(value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("double")
|
||||
public class ExpandDouble {
|
||||
@ZenCaster
|
||||
public static IData asData(double value) {
|
||||
return new DataDouble(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(double value) {
|
||||
return new DataDouble(value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("float")
|
||||
public class ExpandFloat {
|
||||
@ZenCaster
|
||||
public static IData asData(float value) {
|
||||
return new DataFloat(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(float value) {
|
||||
return new DataFloat(value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("int")
|
||||
public class ExpandInt {
|
||||
@ZenCaster
|
||||
public static IData toData(int value) {
|
||||
return new DataInt(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData toData(int value) {
|
||||
return new DataInt(value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IItemStack")
|
||||
public class ExpandItemStack {
|
||||
@ZenCaster
|
||||
public static WeightedItemStack asWeightedItemStack(IItemStack value) {
|
||||
return new WeightedItemStack(value, 1.0f);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static WeightedItemStack asWeightedItemStack(IItemStack value) {
|
||||
return new WeightedItemStack(value, 1.0f);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("long")
|
||||
public class ExpandLong {
|
||||
@ZenCaster
|
||||
public static IData asData(long value) {
|
||||
return new DataLong(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(long value) {
|
||||
return new DataLong(value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
@@ -17,8 +16,9 @@ import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
*/
|
||||
@ZenExpansion("short")
|
||||
public class ExpandShort {
|
||||
@ZenCaster
|
||||
public static IData asNBT(short value) {
|
||||
return new DataShort(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asNBT(short value) {
|
||||
return new DataShort(value);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
* 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.
|
||||
* To change this license header, choose License Headers in Project Properties. To change this template file, choose
|
||||
* Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.expand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
@@ -27,70 +27,69 @@ import stanhebben.zenscript.annotations.ZenOperator;
|
||||
*/
|
||||
@ZenExpansion("string")
|
||||
public class ExpandString {
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
public static IFormattedText add(String str, IFormattedText formattedText) {
|
||||
return MineTweakerAPI.format.string(str).add(formattedText);
|
||||
}
|
||||
|
||||
@ZenOperator(OperatorType.CAT)
|
||||
public static IFormattedText cat(String str, IFormattedText formattedText) {
|
||||
return add(str, formattedText);
|
||||
}
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
public static IFormattedText add(String str, IFormattedText formattedText) {
|
||||
return MineTweakerAPI.format.string(str).add(formattedText);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IData asData(String value) {
|
||||
return new DataString(value);
|
||||
}
|
||||
@ZenOperator(OperatorType.CAT)
|
||||
public static IFormattedText cat(String str, IFormattedText formattedText) {
|
||||
return add(str, formattedText);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IChatMessage asChatMessage(String value) {
|
||||
return MineTweakerImplementationAPI.platform.getMessage(value);
|
||||
}
|
||||
@ZenCaster
|
||||
public static IData asData(String value) {
|
||||
return new DataString(value);
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public static IFormattedText asFormattedText(String value) {
|
||||
return MineTweakerAPI.format.string(value);
|
||||
}
|
||||
@ZenCaster
|
||||
public static IChatMessage asChatMessage(String value) {
|
||||
return MineTweakerImplementationAPI.platform.getMessage(value);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static List<String> split(String value, String separator, @Optional int maximum) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
int minIndex = 0;
|
||||
int numSplits = 0;
|
||||
@ZenCaster
|
||||
public static IFormattedText asFormattedText(String value) {
|
||||
return MineTweakerAPI.format.string(value);
|
||||
}
|
||||
|
||||
while (minIndex + separator.length() <= value.length()) {
|
||||
int index = value.indexOf(separator, minIndex);
|
||||
if (index < 0)
|
||||
break;
|
||||
result.add(value.substring(minIndex, index));
|
||||
minIndex = index + separator.length();
|
||||
@ZenMethod
|
||||
public static List<String> split(String value, String separator, @Optional int maximum) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
int minIndex = 0;
|
||||
int numSplits = 0;
|
||||
|
||||
numSplits++;
|
||||
if (maximum > 0 && numSplits >= maximum)
|
||||
break;
|
||||
}
|
||||
while (minIndex + separator.length() <= value.length()) {
|
||||
int index = value.indexOf(separator, minIndex);
|
||||
if (index < 0) break;
|
||||
result.add(value.substring(minIndex, index));
|
||||
minIndex = index + separator.length();
|
||||
|
||||
result.add(value.substring(minIndex));
|
||||
return result;
|
||||
}
|
||||
numSplits++;
|
||||
if (maximum > 0 && numSplits >= maximum) break;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int indexOf(String value, String needle) {
|
||||
return value.indexOf(needle);
|
||||
}
|
||||
result.add(value.substring(minIndex));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int indexOf(String value, String needle, int fromIndex) {
|
||||
return value.indexOf(needle, fromIndex);
|
||||
}
|
||||
@ZenMethod
|
||||
public static int indexOf(String value, String needle) {
|
||||
return value.indexOf(needle);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int lastIndexOf(String value, String needle) {
|
||||
return value.lastIndexOf(needle);
|
||||
}
|
||||
@ZenMethod
|
||||
public static int indexOf(String value, String needle, int fromIndex) {
|
||||
return value.indexOf(needle, fromIndex);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int lastIndexOf(String value, String needle, int fromIndex) {
|
||||
return value.lastIndexOf(value, fromIndex);
|
||||
}
|
||||
@ZenMethod
|
||||
public static int lastIndexOf(String value, String needle) {
|
||||
return value.lastIndexOf(needle);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static int lastIndexOf(String value, String needle, int fromIndex) {
|
||||
return value.lastIndexOf(value, fromIndex);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 214 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user