mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-24 22:04:23 +00:00
Move sources and resources
This commit is contained in:
1 parent
5044de32dd
commit
7f3b65c4b7
320 files changed
+4
-11598
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class BlockPatternOr implements IBlockPattern {
|
||||
|
||||
private final IBlockPattern[] elements;
|
||||
|
||||
public BlockPatternOr(IBlockPattern[] elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public BlockPatternOr(IBlockPattern a, IBlockPattern b) {
|
||||
this.elements = new IBlockPattern[]{a, b};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
List<IBlock> blocks = new ArrayList<>();
|
||||
for(IBlockPattern pattern : elements) {
|
||||
blocks.addAll(pattern.getBlocks());
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(pattern.matches(block))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
for(IBlockPattern pattern : elements) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(" | ");
|
||||
}
|
||||
|
||||
result.append(pattern.getDisplayName());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(ArrayUtil.append(elements, pattern));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Block interface. Used to interact with blocks in the world.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlock")
|
||||
public interface IBlock extends IBlockPattern {
|
||||
|
||||
/**
|
||||
* Gets the block definition.
|
||||
*
|
||||
* @return block definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IBlockDefinition getDefinition();
|
||||
|
||||
@ZenGetter("meta")
|
||||
int getMeta();
|
||||
|
||||
@ZenGetter("data")
|
||||
IData getTileData();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Blocks definitions provide additional information about blocks.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockDefinition")
|
||||
public interface IBlockDefinition {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockPattern")
|
||||
public interface IBlockPattern {
|
||||
|
||||
@ZenMethod("blocks")
|
||||
List<IBlock> getBlocks();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean matches(IBlock block);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
IBlockPattern or(IBlockPattern pattern);
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package minetweaker.api.chat;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents a chat message. Strings can be converted into chat messages, and
|
||||
* chat messages can be colored and concatenated.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.chat.IChatMessage")
|
||||
public interface IChatMessage {
|
||||
|
||||
/**
|
||||
* Concatenates two chat messages.
|
||||
*
|
||||
* @param other other chat message
|
||||
*
|
||||
* @return concatenated chat message
|
||||
*/
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IChatMessage add(IChatMessage other);
|
||||
|
||||
/**
|
||||
* Retrieves the internal object backing this object. Must be generated by
|
||||
* the implementing platform.
|
||||
*
|
||||
* @return internal object
|
||||
*/
|
||||
Object getInternal();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package minetweaker.api.client;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Interface for client interaction. Only available on clients.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.api.IClient")
|
||||
public interface IClient {
|
||||
|
||||
/**
|
||||
* Gets the current player.
|
||||
*
|
||||
* @return current player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("language")
|
||||
String getLanguage();
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DummyJEIRecipeRegistry implements IJEIRecipeRegistry {
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(Object object, String category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(Object output, String category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFurnace(List<Object> inputs, Object output) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFurnace(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFuel(Collection<Object> input, int burnTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFuel(Object object) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadItemList() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeItem(Object stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(Object stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateTooltips(IIngredient ingredient) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package minetweaker.api.compat;
|
||||
|
||||
import minetweaker.api.item.IIngredient;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface IJEIRecipeRegistry {
|
||||
|
||||
void addRecipe(Object object);
|
||||
|
||||
void addRecipe(Object object, String category);
|
||||
|
||||
void removeRecipe(Object output);
|
||||
|
||||
void removeRecipe(Object output, String category);
|
||||
|
||||
|
||||
void addFurnace(List<Object> inputs, Object output);
|
||||
|
||||
void removeFurnace(Object output);
|
||||
|
||||
void addFuel(Collection<Object> input, int burnTime);
|
||||
|
||||
void removeFuel(Object object);
|
||||
|
||||
void invalidateTooltips(IIngredient ingredient);
|
||||
|
||||
//To update the items in 1.10.2
|
||||
void reloadItemList();
|
||||
|
||||
//To update the items in 1.11.2 both below are used
|
||||
void removeItem(Object stack);
|
||||
|
||||
void addItem(Object stack);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package minetweaker.api.container;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Container interface.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.container.IContainer")
|
||||
public interface IContainer extends Iterable<IItemStack> {
|
||||
|
||||
/**
|
||||
* Gets the container size.
|
||||
*
|
||||
* @return container size
|
||||
*/
|
||||
@ZenGetter("containerSize")
|
||||
int getContainerSize();
|
||||
|
||||
/**
|
||||
* Gets the item stack at the given position. Returns null if there is no
|
||||
* stack at that position.
|
||||
*
|
||||
* @param i stack position
|
||||
*
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Sets the item stack at the given position.
|
||||
*
|
||||
* @param i stack position
|
||||
* @param stack contents, or null to set an empty stack
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package minetweaker.api.damage;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IDamageSource {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a boolean value (true or false).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataBool implements IData {
|
||||
|
||||
private final boolean value;
|
||||
|
||||
public DataBool(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) (value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Boolean.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("a bool is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asBool() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asBool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot compare bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromBool(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot add bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on bool values");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataBool(value & other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataBool(value | other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataBool(value ^ other.asBool());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a bool value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataBool(!value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a byte value (-128 .. 127)
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataByte implements IData {
|
||||
|
||||
private final byte value;
|
||||
|
||||
public DataByte(byte value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a byte to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Byte.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A byte is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asByte() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Byte.compare(value, data.asByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataByte((byte) (value + other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataByte((byte) (value - other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataByte((byte) (value * other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataByte((byte) (value / other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataByte((byte) (value % other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataByte((byte) (value & other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataByte((byte) (value | other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataByte((byte) (value ^ other.asByte()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataByte((byte) (-value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataByte((byte) (~value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a byte array.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataByteArray implements IData {
|
||||
|
||||
private final byte[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataByteArray(byte[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
byte[] otherData = other.asByteArray();
|
||||
byte[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataByteArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a byte array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("[");
|
||||
boolean first = true;
|
||||
for(byte value : data) {
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
result.append(", ");
|
||||
|
||||
result.append(value);
|
||||
}
|
||||
result.append("] as byte[]");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<IData>();
|
||||
for(byte value : data) {
|
||||
result.add(new DataByte(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
int[] result = new int[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataByte(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("byte[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set byte[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataByteArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromByteArray(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as byte[]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a double-precision value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataDouble implements IData {
|
||||
|
||||
private final double value;
|
||||
|
||||
public DataDouble(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a double to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return (float) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Double.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A double is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asDouble() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData other) {
|
||||
return value == other.asDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData other) {
|
||||
return Double.compare(value, other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataDouble(value + other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataDouble(value - other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataDouble(value * other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataDouble(value / other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataDouble(value % other.asDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataDouble(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a single-precision floating point value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataFloat implements IData {
|
||||
|
||||
private final float value;
|
||||
|
||||
public DataFloat(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a float to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return (long) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Float.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A float is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asFloat() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Float.compare(value, data.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataFloat(value + other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataFloat(value - other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataFloat(value * other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataFloat(value / other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataFloat(value % other.asFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataFloat(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise operations on float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as float";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 32-bit integer value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataInt implements IData {
|
||||
|
||||
private final int value;
|
||||
|
||||
public DataInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new RuntimeException("Cannot cast an int to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new RuntimeException("An int is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asInt() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Integer.compare(value, data.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataInt(value + other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataInt(value - other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataInt(value * other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataInt(value / other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataInt(value % other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataInt(value & other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataInt(value | other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataInt(value ^ other.asInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataInt(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataInt(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an int array.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataIntArray implements IData {
|
||||
|
||||
private final int[] data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataIntArray(int[] data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
int[] otherData = other.asIntArray();
|
||||
int[] result = Arrays.copyOf(data, data.length + otherData.length);
|
||||
System.arraycopy(otherData, 0, result, data.length, otherData.length);
|
||||
return new DataIntArray(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from an int array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply with an arary");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on an array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Arrays don't support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast an array to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot cast an array to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot cast an array to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot cast an array to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot cast an array to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot cast an array to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot cast an array to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('[');
|
||||
boolean first = true;
|
||||
for(int value : data) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(value);
|
||||
}
|
||||
result.append(']');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
List<IData> result = new ArrayList<>();
|
||||
for(int value : data) {
|
||||
result.add(new DataInt(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
byte[] result = new byte[data.length];
|
||||
for(int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte) data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataInt(data[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("Cannot modify this byte array");
|
||||
} else {
|
||||
data[i] = value.asInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("int[] doesn't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("cannot set int[] members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return equals(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare arrays");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return Arrays.equals(this.data, data.asIntArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
return new DataIntArray(Arrays.copyOf(this.data, this.data.length), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromIntArray(this.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as int[]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a list.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataList implements IData {
|
||||
|
||||
private final List<IData> values;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataList(List<IData> values, boolean immutable) {
|
||||
this.values = values;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot convert a list to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new IllegalDataException("Cannot convert a list to a byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new IllegalDataException("Cannot convert a list to a short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new IllegalDataException("Cannot convert a list to an int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new IllegalDataException("Cannot convert a list to a long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new IllegalDataException("Cannot convert a list to a float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new IllegalDataException("Cannot convert a list to a double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
if(immutable) {
|
||||
return Collections.unmodifiableList(values);
|
||||
} else {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append('[');
|
||||
boolean first = true;
|
||||
for(IData value : values) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
output.append(", ");
|
||||
}
|
||||
output.append(value.toString());
|
||||
}
|
||||
output.append(']');
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
byte[] result = new byte[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asByte();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
try {
|
||||
int[] result = new int[values.size()];
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
result[i] = values.get(i).asInt();
|
||||
}
|
||||
return result;
|
||||
} catch(IllegalDataException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return values.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("this list is immutable");
|
||||
} else {
|
||||
values.set(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Lists don't have members");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
List<IData> dataValues = data.asList();
|
||||
if(dataValues != null && containsList(dataValues))
|
||||
return true;
|
||||
|
||||
for(IData value : values) {
|
||||
if(value.contains(data))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean containsList(List<IData> dataValues) {
|
||||
outer:
|
||||
for(IData dataValue : dataValues) {
|
||||
for(IData value : values) {
|
||||
if(value.contains(dataValue))
|
||||
continue outer;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
List<IData> otherValues = data.asList();
|
||||
if(otherValues.size() != values.size())
|
||||
return false;
|
||||
|
||||
for(int i = 0; i < values.size(); i++) {
|
||||
if(!values.get(i).equals(otherValues.get(i)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare with a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
List<IData> copy = new ArrayList<>();
|
||||
for(IData value : values) {
|
||||
copy.add(value.immutable());
|
||||
}
|
||||
return new DataList(copy, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
|
||||
List<IData> result = new ArrayList<>();
|
||||
result.addAll(values);
|
||||
result.addAll(data.asList());
|
||||
return new DataList(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromList(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return update(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Lists don't support bitwise operators");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 64-bit long value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataLong implements IData {
|
||||
|
||||
private final long value;
|
||||
|
||||
public DataLong(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a long to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Long.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A long is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asLong() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Long.compare(value, data.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataLong(value + other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataLong(value - other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataLong(value * other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataLong(value / other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataLong(value % other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataLong(value & other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataLong(value | other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataLong(value ^ other.asLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataLong(-value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataLong(~value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as long";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a map, mapping strings to data elements.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataMap implements IData {
|
||||
|
||||
public static final DataMap EMPTY = new DataMap(new HashMap<>(), true);
|
||||
|
||||
private final Map<String, IData> data;
|
||||
private final boolean immutable;
|
||||
|
||||
public DataMap(Map<String, IData> data, boolean immutable) {
|
||||
this.data = data;
|
||||
this.immutable = immutable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : otherMap.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
Map<String, IData> otherMap = other.asMap();
|
||||
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(String key : otherMap.keySet()) {
|
||||
result.remove(key);
|
||||
}
|
||||
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo with maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate maps.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Maps do not support bitwise operations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to byte");
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to short");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to int");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to long");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to float");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
throw new UnsupportedOperationException("Cannot cast map to double");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('{');
|
||||
boolean first = true;
|
||||
for(Map.Entry<String, IData> entry : data.entrySet()) {
|
||||
if(first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
if(isValidIdentifier(entry.getKey())) {
|
||||
result.append(entry.getKey());
|
||||
} else {
|
||||
result.append("\"").append(entry.getKey()).append("\"");
|
||||
}
|
||||
|
||||
result.append(": ");
|
||||
result.append(entry.getValue().toString());
|
||||
}
|
||||
result.append('}');
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
if(immutable) {
|
||||
return Collections.unmodifiableMap(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Cannot index maps with integers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
return data.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
if(immutable) {
|
||||
throw new UnsupportedOperationException("this map is not modifiable");
|
||||
} else {
|
||||
this.data.put(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
if(data instanceof DataString) {
|
||||
return this.data.containsKey(data.asString());
|
||||
}
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap == null)
|
||||
return false;
|
||||
|
||||
for(Map.Entry<String, IData> dataEntry : dataMap.entrySet()) {
|
||||
if(!this.data.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if(!this.data.get(dataEntry.getKey()).contains(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
throw new UnsupportedOperationException("Cannot compare maps");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
if(this == data)
|
||||
return true;
|
||||
|
||||
Map<String, IData> dataMap = data.asMap();
|
||||
if(dataMap.size() != this.data.size())
|
||||
return false;
|
||||
|
||||
for(Map.Entry<String, IData> dataEntry : this.data.entrySet()) {
|
||||
if(!dataMap.containsKey(dataEntry.getKey())) {
|
||||
return false;
|
||||
} else if(!dataMap.get(dataEntry.getKey()).equals(dataEntry.getValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
if(immutable) {
|
||||
return this;
|
||||
} else {
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().immutable());
|
||||
}
|
||||
return new DataMap(result, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
if(immutable)
|
||||
data = data.immutable();
|
||||
|
||||
Map<String, IData> result = new HashMap<>();
|
||||
for(Map.Entry<String, IData> entry : this.data.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for(Map.Entry<String, IData> entry : data.asMap().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return new DataMap(result, immutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromMap(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString();
|
||||
}
|
||||
|
||||
private boolean isValidIdentifier(String str) {
|
||||
if(!Character.isJavaIdentifierStart(str.charAt(0)))
|
||||
return false;
|
||||
|
||||
for(int i = 1; i < str.length(); i++) {
|
||||
if(!Character.isJavaIdentifierPart(str.charAt(i)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a 16-bit short value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataShort implements IData {
|
||||
|
||||
private final short value;
|
||||
|
||||
public DataShort(short value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
throw new IllegalDataException("Cannot cast a short to a bool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return Short.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("A short is not indexable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asShort() == value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value == data.asShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return Short.compare(value, data.asShort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataShort((short) (value + other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
return new DataShort((short) (value - other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
return new DataShort((short) (value * other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
return new DataShort((short) (value / other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
return new DataShort((short) (value % other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
return new DataShort((short) (value & other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
return new DataShort((short) (value | other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
return new DataShort((short) (value ^ other.asShort()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
return new DataShort((short) (-value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
return new DataShort((short) (~value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asString() + " as short";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a string value.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class DataString implements IData {
|
||||
|
||||
private final String value;
|
||||
|
||||
public DataString(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean asBool() {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte asByte() {
|
||||
return Byte.parseByte(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short asShort() {
|
||||
return Short.parseShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int asInt() {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float asFloat() {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double asDouble() {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IData> asList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IData> asMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] asIntArray() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getAt(int i) {
|
||||
return new DataString(value.substring(i, i + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAt(int i, IData value) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData memberGet(String name) {
|
||||
if(name.equals("length")) {
|
||||
return new DataInt(value.length());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("no such member: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memberSet(String name, IData data) {
|
||||
throw new UnsupportedOperationException("Strings are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return value.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IData data) {
|
||||
return data.asString().equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IData data) {
|
||||
return value.equals(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IData data) {
|
||||
return value.compareTo(data.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData immutable() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData update(IData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convert(IDataConverter<T> converter) {
|
||||
return converter.fromString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData add(IData other) {
|
||||
return new DataString(value + other.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData sub(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot subtract from a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mul(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot multiply a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData div(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot divide a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData mod(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform modulo on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData and(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData or(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData xor(IData other) {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData neg() {
|
||||
throw new UnsupportedOperationException("Cannot negate a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData not() {
|
||||
throw new UnsupportedOperationException("Cannot perform bitwise arithmetic on a string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '\"' + value.replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Generic data interface. A data element may contain any kind of basic data
|
||||
* element (bool, byte, short, int, long, float, double, string, list, map, int
|
||||
* array or byte array). Used to store data with stacks, blocks, world, ...
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.data.IData")
|
||||
public interface IData {
|
||||
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IData add(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.SUB)
|
||||
IData sub(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
IData mul(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.DIV)
|
||||
IData div(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
IData mod(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.AND)
|
||||
IData and(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
IData or(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.XOR)
|
||||
IData xor(IData other);
|
||||
|
||||
@ZenOperator(OperatorType.NEG)
|
||||
IData neg();
|
||||
|
||||
@ZenOperator(OperatorType.NOT)
|
||||
IData not();
|
||||
|
||||
@ZenCaster
|
||||
boolean asBool();
|
||||
|
||||
@ZenCaster
|
||||
byte asByte();
|
||||
|
||||
@ZenCaster
|
||||
short asShort();
|
||||
|
||||
@ZenCaster
|
||||
int asInt();
|
||||
|
||||
@ZenCaster
|
||||
long asLong();
|
||||
|
||||
@ZenCaster
|
||||
float asFloat();
|
||||
|
||||
@ZenCaster
|
||||
double asDouble();
|
||||
|
||||
@ZenCaster
|
||||
String asString();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a List. Returns null if this value
|
||||
* cannot be converted to a list.
|
||||
*
|
||||
* @return list data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
List<IData> asList();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a Map. Returns null if this value
|
||||
* cannot be converted to a map.
|
||||
*
|
||||
* @return map data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
Map<String, IData> asMap();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to a byte array. Returns null if this
|
||||
* value cannot be converted to a byte array.
|
||||
*
|
||||
* @return byte array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
byte[] asByteArray();
|
||||
|
||||
/**
|
||||
* Attempts to convert this value to an int array. Returns null if this
|
||||
* value cannot be converted to an int array.
|
||||
*
|
||||
* @return int array data of this value, if any
|
||||
*/
|
||||
@ZenCaster
|
||||
int[] asIntArray();
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
IData getAt(int i);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXSET)
|
||||
void setAt(int i, IData value);
|
||||
|
||||
@ZenMemberGetter
|
||||
IData memberGet(String name);
|
||||
|
||||
@ZenMemberSetter
|
||||
void memberSet(String name, IData data);
|
||||
|
||||
@ZenGetter
|
||||
int length();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.COMPARE)
|
||||
int compareTo(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.EQUALS)
|
||||
boolean equals(IData data);
|
||||
|
||||
@ZenGetter
|
||||
IData immutable();
|
||||
|
||||
@ZenMethod
|
||||
IData update(IData data);
|
||||
|
||||
<T> T convert(IDataConverter<T> converter);
|
||||
|
||||
@Override
|
||||
String toString();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package minetweaker.api.data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Data converter interface. Used to convert data elements to other types.
|
||||
*
|
||||
* @param <T> output type
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IDataConverter<T> {
|
||||
|
||||
T fromBool(boolean value);
|
||||
|
||||
T fromByte(byte value);
|
||||
|
||||
T fromShort(short value);
|
||||
|
||||
T fromInt(int value);
|
||||
|
||||
T fromLong(long value);
|
||||
|
||||
T fromFloat(float value);
|
||||
|
||||
T fromDouble(double value);
|
||||
|
||||
T fromString(String value);
|
||||
|
||||
T fromList(List<IData> values);
|
||||
|
||||
T fromMap(Map<String, IData> values);
|
||||
|
||||
T fromByteArray(byte[] value);
|
||||
|
||||
T fromIntArray(int[] value);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* This file is part of MineTweaker API, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2014 MineTweaker <http://minetweaker3.powerofbytes.com>
|
||||
*/
|
||||
package minetweaker.api.data;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class IllegalDataException extends RuntimeException {
|
||||
|
||||
public IllegalDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.util.Position3f;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Entity interface. Used to obtain information about entities, and modify their
|
||||
* data. Entities are any item that is freely movable in the world, such as
|
||||
* players, monsters, items on the ground, ...
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntity")
|
||||
public interface IEntity {
|
||||
|
||||
/**
|
||||
* Retrieves the dimension this entity is in.
|
||||
*
|
||||
* @return current dimension of this entity
|
||||
*/
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
|
||||
/**
|
||||
* Retrieves the x position of this entity.
|
||||
*
|
||||
* @return entity x position
|
||||
*/
|
||||
@ZenGetter("x")
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Retrieves the y position of this entity.
|
||||
*
|
||||
* @return entity y position
|
||||
*/
|
||||
@ZenGetter("y")
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Retrieves the z position of this entity.
|
||||
*
|
||||
* @return entity z position
|
||||
*/
|
||||
@ZenGetter("z")
|
||||
float getZ();
|
||||
|
||||
/**
|
||||
* Retrieves the position of this entity.
|
||||
*
|
||||
* @return entity position
|
||||
*/
|
||||
@ZenGetter("position")
|
||||
Position3f getPosition();
|
||||
|
||||
/**
|
||||
* Sets the position of this entity. Instantly moves (teleports) the entity
|
||||
* to that position.
|
||||
*
|
||||
* @param position entity position
|
||||
*/
|
||||
@ZenSetter("position")
|
||||
void setPosition(Position3f position);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
import stanhebben.zenscript.value.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntityDefinition")
|
||||
public interface IEntityDefinition {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenMethod
|
||||
void addDrop(IItemStack stack, @Optional int min, @Optional int max);
|
||||
|
||||
@ZenMethod
|
||||
void addPlayerOnlyDrop(IItemStack stack, @Optional int min, @Optional int max);
|
||||
|
||||
@ZenMethod
|
||||
void removeDrop(IItemStack stack);
|
||||
|
||||
Map<IItemStack, IntRange> getDropsToAdd();
|
||||
|
||||
Map<IItemStack, IntRange> getDropsToAddPlayerOnly();
|
||||
|
||||
List<IItemStack> getDropsToRemove();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* Represents an item entity. Item entities are entities representing an item
|
||||
* stack on the ground (or flying through the air).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IEntityItem extends IEntity {
|
||||
|
||||
/**
|
||||
* Gets the entity item.
|
||||
*
|
||||
* @return entity item
|
||||
*/
|
||||
@ZenGetter("item")
|
||||
IItemStack getItem();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package minetweaker.api.entity;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Represents an xp orb.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.entity.IEntityXp")
|
||||
public interface IEntityXp extends IEntity {
|
||||
|
||||
/**
|
||||
* Gets the amount of xp in this orb.
|
||||
*
|
||||
* @return xp amount
|
||||
*/
|
||||
@ZenGetter("xp")
|
||||
float getXp();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
/**
|
||||
* Represents an event handle. Event handles are used to cancel event listeners.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.event.IEventHandler")
|
||||
public interface IEventHandle extends Closeable {
|
||||
|
||||
/**
|
||||
* Closes the event listener (stops listening and unregisters the listener).
|
||||
*/
|
||||
@ZenMethod
|
||||
@Override
|
||||
void close();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.IEventHandler;
|
||||
|
||||
/**
|
||||
* 37 kinds of event handlers!
|
||||
* <p>
|
||||
* NOTE: not all of these are implemented yet, but will be later on.
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IEventManager {
|
||||
|
||||
// implemented
|
||||
IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev);
|
||||
|
||||
// implemented
|
||||
IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev);
|
||||
|
||||
IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev);
|
||||
|
||||
IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev);
|
||||
|
||||
IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev);
|
||||
|
||||
IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev);
|
||||
|
||||
IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev);
|
||||
|
||||
IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev);
|
||||
|
||||
IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev);
|
||||
|
||||
IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev);
|
||||
|
||||
IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev);
|
||||
|
||||
IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev);
|
||||
|
||||
IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev);
|
||||
|
||||
IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev);
|
||||
|
||||
IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev);
|
||||
|
||||
IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev);
|
||||
|
||||
IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev);
|
||||
|
||||
IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev);
|
||||
|
||||
/*
|
||||
* IEventHandle
|
||||
* onPlayerUseItemStop(IEventHandler<PlayerUseItemStopEvent> ev);
|
||||
*
|
||||
* IEventHandle
|
||||
* onPlayerUseItemFinish(IPlayerUserItemFinishEventHandler ev);
|
||||
*
|
||||
* IEventHandle onPlayerChat(IPlayerChatEventHandler ev);
|
||||
*
|
||||
* IEventHandle onTimerSingle(int millis, ITimerEventHandler ev);
|
||||
*
|
||||
* IEventHandle onTimerRepeat(int millis, ITimerEventHandler ev);
|
||||
*
|
||||
* IEventHandle onEntityJoinWorld(IEntityJoinWorldEventHandler ev);
|
||||
*
|
||||
* IEventHandle
|
||||
* onEntityStruckByLightning(IEntityStruckByLightningEventHandler ev);
|
||||
*
|
||||
* IEventHandle
|
||||
* onLivingEnderTeleport(ILivingEnderTeleportEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingAttackEvent(ILivingAttackEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingDeathEvent(ILivingDeathEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingJumpEvent(ILivingJumpEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingFallEvent(ILivingFallEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingHurtEvent(ILivingHurtEventHandler ev);
|
||||
*
|
||||
* IEventHandle onLivingDeathDropsEvent(ILivingDeathDropsEventHandler
|
||||
* ev);
|
||||
*
|
||||
* IEventHandle onItemTossed(IItemTossedEventHandler ev);
|
||||
*
|
||||
* IEventHandle onItemExpired(IItemExpiredEventHandler ev);
|
||||
*
|
||||
* IEventHandle onMinecartCollision(IMinecartCollisionEventHandler
|
||||
* ev);
|
||||
*
|
||||
* IEventHandle onMinecartInteract(IMinecartInteractEventHandler ev);
|
||||
*
|
||||
* IEventHandle onCommand(ICommandEventHandler ev);
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTEventManager implements IEventManager {
|
||||
|
||||
private final EventList<PlayerCraftedEvent> elPlayerCrafted = new EventList<PlayerCraftedEvent>();
|
||||
|
||||
// ##########################
|
||||
// ### PlayerCraftedEvent ###
|
||||
// ##########################
|
||||
private final EventList<PlayerSmeltedEvent> elPlayerSmelted = new EventList<PlayerSmeltedEvent>();
|
||||
private final EventList<PlayerChangedDimensionEvent> elPlayerChangedDimension = new EventList<PlayerChangedDimensionEvent>();
|
||||
private final EventList<PlayerLoggedInEvent> elPlayerLoggedIn = new EventList<PlayerLoggedInEvent>();
|
||||
private final EventList<PlayerLoggedOutEvent> elPlayerLoggedOut = new EventList<PlayerLoggedOutEvent>();
|
||||
|
||||
// ##########################
|
||||
// ### PlayerSmeltedEvent ###
|
||||
// ##########################
|
||||
private final EventList<PlayerRespawnEvent> elPlayerRespawn = new EventList<PlayerRespawnEvent>();
|
||||
private final EventList<PlayerAttackEntityEvent> elPlayerAttackEntity = new EventList<PlayerAttackEntityEvent>();
|
||||
private final EventList<PlayerBonemealEvent> elPlayerBonemeal = new EventList<PlayerBonemealEvent>();
|
||||
private final EventList<PlayerInteractEntityEvent> elPlayerInteractEntity = new EventList<PlayerInteractEntityEvent>();
|
||||
|
||||
// ###################################
|
||||
// ### PlayerChangedDimensionEvent ###
|
||||
// ###################################
|
||||
private final EventList<PlayerPickupEvent> elPlayerPickup = new EventList<PlayerPickupEvent>();
|
||||
private final EventList<PlayerPickupItemEvent> elPlayerPickupItem = new EventList<PlayerPickupItemEvent>();
|
||||
private final EventList<PlayerFillBucketEvent> elPlayerFillBucket = new EventList<PlayerFillBucketEvent>();
|
||||
private final EventList<PlayerDeathDropsEvent> elPlayerDeathDrops = new EventList<PlayerDeathDropsEvent>();
|
||||
|
||||
// ###########################
|
||||
// ### PlayerLoggedInEvent ###
|
||||
// ###########################
|
||||
private final EventList<PlayerInteractEvent> elPlayerInteract = new EventList<PlayerInteractEvent>();
|
||||
private final EventList<PlayerOpenContainerEvent> elPlayerOpenContainer = new EventList<PlayerOpenContainerEvent>();
|
||||
private final EventList<PlayerPickupXpEvent> elPlayerPickupXp = new EventList<PlayerPickupXpEvent>();
|
||||
private final EventList<PlayerSleepInBedEvent> elPlayerSleepInBed = new EventList<PlayerSleepInBedEvent>();
|
||||
|
||||
// ############################
|
||||
// ### PlayerLoggedOutEvent ###
|
||||
// ############################
|
||||
private final EventList<PlayerUseHoeEvent> elPlayerUseHoe = new EventList<PlayerUseHoeEvent>();
|
||||
private final EventList<PlayerUseItemStartEvent> elPlayerUseItemStart = new EventList<PlayerUseItemStartEvent>();
|
||||
private final EventList<PlayerUseItemTickEvent> elPlayerUseItemTick = new EventList<PlayerUseItemTickEvent>();
|
||||
|
||||
public void clear() {
|
||||
elPlayerCrafted.clear();
|
||||
elPlayerSmelted.clear();
|
||||
elPlayerChangedDimension.clear();
|
||||
elPlayerLoggedIn.clear();
|
||||
elPlayerLoggedOut.clear();
|
||||
elPlayerRespawn.clear();
|
||||
elPlayerAttackEntity.clear();
|
||||
elPlayerBonemeal.clear();
|
||||
elPlayerInteractEntity.clear();
|
||||
elPlayerPickup.clear();
|
||||
elPlayerPickupItem.clear();
|
||||
elPlayerFillBucket.clear();
|
||||
elPlayerDeathDrops.clear();
|
||||
elPlayerInteract.clear();
|
||||
elPlayerOpenContainer.clear();
|
||||
elPlayerPickupXp.clear();
|
||||
elPlayerSleepInBed.clear();
|
||||
elPlayerUseHoe.clear();
|
||||
elPlayerUseItemStart.clear();
|
||||
elPlayerUseItemTick.clear();
|
||||
}
|
||||
|
||||
// ##########################
|
||||
// ### PlayerRespawnEvent ###
|
||||
// ##########################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerCrafted(IEventHandler<PlayerCraftedEvent> ev) {
|
||||
return elPlayerCrafted.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerCrafted() {
|
||||
return elPlayerCrafted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerCrafted(PlayerCraftedEvent event) {
|
||||
elPlayerCrafted.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSmelted(IEventHandler<PlayerSmeltedEvent> ev) {
|
||||
return elPlayerSmelted.add(ev);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerAttackEntityEvent ###
|
||||
// ###############################
|
||||
|
||||
public boolean hasPlayerSmelted() {
|
||||
return elPlayerSmelted.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSmelted(PlayerSmeltedEvent event) {
|
||||
elPlayerSmelted.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerChangedDimension(IEventHandler<PlayerChangedDimensionEvent> ev) {
|
||||
return elPlayerChangedDimension.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerChangedDimension() {
|
||||
return elPlayerChangedDimension.hasHandlers();
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerBonemealEvent ###
|
||||
// ###########################
|
||||
|
||||
public void publishPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
elPlayerChangedDimension.publish(event);
|
||||
}
|
||||
|
||||
public IEventHandle onPlayerLoggedIn(IEventHandler<PlayerLoggedInEvent> ev) {
|
||||
return elPlayerLoggedIn.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedIn() {
|
||||
return elPlayerLoggedIn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedIn(PlayerLoggedInEvent event) {
|
||||
elPlayerLoggedIn.publish(event);
|
||||
}
|
||||
|
||||
// #################################
|
||||
// ### PlayerInteractEntityEvent ###
|
||||
// #################################
|
||||
|
||||
public IEventHandle onPlayerLoggedOut(IEventHandler<PlayerLoggedOutEvent> ev) {
|
||||
return elPlayerLoggedOut.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerLoggedOut() {
|
||||
return elPlayerLoggedOut.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerLoggedOut(PlayerLoggedOutEvent event) {
|
||||
elPlayerLoggedOut.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerRespawn(IEventHandler<PlayerRespawnEvent> ev) {
|
||||
return elPlayerRespawn.add(ev);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerPickupEvent ###
|
||||
// #########################
|
||||
|
||||
public boolean hasPlayerRespawn() {
|
||||
return elPlayerRespawn.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerRespawn(PlayerRespawnEvent event) {
|
||||
elPlayerRespawn.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerAttackEntity(IEventHandler<PlayerAttackEntityEvent> ev) {
|
||||
return elPlayerAttackEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerAttackEntity() {
|
||||
return elPlayerAttackEntity.hasHandlers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerPickupItemEvent ###
|
||||
// #############################
|
||||
|
||||
public void publishPlayerAttackEntity(PlayerAttackEntityEvent event) {
|
||||
elPlayerAttackEntity.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerBonemeal(IEventHandler<PlayerBonemealEvent> ev) {
|
||||
return elPlayerBonemeal.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerBonemeal() {
|
||||
return elPlayerBonemeal.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerBonemeal(PlayerBonemealEvent event) {
|
||||
elPlayerBonemeal.publish(event);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerFillBucketEvent ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteractEntity(IEventHandler<PlayerInteractEntityEvent> ev) {
|
||||
return elPlayerInteractEntity.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerInteractEntity() {
|
||||
return elPlayerInteractEntity.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
elPlayerInteractEntity.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickup(IEventHandler<PlayerPickupEvent> ev) {
|
||||
return elPlayerPickup.add(ev);
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerDeathDropsEvent ###
|
||||
// #############################
|
||||
|
||||
public boolean hasPlayerPickup() {
|
||||
return elPlayerPickup.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupEvent event) {
|
||||
elPlayerPickup.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupItem(IEventHandler<PlayerPickupItemEvent> ev) {
|
||||
return elPlayerPickupItem.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupItem() {
|
||||
return elPlayerPickupItem.hasHandlers();
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerInteractEvent ###
|
||||
// ###########################
|
||||
|
||||
public void publishPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
elPlayerPickupItem.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerFillBucket(IEventHandler<PlayerFillBucketEvent> ev) {
|
||||
return elPlayerFillBucket.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerFillBucket() {
|
||||
return elPlayerFillBucket.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerFillBucket(PlayerFillBucketEvent event) {
|
||||
elPlayerFillBucket.publish(event);
|
||||
}
|
||||
|
||||
// ################################
|
||||
// ### PlayerOpenContainerEvent ###
|
||||
// ################################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerDeathDrops(IEventHandler<PlayerDeathDropsEvent> ev) {
|
||||
return elPlayerDeathDrops.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerDeathDrops() {
|
||||
return elPlayerDeathDrops.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerDeathDrops(PlayerDeathDropsEvent event) {
|
||||
elPlayerDeathDrops.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerInteract(IEventHandler<PlayerInteractEvent> ev) {
|
||||
return elPlayerInteract.add(ev);
|
||||
}
|
||||
|
||||
// ###########################
|
||||
// ### PlayerPickupXpEvent ###
|
||||
// ###########################
|
||||
|
||||
public boolean hasPlayerInteract() {
|
||||
return elPlayerInteract.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerInteract(PlayerInteractEvent event) {
|
||||
elPlayerInteract.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerOpenContainer(IEventHandler<PlayerOpenContainerEvent> ev) {
|
||||
return elPlayerOpenContainer.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerOpenContainer() {
|
||||
return elPlayerOpenContainer.hasHandlers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### PlayerSleepInBedEvent ###
|
||||
// #############################
|
||||
|
||||
public void publishPlayerOpenContainer(PlayerOpenContainerEvent event) {
|
||||
elPlayerOpenContainer.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerPickupXp(IEventHandler<PlayerPickupXpEvent> ev) {
|
||||
return elPlayerPickupXp.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerPickupXp() {
|
||||
return elPlayerPickupXp.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerPickup(PlayerPickupXpEvent event) {
|
||||
elPlayerPickupXp.publish(event);
|
||||
}
|
||||
|
||||
// #########################
|
||||
// ### PlayerUseHoeEvent ###
|
||||
// #########################
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerSleepInBed(IEventHandler<PlayerSleepInBedEvent> ev) {
|
||||
return elPlayerSleepInBed.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerSleepInBed() {
|
||||
return elPlayerSleepInBed.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerSleepInBed(PlayerSleepInBedEvent event) {
|
||||
elPlayerSleepInBed.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseHoe(IEventHandler<PlayerUseHoeEvent> ev) {
|
||||
return elPlayerUseHoe.add(ev);
|
||||
}
|
||||
|
||||
// ###############################
|
||||
// ### PlayerUseItemStartEvent ###
|
||||
// ###############################
|
||||
|
||||
public boolean hasPlayerUseHoe() {
|
||||
return elPlayerUseHoe.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseHoe(PlayerUseHoeEvent event) {
|
||||
elPlayerUseHoe.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemStart(IEventHandler<PlayerUseItemStartEvent> ev) {
|
||||
return elPlayerUseItemStart.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemStart() {
|
||||
return elPlayerUseItemStart.hasHandlers();
|
||||
}
|
||||
|
||||
// ##############################
|
||||
// ### PlayerUseItemTickEvent ###
|
||||
// ##############################
|
||||
|
||||
public void publishPlayerUseItemStart(PlayerUseItemStartEvent event) {
|
||||
elPlayerUseItemStart.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventHandle onPlayerUseItemTick(IEventHandler<PlayerUseItemTickEvent> ev) {
|
||||
return elPlayerUseItemTick.add(ev);
|
||||
}
|
||||
|
||||
public boolean hasPlayerUseItemTick() {
|
||||
return elPlayerUseItemTick.hasHandlers();
|
||||
}
|
||||
|
||||
public void publishPlayerUseItemTick(PlayerUseItemTickEvent event) {
|
||||
elPlayerUseItemTick.publish(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerAttackEntityEvent")
|
||||
public class PlayerAttackEntityEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerAttackEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerBonemealEvent")
|
||||
public class PlayerBonemealEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerBonemealEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerChangedDimensionEvent")
|
||||
public class PlayerChangedDimensionEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IDimension from;
|
||||
private final IDimension to;
|
||||
|
||||
public PlayerChangedDimensionEvent(IPlayer player, IDimension from, IDimension to) {
|
||||
this.player = player;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("from")
|
||||
public IDimension getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
@ZenGetter("to")
|
||||
public IDimension getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingInventory;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerCraftingEvent")
|
||||
public class PlayerCraftedEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
private final ICraftingInventory inventory;
|
||||
|
||||
public PlayerCraftedEvent(IPlayer player, IItemStack output, ICraftingInventory inventory) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@ZenGetter("inventory")
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.damage.IDamageSource;
|
||||
import minetweaker.api.entity.IEntityItem;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerDeathDropsEvent")
|
||||
public class PlayerDeathDropsEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final List<IEntityItem> items;
|
||||
private final IDamageSource damageSource;
|
||||
|
||||
public PlayerDeathDropsEvent(IPlayer player, List<IEntityItem> items, IDamageSource damageSource) {
|
||||
this.player = player;
|
||||
this.items = items;
|
||||
this.damageSource = damageSource;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("items")
|
||||
public List<IEntityItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@ZenGetter("damageSource")
|
||||
public IDamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerFillBucketEvent")
|
||||
public class PlayerFillBucketEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private IItemStack result;
|
||||
|
||||
public PlayerFillBucketEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
result = null;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("result")
|
||||
public IItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resulting item. Automatically processes the event, too.
|
||||
*
|
||||
* @param result resulting item
|
||||
*/
|
||||
@ZenSetter("result")
|
||||
public void setResult(IItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerInteractEntityEvent")
|
||||
public class PlayerInteractEntityEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerInteractEntityEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerInteractEvent")
|
||||
public class PlayerInteractEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
private boolean canceled;
|
||||
private boolean useBlock;
|
||||
private boolean useItem;
|
||||
|
||||
public PlayerInteractEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
useBlock = false;
|
||||
useItem = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void useBlock() {
|
||||
useBlock = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void useItem() {
|
||||
useItem = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("usingBlock")
|
||||
public boolean isUsingBlock() {
|
||||
return useBlock;
|
||||
}
|
||||
|
||||
@ZenGetter("usingItem")
|
||||
public boolean isUsingItem() {
|
||||
return useItem;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerLoggedInEvent")
|
||||
public class PlayerLoggedInEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedInEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerLoggedOutEvent")
|
||||
public class PlayerLoggedOutEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerLoggedOutEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.container.IContainer;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerOpenContainerEvent")
|
||||
public class PlayerOpenContainerEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IContainer container;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerOpenContainerEvent(IPlayer player, IContainer container) {
|
||||
this.player = player;
|
||||
this.container = container;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("container")
|
||||
public IContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupEvent")
|
||||
public class PlayerPickupEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerPickupEvent(IPlayer player, IEntity entity) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the event (picks up the entity).
|
||||
*/
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupItemEvent")
|
||||
public class PlayerPickupItemEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
|
||||
public PlayerPickupItemEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.entity.IEntityXp;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerPickupXpEvent")
|
||||
public class PlayerPickupXpEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IEntityXp xp;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerPickupXpEvent(IPlayer player, IEntityXp xp) {
|
||||
this.player = player;
|
||||
this.xp = xp;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("entity")
|
||||
public IEntityXp getEntity() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
@ZenGetter("xp")
|
||||
public float getXp() {
|
||||
return xp.getXp();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerRespawnEvent")
|
||||
public class PlayerRespawnEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
public PlayerRespawnEvent(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerSleepInBedEvent")
|
||||
public class PlayerSleepInBedEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public PlayerSleepInBedEvent(IPlayer player, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class PlayerSmeltedEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack output;
|
||||
|
||||
public PlayerSmeltedEvent(IPlayer player, IItemStack output) {
|
||||
this.player = player;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("output")
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseHoeEvent")
|
||||
public class PlayerUseHoeEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private boolean canceled;
|
||||
private boolean processed;
|
||||
|
||||
public PlayerUseHoeEvent(IPlayer player, IItemStack item, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
canceled = false;
|
||||
processed = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void process() {
|
||||
processed = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("processed")
|
||||
public boolean isProcessed() {
|
||||
return processed;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("blocks")
|
||||
public IBlockGroup getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ZenGetter("x")
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ZenGetter("y")
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@ZenGetter("z")
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@ZenGetter("dimension")
|
||||
public IDimension getDimension() {
|
||||
return blocks.getDimension();
|
||||
}
|
||||
|
||||
@ZenGetter("block")
|
||||
public IBlock getBlock() {
|
||||
return blocks.getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemStartEvent")
|
||||
public class PlayerUseItemStartEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemStartEvent(IPlayer player, IItemStack item) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.event.PlayerUseItemTickEvent")
|
||||
public class PlayerUseItemTickEvent {
|
||||
|
||||
private final IPlayer player;
|
||||
private final IItemStack item;
|
||||
private final int duration;
|
||||
private boolean canceled;
|
||||
|
||||
public PlayerUseItemTickEvent(IPlayer player, IItemStack item, int duration) {
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.duration = duration;
|
||||
|
||||
canceled = false;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
@ZenGetter("canceled")
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@ZenGetter("player")
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@ZenGetter("item")
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ZenGetter("duration")
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package minetweaker.api.formatting;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.formatting.IFormattedText")
|
||||
public interface IFormattedText {
|
||||
|
||||
@ZenOperator(OperatorType.ADD)
|
||||
IFormattedText add(IFormattedText other);
|
||||
|
||||
@ZenOperator(OperatorType.CAT)
|
||||
IFormattedText cat(IFormattedText other);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package minetweaker.api.formatting;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IFormatter {
|
||||
|
||||
IFormattedText string(String text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText black(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkBlue(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkGreen(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkAqua(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkRed(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkPurple(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText gold(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText gray(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText darkGray(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText blue(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText green(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText aqua(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText red(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText lightPurple(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText yellow(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText white(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText obfuscated(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText bold(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText strikethrough(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText underline(IFormattedText text);
|
||||
|
||||
@ZenMethod
|
||||
IFormattedText italic(IFormattedText text);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package minetweaker.api.game;
|
||||
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.entity.IEntityDefinition;
|
||||
import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.liquid.ILiquidDefinition;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Game interface. Used to obtain general game information.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.game.IGame")
|
||||
public interface IGame {
|
||||
|
||||
/**
|
||||
* Retrieves the item definitions in this game.
|
||||
*
|
||||
* @return game items
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemDefinition> getItems();
|
||||
|
||||
/**
|
||||
* Retrieves the block definitions in this game.
|
||||
*
|
||||
* @return block definitions
|
||||
*/
|
||||
@ZenGetter("blocks")
|
||||
List<IBlockDefinition> getBlocks();
|
||||
|
||||
/**
|
||||
* Retrieves the liquids in this game.
|
||||
*
|
||||
* @return game liquids
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidDefinition> getLiquids();
|
||||
|
||||
/**
|
||||
* Retrieves the biomes in this game.
|
||||
*
|
||||
* @return game biomes
|
||||
*/
|
||||
@ZenGetter("biomes")
|
||||
List<IBiome> getBiomes();
|
||||
|
||||
/**
|
||||
* Retrieves the entities in this game.
|
||||
*
|
||||
* @return game entities
|
||||
*/
|
||||
@ZenGetter("entities")
|
||||
List<IEntityDefinition> getEntities();
|
||||
|
||||
@ZenMethod()
|
||||
IEntityDefinition getEntity(String entityName);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String key, String value);
|
||||
|
||||
/**
|
||||
* Sets a localization value.
|
||||
*
|
||||
* @param lang language
|
||||
* @param key localization key
|
||||
* @param value localization value
|
||||
*/
|
||||
@ZenMethod
|
||||
void setLocalization(String lang, String key, String value);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
*
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key);
|
||||
|
||||
/**
|
||||
* Gets a localized string.
|
||||
*
|
||||
* @param key localization key
|
||||
* @param lang language
|
||||
*
|
||||
* @return localized value
|
||||
*/
|
||||
@ZenMethod
|
||||
String localize(String key, String lang);
|
||||
|
||||
/**
|
||||
* Lock the game and disable reload. Recommended for distributed versions.
|
||||
* <p>
|
||||
* Once locked, reload cannot be unlocked - a game restart is required to
|
||||
* alter the scripts.
|
||||
*/
|
||||
@ZenMethod
|
||||
void lock();
|
||||
|
||||
/**
|
||||
* Returns the lock state. True if locked.
|
||||
*
|
||||
* @return lock state
|
||||
*/
|
||||
@ZenGetter("locked")
|
||||
boolean isLocked();
|
||||
|
||||
/**
|
||||
* Signals a modified script while in locked mode.
|
||||
*/
|
||||
void signalLockError();
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a recipe ingredient. An ingredient can be an item, an ore
|
||||
* dictionary entry, an item stack, an ore dictionary entry multiplied with an
|
||||
* amount, or other kinds of ingredients as offered by the API.
|
||||
* <p>
|
||||
* There is no guarantee that every mod will respect the conditions or
|
||||
* transformations, or that every mod will support every kind of ingredient.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IIngredient")
|
||||
public interface IIngredient {
|
||||
|
||||
/**
|
||||
* Gets the mark of the ingredient. Ingredients can be marked so they can be
|
||||
* used in crafting functions.
|
||||
*
|
||||
* @return ingredient mark
|
||||
*/
|
||||
@ZenGetter("mark")
|
||||
String getMark();
|
||||
|
||||
/**
|
||||
* Gets the amount.
|
||||
* <p>
|
||||
* Should return -1 if no amount is available and 1 for a single item.
|
||||
* Stacks return the stack size.
|
||||
*
|
||||
* @return stack size
|
||||
*/
|
||||
@ZenGetter("amount")
|
||||
int getAmount();
|
||||
|
||||
/**
|
||||
* Gets all possible items for this ingredient.
|
||||
* <p>
|
||||
* If there is no item list (for example, it is the <*> wildcard item)
|
||||
* null should be returned.
|
||||
*
|
||||
* @return the items for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
List<IItemStack> getItems();
|
||||
|
||||
/**
|
||||
* Gets all possible liquids for this ingredient.
|
||||
* <p>
|
||||
* If there is no liquid list (for example, it is the <*&ft; wildcard
|
||||
* item) null should be returned.
|
||||
*
|
||||
* @return the liquids for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("liquids")
|
||||
List<ILiquidStack> getLiquids();
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given stack size.
|
||||
*
|
||||
* @param amount new stack size
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
IIngredient amount(int amount);
|
||||
|
||||
/**
|
||||
* Combines multiple ingredients into a single one. Note that ore dictionary
|
||||
* entries are preferred to or statements.
|
||||
*
|
||||
* @param ingredient ingredient to combine with
|
||||
*
|
||||
* @return or-ed ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.OR)
|
||||
@ZenMethod
|
||||
IIngredient or(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
* @param transformer transformer to add
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient transform(IItemTransformer transformer);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given condition added to it.
|
||||
*
|
||||
* @param condition condition to add
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient only(IItemCondition condition);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient marked with the given name.
|
||||
*
|
||||
* @param mark mark to apply
|
||||
*
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient marked(String mark);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
*
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matches(IItemStack item);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item. For liquids, will match
|
||||
* the item if it is a valid container.
|
||||
*
|
||||
* @param item item to check
|
||||
*
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matchesExact(IItemStack item);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given liquid.
|
||||
*
|
||||
* @param liquid liquid to check
|
||||
*
|
||||
* @return true if the liquid matches
|
||||
*/
|
||||
@ZenMethod
|
||||
boolean matches(ILiquidStack liquid);
|
||||
|
||||
/**
|
||||
* Check if this ingredient contains all possible values for the given
|
||||
* ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to check
|
||||
*
|
||||
* @return true if the ingredient contains the given one
|
||||
*/
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Applies transformations after crafting, if any, to the given item.
|
||||
*
|
||||
* @param item item to transform
|
||||
* @param byPlayer player performing the crafting operation
|
||||
*
|
||||
* @return transformed item
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack applyTransform(IItemStack item, IPlayer byPlayer);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient has (or could have) any transformatiosns.
|
||||
*
|
||||
* @return true if there are (or could be) any transformations false
|
||||
* otherwise.
|
||||
*/
|
||||
@ZenGetter("hasTransformations")
|
||||
boolean hasTransformers();
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
* <p>
|
||||
* The value is implementation-dependent and should only be handled by the
|
||||
* internal code. Don't use this value - instead, use the version-specific
|
||||
* helper methods.
|
||||
*
|
||||
* @return internal item
|
||||
*/
|
||||
Object getInternal();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* Item conditions apply additional conditions on item stacks.
|
||||
* <p>
|
||||
* They may, for instance, require specific damage ranges or NBT tags. Custom
|
||||
* implementations of this functional interface may contain any kind of
|
||||
* condition.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemCondition")
|
||||
public interface IItemCondition {
|
||||
|
||||
/**
|
||||
* Returns true if the given stack matches the required conditions.
|
||||
*
|
||||
* @param stack item stack to check
|
||||
*
|
||||
* @return true if the condition applies to this stack
|
||||
*/
|
||||
boolean matches(IItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains an item definition. Item definitions provide general information
|
||||
* about an item, such as its name and ID.
|
||||
* <p>
|
||||
* Item definitions themselves have no localized name, as it could be different
|
||||
* for each subitem or even depend on NBT tags.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemDefinition")
|
||||
public interface IItemDefinition {
|
||||
|
||||
/**
|
||||
* Gets the item ID.
|
||||
*
|
||||
* @return item ID
|
||||
*/
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Makes an item stack from this definition.
|
||||
*
|
||||
* @param meta meta value
|
||||
*
|
||||
* @return item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack makeStack(@Optional int meta);
|
||||
|
||||
/**
|
||||
* Returns all ore entries containing this item. Also contains ore entries
|
||||
* that refer to a specific sub-item.
|
||||
*
|
||||
* @return all the ore entries containing this item.
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains an item stack. An item stack consists of an item definition, a meta
|
||||
* or damage value and NBT data.
|
||||
* <p>
|
||||
* Item stacks can be retrieved using its name (or ID, in 1.6.4) with the
|
||||
* bracket syntax. When using the bracket syntax, by default, the item stack
|
||||
* will match any size when used as ingredient. Item stacks can be multiplied
|
||||
* with an integer to create a stack of different size.
|
||||
* <p>
|
||||
* Item stacks are immutable. You can, however, easily create modified stacks
|
||||
* using the helper methods. Adding conditions and transformations will turn the
|
||||
* item stack into an ingredients.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemStack")
|
||||
public interface IItemStack extends IIngredient {
|
||||
|
||||
/**
|
||||
* Gets the item definition.
|
||||
*
|
||||
* @return item definition
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
IItemDefinition getDefinition();
|
||||
|
||||
/**
|
||||
* Gets the unlocalized item name.
|
||||
*
|
||||
* @return unlocalized item name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the display name. By default, it is the localized item name, but
|
||||
* could also be the display name from NBT data, or another item-specific
|
||||
* name.
|
||||
*
|
||||
* @return item display name
|
||||
*/
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* Sets the display name. Only works if the name is translatable. Does not
|
||||
* override names set by NBT data or using item-specific logic.
|
||||
*
|
||||
* @param name item display name
|
||||
*/
|
||||
@ZenSetter("displayName")
|
||||
void setDisplayName(String name);
|
||||
|
||||
/**
|
||||
* Gets the max stack size for an item
|
||||
*
|
||||
* @return int max stack size
|
||||
*/
|
||||
@ZenGetter("maxStackSize")
|
||||
int getMaxStackSize();
|
||||
|
||||
/**
|
||||
* Sets the ItemStack max stack size.
|
||||
*
|
||||
* @param size the new max size
|
||||
*/
|
||||
@ZenSetter("maxStackSize")
|
||||
void setMaxStackSize(int size);
|
||||
|
||||
/**
|
||||
* Gets the block hardness
|
||||
*/
|
||||
@ZenGetter("hardness")
|
||||
float getBlockHardness();
|
||||
|
||||
/**
|
||||
* Sets the block hardness
|
||||
*
|
||||
* @param hardness the new hardness
|
||||
*/
|
||||
@ZenSetter("hardness")
|
||||
void setBlockHardness(float hardness);
|
||||
|
||||
/**
|
||||
* Gets the item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return item damage
|
||||
*/
|
||||
@ZenGetter("damage")
|
||||
int getDamage();
|
||||
|
||||
/**
|
||||
* Gets the maximum item damage. Returns 0 if the item cannot be damaged.
|
||||
*
|
||||
* @return maximum item damage
|
||||
*/
|
||||
@ZenGetter("maxDamage")
|
||||
int getMaxDamage();
|
||||
|
||||
/**
|
||||
* Sets the max Itemstack damage
|
||||
*
|
||||
* @param damage the new max damage
|
||||
*/
|
||||
@ZenSetter("maxDamage")
|
||||
void setMaxDamage(int damage);
|
||||
|
||||
/**
|
||||
* Gets the item tag. (NBT data) The resulting data is immutable and can
|
||||
* only be changed with updateTag. Returns empty data if there is no data.
|
||||
* Never returns null.
|
||||
*
|
||||
* @return item tag
|
||||
*/
|
||||
@ZenGetter("tag")
|
||||
IData getTag();
|
||||
|
||||
/**
|
||||
* Gets the liquid contained in this item, if any. If this item stack is not
|
||||
* an item container, it returns null. Only returns the amount of liquid in
|
||||
* a single item and doesn't into account stack size.
|
||||
*
|
||||
* @return liquid data
|
||||
*/
|
||||
@ZenGetter("liquid")
|
||||
ILiquidStack getLiquid();
|
||||
|
||||
/**
|
||||
* Creates a new item stack with a different stack size.
|
||||
*
|
||||
* @param amount new item stack size
|
||||
*
|
||||
* @return new item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack amount(int amount);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given percentage chance. Does the
|
||||
* same as item.weight(p * 0.01).
|
||||
*
|
||||
* @param p probability, with percent
|
||||
*
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MOD)
|
||||
WeightedItemStack percent(float p);
|
||||
|
||||
/**
|
||||
* Creates a weighted item stack with the given weight.
|
||||
*
|
||||
* @param p item weight
|
||||
*
|
||||
* @return weighted item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
WeightedItemStack weight(float p);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the same item and stack size, but accepting
|
||||
* any damage value. Only useful for items used as ingredients.
|
||||
*
|
||||
* @return item stack with wildcard damage
|
||||
*/
|
||||
@ZenMethod
|
||||
IIngredient anyDamage();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified damage.
|
||||
*
|
||||
* @param damage damage value
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withDamage(int damage);
|
||||
|
||||
/**
|
||||
* Creates an item stack with the specified stack size.
|
||||
*
|
||||
* @param amount stack size
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
IItemStack withAmount(int amount);
|
||||
|
||||
/**
|
||||
* Creates an item stack with wildcard stack size.
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
|
||||
@ZenMethod
|
||||
IItemStack anyAmount();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the given nbt tag. Ignores existing tags.
|
||||
*
|
||||
* @param tag item tag to be assigned
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withTag(IData tag);
|
||||
|
||||
/**
|
||||
* Create an item stack with an empty nbt tag. Removes previous tag if any.
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack withEmptyTag();
|
||||
|
||||
/**
|
||||
* Creates an item stack without the given nbt tag.
|
||||
*
|
||||
* @param tag item tag to be removed
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack removeTag(String tag);
|
||||
|
||||
/**
|
||||
* Creates an item stack with updated nbt tag. Updates existing tags.
|
||||
*
|
||||
* @param tagUpdate item tag updates
|
||||
*
|
||||
* @return updated item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack updateTag(IData tagUpdate);
|
||||
|
||||
/**
|
||||
* Converts this item stack into a block.
|
||||
*
|
||||
* @return block, or null if this item is not a block
|
||||
*/
|
||||
@ZenCaster
|
||||
IBlock asBlock();
|
||||
|
||||
/**
|
||||
* Retrieves all the ores referring to this item. Includes wildcard ore
|
||||
* entries.
|
||||
*
|
||||
* @return ore entries containing this item stack
|
||||
*/
|
||||
@ZenGetter("ores")
|
||||
List<IOreDictEntry> getOres();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* An item transformer modifies an item stack after crafting. Used to apply
|
||||
* damage, grab multiple items, change NBT tags, replace the item with something
|
||||
* else - or whatever else you'd want to happen to the input stack.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemTransformer")
|
||||
public interface IItemTransformer {
|
||||
|
||||
/**
|
||||
* Transforms the specified item. May modify this item (and return it) or
|
||||
* return an entirely new one.
|
||||
*
|
||||
* @param item input item
|
||||
* @param byPlayer player that performs the crafting
|
||||
*
|
||||
* @return output item
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack transform(IItemStack item, IPlayer byPlayer);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the wildcard ingredient (<*>).
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientAny implements IIngredient {
|
||||
|
||||
public static final IngredientAny INSTANCE = new IngredientAny();
|
||||
|
||||
public static Object INTERNAL_ANY = null; // platforms supporting an "any"
|
||||
// item should fill it here
|
||||
|
||||
private IngredientAny() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[]{transformer});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientAnyAdvanced(null, new IItemCondition[]{condition}, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return INTERNAL_ANY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<*>";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the wildcard ingredient, with conditions and/or transformers
|
||||
* applied to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientAnyAdvanced implements IIngredient {
|
||||
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientAnyAdvanced(String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientAnyAdvanced(mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientAnyAdvanced(mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
// TODO: conditions on liquids?
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for(IItemStack iitem : iitems) {
|
||||
if(!matches(iitem))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Conditions can be used to set requirements for matching items. They can be
|
||||
* used to require specific NBT tags or damage values, requiring changed items
|
||||
* or as complement to damage-consuming or stack-consuming recipes.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientCondition {
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged. A damage value of 1 is enough.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return damaged condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamaged(IIngredient ingredient) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() > 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at least a specified amount.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamageAtLeast(IIngredient ingredient, final int minDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to be damaged with at most a specified amount. An
|
||||
* undamaged item is accepted.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param maxDamage maximum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamageAtMost(IIngredient ingredient, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() <= maxDamage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item damage value to be between two values.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param minDamage minimum damage
|
||||
* @param maxDamage maximum damage
|
||||
*
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyDamageBetween(IIngredient ingredient, final int minDamage, final int maxDamage) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item to contain at least the given tags. It is OK for the
|
||||
* item to contain more data, as remaining data is ignored.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param data required data
|
||||
*
|
||||
* @return data condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyWithTag(IIngredient ingredient, final IData data) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getTag() != null && stack.getTag().contains(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the input stack to contain at least the given number of items.
|
||||
* Used in combination with stack consuming recipes.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount required stack size
|
||||
*
|
||||
* @return stack size condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient onlyStack(IIngredient ingredient, final int amount) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getAmount() >= amount;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an item stack with modifiers applied to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientItem implements IIngredient {
|
||||
|
||||
private final IItemStack item;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
private final List<IItemStack> items;
|
||||
|
||||
public IngredientItem(IItemStack item, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.item = item;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
|
||||
items = Collections.singletonList(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientItem(item, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientItem(item, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(item, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!this.item.matches(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!this.item.matchesExact(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> iitems = ingredient.getItems();
|
||||
for(IItemStack iitem : iitems) {
|
||||
if(!matches(iitem))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(Ingredient) " + item.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientOr implements IIngredient {
|
||||
|
||||
private final IIngredient[] elements;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOr(IIngredient[] elements) {
|
||||
this.elements = elements;
|
||||
mark = null;
|
||||
conditions = ArrayUtil.EMPTY_CONDITIONS;
|
||||
transformers = ArrayUtil.EMPTY_TRANSFORMERS;
|
||||
}
|
||||
|
||||
public IngredientOr(IIngredient a, IIngredient b) {
|
||||
this(new IIngredient[]{a, b});
|
||||
}
|
||||
|
||||
private IngredientOr(IIngredient[] elements, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.elements = elements;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return elements[0].getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
result.addAll(element.getItems());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
List<ILiquidStack> result = new ArrayList<>();
|
||||
for(IIngredient element : elements) {
|
||||
result.addAll(element.getLiquids());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
IIngredient[] result = new IIngredient[elements.length];
|
||||
for(int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].amount(amount);
|
||||
}
|
||||
return new IngredientOr(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOr(elements, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOr(elements, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOr(elements, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(ArrayUtil.append(elements, ingredient));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matchesExact(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
for(IIngredient ingredient : elements) {
|
||||
if(ingredient.matches(liquid))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
for(IItemStack item : items) {
|
||||
if(!matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains an ingredient stack. Is an ingredient with a specific stack size
|
||||
* assigned to it.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientStack implements IIngredient {
|
||||
|
||||
private final IIngredient ingredient;
|
||||
private final int amount;
|
||||
|
||||
public IngredientStack(IIngredient ingredient, int amount) {
|
||||
this.ingredient = ingredient;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return ingredient.getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(ingredient, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientStack(ingredient.transform(transformer), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientStack(ingredient.only(condition), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientStack(ingredient.marked(mark), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matches(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matchesExact(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return this.ingredient.contains(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return ingredient.applyTransform(item, byPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return ingredient.hasTransformers();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "(Ingredients) ";
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
for(IItemStack st : ingredient.getItems()) {
|
||||
names.add(st.getName());
|
||||
}
|
||||
s += String.join(",", names);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Transformations can be used to modify an ingredient after it is used in a
|
||||
* crafting recipe. It could reuse the item, damage it or consume multiple
|
||||
* items.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTransform {
|
||||
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient reuse(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> item.withAmount(item.getAmount() + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item for
|
||||
* 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
* @param ingredient target value
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the item for a specific amount. Also makes the item reusable.
|
||||
* Upon reaching maximum damage, the item will be consumed. Take care to set
|
||||
* the proper condition such that an almost-broken item becomes invalid for
|
||||
* crafting.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
if(newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount()).withDamage(0);
|
||||
} else {
|
||||
return item.withAmount(item.getAmount()).withDamage(newDamage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
*
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(item.getAmount() > 1) {
|
||||
byPlayer.give(withItem);
|
||||
return item;
|
||||
} else {
|
||||
return withItem.withAmount(withItem.getAmount());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes multiple items to be consumed. Take care to set a condition for a
|
||||
* minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
*
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform((item, byPlayer) -> item.withAmount(Math.max(item.getAmount() - amount, 0) + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure there is no return value.
|
||||
*
|
||||
* @param ingredient
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient noReturn(IIngredient ingredient) {
|
||||
return ingredient.transform((item, byPlayer) -> null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives an item back to the player. Also clears the inventory slot at that
|
||||
* position.
|
||||
*
|
||||
* @param ingredient
|
||||
* @param givenItem
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IIngredient giveBack(IIngredient ingredient, @Optional final IItemStack givenItem) {
|
||||
return ingredient.transform((item, byPlayer) -> {
|
||||
if(givenItem == null) {
|
||||
byPlayer.give(item.withAmount(1));
|
||||
return item;
|
||||
} else {
|
||||
byPlayer.give(givenItem);
|
||||
return item;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class IngredientUnknown implements IIngredient {
|
||||
|
||||
public static final IngredientUnknown INSTANCE = new IngredientUnknown(1);
|
||||
|
||||
private final int size;
|
||||
|
||||
public IngredientUnknown(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientUnknown(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedItemStack {
|
||||
|
||||
private final IItemStack stack;
|
||||
private final float p;
|
||||
public WeightedItemStack(IItemStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static List<IItemStack> pickRandomDrops(Random random, WeightedItemStack[] items) {
|
||||
ArrayList<IItemStack> result = new ArrayList<>();
|
||||
|
||||
for(WeightedItemStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public IItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedItemStack other = (WeightedItemStack) obj;
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) && Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains a liquid definition. Liquid definitions provide additional
|
||||
* information about liquids.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.liquid.ILiquidDefinition")
|
||||
public interface ILiquidDefinition {
|
||||
|
||||
/**
|
||||
* Converts this liquid into a liquid stack.
|
||||
*
|
||||
* @param millibuckets item stack size
|
||||
*
|
||||
* @return resulting item stack
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
ILiquidStack asStack(int millibuckets);
|
||||
|
||||
/**
|
||||
* Gets the unlocalized name of this item.
|
||||
*
|
||||
* @return unlocalized name
|
||||
*/
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
int getLuminosity();
|
||||
|
||||
@ZenSetter("luminosity")
|
||||
void setLuminosity(int value);
|
||||
|
||||
@ZenGetter("density")
|
||||
int getDensity();
|
||||
|
||||
@ZenSetter("density")
|
||||
void setDensity(int density);
|
||||
|
||||
@ZenGetter("temperature")
|
||||
int getTemperature();
|
||||
|
||||
@ZenSetter("temperature")
|
||||
void setTemperature(int temperature);
|
||||
|
||||
@ZenGetter("viscosity")
|
||||
int getViscosity();
|
||||
|
||||
@ZenSetter("viscosity")
|
||||
void setViscosity(int viscosity);
|
||||
|
||||
@ZenGetter("gaseous")
|
||||
boolean isGaseous();
|
||||
|
||||
@ZenSetter("gaseous")
|
||||
void setGaseous(boolean gaseous);
|
||||
|
||||
@ZenGetter("containers")
|
||||
List<IItemStack> getContainers();
|
||||
|
||||
@ZenMethod
|
||||
void addContainer(IItemStack filled, IItemStack empty, int amount);
|
||||
|
||||
@ZenMethod
|
||||
void removeContainer(IItemStack filled);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stanneke
|
||||
*/
|
||||
@ZenClass("minetweaker.liquid.ILiquidStack")
|
||||
public interface ILiquidStack extends IIngredient {
|
||||
|
||||
@ZenGetter("definition")
|
||||
ILiquidDefinition getDefinition();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
String getDisplayName();
|
||||
|
||||
@ZenGetter("amount")
|
||||
int getAmount();
|
||||
|
||||
@ZenGetter("luminosity")
|
||||
int getLuminosity();
|
||||
|
||||
@ZenGetter("density")
|
||||
int getDensity();
|
||||
|
||||
@ZenGetter("temperature")
|
||||
int getTemperature();
|
||||
|
||||
@ZenGetter("viscosity")
|
||||
int getViscosity();
|
||||
|
||||
@ZenGetter("gaseous")
|
||||
boolean isGaseous();
|
||||
|
||||
@ZenGetter("tag")
|
||||
IData getTag();
|
||||
|
||||
@ZenMethod
|
||||
ILiquidStack withTag(IData data);
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
ILiquidStack withAmount(int amount);
|
||||
|
||||
Object getInternal();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedLiquidStack {
|
||||
|
||||
private final ILiquidStack stack;
|
||||
private final float p;
|
||||
public WeightedLiquidStack(ILiquidStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static List<ILiquidStack> pickRandomDrops(Random random, WeightedLiquidStack[] items) {
|
||||
ArrayList<ILiquidStack> result = new ArrayList<>();
|
||||
|
||||
for(WeightedLiquidStack item : items) {
|
||||
if(random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ZenGetter("stack")
|
||||
public ILiquidStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@ZenGetter("chance")
|
||||
public float getChance() {
|
||||
return p;
|
||||
}
|
||||
|
||||
@ZenGetter("percent")
|
||||
public float getPercent() {
|
||||
return p * 100;
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 17;
|
||||
hash = 29 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
hash = 29 * hash + Float.floatToIntBits(this.p);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) {
|
||||
return false;
|
||||
}
|
||||
if(getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final WeightedLiquidStack other = (WeightedLiquidStack) obj;
|
||||
return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) && Float.floatToIntBits(this.p) == Float.floatToIntBits(other.p);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package minetweaker.api.logger;
|
||||
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class FileLogger implements ILogger {
|
||||
|
||||
private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]");
|
||||
private final Writer writer;
|
||||
private final PrintWriter printWriter;
|
||||
|
||||
public FileLogger(File output) {
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8");
|
||||
printWriter = new PrintWriter(writer);
|
||||
} catch(UnsupportedEncodingException ex) {
|
||||
throw new RuntimeException("What the heck?");
|
||||
} catch(FileNotFoundException ex) {
|
||||
throw new RuntimeException("Could not open log file " + output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write(stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
try {
|
||||
writer.write("INFO: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
try {
|
||||
writer.write("WARNING: " + stripMessage(message) + "\n");
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
try {
|
||||
writer.write("ERROR: " + stripMessage(message) + "\n");
|
||||
if(exception != null) {
|
||||
exception.printStackTrace(printWriter);
|
||||
}
|
||||
writer.flush();
|
||||
} catch(IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the given string, with formatting codes stripped away.
|
||||
*/
|
||||
public String stripMessage(String message) {
|
||||
return message == null ? null : FORMATTING_CODE_PATTERN.matcher(message).replaceAll("");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package minetweaker.api.logger;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.runtime.ILogger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTLogger implements ILogger {
|
||||
|
||||
private final List<ILogger> loggers = new ArrayList<>();
|
||||
private final List<IPlayer> players = new ArrayList<>();
|
||||
private final List<String> unprocessed = new ArrayList<>();
|
||||
|
||||
public void addLogger(ILogger logger) {
|
||||
loggers.add(logger);
|
||||
}
|
||||
|
||||
public void removeLogger(ILogger logger) {
|
||||
loggers.remove(logger);
|
||||
}
|
||||
|
||||
public void addPlayer(IPlayer player) {
|
||||
players.add(player);
|
||||
|
||||
if(!unprocessed.isEmpty()) {
|
||||
unprocessed.forEach(player::sendChat);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(IPlayer player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
unprocessed.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logCommand(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logInfo(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String message) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logWarning(message);
|
||||
}
|
||||
|
||||
String message2 = "WARNING: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message) {
|
||||
logError(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String message, Throwable exception) {
|
||||
for(ILogger logger : loggers) {
|
||||
logger.logError(message, exception);
|
||||
}
|
||||
|
||||
String message2 = "ERROR: " + message;
|
||||
|
||||
if(players.isEmpty()) {
|
||||
unprocessed.add(message2);
|
||||
} else {
|
||||
for(IPlayer player : players) {
|
||||
player.sendChat(message2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,495 @@
|
||||
package minetweaker.api.minecraft;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IngredientUnknown;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBiome;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import minetweaker.mc1710.block.MCBlockDefinition;
|
||||
import minetweaker.mc1710.block.MCSpecificBlock;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.oredict.MCOreDictEntry;
|
||||
import minetweaker.mc1710.player.MCPlayer;
|
||||
import minetweaker.mc1710.world.MCDimension;
|
||||
import minetweaker.mc1710.block.MCWorldBlock;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
import minetweaker.mc1710.world.MCBiome;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* MineTweaker - MineCraft API bridge.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerMC {
|
||||
private static final Map<Block, MCBlockDefinition> blockDefinitions = new HashMap<Block, MCBlockDefinition>();
|
||||
public static final IBiome[] biomes;
|
||||
|
||||
static {
|
||||
biomes = new IBiome[BiomeGenBase.getBiomeGenArray().length];
|
||||
for (int i = 0; i < BiomeGenBase.getBiomeGenArray().length; i++) {
|
||||
if (BiomeGenBase.getBiomeGenArray()[i] != null)
|
||||
biomes[i] = new MCBiome(BiomeGenBase.getBiomeGenArray()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private MineTweakerMC() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Minecraft item for this MineTweaker item.
|
||||
*
|
||||
* @param item minetweaker item stack
|
||||
* @return minecraft item stack
|
||||
*/
|
||||
public static ItemStack getItemStack(IItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.logError("Not a valid item stack: " + item);
|
||||
}
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Minecraft ingredient for this ingredient. This method is only
|
||||
* useful for ingredients that represent a single item stack.
|
||||
*
|
||||
* @param ingredient item ingredient
|
||||
* @return minecraft item stack
|
||||
*/
|
||||
public static ItemStack getItemStack(IIngredient ingredient) {
|
||||
if (ingredient == null)
|
||||
return null;
|
||||
|
||||
List<IItemStack> items = ingredient.getItems();
|
||||
if (items.size() != 1) {
|
||||
MineTweakerAPI.logError("Not an ingredient with a single item: " + ingredient);
|
||||
}
|
||||
return getItemStack(items.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MineTweaker item stack for this item.
|
||||
*
|
||||
* @param item minecraft item stack
|
||||
* @return minetweaker item stack
|
||||
*/
|
||||
public static IItemStack getIItemStack(ItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with wildcard size.
|
||||
*
|
||||
* @param item minecraft item stack
|
||||
* @return minetweaker stack
|
||||
*/
|
||||
public static IItemStack getIItemStackWildcardSize(ItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(item, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with wildcard size.
|
||||
*
|
||||
* @param item
|
||||
* @param meta
|
||||
* @return minetweaker stack
|
||||
*/
|
||||
public static IItemStack getIItemStackWildcardSize(Item item, int meta) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(new ItemStack(item, 1, meta), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with wildcard damage.
|
||||
*
|
||||
* @param item stack item
|
||||
* @param amount stack size
|
||||
* @return minetweaker item stack
|
||||
*/
|
||||
public static IItemStack getIItemStackWildcard(Item item, int amount) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public static ItemStack[] getExamples(IIngredient ingredient) {
|
||||
List<IItemStack> examples = ingredient.getItems();
|
||||
ItemStack[] result = new ItemStack[examples.size()];
|
||||
for (int i = 0; i < examples.size(); i++) {
|
||||
result[i] = MineTweakerMC.getItemStack(examples.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an item stack with given item, damage and amount.
|
||||
*
|
||||
* @param item stack item
|
||||
* @param damage stack damage
|
||||
* @param amount stack amount
|
||||
* @return minetweaker item stack
|
||||
*/
|
||||
public static IItemStack getItemStack(Item item, int amount, int damage) {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return new MCItemStack(new ItemStack(item, amount, damage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of minetweaker item stacks into an array of minecraft
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minetweker item stacks
|
||||
* @return minecraft item stacks
|
||||
*/
|
||||
public static ItemStack[] getItemStacks(IItemStack... items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
ItemStack[] output = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Object internal = items[i].getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of minetweaker item stacks into an array of minecraft
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minetweaker items
|
||||
* @return minecraft items
|
||||
*/
|
||||
public static ItemStack[] getItemStacks(List<IItemStack> items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
ItemStack[] output = new ItemStack[items.size()];
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Object internal = items.get(i).getInternal();
|
||||
if (internal != null && internal instanceof ItemStack) {
|
||||
output[i] = (ItemStack) internal;
|
||||
} else {
|
||||
MineTweakerAPI.logError("Invalid item stack: " + items.get(i));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of minecraft item stacks into an array of minetweaker
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minecraft item stacks
|
||||
* @return minetweaker item stacks
|
||||
*/
|
||||
public static IItemStack[] getIItemStacks(ItemStack... items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
IItemStack[] result = new IItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = new MCItemStack(items[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of minecraft item stacks into an array of minetweaker
|
||||
* item stacks.
|
||||
*
|
||||
* @param items minecraft item stacks
|
||||
* @return minetweaker item stacks
|
||||
*/
|
||||
public static IItemStack[] getIItemStacks(List<ItemStack> items) {
|
||||
if (items == null)
|
||||
return null;
|
||||
|
||||
IItemStack[] result = new IItemStack[items.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MCItemStack(items.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ore dictionary entry with the given name. If the entry didn't
|
||||
* exist yet, it will create it and return an empty entry.
|
||||
*
|
||||
* @param name ore entry name
|
||||
* @return ore dictionary entry
|
||||
*/
|
||||
public static IOreDictEntry getOreDict(String name) {
|
||||
return new MCOreDictEntry(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft player into a MineTweaker player.
|
||||
*
|
||||
* @param player minecraft player
|
||||
* @return minetweaker player
|
||||
*/
|
||||
public static IPlayer getIPlayer(EntityPlayer player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
|
||||
return new MCPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a MineTweaker player into a Minecraft player.
|
||||
*
|
||||
* @param player minetweaker player
|
||||
* @return minecraft player
|
||||
*/
|
||||
public static EntityPlayer getPlayer(IPlayer player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
|
||||
if (!(player instanceof MCPlayer)) {
|
||||
MineTweakerAPI.logError("Invalid player: " + player);
|
||||
}
|
||||
|
||||
return ((MCPlayer) player).getInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft NBT to an IData instance. The IData instance is
|
||||
* immutable (not modifyiable).
|
||||
*
|
||||
* @param nbt nbt data
|
||||
* @return IData value
|
||||
*/
|
||||
public static IData getIData(NBTBase nbt) {
|
||||
if (nbt == null)
|
||||
return null;
|
||||
|
||||
return NBTConverter.from(nbt, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft NBT to a modifyable IData instance.
|
||||
*
|
||||
* @param nbt nbt data
|
||||
* @return mutable IData value
|
||||
*/
|
||||
public static IData getIDataModifyable(NBTBase nbt) {
|
||||
if (nbt == null)
|
||||
return null;
|
||||
|
||||
return NBTConverter.from(nbt, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IData instance to an NBT value.
|
||||
*
|
||||
* @param data IData value
|
||||
* @return nbt data
|
||||
*/
|
||||
public static NBTBase getNBT(IData data) {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return NBTConverter.from(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an IData instance to an NBT Tag compound.
|
||||
*
|
||||
* @param data IData value
|
||||
* @return nbt compound data
|
||||
*/
|
||||
public static NBTTagCompound getNBTCompound(IData data) {
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
return (NBTTagCompound) NBTConverter.from(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block at the given position.
|
||||
*
|
||||
* @param blocks block access
|
||||
* @param x block x position
|
||||
* @param y block y position
|
||||
* @param z block z position
|
||||
* @return block instance
|
||||
*/
|
||||
public static IBlock getBlock(IBlockAccess blocks, int x, int y, int z) {
|
||||
return new MCWorldBlock(blocks, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block definition for the given block.
|
||||
*
|
||||
* @param block block object
|
||||
* @return block definition
|
||||
*/
|
||||
public static IBlockDefinition getBlockDefinition(Block block) {
|
||||
if (!blockDefinitions.containsKey(block)) {
|
||||
blockDefinitions.put(block, new MCBlockDefinition(block));
|
||||
}
|
||||
return blockDefinitions.get(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the dimension instance for a given world.
|
||||
*
|
||||
* @param world world
|
||||
* @return dimension
|
||||
*/
|
||||
public static IDimension getDimension(World world) {
|
||||
if (world == null)
|
||||
return null;
|
||||
|
||||
return new MCDimension(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the given block.
|
||||
*
|
||||
* @param block MC block definition
|
||||
* @return MT block instance
|
||||
*/
|
||||
public static IBlock getBlockAnyMeta(Block block) {
|
||||
return new MCSpecificBlock(block, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the given block.
|
||||
*
|
||||
* @param block MC block definition
|
||||
* @param meta block meta value
|
||||
* @return MT block instance
|
||||
*/
|
||||
public static IBlock getBlock(Block block, int meta) {
|
||||
return new MCSpecificBlock(block, meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block from an item stack.
|
||||
*
|
||||
* @param itemStack
|
||||
* @return
|
||||
*/
|
||||
public static Block getBlock(IItemStack itemStack) {
|
||||
return ((MCBlockDefinition) itemStack.asBlock().getDefinition()).getInternalBlock();
|
||||
}
|
||||
|
||||
public static Block getBlock(IBlock block) {
|
||||
return ((MCBlockDefinition) block.getDefinition()).getInternalBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the internal fluid stack of the given stack.
|
||||
*
|
||||
* @param stack MT liquid stack
|
||||
* @return MCF fluid stack
|
||||
*/
|
||||
public static FluidStack getLiquidStack(ILiquidStack stack) {
|
||||
if (stack == null)
|
||||
return null;
|
||||
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of MT liquid stacks into an array of MCF fluid stacks
|
||||
*
|
||||
*/
|
||||
public static FluidStack[] getLiquidStacks(ILiquidStack[] stacks) {
|
||||
if (stacks == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack[] res = new FluidStack[stacks.length];
|
||||
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
ILiquidStack liquidStack = stacks[i];
|
||||
res[i] = getLiquidStack(liquidStack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
|
||||
public static IOreDictEntry getOreDictEntryFromArray(List array) {
|
||||
if (!oreDictArrays.containsKey(array)) {
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictionary.getOres(ore) == array) {
|
||||
oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oreDictArrays.get(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Minecraft ingredient to a MineTweaker ingredient.
|
||||
*
|
||||
* @param ingredient minecraft ingredient
|
||||
* @return minetweaker ingredient
|
||||
*/
|
||||
public static IIngredient getIIngredient(Object ingredient) {
|
||||
if (ingredient == null) {
|
||||
return null;
|
||||
} else if (ingredient instanceof String) {
|
||||
return MineTweakerAPI.oreDict.get((String) ingredient);
|
||||
} else if (ingredient instanceof Item) {
|
||||
return getIItemStack(new ItemStack((Item) ingredient, 1, 0));
|
||||
} else if (ingredient instanceof ItemStack) {
|
||||
return getIItemStack((ItemStack) ingredient);
|
||||
} else if (ingredient instanceof List) {
|
||||
IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient);
|
||||
|
||||
if (entry == null) {
|
||||
return IngredientUnknown.INSTANCE;
|
||||
}
|
||||
|
||||
return entry;
|
||||
} else if (ingredient instanceof FluidStack) {
|
||||
return new MCLiquidStack((FluidStack) ingredient);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid ingredient: " + ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package minetweaker.api.mods;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.mods.ILoadedMods")
|
||||
@IterableSimple("minetweaker.mods.IMod")
|
||||
public interface ILoadedMods extends Iterable<IMod> {
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(String name);
|
||||
|
||||
@ZenOperator(OperatorType.INDEXGET)
|
||||
IMod get(String name);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.mods;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public interface IMod {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("version")
|
||||
String getVersion();
|
||||
|
||||
@ZenGetter("decription")
|
||||
String getDescription();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDict")
|
||||
public interface IOreDict {
|
||||
|
||||
@ZenMemberGetter
|
||||
IOreDictEntry get(String name);
|
||||
|
||||
@ZenGetter("entries")
|
||||
List<IOreDictEntry> getEntries();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.oredict.IOreDictEntry")
|
||||
public interface IOreDictEntry extends IIngredient {
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("empty")
|
||||
boolean isEmpty();
|
||||
|
||||
@ZenGetter("firstItem")
|
||||
IItemStack getFirstItem();
|
||||
|
||||
@ZenMethod
|
||||
void add(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void addItems(IItemStack[] items);
|
||||
|
||||
@ZenMethod
|
||||
void addAll(IOreDictEntry entry);
|
||||
|
||||
@ZenMethod
|
||||
void remove(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void removeItems(IItemStack[] items);
|
||||
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
boolean contains(IItemStack item);
|
||||
|
||||
@ZenMethod
|
||||
void mirror(IOreDictEntry other);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package minetweaker.api.oredict;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IngredientOreDict implements IIngredient {
|
||||
|
||||
private final IOreDictEntry entry;
|
||||
private final String mark;
|
||||
private final IItemCondition[] conditions;
|
||||
private final IItemTransformer[] transformers;
|
||||
|
||||
public IngredientOreDict(IOreDictEntry entry, String mark, IItemCondition[] conditions, IItemTransformer[] transformers) {
|
||||
this.entry = entry;
|
||||
this.mark = mark;
|
||||
this.conditions = conditions;
|
||||
this.transformers = transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMark() {
|
||||
return mark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getItems() {
|
||||
return entry.getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
return new IngredientStack(this, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient transform(IItemTransformer transformer) {
|
||||
return new IngredientOreDict(entry, mark, conditions, ArrayUtil.append(transformers, transformer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient only(IItemCondition condition) {
|
||||
return new IngredientOreDict(entry, mark, ArrayUtil.append(conditions, condition), transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(entry, mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if(!entry.matches(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesExact(IItemStack item) {
|
||||
if(!entry.matchesExact(item))
|
||||
return false;
|
||||
|
||||
for(IItemCondition condition : conditions) {
|
||||
if(!condition.matches(item))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILiquidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return entry.contains(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
|
||||
for(IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item, byPlayer);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return entry.getInternal();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package minetweaker.api.player;
|
||||
|
||||
import minetweaker.api.chat.IChatMessage;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.player.IPlayer")
|
||||
public interface IPlayer {
|
||||
|
||||
@ZenGetter("id")
|
||||
String getId();
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
|
||||
@ZenGetter("data")
|
||||
IData getData();
|
||||
|
||||
@ZenGetter("xp")
|
||||
int getXP();
|
||||
|
||||
@ZenSetter("xp")
|
||||
void setXP(int xp);
|
||||
|
||||
@ZenMethod
|
||||
void removeXP(int xp);
|
||||
|
||||
@ZenMethod
|
||||
void update(IData data);
|
||||
|
||||
@ZenMethod
|
||||
void sendChat(IChatMessage message);
|
||||
|
||||
@ZenMethod
|
||||
void sendChat(String message);
|
||||
|
||||
@ZenGetter("hotbarSize")
|
||||
int getHotbarSize();
|
||||
|
||||
@ZenMethod
|
||||
IItemStack getHotbarStack(int i);
|
||||
|
||||
@ZenGetter("inventorySize")
|
||||
int getInventorySize();
|
||||
|
||||
@ZenMethod
|
||||
IItemStack getInventoryStack(int i);
|
||||
|
||||
@ZenGetter("currentItem")
|
||||
IItemStack getCurrentItem();
|
||||
|
||||
@ZenGetter("creative")
|
||||
boolean isCreative();
|
||||
|
||||
@ZenGetter("adventure")
|
||||
boolean isAdventure();
|
||||
|
||||
@ZenMethod
|
||||
void give(IItemStack stack);
|
||||
|
||||
// not an exposed method. risks abuse
|
||||
void openBrowser(String url);
|
||||
|
||||
// not an exposed method, so far. would it be useful?
|
||||
void copyToClipboard(String value);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
|
||||
public class BrewingRecipe implements IBrewingRecipe {
|
||||
|
||||
private final IItemStack output;
|
||||
private final IItemStack input;
|
||||
private final IIngredient ingredient;
|
||||
|
||||
public BrewingRecipe(IItemStack output, IItemStack input, IIngredient ingredient) {
|
||||
this.input = input;
|
||||
this.ingredient = ingredient;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return String.format("brewing.add(%s, %s, %s)", output, input, ingredient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class CraftingInfo implements ICraftingInfo {
|
||||
|
||||
private final ICraftingInventory inventory;
|
||||
private final IDimension dimension;
|
||||
|
||||
public CraftingInfo(ICraftingInventory inventory, IDimension dimension) {
|
||||
this.inventory = inventory;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return inventory.getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
||||
public class FurnaceRecipe implements IFurnaceRecipe {
|
||||
|
||||
private final IItemStack input;
|
||||
private final IItemStack output;
|
||||
private final float xp;
|
||||
|
||||
public FurnaceRecipe(IItemStack input, IItemStack output, float xp) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.xp = xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return String.format("furnace.addRecipe(%s, %s, %s)", output, input, xp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The BrewingManager adds and removes brewing recipes. The IBrewingManager
|
||||
* instance is available through the recipes global variable.
|
||||
*
|
||||
* @author Jared
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IBrewingManager")
|
||||
public interface IBrewingManager {
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<IBrewingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Removes a brewing recipe from the specified item.
|
||||
*
|
||||
* @param output recipe output pattern
|
||||
*/
|
||||
@ZenMethod
|
||||
void remove(IItemStack output);
|
||||
|
||||
/**
|
||||
* Adds a recipe.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe ingredient
|
||||
* @param input recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
void add(IItemStack output, IItemStack ingredient, IItemStack input);
|
||||
|
||||
/**
|
||||
* Removes recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredient
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int remove(IItemStack output, IItemStack ingredients);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
@ZenClass("minetweaker.recipes.IBrewingRecipe")
|
||||
public interface IBrewingRecipe {
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInfo")
|
||||
public interface ICraftingInfo {
|
||||
|
||||
@ZenGetter("inventory")
|
||||
ICraftingInventory getInventory();
|
||||
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
@ZenGetter("dimension")
|
||||
IDimension getDimension();
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* Crafting inventory interface. The crafting inventory is the 2x2 grid in the
|
||||
* player inventory or the 3x3 grid in the crafting bench.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingInventory")
|
||||
public interface ICraftingInventory {
|
||||
|
||||
/**
|
||||
* Gets the player owning this inventory.
|
||||
*
|
||||
* @return inventory player
|
||||
*/
|
||||
@ZenGetter("player")
|
||||
IPlayer getPlayer();
|
||||
|
||||
/**
|
||||
* Gets the size of this inventory.
|
||||
*
|
||||
* @return inventory size
|
||||
*/
|
||||
@ZenGetter("size")
|
||||
int getSize();
|
||||
|
||||
/**
|
||||
* Gets the width of this inventory.
|
||||
*
|
||||
* @return inventory width
|
||||
*/
|
||||
@ZenGetter("width")
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of this inventory.
|
||||
*
|
||||
* @return inventory height
|
||||
*/
|
||||
@ZenGetter("height")
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* Gets the number of stacks that are actually filled in.
|
||||
*
|
||||
* @return effective stack count
|
||||
*/
|
||||
@ZenGetter("stackCount")
|
||||
int getStackCount();
|
||||
|
||||
/**
|
||||
* Gets the stack at the given location.
|
||||
*
|
||||
* @param i stack index
|
||||
*
|
||||
* @return stack contents, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int i);
|
||||
|
||||
/**
|
||||
* Gets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
*
|
||||
* @return item stack, or null if there is no item stack at that position
|
||||
*/
|
||||
@ZenMethod
|
||||
IItemStack getStack(int x, int y);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given position. The top left stack is position (0,
|
||||
* 0).
|
||||
*
|
||||
* @param x stack x position
|
||||
* @param y stack y position
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* position
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int x, int y, IItemStack stack);
|
||||
|
||||
/**
|
||||
* Sets the stack at the given index.
|
||||
*
|
||||
* @param i stack index
|
||||
* @param stack item stack to be set, or null to clear the stack at that
|
||||
* index
|
||||
*/
|
||||
@ZenMethod
|
||||
void setStack(int i, IItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.ICraftingRecipe")
|
||||
public interface ICraftingRecipe {
|
||||
|
||||
boolean matches(ICraftingInventory inventory);
|
||||
|
||||
IItemStack getCraftingResult(ICraftingInventory inventory);
|
||||
|
||||
boolean hasTransformers();
|
||||
|
||||
void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer);
|
||||
|
||||
String toCommandString();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IFurnaceManager")
|
||||
public interface IFurnaceManager {
|
||||
|
||||
@ZenMethod
|
||||
void remove(IIngredient output, @Optional IIngredient input);
|
||||
|
||||
@ZenMethod
|
||||
void addRecipe(IItemStack output, IIngredient input, @Optional double xp);
|
||||
|
||||
@ZenMethod
|
||||
void setFuel(IIngredient item, int fuel);
|
||||
|
||||
@ZenMethod
|
||||
int getFuel(IItemStack item);
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
List<IFurnaceRecipe> getAll();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
/**
|
||||
* Created by Jared on 4/18/2016.
|
||||
*/
|
||||
public interface IFurnaceRecipe {
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeFunction")
|
||||
public interface IRecipeFunction {
|
||||
|
||||
IItemStack process(IItemStack output, Map<String, IItemStack> inputs, ICraftingInfo craftingInfo);
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
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")
|
||||
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);
|
||||
|
||||
int remove(IIngredient output);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function);
|
||||
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeAction action);
|
||||
|
||||
void addShaped(IItemStack output, IIngredient[][] ingredients);
|
||||
/**
|
||||
* Adds a mirrored shaped recipe.
|
||||
*
|
||||
* @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);
|
||||
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function);
|
||||
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, IRecipeAction action);
|
||||
|
||||
void addShapedMirrored(IItemStack output, IIngredient[][] ingredients);
|
||||
/**
|
||||
* Adds a shapeless recipe.
|
||||
*
|
||||
* @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);
|
||||
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeFunction function);
|
||||
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients, IRecipeAction action);
|
||||
|
||||
void addShapeless(IItemStack output, IIngredient[] ingredients);
|
||||
|
||||
/**
|
||||
* Removes shaped recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients);
|
||||
|
||||
int removeShaped(IIngredient output);
|
||||
/**
|
||||
* Removes shapeless recipes.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredients recipe ingredients
|
||||
* @param wildcard if the recipe may contain other ingredients too, besides
|
||||
* the ones specified
|
||||
*
|
||||
* @return number of removed recipes
|
||||
*/
|
||||
@ZenMethod
|
||||
int removeShapeless(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard);
|
||||
|
||||
int removeShapeless(IIngredient output, boolean wildcard);
|
||||
|
||||
int removeShapeless(IIngredient output, IIngredient[] ingredients);
|
||||
|
||||
int removeShapeless(IIngredient output);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipe implements ICraftingRecipe {
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
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[] ingredient : ingredients) {
|
||||
for (IIngredient iIngredient : ingredient) {
|
||||
if (iIngredient != 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;
|
||||
this.posy[ix] = (byte) j;
|
||||
this.ingredients[ix] = row[i];
|
||||
ix++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
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++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
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) {
|
||||
if(ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
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:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, true, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("recipes.addShaped(");
|
||||
if(output != null) {
|
||||
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) {
|
||||
// determine output and apply transformations
|
||||
|
||||
if(function != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* for (int i = 0; i < ingredients.length; i++) { IItemStack transformed
|
||||
* = ingredients[i].applyTransform(stacks[i]); if (transformed !=
|
||||
* stacks[i]) { if (mirrored) { inventory.setStack( inventory.getWidth()
|
||||
* - (offx + posx[i]) - 1, offy + posy[i], transformed); } else {
|
||||
* inventory.setStack( offx + posx[i], offy + posy[i], transformed); } }
|
||||
* }
|
||||
*/
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private void doRecipeTransformers(ICraftingInventory inventory, IItemStack[] stacks, int offx, int offy, boolean mirrored, IPlayer byPlayer) {
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
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);
|
||||
} else {
|
||||
inventory.setStack(offx + posx[i], offy + posy[i], transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IRecipeAction getAction() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.*;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapelessRecipe implements ICraftingRecipe {
|
||||
|
||||
private final IItemStack output;
|
||||
private final IRecipeFunction function;
|
||||
private final IRecipeAction action;
|
||||
private final IIngredient[] ingredients;
|
||||
|
||||
public ShapelessRecipe(IItemStack output, IIngredient[] ingredients, IRecipeFunction function, IRecipeAction action) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package minetweaker.api.resource;
|
||||
|
||||
import stanhebben.zenscript.annotations.*;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.resource.IResourceFile")
|
||||
public interface IResourceFile {
|
||||
|
||||
@ZenGetter("name")
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package minetweaker.api.resource;
|
||||
|
||||
/**
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IResourceManager {
|
||||
|
||||
/**
|
||||
* Retrieves a resource file. Returns null if the resource dosen't exist.
|
||||
*
|
||||
* @param module
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IResourceFile getResource(String module, String name);
|
||||
}
|
||||
Loaded 100 of 320 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user