mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
506 files changed
+11283
-36634
No files matched your search
@@ -0,0 +1,3 @@
|
||||
[submodule "ZenScript"]
|
||||
path = ZenScript
|
||||
url = https://github.com/CraftTweaker/ZenScript.git
|
||||
@@ -3,6 +3,7 @@ package minetweaker;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.client.IClient;
|
||||
import minetweaker.api.compat.*;
|
||||
import minetweaker.api.event.IEventManager;
|
||||
import minetweaker.api.formatting.IFormatter;
|
||||
import minetweaker.api.game.IGame;
|
||||
@@ -68,14 +69,10 @@ public class MineTweakerAPI {
|
||||
"Red",
|
||||
"Black"
|
||||
};
|
||||
|
||||
static {
|
||||
// List<Class> apiClasses = new ArrayList<Class>();
|
||||
// ClassRegistry.getClasses(apiClasses);
|
||||
//
|
||||
// for (Class cls : apiClasses) {
|
||||
// registerClass(cls);
|
||||
// }
|
||||
private static IJEIRecipeRegistry ijeiRecipeRegistry = new DummyJEIRecipeRegistry();
|
||||
|
||||
static {
|
||||
registerClassRegistry(ClassRegistry.class, "MT-API");
|
||||
|
||||
registerGlobalSymbol("logger", getJavaStaticGetterSymbol(MineTweakerAPI.class, "getLogger"));
|
||||
registerGlobalSymbol("recipes", getJavaStaticFieldSymbol(MineTweakerAPI.class, "recipes"));
|
||||
@@ -260,7 +257,7 @@ public class MineTweakerAPI {
|
||||
try {
|
||||
Method method = registryClass.getMethod("getClasses", List.class);
|
||||
if ((method.getModifiers() & Modifier.STATIC) == 0) {
|
||||
System.out.println("ERROR: getClasses method in " + registryClass.getName() + " isn't static");
|
||||
logError("ERROR: getClasses method in " + registryClass.getName() + " isn't static");
|
||||
} else {
|
||||
List<Class> classes = new ArrayList<Class>();
|
||||
method.invoke(null, classes);
|
||||
@@ -285,16 +282,16 @@ public class MineTweakerAPI {
|
||||
}
|
||||
|
||||
if (description != null)
|
||||
System.out.println("Loaded class registry: " + description);
|
||||
logInfo("Loaded class registry: " + description);
|
||||
}
|
||||
} catch (NoSuchMethodException ex) {
|
||||
|
||||
} catch (IllegalAccessException ex) {
|
||||
|
||||
} catch (InvocationTargetException ex) {
|
||||
|
||||
} 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.
|
||||
@@ -445,4 +442,12 @@ public class MineTweakerAPI {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -646,7 +646,7 @@ public class MineTweakerImplementationAPI {
|
||||
MineTweakerAPI.tweaker.rollback();
|
||||
if (MineTweakerAPI.server != null) {
|
||||
if (!MineTweakerAPI.server.isCommandAdded("minetweaker")) {
|
||||
server.addCommand("minetweaker", "", new String[]{"mt"}, new ICommandFunction() {
|
||||
server.addCommand("minetweaker", "", new String[]{"mt", "crafttweaker", "ct"}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length == 0) {
|
||||
|
||||
@@ -1,68 +1,62 @@
|
||||
/*
|
||||
* 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.api.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class BlockPatternOr implements IBlockPattern {
|
||||
private final IBlockPattern[] elements;
|
||||
|
||||
public BlockPatternOr(IBlockPattern[] elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
private final IBlockPattern[] elements;
|
||||
|
||||
public BlockPatternOr(IBlockPattern a, IBlockPattern b) {
|
||||
this.elements = new IBlockPattern[] { a, b };
|
||||
}
|
||||
public BlockPatternOr(IBlockPattern[] elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
List<IBlock> blocks = new ArrayList<IBlock>();
|
||||
for (IBlockPattern pattern : elements) {
|
||||
blocks.addAll(pattern.getBlocks());
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
public BlockPatternOr(IBlockPattern a, IBlockPattern b) {
|
||||
this.elements = new IBlockPattern[]{a, b};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
for (IBlockPattern pattern : elements) {
|
||||
if (pattern.matches(block))
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
List<IBlock> blocks = new ArrayList<>();
|
||||
for(IBlockPattern pattern : elements) {
|
||||
blocks.addAll(pattern.getBlocks());
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(pattern.matches(block))
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (IBlockPattern pattern : elements) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(" | ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
result.append(pattern.getDisplayName());
|
||||
}
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(" | ");
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
result.append(pattern.getDisplayName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(ArrayUtil.append(elements, pattern));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(ArrayUtil.append(elements, pattern));
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Block interface. Used to interact with blocks in the world.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlock")
|
||||
public interface IBlock extends IBlockPattern {
|
||||
/**
|
||||
* Gets the block definition.
|
||||
*
|
||||
* @return block definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
public IBlockDefinition getDefinition();
|
||||
|
||||
@ZenGetter("meta")
|
||||
public int getMeta();
|
||||
/**
|
||||
* Gets the block definition.
|
||||
*
|
||||
* @return block definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IBlockDefinition getDefinition();
|
||||
|
||||
@ZenGetter("data")
|
||||
public IData getTileData();
|
||||
@ZenGetter("meta")
|
||||
int getMeta();
|
||||
|
||||
@ZenGetter("data")
|
||||
IData getTileData();
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Blocks definitions provide additional information about blocks.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockDefinition")
|
||||
public interface IBlockDefinition {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -1,35 +1,25 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockPattern")
|
||||
public interface IBlockPattern {
|
||||
@ZenMethod("blocks")
|
||||
public List<IBlock> getBlocks();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean matches(IBlock block);
|
||||
@ZenMethod("blocks")
|
||||
List<IBlock> getBlocks();
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
public IBlockPattern or(IBlockPattern pattern);
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean matches(IBlock block);
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
@ZenOperator(OperatorType.OR)
|
||||
IBlockPattern or(IBlockPattern pattern);
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
package minetweaker.api.chat;
|
||||
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents a chat message. Strings can be converted into chat messages, and
|
||||
* chat messages can be colored and concatenated.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.chat.IChatMessage")
|
||||
public interface IChatMessage {
|
||||
/**
|
||||
* Concatenates two chat messages.
|
||||
*
|
||||
* @param other other chat message
|
||||
* @return concatenated chat message
|
||||
*/
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
public IChatMessage add(IChatMessage other);
|
||||
|
||||
/**
|
||||
* Retrieves the internal object backing this object. Must be generated by
|
||||
* the implementing platform.
|
||||
*
|
||||
* @return internal object
|
||||
*/
|
||||
public Object getInternal();
|
||||
|
||||
/**
|
||||
* Concatenates two chat messages.
|
||||
*
|
||||
* @param other other chat message
|
||||
*
|
||||
* @return concatenated chat message
|
||||
*/
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IChatMessage add(IChatMessage other);
|
||||
|
||||
/**
|
||||
* Retrieves the internal object backing this object. Must be generated by
|
||||
* the implementing platform.
|
||||
*
|
||||
* @return internal object
|
||||
*/
|
||||
Object getInternal();
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
package minetweaker.api.client;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Interface for client interaction. Only available on clients.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.api.IClient")
|
||||
public interface IClient {
|
||||
/**
|
||||
* Gets the current player.
|
||||
*
|
||||
* @return current player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("language")
|
||||
public String getLanguage();
|
||||
|
||||
/**
|
||||
* Gets the current player.
|
||||
*
|
||||
* @return current player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("language")
|
||||
String getLanguage();
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DummyJEIRecipeRegistry implements IJEIRecipeRegistry {
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object, String category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object output, String category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFurnace(List<Object> inputs, Object output) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFurnace(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFuel(Collection<Object> input, int burnTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFuel(Object object) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadItemList() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeItem(Object stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(Object stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateTooltips(IIngredient ingredient) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface IJEIRecipeRegistry {
|
||||
|
||||
void addRecipe(Object object);
|
||||
|
||||
void addRecipe(Object object, String category);
|
||||
|
||||
void removeRecipe(Object output);
|
||||
|
||||
void removeRecipe(Object output, String category);
|
||||
|
||||
|
||||
void addFurnace(List<Object> inputs, Object output);
|
||||
|
||||
void removeFurnace(Object output);
|
||||
|
||||
void addFuel(Collection<Object> input, int burnTime);
|
||||
|
||||
void removeFuel(Object object);
|
||||
|
||||
void invalidateTooltips(IIngredient ingredient);
|
||||
|
||||
//To update the items in 1.10.2
|
||||
void reloadItemList();
|
||||
|
||||
//To update the items in 1.11.2 both below are used
|
||||
void removeItem(Object stack);
|
||||
|
||||
void addItem(Object stack);
|
||||
}
|
||||
@@ -1,41 +1,41 @@
|
||||
package minetweaker.api.container;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Container interface.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.container.IContainer")
|
||||
public interface IContainer extends Iterable<IItemStack> {
|
||||
/**
|
||||
* Gets the container size.
|
||||
*
|
||||
* @return container size
|
||||
*/
|
||||
@ZenGetter("containerSize")
|
||||
public int getContainerSize();
|
||||
|
||||
/**
|
||||
* Gets the item stack at the given position. Returns null if there is no
|
||||
* stack at that position.
|
||||
*
|
||||
* @param i stack position
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack getStack(int i);
|
||||
/**
|
||||
* Gets the container size.
|
||||
*
|
||||
* @return container size
|
||||
*/
|
||||
@ZenGetter("containerSize")
|
||||
int getContainerSize();
|
||||
|
||||
/**
|
||||
* Sets the item stack at the given position.
|
||||
*
|
||||
* @param i stack position
|
||||
* @param stack contents, or null to set an empty stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public void setStack(int i, IItemStack stack);
|
||||
/**
|
||||
* Gets the item stack at the given position. Returns null if there is no
|
||||
* stack at that position.
|
||||
*
|
||||
* @param i stack position
|
||||
*
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Sets the item stack at the given position.
|
||||
*
|
||||
* @param i stack position
|
||||
* @param stack contents, or null to set an empty stack
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package minetweaker.api.damage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IDamageSource {
|
||||
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a boolean value (true or false).
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataBool implements IData {
|
||||
private final boolean value;
|
||||
|
||||
public DataBool(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final boolean value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return value;
|
||||
}
|
||||
public DataBool(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) (value ? 1 : 0);
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) (value ? 1 : 0);
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asBool() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asBool();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asBool() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot compare bool values");
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asBool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot compare bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromBool(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot add bool values");
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromBool(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract bool values");
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot add bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply bool values");
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide bool values");
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on bool values");
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataBool(value & other.asBool());
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataBool(value | other.asBool());
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataBool(value & other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataBool(value ^ other.asBool());
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataBool(value | other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a bool value");
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataBool(value ^ other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataBool(!value);
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a bool value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataBool(!value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a byte value (-128 .. 127)
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataByte implements IData {
|
||||
private final byte value;
|
||||
|
||||
public DataByte(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final byte value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a byte to a bool");
|
||||
}
|
||||
public DataByte(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a byte to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Byte.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Byte.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asByte() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asByte();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asByte() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Byte.compare(value, data.asByte());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Byte.compare(value, data.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByte(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataByte((byte) (value + other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataByte((byte) (value - other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataByte((byte) (value + other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataByte((byte) (value * other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataByte((byte) (value - other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataByte((byte) (value / other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataByte((byte) (value * other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataByte((byte) (value % other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataByte((byte) (value / other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataByte((byte) (value & other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataByte((byte) (value % other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataByte((byte) (value | other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataByte((byte) (value & other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataByte((byte) (value ^ other.asByte()));
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataByte((byte) (value | other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataByte((byte) (-value));
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataByte((byte) (value ^ other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataByte((byte) (~value));
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataByte((byte) (-value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte";
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataByte((byte) (~value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte";
|
||||
}
|
||||
}
|
||||
@@ -1,222 +1,220 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a byte array.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataByteArray implements IData {
|
||||
private final byte[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataByteArray(byte[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
private final byte[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
byte[] otherData = other.asByteArray();
|
||||
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataByteArray(result, immutable);
|
||||
}
|
||||
public DataByteArray(byte[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a byte array");
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
byte[] otherData = other.asByteArray();
|
||||
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataByteArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast an array to bool");
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot cast an array to byte");
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot cast an array to short");
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot cast an array to int");
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot cast an array to long");
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot cast an array to float");
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot cast an array to double");
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("[");
|
||||
boolean first = true;
|
||||
for (byte value : data) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
result.append(", ");
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
result.append(value);
|
||||
}
|
||||
result.append("] as byte[]");
|
||||
return result.toString();
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("[");
|
||||
boolean first = true;
|
||||
for(byte value : data) {
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
result.append(", ");
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for (byte value : data) {
|
||||
result.add(new DataByte(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
result.append(value);
|
||||
}
|
||||
result.append("] as byte[]");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for(byte value : data) {
|
||||
result.add(new DataByte(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[data.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataByte(data[i]);
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asByte();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataByte(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("byte[] doesn't have members");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set byte[] members");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("byte[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set byte[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asByteArray());
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByteArray(this.data);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte[]";
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByteArray(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte[]";
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a double-precision value.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataDouble implements IData {
|
||||
private final double value;
|
||||
|
||||
public DataDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final double value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a double to a bool");
|
||||
}
|
||||
public DataDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a double to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return (float) value;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return (float) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Double.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Double.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asDouble() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asDouble();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asDouble() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
return Double.compare(value, other.asDouble());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
return Double.compare(value, other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromDouble(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataDouble(value + other.asDouble());
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataDouble(value - other.asDouble());
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataDouble(value + other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataDouble(value * other.asDouble());
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataDouble(value - other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataDouble(value / other.asDouble());
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataDouble(value * other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataDouble(value % other.asDouble());
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataDouble(value / other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataDouble(value % other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataDouble(-value);
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataDouble(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a single-precision floating point value.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataFloat implements IData {
|
||||
private final float value;
|
||||
|
||||
public DataFloat(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final float value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a float to a bool");
|
||||
}
|
||||
public DataFloat(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a float to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Float.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Float.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asFloat() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asFloat();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asFloat() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Float.compare(value, data.asFloat());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Float.compare(value, data.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromFloat(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataFloat(value + other.asFloat());
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataFloat(value - other.asFloat());
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataFloat(value + other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataFloat(value * other.asFloat());
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataFloat(value - other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataFloat(value / other.asFloat());
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataFloat(value * other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataFloat(value % other.asFloat());
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataFloat(value / other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataFloat(value % other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataFloat(-value);
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataFloat(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as float";
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as float";
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 32-bit integer value.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataInt implements IData {
|
||||
private final int value;
|
||||
|
||||
public DataInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final int value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast an int to a bool");
|
||||
}
|
||||
public DataInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast an int to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asInt() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asInt();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asInt() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Integer.compare(value, data.asInt());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Integer.compare(value, data.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromInt(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataInt(value + other.asInt());
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataInt(value - other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataInt(value + other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataInt(value * other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataInt(value - other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataInt(value / other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataInt(value * other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataInt(value % other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataInt(value / other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataInt(value & other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataInt(value % other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataInt(value | other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataInt(value & other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataInt(value ^ other.asInt());
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataInt(value | other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataInt(-value);
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataInt(value ^ other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataInt(~value);
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataInt(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataInt(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an int array.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataIntArray implements IData {
|
||||
|
||||
private final int[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
@@ -112,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(", ");
|
||||
@@ -126,8 +124,8 @@ public class DataIntArray implements IData {
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for (int value : data) {
|
||||
List<IData> result = new ArrayList<>();
|
||||
for(int value : data) {
|
||||
result.add(new DataInt(value));
|
||||
}
|
||||
return result;
|
||||
@@ -141,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;
|
||||
@@ -159,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();
|
||||
@@ -198,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);
|
||||
|
||||
@@ -1,272 +1,271 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a list.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataList implements IData {
|
||||
private final List<IData> values;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataList(List<IData> values, boolean immutable) {
|
||||
this.values = values;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
private final List<IData> values;
|
||||
private final boolean immutable;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot convert a list to a bool");
|
||||
}
|
||||
public DataList(List<IData> values, boolean immutable) {
|
||||
this.values = values;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot convert a list to a byte");
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot convert a list to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot convert a list to a short");
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot convert a list to a byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot convert a list to an int");
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot convert a list to a short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot convert a list to a long");
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot convert a list to an int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot convert a list to a float");
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot convert a list to a long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot convert a list to a double");
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot convert a list to a float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
if (immutable) {
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot convert a list to a double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
if(immutable) {
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append('[');
|
||||
boolean first = true;
|
||||
for (IData value : values) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
output.append(", ");
|
||||
}
|
||||
output.append(value.toString());
|
||||
}
|
||||
output.append(']');
|
||||
return output.toString();
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
byte[] result = new byte[values.size()];
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asByte();
|
||||
}
|
||||
return result;
|
||||
} catch (IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append('[');
|
||||
boolean first = true;
|
||||
for(IData value : values) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
output.append(", ");
|
||||
}
|
||||
output.append(value.toString());
|
||||
}
|
||||
output.append(']');
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
try {
|
||||
int[] result = new int[values.size()];
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asInt();
|
||||
}
|
||||
return result;
|
||||
} catch (IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
byte[] result = new byte[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asByte();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return values.get(i);
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
try {
|
||||
int[] result = new int[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asInt();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("this list is immutable");
|
||||
} else {
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return values.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("this list is immutable");
|
||||
} else {
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return values.size();
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
List<IData> dataValues = data.asList();
|
||||
if (dataValues != null && containsList(dataValues))
|
||||
return true;
|
||||
@Override
|
||||
public int length() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
for (IData value : values) {
|
||||
if (value.contains(data))
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
List<IData> dataValues = data.asList();
|
||||
if(dataValues != null && containsList(dataValues))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
for(IData value : values) {
|
||||
if(value.contains(data))
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean containsList(List<IData> dataValues) {
|
||||
outer: for (IData dataValue : dataValues) {
|
||||
for (IData value : values) {
|
||||
if (value.contains(dataValue))
|
||||
continue outer;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
private boolean containsList(List<IData> dataValues) {
|
||||
outer:
|
||||
for(IData dataValue : dataValues) {
|
||||
for(IData value : values) {
|
||||
if(value.contains(dataValue))
|
||||
continue outer;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
List<IData> otherValues = data.asList();
|
||||
if (otherValues.size() != values.size())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
if (!values.get(i).equals(otherValues.get(i)))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
List<IData> otherValues = data.asList();
|
||||
if(otherValues.size() != values.size())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if(!values.get(i).equals(otherValues.get(i)))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare with a list");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
List<IData> copy = new ArrayList<IData>();
|
||||
for (IData value : values) {
|
||||
copy.add(value.immutable());
|
||||
}
|
||||
return new DataList(copy, true);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare with a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if (immutable)
|
||||
data = data.immutable();
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
List<IData> copy = new ArrayList<>();
|
||||
for(IData value : values) {
|
||||
copy.add(value.immutable());
|
||||
}
|
||||
return new DataList(copy, true);
|
||||
}
|
||||
}
|
||||
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
result.addAll(values);
|
||||
result.addAll(data.asList());
|
||||
return new DataList(result, immutable);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromList(values);
|
||||
}
|
||||
List<IData> result = new ArrayList<>();
|
||||
result.addAll(values);
|
||||
result.addAll(data.asList());
|
||||
return new DataList(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return update(other);
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromList(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a list");
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return update(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a list");
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a list");
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a list");
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a list");
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 64-bit long value.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataLong implements IData {
|
||||
private final long value;
|
||||
|
||||
public DataLong(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final long value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a long to a bool");
|
||||
}
|
||||
public DataLong(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a long to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Long.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Long.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asLong() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asLong();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asLong() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Long.compare(value, data.asLong());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Long.compare(value, data.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromLong(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataLong(value + other.asLong());
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataLong(value - other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataLong(value + other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataLong(value * other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataLong(value - other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataLong(value / other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataLong(value * other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataLong(value % other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataLong(value / other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataLong(value & other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataLong(value % other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataLong(value | other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataLong(value & other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataLong(value ^ other.asLong());
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataLong(value | other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataLong(-value);
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataLong(value ^ other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataLong(~value);
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataLong(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as long";
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataLong(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as long";
|
||||
}
|
||||
}
|
||||
@@ -1,302 +1,300 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a map, mapping strings to data elements.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataMap implements IData {
|
||||
public static final DataMap EMPTY = new DataMap(new HashMap<String, IData>(), true);
|
||||
|
||||
private final Map<String, IData> data;
|
||||
private final boolean immutable;
|
||||
public static final DataMap EMPTY = new DataMap(new HashMap<>(), true);
|
||||
|
||||
public DataMap(Map<String, IData> data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
private final Map<String, IData> data;
|
||||
private final boolean immutable;
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
public DataMap(Map<String, IData> data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (String key : otherMap.keySet()) {
|
||||
result.remove(key);
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(String key : otherMap.keySet()) {
|
||||
result.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply maps");
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide maps");
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo with maps");
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo with maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate maps.");
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate maps.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to bool");
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to byte");
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to short");
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to int");
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to long");
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to float");
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to double");
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('{');
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to double");
|
||||
}
|
||||
|
||||
if (isValidIdentifier(entry.getKey())) {
|
||||
result.append(entry.getKey());
|
||||
} else {
|
||||
result.append("\"").append(entry.getKey()).append("\"");
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('{');
|
||||
boolean first = true;
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
result.append(": ");
|
||||
result.append(entry.getValue().toString());
|
||||
}
|
||||
result.append('}');
|
||||
return result.toString();
|
||||
}
|
||||
if(isValidIdentifier(entry.getKey())) {
|
||||
result.append(entry.getKey());
|
||||
} else {
|
||||
result.append("\"").append(entry.getKey()).append("\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
result.append(": ");
|
||||
result.append(entry.getValue().toString());
|
||||
}
|
||||
result.append('}');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
if (immutable) {
|
||||
return Collections.unmodifiableMap(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
if(immutable) {
|
||||
return Collections.unmodifiableMap(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
return data.get(name);
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
if (immutable) {
|
||||
throw new UnsupportedOperationException("this map is not modifiable");
|
||||
} else {
|
||||
this.data.put(name, data);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
return data.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.size();
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("this map is not modifiable");
|
||||
} else {
|
||||
this.data.put(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if (data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if (dataMap == null)
|
||||
return false;
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if(data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if (!this.data.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if (!this.data.get(dataEntry.getKey()).contains(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if(!this.data.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if(!this.data.get(dataEntry.getKey()).contains(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare maps");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
if (this == data)
|
||||
return true;
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare maps");
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if (dataMap.size() != this.data.size())
|
||||
return false;
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
if(this == data)
|
||||
return true;
|
||||
|
||||
for (Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
|
||||
if (!dataMap.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if (!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap.size() != this.data.size())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
|
||||
if(!dataMap.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if(!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if (immutable) {
|
||||
return this;
|
||||
} else {
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().immutable());
|
||||
}
|
||||
return new DataMap(result, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if (immutable)
|
||||
data = data.immutable();
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().immutable());
|
||||
}
|
||||
return new DataMap(result, true);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, IData> result = new HashMap<String, IData>();
|
||||
for (Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromMap(data);
|
||||
}
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromMap(data);
|
||||
}
|
||||
|
||||
private boolean isValidIdentifier(String str) {
|
||||
if (!Character.isJavaIdentifierStart(str.charAt(0)))
|
||||
return false;
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
|
||||
for (int i = 1; i < str.length(); i++) {
|
||||
if (!Character.isJavaIdentifierPart(str.charAt(i)))
|
||||
return false;
|
||||
}
|
||||
private boolean isValidIdentifier(String str) {
|
||||
if(!Character.isJavaIdentifierStart(str.charAt(0)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(int i = 1; i < str.length(); i++) {
|
||||
if(!Character.isJavaIdentifierPart(str.charAt(i)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 16-bit short value.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataShort implements IData {
|
||||
private final short value;
|
||||
|
||||
public DataShort(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final short value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a short to a bool");
|
||||
}
|
||||
public DataShort(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a short to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Short.toString(value);
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return Short.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asShort() == value;
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asShort();
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asShort() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Short.compare(value, data.asShort());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Short.compare(value, data.asShort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromShort(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataShort((short) (value + other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataShort((short) (value - other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataShort((short) (value + other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataShort((short) (value * other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataShort((short) (value - other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataShort((short) (value / other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataShort((short) (value * other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataShort((short) (value % other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataShort((short) (value / other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataShort((short) (value & other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataShort((short) (value % other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataShort((short) (value | other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataShort((short) (value & other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataShort((short) (value ^ other.asShort()));
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataShort((short) (value | other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataShort((short) (-value));
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataShort((short) (value ^ other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataShort((short) (~value));
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataShort((short) (-value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as short";
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataShort((short) (~value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as short";
|
||||
}
|
||||
}
|
||||
@@ -1,191 +1,191 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a string value.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataString implements IData {
|
||||
private final String value;
|
||||
|
||||
public DataString(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
private final String value;
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
public DataString(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return Byte.parseByte(value);
|
||||
}
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return Short.parseShort(value);
|
||||
}
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return Byte.parseByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
@Override
|
||||
public short asShort() {
|
||||
return Short.parseShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
@Override
|
||||
public int asInt() {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
@Override
|
||||
public long asLong() {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String asString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataString(value.substring(i, i + 1));
|
||||
}
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataString(value.substring(i, i + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
if (name.equals("length")) {
|
||||
return new DataInt(value.length());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("no such member: " + name);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
if(name.equals("length")) {
|
||||
return new DataInt(value.length());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("no such member: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return value.length();
|
||||
}
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asString().equals(value);
|
||||
}
|
||||
@Override
|
||||
public int length() {
|
||||
return value.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value.equals(data.asString());
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asString().equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return value.compareTo(data.asString());
|
||||
}
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value.equals(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return value.compareTo(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromString(value);
|
||||
}
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataString(value + other.asString());
|
||||
}
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a string");
|
||||
}
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataString(value + other.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a string");
|
||||
}
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a string");
|
||||
}
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a string");
|
||||
}
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a string");
|
||||
}
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '\"' + value.replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '\"' + value.replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
}
|
||||
@@ -1,147 +1,141 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberSetter;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Generic data interface. A data element may contain any kind of basic data
|
||||
* element (bool, byte, short, int, long, float, double, string, list, map, int
|
||||
* array or byte array). Used to store data with stacks, blocks, world, ...
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.data.IData")
|
||||
public interface IData {
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
public IData add(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.SUB)
|
||||
public IData sub(IData other);
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IData add(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
public IData mul(IData other);
|
||||
@ZenOperator(OperatorType.SUB)
|
||||
IData sub(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.DIV)
|
||||
public IData div(IData other);
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
IData mul(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
public IData mod(IData other);
|
||||
@ZenOperator(OperatorType.DIV)
|
||||
IData div(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.AND)
|
||||
public IData and(IData other);
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
IData mod(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
public IData or(IData other);
|
||||
@ZenOperator(OperatorType.AND)
|
||||
IData and(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.XOR)
|
||||
public IData xor(IData other);
|
||||
@ZenOperator(OperatorType.OR)
|
||||
IData or(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.NEG)
|
||||
public IData neg();
|
||||
@ZenOperator(OperatorType.XOR)
|
||||
IData xor(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.NOT)
|
||||
public IData not();
|
||||
@ZenOperator(OperatorType.NEG)
|
||||
IData neg();
|
||||
|
||||
@ZenCaster
|
||||
public boolean asBool();
|
||||
@ZenOperator(OperatorType.NOT)
|
||||
IData not();
|
||||
|
||||
@ZenCaster
|
||||
public byte asByte();
|
||||
@ZenCaster
|
||||
boolean asBool();
|
||||
|
||||
@ZenCaster
|
||||
public short asShort();
|
||||
@ZenCaster
|
||||
byte asByte();
|
||||
|
||||
@ZenCaster
|
||||
public int asInt();
|
||||
@ZenCaster
|
||||
short asShort();
|
||||
|
||||
@ZenCaster
|
||||
public long asLong();
|
||||
@ZenCaster
|
||||
int asInt();
|
||||
|
||||
@ZenCaster
|
||||
public float asFloat();
|
||||
@ZenCaster
|
||||
long asLong();
|
||||
|
||||
@ZenCaster
|
||||
public double asDouble();
|
||||
@ZenCaster
|
||||
float asFloat();
|
||||
|
||||
@ZenCaster
|
||||
public String asString();
|
||||
@ZenCaster
|
||||
double asDouble();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a List. Returns null if this value
|
||||
* cannot be converted to a list.
|
||||
*
|
||||
* @return list data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
public List<IData> asList();
|
||||
@ZenCaster
|
||||
String asString();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a Map. Returns null if this value
|
||||
* cannot be converted to a map.
|
||||
*
|
||||
* @return map data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
public Map<String, IData> asMap();
|
||||
/**
|
||||
* Attempts to convert this value to a List. Returns null if this value
|
||||
* cannot be converted to a list.
|
||||
*
|
||||
* @return list data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
List<IData> asList();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a byte array. Returns null if this
|
||||
* value cannot be converted to a byte array.
|
||||
*
|
||||
* @return byte array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
public byte[] asByteArray();
|
||||
/**
|
||||
* Attempts to convert this value to a Map. Returns null if this value
|
||||
* cannot be converted to a map.
|
||||
*
|
||||
* @return map data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
Map<String, IData> asMap();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to an int array. Returns null if this
|
||||
* value cannot be converted to an int array.
|
||||
*
|
||||
* @return int array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
public int[] asIntArray();
|
||||
/**
|
||||
* Attempts to convert this value to a byte array. Returns null if this
|
||||
* value cannot be converted to a byte array.
|
||||
*
|
||||
* @return byte array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
byte[] asByteArray();
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
public IData getAt(int i);
|
||||
/**
|
||||
* Attempts to convert this value to an int array. Returns null if this
|
||||
* value cannot be converted to an int array.
|
||||
*
|
||||
* @return int array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
int[] asIntArray();
|
||||
|
||||
@ZenOperator(OperatorType.INDEXSET)
|
||||
public void setAt(int i, IData value);
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
IData getAt(int i);
|
||||
|
||||
@ZenMemberGetter
|
||||
public IData memberGet(String name);
|
||||
@ZenOperator(OperatorType.INDEXSET)
|
||||
void setAt(int i, IData value);
|
||||
|
||||
@ZenMemberSetter
|
||||
public void memberSet(String name, IData data);
|
||||
@ZenMemberGetter
|
||||
IData memberGet(String name);
|
||||
|
||||
@ZenGetter
|
||||
public int length();
|
||||
@ZenMemberSetter
|
||||
void memberSet(String name, IData data);
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean contains(IData data);
|
||||
@ZenGetter
|
||||
int length();
|
||||
|
||||
@ZenOperator(OperatorType.COMPARE)
|
||||
public int compareTo(IData data);
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.EQUALS)
|
||||
public boolean equals(IData data);
|
||||
@ZenOperator(OperatorType.COMPARE)
|
||||
int compareTo(IData data);
|
||||
|
||||
@ZenGetter
|
||||
public IData immutable();
|
||||
@ZenOperator(OperatorType.EQUALS)
|
||||
boolean equals(IData data);
|
||||
|
||||
@ZenMethod
|
||||
public IData update(IData data);
|
||||
@ZenGetter
|
||||
IData immutable();
|
||||
|
||||
public <T> T convert(IDataConverter<T> converter);
|
||||
@ZenMethod
|
||||
IData update(IData data);
|
||||
|
||||
@Override
|
||||
public String toString();
|
||||
<T> T convert(IDataConverter<T> converter);
|
||||
|
||||
@Override
|
||||
String toString();
|
||||
}
|
||||
@@ -1,36 +1,37 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Data converter interface. Used to convert data elements to other types.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*
|
||||
* @param <T> output type
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IDataConverter<T> {
|
||||
public T fromBool(boolean value);
|
||||
|
||||
public T fromByte(byte value);
|
||||
T fromBool(boolean value);
|
||||
|
||||
public T fromShort(short value);
|
||||
T fromByte(byte value);
|
||||
|
||||
public T fromInt(int value);
|
||||
T fromShort(short value);
|
||||
|
||||
public T fromLong(long value);
|
||||
T fromInt(int value);
|
||||
|
||||
public T fromFloat(float value);
|
||||
T fromLong(long value);
|
||||
|
||||
public T fromDouble(double value);
|
||||
T fromFloat(float value);
|
||||
|
||||
public T fromString(String value);
|
||||
T fromDouble(double value);
|
||||
|
||||
public T fromList(List<IData> values);
|
||||
T fromString(String value);
|
||||
|
||||
public T fromMap(Map<String, IData> values);
|
||||
T fromList(List<IData> values);
|
||||
|
||||
public T fromByteArray(byte[] value);
|
||||
T fromMap(Map<String, IData> values);
|
||||
|
||||
public T fromIntArray(int[] value);
|
||||
T fromByteArray(byte[] value);
|
||||
|
||||
T fromIntArray(int[] value);
|
||||
}
|
||||
@@ -6,12 +6,11 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IllegalDataException extends RuntimeException
|
||||
{
|
||||
public IllegalDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public class IllegalDataException extends RuntimeException {
|
||||
|
||||
public IllegalDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -2,65 +2,64 @@ package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.util.Position3f;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Entity interface. Used to obtain information about entities, and modify their
|
||||
* data. Entities are any item that is freely movable in the world, such as
|
||||
* players, monsters, items on the ground, ...
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntity")
|
||||
public interface IEntity {
|
||||
/**
|
||||
* Retrieves the dimension this entity is in.
|
||||
*
|
||||
* @return current dimension of this entity
|
||||
*/
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension();
|
||||
|
||||
/**
|
||||
* Retrieves the x position of this entity.
|
||||
*
|
||||
* @return entity x position
|
||||
*/
|
||||
@ZenGetter("x")
|
||||
public float getX();
|
||||
/**
|
||||
* Retrieves the dimension this entity is in.
|
||||
*
|
||||
* @return current dimension of this entity
|
||||
*/
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
|
||||
/**
|
||||
* Retrieves the y position of this entity.
|
||||
*
|
||||
* @return entity y position
|
||||
*/
|
||||
@ZenGetter("y")
|
||||
public float getY();
|
||||
/**
|
||||
* Retrieves the x position of this entity.
|
||||
*
|
||||
* @return entity x position
|
||||
*/
|
||||
@ZenGetter("x")
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Retrieves the z position of this entity.
|
||||
*
|
||||
* @return entity z position
|
||||
*/
|
||||
@ZenGetter("z")
|
||||
public float getZ();
|
||||
/**
|
||||
* Retrieves the y position of this entity.
|
||||
*
|
||||
* @return entity y position
|
||||
*/
|
||||
@ZenGetter("y")
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Retrieves the position of this entity.
|
||||
*
|
||||
* @return entity position
|
||||
*/
|
||||
@ZenGetter("position")
|
||||
public Position3f getPosition();
|
||||
/**
|
||||
* Retrieves the z position of this entity.
|
||||
*
|
||||
* @return entity z position
|
||||
*/
|
||||
@ZenGetter("z")
|
||||
float getZ();
|
||||
|
||||
/**
|
||||
* Sets the position of this entity. Instantly moves (teleports) the entity
|
||||
* to that position.
|
||||
*
|
||||
* @param position entity position
|
||||
*/
|
||||
@ZenSetter("position")
|
||||
public void setPosition(Position3f position);
|
||||
/**
|
||||
* Retrieves the position of this entity.
|
||||
*
|
||||
* @return entity position
|
||||
*/
|
||||
@ZenGetter("position")
|
||||
Position3f getPosition();
|
||||
|
||||
/**
|
||||
* Sets the position of this entity. Instantly moves (teleports) the entity
|
||||
* to that position.
|
||||
*
|
||||
* @param position entity position
|
||||
*/
|
||||
@ZenSetter("position")
|
||||
void setPosition(Position3f position);
|
||||
}
|
||||
@@ -1,23 +1,38 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
import stanhebben.zenscript.value.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntityDefinition")
|
||||
public interface IEntityDefinition {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@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();
|
||||
|
||||
}
|
||||
@@ -6,15 +6,16 @@ import stanhebben.zenscript.annotations.ZenGetter;
|
||||
/**
|
||||
* Represents an item entity. Item entities are entities representing an item
|
||||
* stack on the ground (or flying through the air).
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IEntityItem extends IEntity {
|
||||
/**
|
||||
* Gets the entity item.
|
||||
*
|
||||
* @return entity item
|
||||
*/
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem();
|
||||
|
||||
/**
|
||||
* Gets the entity item.
|
||||
*
|
||||
* @return entity item
|
||||
*/
|
||||
@ZenGetter("item")
|
||||
IItemStack getItem();
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents an xp orb.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntityXp")
|
||||
public interface IEntityXp extends IEntity {
|
||||
/**
|
||||
* Gets the amount of xp in this orb.
|
||||
*
|
||||
* @return xp amount
|
||||
*/
|
||||
@ZenGetter("xp")
|
||||
public float getXp();
|
||||
|
||||
/**
|
||||
* Gets the amount of xp in this orb.
|
||||
*
|
||||
* @return xp amount
|
||||
*/
|
||||
@ZenGetter("xp")
|
||||
float getXp();
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.io.Closeable;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Represents an event handle. Event handles are used to cancel event listeners.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IEventHandler")
|
||||
public interface IEventHandle extends Closeable {
|
||||
/**
|
||||
* Closes the event listener (stops listening and unregisters the listener).
|
||||
*/
|
||||
@ZenMethod
|
||||
@Override
|
||||
public void close();
|
||||
|
||||
/**
|
||||
* Closes the event listener (stops listening and unregisters the listener).
|
||||
*/
|
||||
@ZenMethod
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
@@ -4,93 +4,94 @@ import minetweaker.util.IEventHandler;
|
||||
|
||||
/**
|
||||
* 37 kinds of event handlers!
|
||||
*
|
||||
* <p>
|
||||
* NOTE: not all of these are implemented yet, but will be later on.
|
||||
*
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IEventManager {
|
||||
// implemented
|
||||
public IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev);
|
||||
|
||||
// implemented
|
||||
public IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev);
|
||||
|
||||
public IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev);
|
||||
|
||||
// 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);
|
||||
|
||||
/*
|
||||
* public IEventHandle
|
||||
* IEventHandle
|
||||
* onPlayerUseItemStop(IEventHandler<PlayerUseItemStopEvent> ev);
|
||||
*
|
||||
* public IEventHandle
|
||||
* IEventHandle
|
||||
* onPlayerUseItemFinish(IPlayerUserItemFinishEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onPlayerChat(IPlayerChatEventHandler ev);
|
||||
* IEventHandle onPlayerChat(IPlayerChatEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onTimerSingle(int millis, ITimerEventHandler ev);
|
||||
* IEventHandle onTimerSingle(int millis, ITimerEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onTimerRepeat(int millis, ITimerEventHandler ev);
|
||||
* IEventHandle onTimerRepeat(int millis, ITimerEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onEntityJoinWorld(IEntityJoinWorldEventHandler ev);
|
||||
* IEventHandle onEntityJoinWorld(IEntityJoinWorldEventHandler ev);
|
||||
*
|
||||
* public IEventHandle
|
||||
* IEventHandle
|
||||
* onEntityStruckByLightning(IEntityStruckByLightningEventHandler ev);
|
||||
*
|
||||
* public IEventHandle
|
||||
* IEventHandle
|
||||
* onLivingEnderTeleport(ILivingEnderTeleportEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onLivingAttackEvent(ILivingAttackEventHandler ev);
|
||||
* IEventHandle onLivingAttackEvent(ILivingAttackEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onLivingDeathEvent(ILivingDeathEventHandler ev);
|
||||
* IEventHandle onLivingDeathEvent(ILivingDeathEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onLivingJumpEvent(ILivingJumpEventHandler ev);
|
||||
* IEventHandle onLivingJumpEvent(ILivingJumpEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onLivingFallEvent(ILivingFallEventHandler ev);
|
||||
* IEventHandle onLivingFallEvent(ILivingFallEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onLivingHurtEvent(ILivingHurtEventHandler ev);
|
||||
* IEventHandle onLivingHurtEvent(ILivingHurtEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onLivingDeathDropsEvent(ILivingDeathDropsEventHandler
|
||||
* IEventHandle onLivingDeathDropsEvent(ILivingDeathDropsEventHandler
|
||||
* ev);
|
||||
*
|
||||
* public IEventHandle onItemTossed(IItemTossedEventHandler ev);
|
||||
* IEventHandle onItemTossed(IItemTossedEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onItemExpired(IItemExpiredEventHandler ev);
|
||||
* IEventHandle onItemExpired(IItemExpiredEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onMinecartCollision(IMinecartCollisionEventHandler
|
||||
* IEventHandle onMinecartCollision(IMinecartCollisionEventHandler
|
||||
* ev);
|
||||
*
|
||||
* public IEventHandle onMinecartInteract(IMinecartInteractEventHandler ev);
|
||||
* IEventHandle onMinecartInteract(IMinecartInteractEventHandler ev);
|
||||
*
|
||||
* public IEventHandle onCommand(ICommandEventHandler ev);
|
||||
* IEventHandle onCommand(ICommandEventHandler ev);
|
||||
*/
|
||||
}
|
||||
@@ -1,417 +1,391 @@
|
||||
/*
|
||||
* 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.api.event;
|
||||
|
||||
import minetweaker.util.EventList;
|
||||
import minetweaker.util.IEventHandler;
|
||||
import minetweaker.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTEventManager implements IEventManager {
|
||||
public void clear() {
|
||||
elPlayerCrafted.clear();
|
||||
elPlayerSmelted.clear();
|
||||
elPlayerChangedDimension.clear();
|
||||
elPlayerLoggedIn.clear();
|
||||
elPlayerLoggedOut.clear();
|
||||
elPlayerRespawn.clear();
|
||||
elPlayerAttackEntity.clear();
|
||||
elPlayerBonemeal.clear();
|
||||
elPlayerInteractEntity.clear();
|
||||
elPlayerPickup.clear();
|
||||
elPlayerPickupItem.clear();
|
||||
elPlayerFillBucket.clear();
|
||||
elPlayerDeathDrops.clear();
|
||||
elPlayerInteract.clear();
|
||||
elPlayerOpenContainer.clear();
|
||||
elPlayerPickupXp.clear();
|
||||
elPlayerSleepInBed.clear();
|
||||
elPlayerUseHoe.clear();
|
||||
elPlayerUseItemStart.clear();
|
||||
elPlayerUseItemTick.clear();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
|
||||
private final EventList<PlayerCraftedEvent> elPlayerCrafted = new EventList<PlayerCraftedEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev) {
|
||||
return elPlayerCrafted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerCrafted() {
|
||||
return elPlayerCrafted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerCrafted(PlayerCraftedEvent event) {
|
||||
elPlayerCrafted.publish(event);
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerSmeltedEvent ###
|
||||
// ##########################
|
||||
|
||||
private final EventList<PlayerSmeltedEvent> elPlayerSmelted = new EventList<PlayerSmeltedEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev) {
|
||||
return elPlayerSmelted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSmelted() {
|
||||
return elPlayerSmelted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSmelted(PlayerSmeltedEvent event) {
|
||||
elPlayerSmelted.publish(event);
|
||||
}
|
||||
|
||||
// ###################################
|
||||
// ### PlayerChangedDimensionEvent ###
|
||||
// ###################################
|
||||
|
||||
private final EventList<PlayerChangedDimensionEvent> elPlayerChangedDimension = new EventList<PlayerChangedDimensionEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev) {
|
||||
return elPlayerChangedDimension.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerChangedDimension() {
|
||||
return elPlayerChangedDimension.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
elPlayerChangedDimension.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerLoggedInEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerLoggedInEvent> elPlayerLoggedIn = new EventList<PlayerLoggedInEvent>();
|
||||
|
||||
public IEventHandle onPlayerLoggedIn(IEventHandler<PlayerLoggedInEvent> ev) {
|
||||
return elPlayerLoggedIn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedIn() {
|
||||
return elPlayerLoggedIn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedIn(PlayerLoggedInEvent event) {
|
||||
elPlayerLoggedIn.publish(event);
|
||||
}
|
||||
|
||||
// ############################
|
||||
// ### PlayerLoggedOutEvent ###
|
||||
// ############################
|
||||
|
||||
private final EventList<PlayerLoggedOutEvent> elPlayerLoggedOut = new EventList<PlayerLoggedOutEvent>();
|
||||
|
||||
public IEventHandle onPlayerLoggedOut(IEventHandler<PlayerLoggedOutEvent> ev) {
|
||||
return elPlayerLoggedOut.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedOut() {
|
||||
return elPlayerLoggedOut.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedOut(PlayerLoggedOutEvent event) {
|
||||
elPlayerLoggedOut.publish(event);
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerRespawnEvent ###
|
||||
// ##########################
|
||||
|
||||
private final EventList<PlayerRespawnEvent> elPlayerRespawn = new EventList<PlayerRespawnEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev) {
|
||||
return elPlayerRespawn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerRespawn() {
|
||||
return elPlayerRespawn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerRespawn(PlayerRespawnEvent event) {
|
||||
elPlayerRespawn.publish(event);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerAttackEntityEvent ###
|
||||
// ###############################
|
||||
|
||||
private final EventList<PlayerAttackEntityEvent> elPlayerAttackEntity = new EventList<PlayerAttackEntityEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev) {
|
||||
return elPlayerAttackEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerAttackEntity() {
|
||||
return elPlayerAttackEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerAttackEntity(PlayerAttackEntityEvent event) {
|
||||
elPlayerAttackEntity.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerBonemealEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerBonemealEvent> elPlayerBonemeal = new EventList<PlayerBonemealEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev) {
|
||||
return elPlayerBonemeal.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerBonemeal() {
|
||||
return elPlayerBonemeal.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerBonemeal(PlayerBonemealEvent event) {
|
||||
elPlayerBonemeal.publish(event);
|
||||
}
|
||||
|
||||
// #################################
|
||||
// ### PlayerInteractEntityEvent ###
|
||||
// #################################
|
||||
|
||||
private final EventList<PlayerInteractEntityEvent> elPlayerInteractEntity = new EventList<PlayerInteractEntityEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev) {
|
||||
return elPlayerInteractEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteractEntity() {
|
||||
return elPlayerInteractEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
elPlayerInteractEntity.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerPickupEvent ###
|
||||
// #########################
|
||||
|
||||
private final EventList<PlayerPickupEvent> elPlayerPickup = new EventList<PlayerPickupEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev) {
|
||||
return elPlayerPickup.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickup() {
|
||||
return elPlayerPickup.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupEvent event) {
|
||||
elPlayerPickup.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerPickupItemEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerPickupItemEvent> elPlayerPickupItem = new EventList<PlayerPickupItemEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev) {
|
||||
return elPlayerPickupItem.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupItem() {
|
||||
return elPlayerPickupItem.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
elPlayerPickupItem.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerFillBucketEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerFillBucketEvent> elPlayerFillBucket = new EventList<PlayerFillBucketEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev) {
|
||||
return elPlayerFillBucket.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerFillBucket() {
|
||||
return elPlayerFillBucket.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerFillBucket(PlayerFillBucketEvent event) {
|
||||
elPlayerFillBucket.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerDeathDropsEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerDeathDropsEvent> elPlayerDeathDrops = new EventList<PlayerDeathDropsEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev) {
|
||||
return elPlayerDeathDrops.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerDeathDrops() {
|
||||
return elPlayerDeathDrops.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerDeathDrops(PlayerDeathDropsEvent event) {
|
||||
elPlayerDeathDrops.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerInteractEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerInteractEvent> elPlayerInteract = new EventList<PlayerInteractEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev) {
|
||||
return elPlayerInteract.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteract() {
|
||||
return elPlayerInteract.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteract(PlayerInteractEvent event) {
|
||||
elPlayerInteract.publish(event);
|
||||
}
|
||||
|
||||
// ################################
|
||||
// ### PlayerOpenContainerEvent ###
|
||||
// ################################
|
||||
|
||||
private final EventList<PlayerOpenContainerEvent> elPlayerOpenContainer = new EventList<PlayerOpenContainerEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev) {
|
||||
return elPlayerOpenContainer.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerOpenContainer() {
|
||||
return elPlayerOpenContainer.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerOpenContainer(PlayerOpenContainerEvent event) {
|
||||
elPlayerOpenContainer.publish(event);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerPickupXpEvent ###
|
||||
// ###########################
|
||||
|
||||
private final EventList<PlayerPickupXpEvent> elPlayerPickupXp = new EventList<PlayerPickupXpEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev) {
|
||||
return elPlayerPickupXp.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupXp() {
|
||||
return elPlayerPickupXp.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupXpEvent event) {
|
||||
elPlayerPickupXp.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerSleepInBedEvent ###
|
||||
// #############################
|
||||
|
||||
private final EventList<PlayerSleepInBedEvent> elPlayerSleepInBed = new EventList<PlayerSleepInBedEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev) {
|
||||
return elPlayerSleepInBed.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSleepInBed() {
|
||||
return elPlayerSleepInBed.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSleepInBed(PlayerSleepInBedEvent event) {
|
||||
elPlayerSleepInBed.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerUseHoeEvent ###
|
||||
// #########################
|
||||
|
||||
private final EventList<PlayerUseHoeEvent> elPlayerUseHoe = new EventList<PlayerUseHoeEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev) {
|
||||
return elPlayerUseHoe.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseHoe() {
|
||||
return elPlayerUseHoe.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseHoe(PlayerUseHoeEvent event) {
|
||||
elPlayerUseHoe.publish(event);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerUseItemStartEvent ###
|
||||
// ###############################
|
||||
|
||||
private final EventList<PlayerUseItemStartEvent> elPlayerUseItemStart = new EventList<PlayerUseItemStartEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev) {
|
||||
return elPlayerUseItemStart.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemStart() {
|
||||
return elPlayerUseItemStart.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemStart(PlayerUseItemStartEvent event) {
|
||||
elPlayerUseItemStart.publish(event);
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### PlayerUseItemTickEvent ###
|
||||
// ##############################
|
||||
|
||||
private final EventList<PlayerUseItemTickEvent> elPlayerUseItemTick = new EventList<PlayerUseItemTickEvent>();
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev) {
|
||||
return elPlayerUseItemTick.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemTick() {
|
||||
return elPlayerUseItemTick.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemTick(PlayerUseItemTickEvent event) {
|
||||
elPlayerUseItemTick.publish(event);
|
||||
}
|
||||
private final EventList<PlayerCraftedEvent> elPlayerCrafted = new EventList<PlayerCraftedEvent>();
|
||||
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
private final EventList<PlayerSmeltedEvent> elPlayerSmelted = new EventList<PlayerSmeltedEvent>();
|
||||
private final EventList<PlayerChangedDimensionEvent> elPlayerChangedDimension = new EventList<PlayerChangedDimensionEvent>();
|
||||
private final EventList<PlayerLoggedInEvent> elPlayerLoggedIn = new EventList<PlayerLoggedInEvent>();
|
||||
private final EventList<PlayerLoggedOutEvent> elPlayerLoggedOut = new EventList<PlayerLoggedOutEvent>();
|
||||
|
||||
// ##########################
|
||||
// ### PlayerSmeltedEvent ###
|
||||
// ##########################
|
||||
private final EventList<PlayerRespawnEvent> elPlayerRespawn = new EventList<PlayerRespawnEvent>();
|
||||
private final EventList<PlayerAttackEntityEvent> elPlayerAttackEntity = new EventList<PlayerAttackEntityEvent>();
|
||||
private final EventList<PlayerBonemealEvent> elPlayerBonemeal = new EventList<PlayerBonemealEvent>();
|
||||
private final EventList<PlayerInteractEntityEvent> elPlayerInteractEntity = new EventList<PlayerInteractEntityEvent>();
|
||||
|
||||
// ###################################
|
||||
// ### PlayerChangedDimensionEvent ###
|
||||
// ###################################
|
||||
private final EventList<PlayerPickupEvent> elPlayerPickup = new EventList<PlayerPickupEvent>();
|
||||
private final EventList<PlayerPickupItemEvent> elPlayerPickupItem = new EventList<PlayerPickupItemEvent>();
|
||||
private final EventList<PlayerFillBucketEvent> elPlayerFillBucket = new EventList<PlayerFillBucketEvent>();
|
||||
private final EventList<PlayerDeathDropsEvent> elPlayerDeathDrops = new EventList<PlayerDeathDropsEvent>();
|
||||
|
||||
// ###########################
|
||||
// ### PlayerLoggedInEvent ###
|
||||
// ###########################
|
||||
private final EventList<PlayerInteractEvent> elPlayerInteract = new EventList<PlayerInteractEvent>();
|
||||
private final EventList<PlayerOpenContainerEvent> elPlayerOpenContainer = new EventList<PlayerOpenContainerEvent>();
|
||||
private final EventList<PlayerPickupXpEvent> elPlayerPickupXp = new EventList<PlayerPickupXpEvent>();
|
||||
private final EventList<PlayerSleepInBedEvent> elPlayerSleepInBed = new EventList<PlayerSleepInBedEvent>();
|
||||
|
||||
// ############################
|
||||
// ### PlayerLoggedOutEvent ###
|
||||
// ############################
|
||||
private final EventList<PlayerUseHoeEvent> elPlayerUseHoe = new EventList<PlayerUseHoeEvent>();
|
||||
private final EventList<PlayerUseItemStartEvent> elPlayerUseItemStart = new EventList<PlayerUseItemStartEvent>();
|
||||
private final EventList<PlayerUseItemTickEvent> elPlayerUseItemTick = new EventList<PlayerUseItemTickEvent>();
|
||||
|
||||
public void clear() {
|
||||
elPlayerCrafted.clear();
|
||||
elPlayerSmelted.clear();
|
||||
elPlayerChangedDimension.clear();
|
||||
elPlayerLoggedIn.clear();
|
||||
elPlayerLoggedOut.clear();
|
||||
elPlayerRespawn.clear();
|
||||
elPlayerAttackEntity.clear();
|
||||
elPlayerBonemeal.clear();
|
||||
elPlayerInteractEntity.clear();
|
||||
elPlayerPickup.clear();
|
||||
elPlayerPickupItem.clear();
|
||||
elPlayerFillBucket.clear();
|
||||
elPlayerDeathDrops.clear();
|
||||
elPlayerInteract.clear();
|
||||
elPlayerOpenContainer.clear();
|
||||
elPlayerPickupXp.clear();
|
||||
elPlayerSleepInBed.clear();
|
||||
elPlayerUseHoe.clear();
|
||||
elPlayerUseItemStart.clear();
|
||||
elPlayerUseItemTick.clear();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerRespawnEvent ###
|
||||
// ##########################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev) {
|
||||
return elPlayerCrafted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerCrafted() {
|
||||
return elPlayerCrafted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerCrafted(PlayerCraftedEvent event) {
|
||||
elPlayerCrafted.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev) {
|
||||
return elPlayerSmelted.add(ev);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerAttackEntityEvent ###
|
||||
// ###############################
|
||||
|
||||
public boolean hasPlayerSmelted() {
|
||||
return elPlayerSmelted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSmelted(PlayerSmeltedEvent event) {
|
||||
elPlayerSmelted.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev) {
|
||||
return elPlayerChangedDimension.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerChangedDimension() {
|
||||
return elPlayerChangedDimension.hasHandlers();
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerBonemealEvent ###
|
||||
// ###########################
|
||||
|
||||
public void publishPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
elPlayerChangedDimension.publish(event);
|
||||
}
|
||||
|
||||
public IEventHandle onPlayerLoggedIn(IEventHandler<PlayerLoggedInEvent> ev) {
|
||||
return elPlayerLoggedIn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedIn() {
|
||||
return elPlayerLoggedIn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedIn(PlayerLoggedInEvent event) {
|
||||
elPlayerLoggedIn.publish(event);
|
||||
}
|
||||
|
||||
// #################################
|
||||
// ### PlayerInteractEntityEvent ###
|
||||
// #################################
|
||||
|
||||
public IEventHandle onPlayerLoggedOut(IEventHandler<PlayerLoggedOutEvent> ev) {
|
||||
return elPlayerLoggedOut.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedOut() {
|
||||
return elPlayerLoggedOut.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedOut(PlayerLoggedOutEvent event) {
|
||||
elPlayerLoggedOut.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev) {
|
||||
return elPlayerRespawn.add(ev);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerPickupEvent ###
|
||||
// #########################
|
||||
|
||||
public boolean hasPlayerRespawn() {
|
||||
return elPlayerRespawn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerRespawn(PlayerRespawnEvent event) {
|
||||
elPlayerRespawn.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev) {
|
||||
return elPlayerAttackEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerAttackEntity() {
|
||||
return elPlayerAttackEntity.hasHandlers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerPickupItemEvent ###
|
||||
// #############################
|
||||
|
||||
public void publishPlayerAttackEntity(PlayerAttackEntityEvent event) {
|
||||
elPlayerAttackEntity.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev) {
|
||||
return elPlayerBonemeal.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerBonemeal() {
|
||||
return elPlayerBonemeal.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerBonemeal(PlayerBonemealEvent event) {
|
||||
elPlayerBonemeal.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerFillBucketEvent ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev) {
|
||||
return elPlayerInteractEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteractEntity() {
|
||||
return elPlayerInteractEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
elPlayerInteractEntity.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev) {
|
||||
return elPlayerPickup.add(ev);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerDeathDropsEvent ###
|
||||
// #############################
|
||||
|
||||
public boolean hasPlayerPickup() {
|
||||
return elPlayerPickup.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupEvent event) {
|
||||
elPlayerPickup.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev) {
|
||||
return elPlayerPickupItem.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupItem() {
|
||||
return elPlayerPickupItem.hasHandlers();
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerInteractEvent ###
|
||||
// ###########################
|
||||
|
||||
public void publishPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
elPlayerPickupItem.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev) {
|
||||
return elPlayerFillBucket.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerFillBucket() {
|
||||
return elPlayerFillBucket.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerFillBucket(PlayerFillBucketEvent event) {
|
||||
elPlayerFillBucket.publish(event);
|
||||
}
|
||||
|
||||
// ################################
|
||||
// ### PlayerOpenContainerEvent ###
|
||||
// ################################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev) {
|
||||
return elPlayerDeathDrops.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerDeathDrops() {
|
||||
return elPlayerDeathDrops.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerDeathDrops(PlayerDeathDropsEvent event) {
|
||||
elPlayerDeathDrops.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev) {
|
||||
return elPlayerInteract.add(ev);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerPickupXpEvent ###
|
||||
// ###########################
|
||||
|
||||
public boolean hasPlayerInteract() {
|
||||
return elPlayerInteract.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteract(PlayerInteractEvent event) {
|
||||
elPlayerInteract.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev) {
|
||||
return elPlayerOpenContainer.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerOpenContainer() {
|
||||
return elPlayerOpenContainer.hasHandlers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerSleepInBedEvent ###
|
||||
// #############################
|
||||
|
||||
public void publishPlayerOpenContainer(PlayerOpenContainerEvent event) {
|
||||
elPlayerOpenContainer.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev) {
|
||||
return elPlayerPickupXp.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupXp() {
|
||||
return elPlayerPickupXp.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupXpEvent event) {
|
||||
elPlayerPickupXp.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerUseHoeEvent ###
|
||||
// #########################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev) {
|
||||
return elPlayerSleepInBed.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSleepInBed() {
|
||||
return elPlayerSleepInBed.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSleepInBed(PlayerSleepInBedEvent event) {
|
||||
elPlayerSleepInBed.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev) {
|
||||
return elPlayerUseHoe.add(ev);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerUseItemStartEvent ###
|
||||
// ###############################
|
||||
|
||||
public boolean hasPlayerUseHoe() {
|
||||
return elPlayerUseHoe.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseHoe(PlayerUseHoeEvent event) {
|
||||
elPlayerUseHoe.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev) {
|
||||
return elPlayerUseItemStart.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemStart() {
|
||||
return elPlayerUseItemStart.hasHandlers();
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### PlayerUseItemTickEvent ###
|
||||
// ##############################
|
||||
|
||||
public void publishPlayerUseItemStart(PlayerUseItemStartEvent event) {
|
||||
elPlayerUseItemStart.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev) {
|
||||
return elPlayerUseItemTick.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemTick() {
|
||||
return elPlayerUseItemTick.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemTick(PlayerUseItemTickEvent event) {
|
||||
elPlayerUseItemTick.publish(event);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerAttackEntityEvent")
|
||||
public class PlayerAttackEntityEvent {
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerAttackEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
public PlayerAttackEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +1,87 @@
|
||||
/*
|
||||
* 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.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBlockGroup;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerBonemealEvent")
|
||||
public class PlayerBonemealEvent {
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerBonemealEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
public PlayerBonemealEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
+22
-29
@@ -1,44 +1,37 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerChangedDimensionEvent")
|
||||
public class PlayerChangedDimensionEvent {
|
||||
private final IPlayer player;
|
||||
private final IDimension from;
|
||||
private final IDimension to;
|
||||
|
||||
public PlayerChangedDimensionEvent(IPlayer player, IDimension from, IDimension to) {
|
||||
this.player = player;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final IDimension from;
|
||||
private final IDimension to;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerChangedDimensionEvent(IPlayer player, IDimension from, IDimension to) {
|
||||
this.player = player;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@ZenGetter("from")
|
||||
public IDimension getFrom() {
|
||||
return from;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("to")
|
||||
public IDimension getTo() {
|
||||
return to;
|
||||
}
|
||||
@ZenGetter("from")
|
||||
public IDimension getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
@ZenGetter("to")
|
||||
public IDimension getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,38 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingInventory;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerCraftingEvent")
|
||||
public class PlayerCraftedEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
private final ICraftingInventory inventory;
|
||||
|
||||
public PlayerCraftedEvent(IPlayer player, IItemStack output, ICraftingInventory inventory) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
private final ICraftingInventory inventory;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerCraftedEvent(IPlayer player, IItemStack output, ICraftingInventory inventory) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,40 @@
|
||||
/*
|
||||
* 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.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.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerDeathDropsEvent")
|
||||
public class PlayerDeathDropsEvent {
|
||||
private final IPlayer player;
|
||||
private final List<IEntityItem> items;
|
||||
private final IDamageSource damageSource;
|
||||
|
||||
public PlayerDeathDropsEvent(IPlayer player, List<IEntityItem> items, IDamageSource damageSource) {
|
||||
this.player = player;
|
||||
this.items = items;
|
||||
this.damageSource = damageSource;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final List<IEntityItem> items;
|
||||
private final IDamageSource damageSource;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerDeathDropsEvent(IPlayer player, List<IEntityItem> items, IDamageSource damageSource) {
|
||||
this.player = player;
|
||||
this.items = items;
|
||||
this.damageSource = damageSource;
|
||||
}
|
||||
|
||||
@ZenGetter("items")
|
||||
public List<IEntityItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("damageSource")
|
||||
public IDamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
@ZenGetter("items")
|
||||
public List<IEntityItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@ZenGetter("damageSource")
|
||||
public IDamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
}
|
||||
@@ -1,103 +1,93 @@
|
||||
/*
|
||||
* 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.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBlockGroup;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerFillBucketEvent")
|
||||
public class PlayerFillBucketEvent {
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private IItemStack result;
|
||||
|
||||
public PlayerFillBucketEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private IItemStack result;
|
||||
|
||||
canceled = false;
|
||||
result = null;
|
||||
}
|
||||
public PlayerFillBucketEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
result = null;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resulting item. Automatically processes the event, too.
|
||||
*
|
||||
* @param result resulting item
|
||||
*/
|
||||
@ZenSetter("result")
|
||||
public void setResult(IItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("result")
|
||||
public IItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
@ZenGetter("result")
|
||||
public IItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
/**
|
||||
* Sets the resulting item. Automatically processes the event, too.
|
||||
*
|
||||
* @param result resulting item
|
||||
*/
|
||||
@ZenSetter("result")
|
||||
public void setResult(IItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
+26
-34
@@ -1,50 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerInteractEntityEvent")
|
||||
public class PlayerInteractEntityEvent {
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerInteractEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
public PlayerInteractEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -1,109 +1,100 @@
|
||||
/*
|
||||
* 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.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBlockGroup;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerInteractEvent")
|
||||
public class PlayerInteractEvent {
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
private boolean canceled;
|
||||
private boolean useBlock;
|
||||
private boolean useItem;
|
||||
|
||||
public PlayerInteractEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
useBlock = false;
|
||||
useItem = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void useBlock() {
|
||||
useBlock = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void useItem() {
|
||||
useItem = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("usingBlock")
|
||||
public boolean isUsingBlock() {
|
||||
return useBlock;
|
||||
}
|
||||
|
||||
@ZenGetter("usingItem")
|
||||
public boolean isUsingItem() {
|
||||
return useItem;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerLoggedInEvent")
|
||||
public class PlayerLoggedInEvent {
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedInEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedInEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerLoggedOutEvent")
|
||||
public class PlayerLoggedOutEvent {
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedOutEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedOutEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
+32
-40
@@ -1,51 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.container.IContainer;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerOpenContainerEvent")
|
||||
public class PlayerOpenContainerEvent {
|
||||
private final IPlayer player;
|
||||
private final IContainer container;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerOpenContainerEvent(IPlayer player, IContainer container) {
|
||||
this.player = player;
|
||||
this.container = container;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("container")
|
||||
public IContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +1,58 @@
|
||||
/*
|
||||
* 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.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupEvent")
|
||||
public class PlayerPickupEvent {
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerPickupEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
public PlayerPickupEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the event (picks up the entity).
|
||||
*/
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
/**
|
||||
* Processes the event (picks up the entity).
|
||||
*/
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,30 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupItemEvent")
|
||||
public class PlayerPickupItemEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
|
||||
public PlayerPickupItemEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerPickupItemEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,48 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntityXp;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupXpEvent")
|
||||
public class PlayerPickupXpEvent {
|
||||
private final IPlayer player;
|
||||
private final IEntityXp xp;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerPickupXpEvent(IPlayer player, IEntityXp xp) {
|
||||
this.player = player;
|
||||
this.xp = xp;
|
||||
private final IPlayer player;
|
||||
private final IEntityXp xp;
|
||||
private boolean canceled;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
public PlayerPickupXpEvent(IPlayer player, IEntityXp xp) {
|
||||
this.player = player;
|
||||
this.xp = xp;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntityXp getEntity() {
|
||||
return xp;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("xp")
|
||||
public float getXp() {
|
||||
return xp.getXp();
|
||||
}
|
||||
@ZenGetter("entity")
|
||||
public IEntityXp getEntity() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
@ZenGetter("xp")
|
||||
public float getXp() {
|
||||
return xp.getXp();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerRespawnEvent")
|
||||
public class PlayerRespawnEvent {
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerRespawnEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
private final IPlayer player;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerRespawnEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerSleepInBedEvent")
|
||||
public class PlayerSleepInBedEvent {
|
||||
private final IPlayer player;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public PlayerSleepInBedEvent(IPlayer player, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerSleepInBedEvent(IPlayer player, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
@@ -11,25 +5,25 @@ import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class PlayerSmeltedEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
|
||||
public PlayerSmeltedEvent(IPlayer player, IItemStack output) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
}
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
public PlayerSmeltedEvent(IPlayer player, IItemStack output) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +1,95 @@
|
||||
/*
|
||||
* 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.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBlockGroup;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseHoeEvent")
|
||||
public class PlayerUseHoeEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerUseHoeEvent(IPlayer player, IItemStack item, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
public PlayerUseHoeEvent(IPlayer player, IItemStack item, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
@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();
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemStartEvent")
|
||||
public class PlayerUseItemStartEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemStartEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private boolean canceled;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
public PlayerUseItemStartEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +1,50 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemTickEvent")
|
||||
public class PlayerUseItemTickEvent {
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final int duration;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemTickEvent(IPlayer player, IItemStack item, int duration) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.duration = duration;
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final int duration;
|
||||
private boolean canceled;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
public PlayerUseItemTickEvent(IPlayer player, IItemStack item, int duration) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.duration = duration;
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("duration")
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("duration")
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,16 @@
|
||||
/*
|
||||
* 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.api.formatting;
|
||||
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.formatting.IFormattedText")
|
||||
public interface IFormattedText {
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
public IFormattedText add(IFormattedText other);
|
||||
|
||||
@ZenOperator(OperatorType.CAT)
|
||||
public IFormattedText cat(IFormattedText other);
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IFormattedText add(IFormattedText other);
|
||||
|
||||
@ZenOperator(OperatorType.CAT)
|
||||
IFormattedText cat(IFormattedText other);
|
||||
}
|
||||
@@ -1,80 +1,74 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.formatting;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IFormatter {
|
||||
public IFormattedText string(String text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText black(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText darkBlue(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText darkGreen(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText darkAqua(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText darkRed(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText darkPurple(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText gold(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText gray(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText darkGray(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText blue(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText green(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText aqua(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText red(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText lightPurple(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText yellow(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText white(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText obfuscated(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText bold(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText strikethrough(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText underline(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
public IFormattedText italic(IFormattedText text);
|
||||
|
||||
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,119 +1,124 @@
|
||||
package minetweaker.api.game;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.entity.IEntityDefinition;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Game interface. Used to obtain general game information.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.game.IGame")
|
||||
public interface IGame {
|
||||
/**
|
||||
* Retrieves the item definitions in this game.
|
||||
*
|
||||
* @return game items
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
public List<IItemDefinition> getItems();
|
||||
|
||||
/**
|
||||
* Retrieves the block definitions in this game.
|
||||
*
|
||||
* @return block definitions
|
||||
*/
|
||||
@ZenGetter("blocks")
|
||||
public List<IBlockDefinition> getBlocks();
|
||||
|
||||
/**
|
||||
* Retrieves the liquids in this game.
|
||||
*
|
||||
* @return game liquids
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
public List<ILiquidDefinition> getLiquids();
|
||||
|
||||
/**
|
||||
* Retrieves the biomes in this game.
|
||||
*
|
||||
* @return game biomes
|
||||
*/
|
||||
@ZenGetter("biomes")
|
||||
public List<IBiome> getBiomes();
|
||||
|
||||
/**
|
||||
* Retrieves the entities in this game.
|
||||
*
|
||||
* @return game entities
|
||||
*/
|
||||
@ZenGetter("entities")
|
||||
public List<IEntityDefinition> getEntities();
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
public void setLocalization(String key, String value);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param lang language
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
public void setLocalization(String lang, String key, String value);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
public String localize(String key);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param lang language
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
public String localize(String key, String lang);
|
||||
|
||||
/**
|
||||
* Lock the game and disable reload. Recommended for distributed versions.
|
||||
*
|
||||
* Once locked, reload cannot be unlocked - a game restart is required to
|
||||
* alter the scripts.
|
||||
*/
|
||||
@ZenMethod
|
||||
public void lock();
|
||||
|
||||
/**
|
||||
* Returns the lock state. True if locked.
|
||||
*
|
||||
* @return lock state
|
||||
*/
|
||||
@ZenGetter("locked")
|
||||
public boolean isLocked();
|
||||
|
||||
/**
|
||||
* Signals a modified script while in locked mode.
|
||||
*/
|
||||
public void signalLockError();
|
||||
|
||||
/**
|
||||
* Retrieves the item definitions in this game.
|
||||
*
|
||||
* @return game items
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemDefinition> getItems();
|
||||
|
||||
/**
|
||||
* Retrieves the block definitions in this game.
|
||||
*
|
||||
* @return block definitions
|
||||
*/
|
||||
@ZenGetter("blocks")
|
||||
List<IBlockDefinition> getBlocks();
|
||||
|
||||
/**
|
||||
* Retrieves the liquids in this game.
|
||||
*
|
||||
* @return game liquids
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidDefinition> getLiquids();
|
||||
|
||||
/**
|
||||
* Retrieves the biomes in this game.
|
||||
*
|
||||
* @return game biomes
|
||||
*/
|
||||
@ZenGetter("biomes")
|
||||
List<IBiome> getBiomes();
|
||||
|
||||
/**
|
||||
* Retrieves the entities in this game.
|
||||
*
|
||||
* @return game entities
|
||||
*/
|
||||
@ZenGetter("entities")
|
||||
List<IEntityDefinition> getEntities();
|
||||
|
||||
@ZenMethod()
|
||||
IEntityDefinition getEntity(String entityName);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String key, String value);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param lang language
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String lang, String key, String value);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
*
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param lang language
|
||||
*
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key, String lang);
|
||||
|
||||
/**
|
||||
* Lock the game and disable reload. Recommended for distributed versions.
|
||||
* <p>
|
||||
* Once locked, reload cannot be unlocked - a game restart is required to
|
||||
* alter the scripts.
|
||||
*/
|
||||
@ZenMethod
|
||||
void lock();
|
||||
|
||||
/**
|
||||
* Returns the lock state. True if locked.
|
||||
*
|
||||
* @return lock state
|
||||
*/
|
||||
@ZenGetter("locked")
|
||||
boolean isLocked();
|
||||
|
||||
/**
|
||||
* Signals a modified script while in locked mode.
|
||||
*/
|
||||
void signalLockError();
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
* Represents a recipe ingredient. An ingredient can be an item, an ore
|
||||
* dictionary entry, an item stack, an ore dictionary entry multiplied with an
|
||||
* amount, or other kinds of ingredients as offered by the API.
|
||||
*
|
||||
* <p>
|
||||
* There is no guarantee that every mod will respect the conditions or
|
||||
* transformations, or that every mod will support every kind of ingredient.
|
||||
*
|
||||
@@ -18,164 +18,175 @@ import java.util.List;
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IIngredient")
|
||||
public interface IIngredient {
|
||||
/**
|
||||
* Gets the mark of the ingredient. Ingredients can be marked so they can be
|
||||
* used in crafting functions.
|
||||
*
|
||||
* @return ingredient mark
|
||||
*/
|
||||
@ZenGetter("mark")
|
||||
public String getMark();
|
||||
|
||||
/**
|
||||
* Gets the amount.
|
||||
*
|
||||
* Should return -1 if no amount is available and 1 for a single item.
|
||||
* Stacks return the stack size.
|
||||
*
|
||||
* @return stack size
|
||||
*/
|
||||
@ZenGetter("amount")
|
||||
public int getAmount();
|
||||
|
||||
/**
|
||||
* Gets all possible items for this ingredient.
|
||||
*
|
||||
* If there is no item list (for example, it is the <*> wildcard item)
|
||||
* null should be returned.
|
||||
*
|
||||
* @return the items for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
public List<IItemStack> getItems();
|
||||
|
||||
/**
|
||||
* Gets all possible liquids for this ingredient.
|
||||
*
|
||||
* 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")
|
||||
public List<ILiquidStack> getLiquids();
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given stack size.
|
||||
*
|
||||
* @param amount new stack size
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public IIngredient amount(int amount);
|
||||
|
||||
/**
|
||||
* Combines multiple ingredients into a single one. Note that ore dictionary
|
||||
* entries are preferred to or statements.
|
||||
*
|
||||
* @param ingredient ingredient to combine with
|
||||
* @return or-ed ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.OR)
|
||||
@ZenMethod
|
||||
public IIngredient or(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
* @param transformer transformer to add
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient transform(IItemTransformer transformer);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given condition added to it.
|
||||
*
|
||||
* @param condition condition to add
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient only(IItemCondition condition);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient marked with the given name.
|
||||
*
|
||||
* @param mark mark to apply
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient marked(String mark);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
public boolean matches(IItemStack item);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the mark of the ingredient. Ingredients can be marked so they can be
|
||||
* used in crafting functions.
|
||||
*
|
||||
* @return ingredient mark
|
||||
*/
|
||||
@ZenGetter("mark")
|
||||
String getMark();
|
||||
|
||||
/**
|
||||
* Gets the amount.
|
||||
* <p>
|
||||
* Should return -1 if no amount is available and 1 for a single item.
|
||||
* Stacks return the stack size.
|
||||
*
|
||||
* @return stack size
|
||||
*/
|
||||
@ZenGetter("amount")
|
||||
int getAmount();
|
||||
|
||||
/**
|
||||
* Gets all possible items for this ingredient.
|
||||
* <p>
|
||||
* If there is no item list (for example, it is the <*> wildcard item)
|
||||
* null should be returned.
|
||||
*
|
||||
* @return the items for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemStack> getItems();
|
||||
|
||||
/**
|
||||
* Gets all possible liquids for this ingredient.
|
||||
* <p>
|
||||
* If there is no liquid list (for example, it is the <*&ft; wildcard
|
||||
* item) null should be returned.
|
||||
*
|
||||
* @return the liquids for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidStack> getLiquids();
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given stack size.
|
||||
*
|
||||
* @param amount new stack size
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
IIngredient amount(int amount);
|
||||
|
||||
/**
|
||||
* Combines multiple ingredients into a single one. Note that ore dictionary
|
||||
* entries are preferred to or statements.
|
||||
*
|
||||
* @param ingredient ingredient to combine with
|
||||
*
|
||||
* @return or-ed ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.OR)
|
||||
@ZenMethod
|
||||
IIngredient or(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
* @param transformer transformer to add
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient transform(IItemTransformer transformer);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given condition added to it.
|
||||
*
|
||||
* @param condition condition to add
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient only(IItemCondition condition);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient marked with the given name.
|
||||
*
|
||||
* @param mark mark to apply
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient marked(String mark);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
*
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
public boolean matchesExact(IItemStack item);
|
||||
|
||||
|
||||
boolean matches(IItemStack item);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given liquid.
|
||||
*
|
||||
* @param liquid
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public boolean matches(ILiquidStack liquid);
|
||||
|
||||
/**
|
||||
* Check if this ingredient contains all possible values for the given
|
||||
* ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to check
|
||||
* @return true if the ingredient contains the given one
|
||||
*/
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean contains(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Applies transformations after crafting, if any, to the given item.
|
||||
*
|
||||
* @param item item to transform
|
||||
* @param byPlayer player performing the crafting operation
|
||||
* @return transformed item
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient has (or could have) any transformatiosns.
|
||||
*
|
||||
* @return true if there are (or could be) any transformations false
|
||||
* otherwise.
|
||||
*/
|
||||
@ZenGetter("hasTransformations")
|
||||
public boolean hasTransformers();
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public Object getInternal();
|
||||
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
*
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matchesExact(IItemStack item);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given liquid.
|
||||
*
|
||||
* @param liquid liquid to check
|
||||
*
|
||||
* @return true if the liquid matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matches(ILiquidStack liquid);
|
||||
|
||||
/**
|
||||
* Check if this ingredient contains all possible values for the given
|
||||
* ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to check
|
||||
*
|
||||
* @return true if the ingredient contains the given one
|
||||
*/
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Applies transformations after crafting, if any, to the given item.
|
||||
*
|
||||
* @param item item to transform
|
||||
* @param byPlayer player performing the crafting operation
|
||||
*
|
||||
* @return transformed item
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack applyTransform(IItemStack item, IPlayer byPlayer);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient has (or could have) any transformatiosns.
|
||||
*
|
||||
* @return true if there are (or could be) any transformations false
|
||||
* otherwise.
|
||||
*/
|
||||
@ZenGetter("hasTransformations")
|
||||
boolean hasTransformers();
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
* <p>
|
||||
* The value is implementation-dependent and should only be handled by the
|
||||
* internal code. Don't use this value - instead, use the version-specific
|
||||
* helper methods.
|
||||
*
|
||||
* @return internal item
|
||||
*/
|
||||
Object getInternal();
|
||||
|
||||
}
|
||||
@@ -4,20 +4,22 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* Item conditions apply additional conditions on item stacks.
|
||||
*
|
||||
* <p>
|
||||
* They may, for instance, require specific damage ranges or NBT tags. Custom
|
||||
* implementations of this functional interface may contain any kind of
|
||||
* condition.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemCondition")
|
||||
public interface IItemCondition {
|
||||
/**
|
||||
* Returns true if the given stack matches the required conditions.
|
||||
*
|
||||
* @param stack item stack to check
|
||||
* @return true if the condition applies to this stack
|
||||
*/
|
||||
public boolean matches(IItemStack stack);
|
||||
|
||||
/**
|
||||
* Returns true if the given stack matches the required conditions.
|
||||
*
|
||||
* @param stack item stack to check
|
||||
*
|
||||
* @return true if the condition applies to this stack
|
||||
*/
|
||||
boolean matches(IItemStack stack);
|
||||
}
|
||||
@@ -1,54 +1,54 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains an item definition. Item definitions provide general information
|
||||
* about an item, such as its name and ID.
|
||||
*
|
||||
* <p>
|
||||
* Item definitions themselves have no localized name, as it could be different
|
||||
* for each subitem or even depend on NBT tags.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemDefinition")
|
||||
public interface IItemDefinition {
|
||||
/**
|
||||
* Gets the item ID.
|
||||
*
|
||||
* @return item ID
|
||||
*/
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Makes an item stack from this definition.
|
||||
*
|
||||
* @param meta meta value
|
||||
* @return item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack makeStack(@Optional int meta);
|
||||
|
||||
/**
|
||||
* Returns all ore entries containing this item. Also contains ore entries
|
||||
* that refer to a specific sub-item.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
public List<IOreDictEntry> getOres();
|
||||
|
||||
/**
|
||||
* Gets the item ID.
|
||||
*
|
||||
* @return item ID
|
||||
*/
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Makes an item stack from this definition.
|
||||
*
|
||||
* @param meta meta value
|
||||
*
|
||||
* @return item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack makeStack(@Optional int meta);
|
||||
|
||||
/**
|
||||
* Returns all ore entries containing this item. Also contains ore entries
|
||||
* that refer to a specific sub-item.
|
||||
*
|
||||
* @return all the ore entries containing this item.
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -11,234 +11,252 @@ import java.util.List;
|
||||
/**
|
||||
* Contains an item stack. An item stack consists of an item definition, a meta
|
||||
* or damage value and NBT data.
|
||||
*
|
||||
* <p>
|
||||
* Item stacks can be retrieved using its name (or ID, in 1.6.4) with the
|
||||
* bracket syntax. When using the bracket syntax, by default, the item stack
|
||||
* will match any size when used as ingredient. Item stacks can be multiplied
|
||||
* with an integer to create a stack of different size.
|
||||
*
|
||||
* <p>
|
||||
* Item stacks are immutable. You can, however, easily create modified stacks
|
||||
* using the helper methods. Adding conditions and transformations will turn the
|
||||
* item stack into an ingredients.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemStack")
|
||||
public interface IItemStack extends IIngredient {
|
||||
/**
|
||||
* Gets the item definition.
|
||||
*
|
||||
* @return item definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
public IItemDefinition getDefinition();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return unlocalized item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Gets the display name. By default, it is the localized item name, but
|
||||
* could also be the display name from NBT data, or another item-specific
|
||||
* name.
|
||||
*
|
||||
* @return item display name
|
||||
*/
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
/**
|
||||
* Sets the display name. Only works if the name is translatable. Does not
|
||||
* override names set by NBT data or using item-specific logic.
|
||||
*
|
||||
* @param name item display name
|
||||
*/
|
||||
@ZenSetter("displayName")
|
||||
public void setDisplayName(String name);
|
||||
|
||||
/**
|
||||
* Gets the max stack size for an item
|
||||
*
|
||||
* @return int max stack size
|
||||
*/
|
||||
@ZenGetter("maxStackSize")
|
||||
public int getMaxStackSize();
|
||||
|
||||
/**
|
||||
* Sets the ItemStack max stack size.
|
||||
*
|
||||
* @param size the new max size
|
||||
*/
|
||||
@ZenSetter("maxStackSize")
|
||||
public void setMaxStackSize(int size);
|
||||
|
||||
/**
|
||||
* Gets the block hardness
|
||||
*/
|
||||
@ZenGetter("hardness")
|
||||
public float getBlockHardness();
|
||||
|
||||
/**
|
||||
* Sets the block hardness
|
||||
*
|
||||
* @param hardness the new hardness
|
||||
*/
|
||||
@ZenSetter("hardness")
|
||||
public void setBlockHardness(float hardness);
|
||||
|
||||
/**
|
||||
* Gets the item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return item damage
|
||||
*/
|
||||
@ZenGetter("damage")
|
||||
public int getDamage();
|
||||
|
||||
/**
|
||||
* Gets the maximum item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return maximum item damage
|
||||
*/
|
||||
@ZenGetter("maxDamage")
|
||||
public int getMaxDamage();
|
||||
|
||||
/**
|
||||
* Sets the max Itemstack damage
|
||||
*
|
||||
* @param damage the new max damage
|
||||
*/
|
||||
@ZenSetter("maxDamage")
|
||||
public void setMaxDamage(int damage);
|
||||
|
||||
/**
|
||||
* Gets the item tag. (NBT data) The resulting data is immutable and can
|
||||
* only be changed with updateTag. Returns empty data if there is no data.
|
||||
* Never returns null.
|
||||
*
|
||||
* @return item tag
|
||||
*/
|
||||
@ZenGetter("tag")
|
||||
public IData getTag();
|
||||
|
||||
/**
|
||||
* Gets the liquid contained in this item, if any. If this item stack is not
|
||||
* an item container, it returns null. Only returns the amount of liquid in
|
||||
* a single item and doesn't into account stack size.
|
||||
*
|
||||
* @return liquid data
|
||||
*/
|
||||
@ZenGetter("liquid")
|
||||
public ILiquidStack getLiquid();
|
||||
|
||||
/**
|
||||
* Creates a new item stack with a different stack size.
|
||||
*
|
||||
* @param amount new item stack size
|
||||
* @return new item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public IItemStack amount(int amount);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given percentage chance. Does the
|
||||
* same as item.weight(p * 0.01).
|
||||
*
|
||||
* @param p probability, with percent
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
public WeightedItemStack percent(float p);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given weight.
|
||||
*
|
||||
* @param p item weight
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public WeightedItemStack weight(float p);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the same item and stack size, but accepting
|
||||
* any damage value. Only useful for items used as ingredients.
|
||||
*
|
||||
* @return item stack with wildcard damage
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient anyDamage();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified damage.
|
||||
*
|
||||
* @param damage damage value
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack withDamage(int damage);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified stack size.
|
||||
*
|
||||
* @param amount stack size
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack withAmount(int amount);
|
||||
|
||||
/**
|
||||
* Creates an item stack with wildcard stack size.
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack anyAmount();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the given nbt tag. Ignores existing tags.
|
||||
*
|
||||
* @param tag item tag to be assigned
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack withTag(IData tag);
|
||||
|
||||
/**
|
||||
* Creates an item stack without the given nbt tag.
|
||||
*
|
||||
* @param tag item tag to be removed
|
||||
|
||||
/**
|
||||
* Gets the item definition.
|
||||
*
|
||||
* @return item definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IItemDefinition getDefinition();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return unlocalized item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the display name. By default, it is the localized item name, but
|
||||
* could also be the display name from NBT data, or another item-specific
|
||||
* name.
|
||||
*
|
||||
* @return item display name
|
||||
*/
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* Sets the display name. Only works if the name is translatable. Does not
|
||||
* override names set by NBT data or using item-specific logic.
|
||||
*
|
||||
* @param name item display name
|
||||
*/
|
||||
@ZenSetter("displayName")
|
||||
void setDisplayName(String name);
|
||||
|
||||
/**
|
||||
* Gets the max stack size for an item
|
||||
*
|
||||
* @return int max stack size
|
||||
*/
|
||||
@ZenGetter("maxStackSize")
|
||||
int getMaxStackSize();
|
||||
|
||||
/**
|
||||
* Sets the ItemStack max stack size.
|
||||
*
|
||||
* @param size the new max size
|
||||
*/
|
||||
@ZenSetter("maxStackSize")
|
||||
void setMaxStackSize(int size);
|
||||
|
||||
/**
|
||||
* Gets the block hardness
|
||||
*/
|
||||
@ZenGetter("hardness")
|
||||
float getBlockHardness();
|
||||
|
||||
/**
|
||||
* Sets the block hardness
|
||||
*
|
||||
* @param hardness the new hardness
|
||||
*/
|
||||
@ZenSetter("hardness")
|
||||
void setBlockHardness(float hardness);
|
||||
|
||||
/**
|
||||
* Gets the item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return item damage
|
||||
*/
|
||||
@ZenGetter("damage")
|
||||
int getDamage();
|
||||
|
||||
/**
|
||||
* Gets the maximum item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return maximum item damage
|
||||
*/
|
||||
@ZenGetter("maxDamage")
|
||||
int getMaxDamage();
|
||||
|
||||
/**
|
||||
* Sets the max Itemstack damage
|
||||
*
|
||||
* @param damage the new max damage
|
||||
*/
|
||||
@ZenSetter("maxDamage")
|
||||
void setMaxDamage(int damage);
|
||||
|
||||
/**
|
||||
* Gets the item tag. (NBT data) The resulting data is immutable and can
|
||||
* only be changed with updateTag. Returns empty data if there is no data.
|
||||
* Never returns null.
|
||||
*
|
||||
* @return item tag
|
||||
*/
|
||||
@ZenGetter("tag")
|
||||
IData getTag();
|
||||
|
||||
/**
|
||||
* Gets the liquid contained in this item, if any. If this item stack is not
|
||||
* an item container, it returns null. Only returns the amount of liquid in
|
||||
* a single item and doesn't into account stack size.
|
||||
*
|
||||
* @return liquid data
|
||||
*/
|
||||
@ZenGetter("liquid")
|
||||
ILiquidStack getLiquid();
|
||||
|
||||
/**
|
||||
* Creates a new item stack with a different stack size.
|
||||
*
|
||||
* @param amount new item stack size
|
||||
*
|
||||
* @return new item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack amount(int amount);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given percentage chance. Does the
|
||||
* same as item.weight(p * 0.01).
|
||||
*
|
||||
* @param p probability, with percent
|
||||
*
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
WeightedItemStack percent(float p);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given weight.
|
||||
*
|
||||
* @param p item weight
|
||||
*
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
WeightedItemStack weight(float p);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the same item and stack size, but accepting
|
||||
* any damage value. Only useful for items used as ingredients.
|
||||
*
|
||||
* @return item stack with wildcard damage
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient anyDamage();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified damage.
|
||||
*
|
||||
* @param damage damage value
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withDamage(int damage);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified stack size.
|
||||
*
|
||||
* @param amount stack size
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
IItemStack withAmount(int amount);
|
||||
|
||||
/**
|
||||
* Creates an item stack with wildcard stack size.
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
|
||||
@ZenMethod
|
||||
IItemStack anyAmount();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the given nbt tag. Ignores existing tags.
|
||||
*
|
||||
* @param tag item tag to be assigned
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack removeTag(String tag);
|
||||
|
||||
/**
|
||||
* Creates an item stack with updated nbt tag. Updates existing tags.
|
||||
*
|
||||
* @param tagUpdate item tag updates
|
||||
* @return updated item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack updateTag(IData tagUpdate);
|
||||
|
||||
/**
|
||||
* Converts this item stack into a block.
|
||||
*
|
||||
* @return block, or null if this item is not a block
|
||||
*/
|
||||
@ZenCaster
|
||||
public IBlock asBlock();
|
||||
|
||||
/**
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore
|
||||
* entries.
|
||||
*
|
||||
* @return ore entries containing this item stack
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
public List<IOreDictEntry> getOres();
|
||||
IItemStack withTag(IData tag);
|
||||
|
||||
/**
|
||||
* Create an item stack with an empty nbt tag. Removes previous tag if any.
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withEmptyTag();
|
||||
|
||||
/**
|
||||
* Creates an item stack without the given nbt tag.
|
||||
*
|
||||
* @param tag item tag to be removed
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack removeTag(String tag);
|
||||
|
||||
/**
|
||||
* Creates an item stack with updated nbt tag. Updates existing tags.
|
||||
*
|
||||
* @param tagUpdate item tag updates
|
||||
*
|
||||
* @return updated item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack updateTag(IData tagUpdate);
|
||||
|
||||
/**
|
||||
* Converts this item stack into a block.
|
||||
*
|
||||
* @return block, or null if this item is not a block
|
||||
*/
|
||||
@ZenCaster
|
||||
IBlock asBlock();
|
||||
|
||||
/**
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore
|
||||
* entries.
|
||||
*
|
||||
* @return ore entries containing this item stack
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -1,26 +1,27 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* An item transformer modifies an item stack after crafting. Used to apply
|
||||
* damage, grab multiple items, change NBT tags, replace the item with something
|
||||
* else - or whatever else you'd want to happen to the input stack.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemTransformer")
|
||||
public interface IItemTransformer {
|
||||
/**
|
||||
* Transforms the specified item. May modify this item (and return it) or
|
||||
* return an entirely new one.
|
||||
*
|
||||
* @param item input item
|
||||
* @param byPlayer player that performs the crafting
|
||||
* @return output item
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer);
|
||||
|
||||
/**
|
||||
* Transforms the specified item. May modify this item (and return it) or
|
||||
* return an entirely new one.
|
||||
*
|
||||
* @param item input item
|
||||
* @param byPlayer player that performs the crafting
|
||||
*
|
||||
* @return output item
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack transform(IItemStack item, IPlayer byPlayer);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientAny implements IIngredient {
|
||||
|
||||
public static final IngredientAny INSTANCE = new IngredientAny();
|
||||
|
||||
public static Object INTERNAL_ANY = null; // platforms supporting an "any"
|
||||
|
||||
@@ -9,118 +9,119 @@ import java.util.List;
|
||||
/**
|
||||
* Represents the wildcard ingredient, with conditions and/or transformers
|
||||
* applied to it.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientAnyAdvanced implements IIngredient {
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientAnyAdvanced(String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
public IngredientAnyAdvanced(String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
// TODO: conditions on liquids?
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for (IItemStack iitem : iitems) {
|
||||
if (!matches(iitem))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
// TODO: conditions on liquids?
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for(IItemStack iitem : iitems) {
|
||||
if(!matches(iitem))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for (IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
}
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Conditions can be used to set requirements for matching items. They can be
|
||||
@@ -13,10 +12,12 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientCondition {
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged. A damage value of 1 is enough.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return damaged condition
|
||||
*/
|
||||
@ZenMethod
|
||||
@@ -34,6 +35,7 @@ public class IngredientCondition {
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
@@ -52,6 +54,7 @@ public class IngredientCondition {
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param maxDamage maximum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
@@ -70,6 +73,7 @@ public class IngredientCondition {
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @param maxDamage maximum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
@@ -88,6 +92,7 @@ public class IngredientCondition {
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param data required data
|
||||
*
|
||||
* @return data condition
|
||||
*/
|
||||
@ZenMethod
|
||||
@@ -106,6 +111,7 @@ public class IngredientCondition {
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount required stack size
|
||||
*
|
||||
* @return stack size condition
|
||||
*/
|
||||
@ZenMethod
|
||||
|
||||
@@ -4,142 +4,142 @@ import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an item stack with modifiers applied to it.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientItem implements IIngredient {
|
||||
private final IItemStack item;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
private final List<IItemStack> items;
|
||||
|
||||
public IngredientItem(IItemStack item, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.item = item;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
private final IItemStack item;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
private final List<IItemStack> items;
|
||||
|
||||
items = Collections.singletonList(item);
|
||||
}
|
||||
public IngredientItem(IItemStack item, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.item = item;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
items = Collections.singletonList(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientItem(item, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientItem(item, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientItem(item, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(item, mark, conditions, transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientItem(item, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(item, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if (!this.item.matches(item))
|
||||
return false;
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!this.item.matches(item))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if (!this.item.matchesExact(item))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!this.item.matchesExact(item))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for (IItemStack iitem : iitems) {
|
||||
if (!matches(iitem))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for(IItemStack iitem : iitems) {
|
||||
if(!matches(iitem))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for (IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
}
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(Ingredient) " + item.toString();
|
||||
}
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(Ingredient) " + item.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,159 +1,153 @@
|
||||
/*
|
||||
* 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.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientOr implements IIngredient {
|
||||
private final IIngredient[] elements;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOr(IIngredient[] elements) {
|
||||
this.elements = elements;
|
||||
mark = null;
|
||||
conditions = ArrayUtil.EMPTY_CONDITIONS;
|
||||
transformers = ArrayUtil.EMPTY_TRANSFORMERS;
|
||||
}
|
||||
private final IIngredient[] elements;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOr(IIngredient a, IIngredient b) {
|
||||
this(new IIngredient[] { a, b });
|
||||
}
|
||||
public IngredientOr(IIngredient[] elements) {
|
||||
this.elements = elements;
|
||||
mark = null;
|
||||
conditions = ArrayUtil.EMPTY_CONDITIONS;
|
||||
transformers = ArrayUtil.EMPTY_TRANSFORMERS;
|
||||
}
|
||||
|
||||
private IngredientOr(IIngredient[] elements, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.elements = elements;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
public IngredientOr(IIngredient a, IIngredient b) {
|
||||
this(new IIngredient[]{a, b});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
private IngredientOr(IIngredient[] elements, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.elements = elements;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return elements[0].getAmount();
|
||||
}
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<IItemStack>();
|
||||
for (IIngredient element : elements) {
|
||||
result.addAll(element.getItems());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return elements[0].getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
List<ILiquidStack> result = new ArrayList<ILiquidStack>();
|
||||
for (IIngredient element : elements) {
|
||||
result.addAll(element.getLiquids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
result.addAll(element.getItems());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
IIngredient[] result = new IIngredient[elements.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].amount(amount);
|
||||
}
|
||||
return new IngredientOr(result);
|
||||
}
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
List<ILiquidStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
result.addAll(element.getLiquids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOr(elements, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
IIngredient[] result = new IIngredient[elements.length];
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].amount(amount);
|
||||
}
|
||||
return new IngredientOr(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOr(elements, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOr(elements, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOr(elements, mark, conditions, transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOr(elements, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(ArrayUtil.append(elements, ingredient));
|
||||
}
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOr(elements, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for (IIngredient ingredient : elements) {
|
||||
if (ingredient.matches(item))
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(ArrayUtil.append(elements, ingredient));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for (IIngredient ingredient : elements) {
|
||||
if (ingredient.matchesExact(item))
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
for (IIngredient ingredient : elements) {
|
||||
if (ingredient.matches(liquid))
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matchesExact(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for (IItemStack item : items) {
|
||||
if (!matches(item))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(liquid))
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for (IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for(IItemStack item : items) {
|
||||
if(!matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an ingredient stack. Is an ingredient with a specific stack size
|
||||
* assigned to it.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientStack implements IIngredient {
|
||||
|
||||
private final IIngredient ingredient;
|
||||
private final int amount;
|
||||
|
||||
@@ -71,6 +70,7 @@ public class IngredientStack implements IIngredient {
|
||||
public boolean matches(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matches(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matchesExact(item);
|
||||
@@ -108,12 +108,12 @@ public class IngredientStack implements IIngredient {
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "(Ingredients) ";
|
||||
List<String> names = new ArrayList<String>();
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
for (IItemStack st : ingredient.getItems()) {
|
||||
for(IItemStack st : ingredient.getItems()) {
|
||||
names.add(st.getName());
|
||||
}
|
||||
s = s.join(",", names);
|
||||
s += String.join(",", names);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Transformations can be used to modify an ingredient after it is used in a
|
||||
@@ -14,148 +11,129 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTransform {
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient reuse(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
return item.withAmount(item.getAmount());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item for
|
||||
* 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient reuse(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> item.withAmount(item.getAmount() + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item for a specific amount. Also makes the item reusable.
|
||||
* Upon reaching maximum damage, the item will be consumed. Take care to set
|
||||
* the proper condition such that an almost-broken item becomes invalid for
|
||||
* crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
System.out.println("Transform damage: " + item);
|
||||
int newDamage = item.getDamage() + damage;
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount()).withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item for
|
||||
* 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
if (item.getAmount() > 1) {
|
||||
byPlayer.give(withItem);
|
||||
return item;
|
||||
} else {
|
||||
return withItem.withAmount(withItem.getAmount());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Damages the item for a specific amount. Also makes the item reusable.
|
||||
* Upon reaching maximum damage, the item will be consumed. Take care to set
|
||||
* the proper condition such that an almost-broken item becomes invalid for
|
||||
* crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount()).withDamage(newDamage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes multiple items to be consumed. Take care to set a condition for a
|
||||
* minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
return item.withAmount(Math.max(item.getAmount() - amount, 0) + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
*
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(item.getAmount() > 1) {
|
||||
byPlayer.give(withItem);
|
||||
return item;
|
||||
} else {
|
||||
return withItem.withAmount(withItem.getAmount());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure there is no return value.
|
||||
*
|
||||
* @param ingredient
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient noReturn(IIngredient ingredient) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Causes multiple items to be consumed. Take care to set a condition for a
|
||||
* minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
*
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform((item, byPlayer) -> item.withAmount(Math.max(item.getAmount() - amount, 0) + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives an item back to the player. Also clears the inventory slot at that
|
||||
* position.
|
||||
*
|
||||
* @param ingredient
|
||||
* @param givenItem
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient giveBack(IIngredient ingredient, @Optional final IItemStack givenItem) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
if (givenItem == null) {
|
||||
byPlayer.give(item);
|
||||
} else {
|
||||
byPlayer.give(givenItem);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Makes sure there is no return value.
|
||||
*
|
||||
* @param ingredient
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient noReturn(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives an item back to the player. Also clears the inventory slot at that
|
||||
* position.
|
||||
*
|
||||
* @param ingredient
|
||||
* @param givenItem
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient giveBack(IIngredient ingredient, @Optional final IItemStack givenItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(givenItem == null) {
|
||||
byPlayer.give(item.withAmount(1));
|
||||
return item;
|
||||
} else {
|
||||
byPlayer.give(givenItem);
|
||||
return item;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,125 +1,101 @@
|
||||
/*
|
||||
* 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.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientUnknown implements IIngredient
|
||||
{
|
||||
public static final IngredientUnknown INSTANCE = new IngredientUnknown(1);
|
||||
public class IngredientUnknown implements IIngredient {
|
||||
|
||||
private final int size;
|
||||
public static final IngredientUnknown INSTANCE = new IngredientUnknown(1);
|
||||
|
||||
public IngredientUnknown(int size)
|
||||
{
|
||||
this.size = size;
|
||||
}
|
||||
private final int size;
|
||||
|
||||
@Override
|
||||
public String getMark()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public IngredientUnknown(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount)
|
||||
{
|
||||
return new IngredientUnknown(amount);
|
||||
}
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient)
|
||||
{
|
||||
return ingredient;
|
||||
}
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientUnknown(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +1,73 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedItemStack {
|
||||
public static List<IItemStack> pickRandomDrops(Random random, WeightedItemStack[] items) {
|
||||
ArrayList<IItemStack> result = new ArrayList<IItemStack>();
|
||||
|
||||
for (WeightedItemStack item : items) {
|
||||
if (random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private final IItemStack stack;
|
||||
private final float p;
|
||||
|
||||
public WeightedItemStack(IItemStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public IItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedItemStack other = (WeightedItemStack) obj;
|
||||
if (this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) {
|
||||
return false;
|
||||
}
|
||||
if (Float.floatToIntBits(this.p) != Float.floatToIntBits(other.p)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private final IItemStack stack;
|
||||
private final float p;
|
||||
public WeightedItemStack(IItemStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static List<IItemStack> pickRandomDrops(Random random, WeightedItemStack[] items) {
|
||||
ArrayList<IItemStack> result = new ArrayList<>();
|
||||
|
||||
for(WeightedItemStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public IItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedItemStack other = (WeightedItemStack) obj;
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) && Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +1,76 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains a liquid definition. Liquid definitions provide additional
|
||||
* information about liquids.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.liquid.ILiquidDefinition")
|
||||
public interface ILiquidDefinition {
|
||||
/**
|
||||
* Converts this liquid into a liquid stack.
|
||||
*
|
||||
* @param millibuckets item stack size
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
public ILiquidStack asStack(int millibuckets);
|
||||
|
||||
/**
|
||||
* Gets the unlocalized name of this item.
|
||||
*
|
||||
* @return unlocalized name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
/**
|
||||
* Converts this liquid into a liquid stack.
|
||||
*
|
||||
* @param millibuckets item stack size
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
ILiquidStack asStack(int millibuckets);
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
/**
|
||||
* Gets the unlocalized name of this item.
|
||||
*
|
||||
* @return unlocalized name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
public int getLuminosity();
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
@ZenSetter("luminosity")
|
||||
public void setLuminosity(int value);
|
||||
@ZenGetter("luminosity")
|
||||
int getLuminosity();
|
||||
|
||||
@ZenGetter("density")
|
||||
public int getDensity();
|
||||
@ZenSetter("luminosity")
|
||||
void setLuminosity(int value);
|
||||
|
||||
@ZenSetter("density")
|
||||
public void setDensity(int density);
|
||||
@ZenGetter("density")
|
||||
int getDensity();
|
||||
|
||||
@ZenGetter("temperature")
|
||||
public int getTemperature();
|
||||
@ZenSetter("density")
|
||||
void setDensity(int density);
|
||||
|
||||
@ZenSetter("temperature")
|
||||
public void setTemperature(int temperature);
|
||||
@ZenGetter("temperature")
|
||||
int getTemperature();
|
||||
|
||||
@ZenGetter("viscosity")
|
||||
public int getViscosity();
|
||||
@ZenSetter("temperature")
|
||||
void setTemperature(int temperature);
|
||||
|
||||
@ZenSetter("viscosity")
|
||||
public void setViscosity(int viscosity);
|
||||
@ZenGetter("viscosity")
|
||||
int getViscosity();
|
||||
|
||||
@ZenGetter("gaseous")
|
||||
public boolean isGaseous();
|
||||
@ZenSetter("viscosity")
|
||||
void setViscosity(int viscosity);
|
||||
|
||||
@ZenSetter("gaseous")
|
||||
public void setGaseous(boolean gaseous);
|
||||
@ZenGetter("gaseous")
|
||||
boolean isGaseous();
|
||||
|
||||
@ZenGetter("containers")
|
||||
public List<IItemStack> getContainers();
|
||||
@ZenSetter("gaseous")
|
||||
void setGaseous(boolean gaseous);
|
||||
|
||||
@ZenMethod
|
||||
public void addContainer(IItemStack filled, IItemStack empty, int amount);
|
||||
@ZenGetter("containers")
|
||||
List<IItemStack> getContainers();
|
||||
|
||||
@ZenMethod
|
||||
public void removeContainer(IItemStack filled);
|
||||
@ZenMethod
|
||||
void addContainer(IItemStack filled, IItemStack empty, int amount);
|
||||
|
||||
@ZenMethod
|
||||
void removeContainer(IItemStack filled);
|
||||
}
|
||||
@@ -1,61 +1,51 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
@ZenClass("minetweaker.liquid.ILiquidStack")
|
||||
public interface ILiquidStack extends IIngredient {
|
||||
@ZenGetter("definition")
|
||||
public ILiquidDefinition getDefinition();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
@ZenGetter("amount")
|
||||
public int getAmount();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
public int getLuminosity();
|
||||
|
||||
@ZenGetter("density")
|
||||
public int getDensity();
|
||||
|
||||
@ZenGetter("temperature")
|
||||
public int getTemperature();
|
||||
|
||||
@ZenGetter("viscosity")
|
||||
public int getViscosity();
|
||||
|
||||
@ZenGetter("gaseous")
|
||||
public boolean isGaseous();
|
||||
|
||||
@ZenGetter("tag")
|
||||
public IData getTag();
|
||||
|
||||
@ZenMethod
|
||||
public ILiquidStack withTag(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public ILiquidStack withAmount(int amount);
|
||||
|
||||
public Object getInternal();
|
||||
|
||||
@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,81 +1,73 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedLiquidStack {
|
||||
public static List<ILiquidStack> pickRandomDrops(Random random, WeightedLiquidStack[] items) {
|
||||
ArrayList<ILiquidStack> result = new ArrayList<ILiquidStack>();
|
||||
|
||||
for (WeightedLiquidStack item : items) {
|
||||
if (random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
private final ILiquidStack stack;
|
||||
private final float p;
|
||||
public WeightedLiquidStack(ILiquidStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public static List<ILiquidStack> pickRandomDrops(Random random, WeightedLiquidStack[] items) {
|
||||
ArrayList<ILiquidStack> result = new ArrayList<>();
|
||||
|
||||
private final ILiquidStack stack;
|
||||
private final float p;
|
||||
for(WeightedLiquidStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
public WeightedLiquidStack(ILiquidStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public ILiquidStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
@ZenGetter("stack")
|
||||
public ILiquidStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedLiquidStack other = (WeightedLiquidStack) obj;
|
||||
if (this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) {
|
||||
return false;
|
||||
}
|
||||
if (Float.floatToIntBits(this.p) != Float.floatToIntBits(other.p)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedLiquidStack other = (WeightedLiquidStack) obj;
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) && Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +1,83 @@
|
||||
/*
|
||||
* 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.api.logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class FileLogger implements ILogger {
|
||||
private final Writer writer;
|
||||
private final PrintWriter printWriter;
|
||||
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
printWriter = new PrintWriter(writer);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new RuntimeException("Could not open log file " + output);
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write(message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
printWriter = new PrintWriter(writer);
|
||||
} catch(UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch(FileNotFoundException ex) {
|
||||
throw new RuntimeException("Could not open log file " + output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.write("INFO: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write(stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.write("WARNING: " + message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.write("INFO: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.write("WARNING: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
try {
|
||||
writer.write("ERROR: " + message + "\n");
|
||||
if (exception != null) {
|
||||
exception.printStackTrace(printWriter);
|
||||
}
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
try {
|
||||
writer.write("ERROR: " + stripMessage(message) + "\n");
|
||||
if(exception != null) {
|
||||
exception.printStackTrace(printWriter);
|
||||
}
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the given string, with formatting codes stripped away.
|
||||
*/
|
||||
public String stripMessage(String message) {
|
||||
return message == null ? null : FORMATTING_CODE_PATTERN.matcher(message).replaceAll("");
|
||||
}
|
||||
}
|
||||
@@ -1,101 +1,93 @@
|
||||
/*
|
||||
* 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.api.logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTLogger implements ILogger {
|
||||
private final List<ILogger> loggers = new ArrayList<ILogger>();
|
||||
private final List<IPlayer> players = new ArrayList<IPlayer>();
|
||||
private final List<String> unprocessed = new ArrayList<String>();
|
||||
|
||||
public void addLogger(ILogger logger) {
|
||||
loggers.add(logger);
|
||||
}
|
||||
private final List<ILogger> loggers = new ArrayList<>();
|
||||
private final List<IPlayer> players = new ArrayList<>();
|
||||
private final List<String> unprocessed = new ArrayList<>();
|
||||
|
||||
public void removeLogger(ILogger logger) {
|
||||
loggers.remove(logger);
|
||||
}
|
||||
public void addLogger(ILogger logger) {
|
||||
loggers.add(logger);
|
||||
}
|
||||
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
public void removeLogger(ILogger logger) {
|
||||
loggers.remove(logger);
|
||||
}
|
||||
|
||||
if (!unprocessed.isEmpty()) {
|
||||
for (String message : unprocessed) {
|
||||
player.sendChat(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
|
||||
public void removePlayer(IPlayer player) {
|
||||
players.remove(player);
|
||||
}
|
||||
if(!unprocessed.isEmpty()) {
|
||||
unprocessed.forEach(player::sendChat);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
unprocessed.clear();
|
||||
}
|
||||
public void removePlayer(IPlayer player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
public void clear() {
|
||||
unprocessed.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
String message2 = "WARNING: " + message;
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
String message2 = "WARNING: " + message;
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
if(players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
for (ILogger logger : loggers) {
|
||||
logger.logError(message, exception);
|
||||
}
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logError(message, exception);
|
||||
}
|
||||
|
||||
if (players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for (IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.mods;
|
||||
|
||||
import stanhebben.zenscript.annotations.IterableSimple;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.mods.ILoadedMods")
|
||||
@IterableSimple("minetweaker.mods.IMod")
|
||||
public interface ILoadedMods extends Iterable<IMod> {
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean contains(String name);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
public IMod get(String name);
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(String name);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
IMod get(String name);
|
||||
}
|
||||
@@ -3,20 +3,19 @@ package minetweaker.api.mods;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IMod {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("version")
|
||||
public String getVersion();
|
||||
|
||||
@ZenGetter("decription")
|
||||
public String getDescription();
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("version")
|
||||
String getVersion();
|
||||
|
||||
@ZenGetter("decription")
|
||||
String getDescription();
|
||||
}
|
||||
@@ -1,25 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMemberGetter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDict")
|
||||
public interface IOreDict {
|
||||
@ZenMemberGetter
|
||||
public IOreDictEntry get(String name);
|
||||
|
||||
@ZenGetter("entries")
|
||||
public List<IOreDictEntry> getEntries();
|
||||
|
||||
@ZenMemberGetter
|
||||
IOreDictEntry get(String name);
|
||||
|
||||
@ZenGetter("entries")
|
||||
List<IOreDictEntry> getEntries();
|
||||
}
|
||||
@@ -1,53 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDictEntry")
|
||||
public interface IOreDictEntry extends IIngredient {
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("empty")
|
||||
public boolean isEmpty();
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("firstItem")
|
||||
public IItemStack getFirstItem();
|
||||
@ZenGetter("empty")
|
||||
boolean isEmpty();
|
||||
|
||||
@ZenMethod
|
||||
public void add(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
public void addItems(IItemStack[] items);
|
||||
|
||||
@ZenMethod
|
||||
public void addAll(IOreDictEntry entry);
|
||||
|
||||
@ZenMethod
|
||||
public void remove(IItemStack item);
|
||||
@ZenGetter("firstItem")
|
||||
IItemStack getFirstItem();
|
||||
|
||||
@ZenMethod
|
||||
public void removeItems(IItemStack[] items);
|
||||
void add(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void addItems(IItemStack[] items);
|
||||
|
||||
@ZenMethod
|
||||
void addAll(IOreDictEntry entry);
|
||||
|
||||
@ZenMethod
|
||||
void remove(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void removeItems(IItemStack[] items);
|
||||
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean contains(IItemStack item);
|
||||
boolean contains(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
public void mirror(IOreDictEntry other);
|
||||
@ZenMethod
|
||||
void mirror(IOreDictEntry other);
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
@@ -11,127 +5,122 @@ import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientOreDict implements IIngredient {
|
||||
private final IOreDictEntry entry;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOreDict(
|
||||
IOreDictEntry entry,
|
||||
String mark,
|
||||
IItemCondition[] conditions,
|
||||
IItemTransformer[] transformers) {
|
||||
this.entry = entry;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
private final IOreDictEntry entry;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
public IngredientOreDict(IOreDictEntry entry, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.entry = entry;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return entry.getItems();
|
||||
}
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return entry.getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOreDict(entry, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOreDict(entry, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOreDict(entry, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(entry, mark, conditions, transformers);
|
||||
}
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOreDict(entry, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(entry, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if (!entry.matches(item))
|
||||
return false;
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!entry.matches(item))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if (!entry.matchesExact(item))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!entry.matchesExact(item))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return entry.contains(ingredient);
|
||||
}
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for (IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return entry.contains(ingredient);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return entry.getInternal();
|
||||
}
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return entry.getInternal();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,70 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.player.IPlayer")
|
||||
public interface IPlayer {
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("data")
|
||||
public IData getData();
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenMethod
|
||||
public void update(IData data);
|
||||
@ZenGetter("data")
|
||||
IData getData();
|
||||
|
||||
@ZenMethod
|
||||
public void sendChat(IChatMessage message);
|
||||
@ZenGetter("xp")
|
||||
int getXP();
|
||||
|
||||
@ZenMethod
|
||||
public void sendChat(String message);
|
||||
@ZenSetter("xp")
|
||||
void setXP(int xp);
|
||||
|
||||
@ZenGetter("hotbarSize")
|
||||
public int getHotbarSize();
|
||||
@ZenMethod
|
||||
void removeXP(int xp);
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getHotbarStack(int i);
|
||||
@ZenMethod
|
||||
void update(IData data);
|
||||
|
||||
@ZenGetter("inventorySize")
|
||||
public int getInventorySize();
|
||||
@ZenMethod
|
||||
void sendChat(IChatMessage message);
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack getInventoryStack(int i);
|
||||
@ZenMethod
|
||||
void sendChat(String message);
|
||||
|
||||
@ZenGetter("currentItem")
|
||||
public IItemStack getCurrentItem();
|
||||
@ZenGetter("hotbarSize")
|
||||
int getHotbarSize();
|
||||
|
||||
@ZenGetter("creative")
|
||||
public boolean isCreative();
|
||||
@ZenMethod
|
||||
IItemStack getHotbarStack(int i);
|
||||
|
||||
@ZenGetter("adventure")
|
||||
public boolean isAdventure();
|
||||
@ZenGetter("inventorySize")
|
||||
int getInventorySize();
|
||||
|
||||
@ZenMethod
|
||||
public void give(IItemStack stack);
|
||||
@ZenMethod
|
||||
IItemStack getInventoryStack(int i);
|
||||
|
||||
// not an exposed method. risks abuse
|
||||
public void openBrowser(String url);
|
||||
@ZenGetter("currentItem")
|
||||
IItemStack getCurrentItem();
|
||||
|
||||
// not an exposed method, so far. would it be useful?
|
||||
public void copyToClipboard(String value);
|
||||
@ZenGetter("creative")
|
||||
boolean isCreative();
|
||||
|
||||
@ZenGetter("adventure")
|
||||
boolean isAdventure();
|
||||
|
||||
@ZenMethod
|
||||
void give(IItemStack stack);
|
||||
|
||||
// not an exposed method. risks abuse
|
||||
void openBrowser(String url);
|
||||
|
||||
// not an exposed method, so far. would it be useful?
|
||||
void copyToClipboard(String value);
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.*;
|
||||
|
||||
/**
|
||||
* Created by Jared on 6/3/2016.
|
||||
*/
|
||||
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);
|
||||
|
||||
@@ -1,39 +1,33 @@
|
||||
/*
|
||||
* 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.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class CraftingInfo implements ICraftingInfo {
|
||||
private final ICraftingInventory inventory;
|
||||
private final IDimension dimension;
|
||||
|
||||
public CraftingInfo(ICraftingInventory inventory, IDimension dimension) {
|
||||
this.inventory = inventory;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return inventory.getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,21 @@ package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
||||
/**
|
||||
* Created by Jared on 4/18/2016.
|
||||
*/
|
||||
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,9 +1,7 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,24 +13,23 @@ import java.util.List;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IBrewingManager")
|
||||
public interface IBrewingManager {
|
||||
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
public List<IBrewingRecipe> getAll();
|
||||
|
||||
List<IBrewingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Removes a brewing recipe from the specified item.
|
||||
*
|
||||
* @param output recipe output pattern
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
public void remove(IItemStack output);
|
||||
|
||||
void remove(IItemStack output);
|
||||
|
||||
/**
|
||||
* Adds a recipe.
|
||||
*
|
||||
@@ -41,21 +38,17 @@ public interface IBrewingManager {
|
||||
* @param input recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
public void add(
|
||||
IItemStack output,
|
||||
IItemStack ingredient,
|
||||
IItemStack input);
|
||||
|
||||
void add(IItemStack output, IItemStack ingredient, IItemStack input);
|
||||
|
||||
/**
|
||||
* Removes recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredient
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
public int remove(
|
||||
IItemStack output,
|
||||
IItemStack ingredients);
|
||||
|
||||
int remove(IItemStack output, IItemStack ingredients);
|
||||
|
||||
}
|
||||
@@ -2,11 +2,8 @@ package minetweaker.api.recipes;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* Created by Jared on 6/2/2016.
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IBrewingRecipe")
|
||||
public interface IBrewingRecipe {
|
||||
|
||||
public String toCommandString();
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -1,28 +1,21 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInfo")
|
||||
public interface ICraftingInfo {
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory();
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension();
|
||||
|
||||
@ZenGetter("inventory")
|
||||
ICraftingInventory getInventory();
|
||||
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
}
|
||||
@@ -1,104 +1,99 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Crafting inventory interface. The crafting inventory is the 2x2 grid in the
|
||||
* player inventory or the 3x3 grid in the crafting bench.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInventory")
|
||||
public interface ICraftingInventory {
|
||||
/**
|
||||
* Gets the player owning this inventory.
|
||||
*
|
||||
* @return inventory player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer();
|
||||
|
||||
/**
|
||||
* Gets the size of this inventory.
|
||||
*
|
||||
* @return inventory size
|
||||
*/
|
||||
@ZenGetter("size")
|
||||
public int getSize();
|
||||
|
||||
/**
|
||||
* Gets the width of this inventory.
|
||||
*
|
||||
* @return inventory width
|
||||
*/
|
||||
@ZenGetter("width")
|
||||
public int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of this inventory.
|
||||
*
|
||||
* @return inventory height
|
||||
*/
|
||||
@ZenGetter("height")
|
||||
public int getHeight();
|
||||
|
||||
/**
|
||||
* Gets the number of stacks that are actually filled in.
|
||||
*
|
||||
* @return effective stack count
|
||||
*/
|
||||
@ZenGetter("stackCount")
|
||||
public int getStackCount();
|
||||
|
||||
/**
|
||||
* Gets the stack at the given location.
|
||||
*
|
||||
* @param i stack index
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Gets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
* @return item stack, or null if there is no item stack at that position
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack getStack(int x, int y);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* position
|
||||
*/
|
||||
@ZenMethod
|
||||
public void setStack(int x, int y, IItemStack stack);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given index.
|
||||
*
|
||||
* @param i stack index
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* index
|
||||
*/
|
||||
@ZenMethod
|
||||
public void setStack(int i, IItemStack stack);
|
||||
|
||||
/**
|
||||
* Gets the player owning this inventory.
|
||||
*
|
||||
* @return inventory player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
/**
|
||||
* Gets the size of this inventory.
|
||||
*
|
||||
* @return inventory size
|
||||
*/
|
||||
@ZenGetter("size")
|
||||
int getSize();
|
||||
|
||||
/**
|
||||
* Gets the width of this inventory.
|
||||
*
|
||||
* @return inventory width
|
||||
*/
|
||||
@ZenGetter("width")
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of this inventory.
|
||||
*
|
||||
* @return inventory height
|
||||
*/
|
||||
@ZenGetter("height")
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* Gets the number of stacks that are actually filled in.
|
||||
*
|
||||
* @return effective stack count
|
||||
*/
|
||||
@ZenGetter("stackCount")
|
||||
int getStackCount();
|
||||
|
||||
/**
|
||||
* Gets the stack at the given location.
|
||||
*
|
||||
* @param i stack index
|
||||
*
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Gets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
*
|
||||
* @return item stack, or null if there is no item stack at that position
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int x, int y);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* position
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int x, int y, IItemStack stack);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given index.
|
||||
*
|
||||
* @param i stack index
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* index
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
@@ -11,18 +5,18 @@ import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingRecipe")
|
||||
public interface ICraftingRecipe {
|
||||
public boolean matches(ICraftingInventory inventory);
|
||||
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory);
|
||||
|
||||
public boolean hasTransformers();
|
||||
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer);
|
||||
|
||||
public String toCommandString();
|
||||
|
||||
boolean matches(ICraftingInventory inventory);
|
||||
|
||||
IItemStack getCraftingResult(ICraftingInventory inventory);
|
||||
|
||||
boolean hasTransformers();
|
||||
|
||||
void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer);
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -1,43 +1,33 @@
|
||||
/*
|
||||
* 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.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IFurnaceManager")
|
||||
public interface IFurnaceManager {
|
||||
@ZenMethod
|
||||
public void remove(IIngredient output, @Optional IIngredient input);
|
||||
|
||||
@ZenMethod
|
||||
public void addRecipe(IItemStack output, IIngredient input, @Optional double xp);
|
||||
|
||||
@ZenMethod
|
||||
public void setFuel(IIngredient item, int fuel);
|
||||
|
||||
@ZenMethod
|
||||
public int getFuel(IItemStack item);
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
public List<IFurnaceRecipe> getAll();
|
||||
|
||||
@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.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<IFurnaceRecipe> getAll();
|
||||
}
|
||||
@@ -4,7 +4,7 @@ package minetweaker.api.recipes;
|
||||
* Created by Jared on 4/18/2016.
|
||||
*/
|
||||
public interface IFurnaceRecipe {
|
||||
|
||||
|
||||
public String toCommandString();
|
||||
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
public interface IMTRecipe {
|
||||
|
||||
|
||||
ICraftingRecipe getRecipe();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* @author Jared
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeAction")
|
||||
public interface IRecipeAction {
|
||||
|
||||
void process(IItemStack output, ICraftingInfo craftingInfo, IPlayer player);
|
||||
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.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 {
|
||||
public IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInfo craftingInfo);
|
||||
|
||||
IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInfo craftingInfo);
|
||||
}
|
||||
@@ -1,123 +1,110 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
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.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeManager")
|
||||
public interface IRecipeManager {
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
public List<ICraftingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes resulting in the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to find
|
||||
* @return crafting recipes for the given item(s)
|
||||
*/
|
||||
@ZenMethod
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Removes all crafting recipes crafting the specified item.
|
||||
*
|
||||
* @param output recipe output pattern
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
public int remove(IIngredient output, @Optional boolean nbtMatch);
|
||||
|
||||
/**
|
||||
* Adds a shaped recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
public void addShaped(
|
||||
IItemStack output,
|
||||
IIngredient[][] ingredients,
|
||||
@Optional IRecipeFunction function);
|
||||
|
||||
/**
|
||||
* Adds a mirrored shaped recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
public void addShapedMirrored(
|
||||
IItemStack output,
|
||||
IIngredient[][] ingredients,
|
||||
@Optional IRecipeFunction function);
|
||||
|
||||
/**
|
||||
* Adds a shapeless recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
public void addShapeless(
|
||||
IItemStack output,
|
||||
IIngredient[] ingredients,
|
||||
@Optional IRecipeFunction function);
|
||||
|
||||
/**
|
||||
* Removes shaped recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
public int removeShaped(
|
||||
IIngredient output,
|
||||
@Optional IIngredient[][] ingredients);
|
||||
|
||||
/**
|
||||
* Removes shapeless recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param wildcard if the recipe may contain other ingredients too, besides
|
||||
* the ones specified
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
public int removeShapeless(
|
||||
IIngredient output,
|
||||
@Optional IIngredient[] ingredients,
|
||||
@Optional boolean wildcard);
|
||||
|
||||
/**
|
||||
* Performs a crafting with the specified ingredients. Returns null if no
|
||||
* crafting recipe exists.
|
||||
*
|
||||
* @param contents crafting inventory contents
|
||||
* @return crafting result, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack craft(IItemStack[][] contents);
|
||||
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<ICraftingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes resulting in the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to find
|
||||
*
|
||||
* @return crafting recipes for the given item(s)
|
||||
*/
|
||||
@ZenMethod
|
||||
List<ICraftingRecipe> getRecipesFor(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Removes all crafting recipes crafting the specified item.
|
||||
*
|
||||
* @param output recipe output pattern
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int remove(IIngredient output, @Optional boolean nbtMatch);
|
||||
|
||||
/**
|
||||
* Adds a shaped recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||
|
||||
/**
|
||||
* Adds a mirrored shaped recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||
|
||||
/**
|
||||
* Adds a shapeless recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param function recipe function (optional)
|
||||
*/
|
||||
@ZenMethod
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action);
|
||||
|
||||
/**
|
||||
* Removes shaped recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients);
|
||||
|
||||
/**
|
||||
* Removes shapeless recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param wildcard if the recipe may contain other ingredients too, besides
|
||||
* the ones specified
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int removeShapeless(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard);
|
||||
|
||||
/**
|
||||
* Performs a crafting with the specified ingredients. Returns null if no
|
||||
* crafting recipe exists.
|
||||
*
|
||||
* @param contents crafting inventory contents
|
||||
*
|
||||
* @return crafting result, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack craft(IItemStack[][] contents);
|
||||
|
||||
}
|
||||
@@ -1,56 +1,63 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipe implements ICraftingRecipe {
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
private final byte[] posy;
|
||||
private final boolean mirrored;
|
||||
private final IRecipeFunction function;
|
||||
|
||||
private final 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) {
|
||||
int numIngredients = 0;
|
||||
for(IIngredient[] row : ingredients) {
|
||||
for(IIngredient ingredient : row) {
|
||||
if(ingredient != null) {
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
IIngredient[] ingredient = ingredients[i];
|
||||
for(int i1 = 0; i1 < ingredient.length; i1++) {
|
||||
if(ingredient[i1] != null) {
|
||||
numIngredients++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for(IIngredient[] row : ingredients) {
|
||||
// for(IIngredient ingredient : row) {
|
||||
// if(ingredient != null) {
|
||||
// numIngredients++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
this.posx = new byte[numIngredients];
|
||||
this.posy = new byte[numIngredients];
|
||||
this.output = output;
|
||||
this.ingredients = new IIngredient[numIngredients];
|
||||
this.function = function;
|
||||
|
||||
this.action = action;
|
||||
|
||||
int width1 = 0;
|
||||
int height1 = ingredients.length;
|
||||
|
||||
|
||||
int ix = 0;
|
||||
for(int j = 0; j < ingredients.length; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
width1 = Math.max(width1, row.length);
|
||||
|
||||
|
||||
for(int i = 0; i < row.length; i++) {
|
||||
if(row[i] != null) {
|
||||
this.posx[ix] = (byte) i;
|
||||
@@ -60,46 +67,45 @@ 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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
@@ -107,15 +113,15 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
@@ -124,23 +130,23 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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++) {
|
||||
@@ -148,16 +154,16 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
@@ -166,20 +172,20 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
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;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for(IIngredient ingredient : ingredients) {
|
||||
@@ -187,14 +193,14 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
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++) {
|
||||
@@ -202,17 +208,17 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, false, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
@@ -221,73 +227,72 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
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;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, true, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("recipes.addShaped(");
|
||||
result.append(output);
|
||||
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++) {
|
||||
ingredientsArray[posy[i]][posx[i]] = ingredients[i];
|
||||
}
|
||||
|
||||
|
||||
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(", ");
|
||||
|
||||
|
||||
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) {
|
||||
Map<String, IItemStack> tagged = new HashMap<String, IItemStack>();
|
||||
Map<String, IItemStack> tagged = new HashMap<>();
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
@@ -300,31 +305,24 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
* 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) {
|
||||
|
||||
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) {
|
||||
inventory.setStack(
|
||||
inventory.getWidth() - (offx + posx[i]) - 1,
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
inventory.setStack(inventory.getWidth() - (offx + posx[i]) - 1, offy + posy[i], transformed);
|
||||
} else {
|
||||
inventory.setStack(
|
||||
offx + posx[i],
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
inventory.setStack(offx + posx[i], offy + posy[i], transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IRecipeAction getAction() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
@@ -1,169 +1,172 @@
|
||||
/*
|
||||
* 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.api.recipes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
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 IIngredient[] ingredients;
|
||||
|
||||
public ShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function) {
|
||||
this.output = output;
|
||||
this.function = function;
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return ingredients.length;
|
||||
}
|
||||
|
||||
public IIngredient[] getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@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) {
|
||||
Map<String, IItemStack> map = new HashMap<String, IItemStack>();
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (ingredients[i].getMark() != null) {
|
||||
map.put(ingredients[i].getMark(), matching.inputs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
actualOutput = function.process(actualOutput, map, new CraftingInfo(inventory, 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++) {
|
||||
IIngredient ingredient = ingredients[i];
|
||||
IItemStack transformed = ingredient.applyTransform(matching.inputs[i], byPlayer);
|
||||
if (transformed != matching.inputs[i]) {
|
||||
inventory.setStack(matching.indices[i], transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
result.append("recipes.addShapeless(");
|
||||
result.append(output);
|
||||
result.append(", [");
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (i > 0)
|
||||
result.append(", ");
|
||||
|
||||
result.append(ingredients[i]);
|
||||
}
|
||||
|
||||
result.append("]);");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders ingredients to match the given shapeless recipe.
|
||||
*
|
||||
* @param recipe shapeless recipe
|
||||
* @param ingredients crafting input
|
||||
* @return reordered inputs, or null if no match was found
|
||||
*/
|
||||
private static RecipeMatching matchShapeless(
|
||||
IIngredient[] recipe,
|
||||
ICraftingInventory ingredients) {
|
||||
int numItems = 0;
|
||||
for (int i = 0; i < ingredients.getSize(); i++) {
|
||||
if (ingredients.getStack(i) != null) {
|
||||
numItems++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numItems != recipe.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IItemStack[] matched = new IItemStack[recipe.length];
|
||||
int[] indices = new int[recipe.length];
|
||||
|
||||
outer: for (int i = 0; i < ingredients.getSize(); i++) {
|
||||
IItemStack ingredient = ingredients.getStack(i);
|
||||
if (ingredient == null)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < recipe.length; j++) {
|
||||
if (matched[j] != null)
|
||||
continue;
|
||||
|
||||
if (recipe[j].matches(ingredient)) {
|
||||
matched[j] = ingredient;
|
||||
indices[j] = i;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RecipeMatching(matched, indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class RecipeMatching {
|
||||
public final IItemStack[] inputs;
|
||||
public final int[] indices;
|
||||
|
||||
public RecipeMatching(IItemStack[] inputs, int[] indices) {
|
||||
this.inputs = inputs;
|
||||
this.indices = indices;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
this.output = output;
|
||||
this.function = function;
|
||||
this.ingredients = ingredients;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders ingredients to match the given shapeless recipe.
|
||||
*
|
||||
* @param recipe shapeless recipe
|
||||
* @param ingredients crafting input
|
||||
*
|
||||
* @return reordered inputs, or null if no match was found
|
||||
*/
|
||||
private static RecipeMatching matchShapeless(IIngredient[] recipe, ICraftingInventory ingredients) {
|
||||
int numItems = 0;
|
||||
for(int i = 0; i < ingredients.getSize(); i++) {
|
||||
if(ingredients.getStack(i) != null) {
|
||||
numItems++;
|
||||
}
|
||||
}
|
||||
|
||||
if(numItems != recipe.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IItemStack[] matched = new IItemStack[recipe.length];
|
||||
int[] indices = new int[recipe.length];
|
||||
|
||||
outer:
|
||||
for(int i = 0; i < ingredients.getSize(); i++) {
|
||||
IItemStack ingredient = ingredients.getStack(i);
|
||||
if(ingredient == null)
|
||||
continue;
|
||||
|
||||
for(int j = 0; j < recipe.length; j++) {
|
||||
if(matched[j] != null)
|
||||
continue;
|
||||
if(recipe[j].matches(ingredient)) {
|
||||
matched[j] = ingredient;
|
||||
indices[j] = i;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RecipeMatching(matched, indices);
|
||||
}
|
||||
|
||||
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) {
|
||||
Map<String, IItemStack> map = new HashMap<>();
|
||||
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) {
|
||||
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++) {
|
||||
IIngredient ingredient = ingredients[i];
|
||||
IItemStack transformed = ingredient.applyTransform(matching.inputs[i], byPlayer);
|
||||
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){
|
||||
result.append(output);
|
||||
}else{
|
||||
result.append("null");
|
||||
}
|
||||
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()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,41 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 506 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user