mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-28 07:35:40 +00:00
- Refactored code into different packages
- Fixed some non-static expansion methods - Fixed scripts not reloading properly - Implemented mod support build system - Fixed recipe removal breaking on recipes without predefined output - Fixed NPE on parsing a bracket expression that doesn't exist - now prints an appropriate error
This commit is contained in:
1 parent
1789aa74b5
commit
2de467d7d8
93 files changed
+321
-262
No files matched your search
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@ZenClass("minetweaker.item.Condition")
|
||||
public class Condition {
|
||||
/**
|
||||
* Requires the item to be damaged. A damage value of 1 is enough.
|
||||
*
|
||||
* @return damaged condition
|
||||
*/
|
||||
@ZenGetter
|
||||
public static IItemCondition damaged() {
|
||||
return 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 minDamage minimum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageAtLeast(final int minDamage) {
|
||||
return 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 maxDamage maximum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageAtMost(final int maxDamage) {
|
||||
return new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getDamage() <= maxDamage;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires the item damage value to be between two values.
|
||||
*
|
||||
* @param minDamage minimum damage
|
||||
* @param maxDamage maximum damage
|
||||
* @return damage condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition damageBetween(final int minDamage, final int maxDamage) {
|
||||
return 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 data required data
|
||||
* @return data condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition data(final IData data) {
|
||||
return 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 amount required stack size
|
||||
* @return stack size condition
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemCondition stack(final int amount) {
|
||||
return new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return stack.getAmount() >= amount;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* 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")
|
||||
public String getMark();
|
||||
|
||||
/**
|
||||
* Gets the amount.
|
||||
*
|
||||
* Should return -1 if no amount is available and 1 for a single item.
|
||||
* Stacks return the stack size.
|
||||
*
|
||||
* @return stack size
|
||||
*/
|
||||
@ZenGetter("amount")
|
||||
public int getAmount();
|
||||
|
||||
/**
|
||||
* Gets all possible items for this ingredient.
|
||||
*
|
||||
* If there is no item list (for example, it is the <*> wildcard item)
|
||||
* null should be returned.
|
||||
*
|
||||
* @return the items for this ingredient, or null
|
||||
*/
|
||||
@ZenGetter("items")
|
||||
public List<IItemStack> getItems();
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given stack size.
|
||||
*
|
||||
* @param amount new stack size
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public IIngredient amount(int amount);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given transform added to it.
|
||||
*
|
||||
* @param transformer transformer to add
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient transform(IItemTransformer transformer);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient with the given condition added to it.
|
||||
*
|
||||
* @param condition condition to add
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient only(IItemCondition condition);
|
||||
|
||||
/**
|
||||
* Returns a new ingredient marked with the given name.
|
||||
*
|
||||
* @param mark mark to apply
|
||||
* @return modified ingredient
|
||||
*/
|
||||
@ZenMethod
|
||||
public IIngredient marked(String mark);
|
||||
|
||||
/**
|
||||
* Checks if this ingredient matches the given item.
|
||||
*
|
||||
* @param item item to check
|
||||
* @return true if the item matches
|
||||
*/
|
||||
@ZenMethod
|
||||
public boolean matches(IItemStack item);
|
||||
|
||||
/**
|
||||
* Check if this ingredient contains all possible values for the given
|
||||
* ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to check
|
||||
* @return true if the ingredient contains the given one
|
||||
*/
|
||||
@ZenOperator(OperatorType.CONTAINS)
|
||||
public boolean contains(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Applies transformations, if any, to the given item.
|
||||
*
|
||||
* @param item item to transform
|
||||
* @return transformed item
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack applyTransform(IItemStack item);
|
||||
|
||||
/**
|
||||
* Gets the internal item backing this ingredient.
|
||||
*
|
||||
* The value is implementation-dependent.
|
||||
*
|
||||
* @return internal item
|
||||
*/
|
||||
public Object getInternal();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
* Item conditions apply additional conditions on item stacks.
|
||||
*
|
||||
* They may, for instance, require specific damage ranges or NBT tags. Custom
|
||||
* implementations of this functional interface may contain any kind of condition.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemCondition")
|
||||
public interface IItemCondition {
|
||||
/**
|
||||
* Returns true if the given stack matches the required conditions.
|
||||
*
|
||||
* @param stack item stack to check
|
||||
* @return true if the condition applies to this stack
|
||||
*/
|
||||
public boolean matches(IItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.item.IItemDefinition")
|
||||
public interface IItemDefinition {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.item;
|
||||
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
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.item.IItemStack")
|
||||
public interface IItemStack extends IIngredient {
|
||||
@ZenGetter("definition")
|
||||
public IItemDefinition getDefinition();
|
||||
|
||||
@ZenGetter("name")
|
||||
public String getName();
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String getDisplayName();
|
||||
|
||||
@ZenGetter("damage")
|
||||
public int getDamage();
|
||||
|
||||
@ZenGetter("tag")
|
||||
public IData getTag();
|
||||
|
||||
@ZenGetter("maxDamage")
|
||||
public int getMaxDamage();
|
||||
|
||||
@ZenGetter("liquid")
|
||||
public ILiquidStack getLiquid();
|
||||
|
||||
@ZenOperator(OperatorType.MUL)
|
||||
@ZenMethod
|
||||
public IItemStack amount(int amount);
|
||||
|
||||
@ZenMethod
|
||||
public IIngredient anyDamage();
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack withDamage(int damage);
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack withAmount(int amount);
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack withTag(IData tag);
|
||||
|
||||
@ZenMethod
|
||||
public IItemStack updateTag(IData tagUpdate);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package minetweaker.api.item;
|
||||
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* An item transformer modifies an item stack. 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
|
||||
* @return output item
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack transform(IItemStack item);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.List;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
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 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 boolean matches(IItemStack item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.List;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
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 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 boolean matches(IItemStack item) {
|
||||
if (!item.matches(item)) return false;
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
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) {
|
||||
for (IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return IngredientAny.INTERNAL_ANY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
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 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 boolean matches(IItemStack item) {
|
||||
if (!item.matches(item)) return false;
|
||||
|
||||
for (IItemCondition condition : conditions) {
|
||||
if (!condition.matches(item)) return false;
|
||||
}
|
||||
|
||||
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) {
|
||||
for (IItemTransformer transform : transformers) {
|
||||
item = transform.transform(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return item.getInternal();
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Object implementation ###
|
||||
// #############################
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(Ingredient) " + item.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
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 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 boolean matches(IItemStack item) {
|
||||
return item.getAmount() == amount && ingredient.matches(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IIngredient ingredient) {
|
||||
return this.ingredient.contains(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack applyTransform(IItemStack item) {
|
||||
return ingredient.applyTransform(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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 stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("minetweaker.item.Transform")
|
||||
public class Transform {
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer reuse() {
|
||||
return new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return 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.
|
||||
*
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer damage() {
|
||||
return new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
int newDamage = item.getDamage() + 1;
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount() - 1).withDamage(0);
|
||||
} else {
|
||||
return item.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 damage damage to be applied
|
||||
* @return damage transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer damage(final int damage) {
|
||||
return new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
int newDamage = item.getDamage() + damage;
|
||||
if (newDamage >= item.getMaxDamage()) {
|
||||
return item.withAmount(item.getAmount() - 1).withDamage(newDamage - item.getMaxDamage());
|
||||
} else {
|
||||
return item.withDamage(newDamage);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
* @param withItem replacement item
|
||||
* @return replacement transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer replaceWith(IItemStack withItem) {
|
||||
final IItemStack result = withItem.withAmount(withItem.getAmount() + 1);
|
||||
|
||||
return new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 amount consumption amount
|
||||
* @return consuming transformer
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemTransformer consume(final int amount) {
|
||||
return new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item) {
|
||||
return item.withAmount(Math.max(item.getAmount() - amount, 0) + 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user