mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-18 11:19:31 +00:00
- Added MFR support for 1.6.4
- Improved API for blocks - NBT compound tags with non-identifier keys should now be output properly
This commit is contained in:
1 parent
e644398505
commit
e2b4f50dfc
97 files changed
+5307
-216
No files matched your search
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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<IBlock>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
@@ -9,7 +10,7 @@ import stanhebben.zenscript.annotations.ZenGetter;
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlock")
|
||||
public interface IBlock {
|
||||
public interface IBlock extends IBlockPattern {
|
||||
/**
|
||||
* Gets the block definition.
|
||||
*
|
||||
@@ -17,4 +18,10 @@ public interface IBlock {
|
||||
*/
|
||||
@ZenGetter("definition")
|
||||
public IBlockDefinition getDefinition();
|
||||
|
||||
@ZenGetter("meta")
|
||||
public int getMeta();
|
||||
|
||||
@ZenGetter("data")
|
||||
public IData getTileData();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package minetweaker.api.block;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* Blocks definitions provide additional information about blocks.
|
||||
@@ -9,5 +10,6 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockDefinition")
|
||||
public interface IBlockDefinition {
|
||||
|
||||
@ZenGetter("id")
|
||||
public String getId();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.block;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenOperator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.block.IBlockPattern")
|
||||
public interface IBlockPattern {
|
||||
@ZenMethod("blocks")
|
||||
public List<IBlock> getBlocks();
|
||||
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean matches(IBlock block);
|
||||
|
||||
@ZenOperator(OperatorType.OR)
|
||||
public IBlockPattern or(IBlockPattern pattern);
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
}
|
||||
@@ -137,7 +137,13 @@ public class DataMap implements IData {
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(entry.getKey());
|
||||
|
||||
if (isValidIdentifier(entry.getKey())) {
|
||||
result.append(entry.getKey());
|
||||
} else {
|
||||
result.append("\"").append(entry.getKey()).append("\"");
|
||||
}
|
||||
|
||||
result.append(": ");
|
||||
result.append(entry.getValue().toString());
|
||||
}
|
||||
@@ -275,4 +281,16 @@ public class DataMap implements IData {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
package minetweaker.api.event;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IBlockGroup;
|
||||
import minetweaker.api.world.IDimension;
|
||||
@@ -22,7 +21,6 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@ZenClass("minetweaker.event.PlayerInteractEvent")
|
||||
public class PlayerInteractEvent {
|
||||
private final IPlayer player;
|
||||
private final IEntity entity;
|
||||
private final IBlockGroup blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
@@ -32,9 +30,8 @@ public class PlayerInteractEvent {
|
||||
private boolean useBlock;
|
||||
private boolean useItem;
|
||||
|
||||
public PlayerInteractEvent(IPlayer player, IEntity entity, IBlockGroup blocks, int x, int y, int z) {
|
||||
public PlayerInteractEvent(IPlayer player, IBlockGroup blocks, int x, int y, int z) {
|
||||
this.player = player;
|
||||
this.entity = entity;
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@@ -60,6 +60,17 @@ public interface IIngredient {
|
||||
@ZenMethod
|
||||
public IIngredient amount(int amount);
|
||||
|
||||
/**
|
||||
* Combines multiple ingredients into a single one. Note that ore dictionary
|
||||
* entries are preferred to or statements.
|
||||
*
|
||||
* @param ingredient ingredient to combine with
|
||||
* @return or-ed ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.OR)
|
||||
@ZenMethod
|
||||
public IIngredient or(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import stanhebben.zenscript.annotations.OperatorType;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@@ -170,4 +172,12 @@ public interface IItemStack extends IIngredient {
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack updateTag(IData tagUpdate);
|
||||
|
||||
/**
|
||||
* Converts this item stack into a block.
|
||||
*
|
||||
* @return block, or null if this item is not a block
|
||||
*/
|
||||
@ZenCaster
|
||||
public IBlock asBlock();
|
||||
}
|
||||
@@ -50,6 +50,11 @@ public class IngredientAny implements IIngredient {
|
||||
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;
|
||||
|
||||
@@ -55,6 +55,11 @@ public class IngredientAnyAdvanced implements IIngredient {
|
||||
return new IngredientAnyAdvanced(mark, conditions, transformers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
if (!item.matches(item)) return false;
|
||||
|
||||
@@ -60,6 +60,11 @@ public class IngredientItem implements IIngredient {
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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<IItemStack>();
|
||||
for (IIngredient element : elements) {
|
||||
result.addAll(element.getItems());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient amount(int amount) {
|
||||
IIngredient[] result = new IIngredient[elements.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
result[i] = elements[i].amount(amount);
|
||||
}
|
||||
return new IngredientOr(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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 : item.getItems()) {
|
||||
if (ingredient.matches(item))
|
||||
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) {
|
||||
for (IItemTransformer transformer : transformers) {
|
||||
item = transformer.transform(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return transformers.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,11 @@ public class IngredientStack implements IIngredient {
|
||||
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);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
@@ -11,6 +14,18 @@ import stanhebben.zenscript.annotations.ZenGetter;
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedItemStack {
|
||||
public static List<IItemStack> pickRandomDrops(Random random, WeightedItemStack[] items) {
|
||||
ArrayList<IItemStack> result = new ArrayList<IItemStack>();
|
||||
|
||||
for (WeightedItemStack item : items) {
|
||||
if (random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private final IItemStack stack;
|
||||
private final float p;
|
||||
|
||||
@@ -37,6 +52,7 @@ public final class WeightedItemStack {
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package minetweaker.api.liquid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
|
||||
/**
|
||||
* Contains a weighted item stack. Weighted item stacks simply contain a stack
|
||||
* and a weight.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.WeightedItemStack")
|
||||
public final class WeightedLiquidStack {
|
||||
public static List<ILiquidStack> pickRandomDrops(Random random, WeightedLiquidStack[] items) {
|
||||
ArrayList<ILiquidStack> result = new ArrayList<ILiquidStack>();
|
||||
|
||||
for (WeightedLiquidStack item : items) {
|
||||
if (random.nextFloat() <= item.getChance()) {
|
||||
result.add(item.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private final ILiquidStack stack;
|
||||
private final float p;
|
||||
|
||||
public WeightedLiquidStack(ILiquidStack stack, float p) {
|
||||
this.stack = stack;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@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;
|
||||
if (this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) {
|
||||
return false;
|
||||
}
|
||||
if (Float.floatToIntBits(this.p) != Float.floatToIntBits(other.p)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientOr;
|
||||
import minetweaker.api.item.IngredientStack;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
@@ -70,6 +71,11 @@ public class IngredientOreDict implements IIngredient {
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user