hopefully the last bunch

woops


forgot about these


potential fix for #23
This commit is contained in:
Jared committed 2016-09-20 10:24:18 +02:00
1 parent 54c9d48b2a
commit efe0f0afe0
21 files changed
+1324 -1171

No files matched your search

@@ -1,22 +1,19 @@
package minetweaker.api.item;
import java.util.List;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenOperator;
import stanhebben.zenscript.annotations.*;
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.
*
*
* 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")
@@ -24,7 +21,7 @@ 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")
@@ -32,10 +29,10 @@ public interface IIngredient {
/**
* 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")
@@ -43,10 +40,10 @@ public interface IIngredient {
/**
* 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")
@@ -54,10 +51,10 @@ public interface IIngredient {
/**
* Gets all possible liquids for this ingredient.
*
*
* If there is no liquid list (for example, it is the <*&ft; wildcard
* item) null should be returned.
*
*
* @return the liquids for this ingredient, or null
*/
@ZenGetter("liquids")
@@ -65,7 +62,7 @@ public interface IIngredient {
/**
* Returns a new ingredient with the given stack size.
*
*
* @param amount new stack size
* @return modified ingredient
*/
@@ -76,7 +73,7 @@ public interface IIngredient {
/**
* 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
*/
@@ -86,7 +83,7 @@ public interface IIngredient {
/**
* Returns a new ingredient with the given transform added to it.
*
*
* @param transformer transformer to add
* @return modified ingredient
*/
@@ -95,7 +92,7 @@ public interface IIngredient {
/**
* Returns a new ingredient with the given condition added to it.
*
*
* @param condition condition to add
* @return modified ingredient
*/
@@ -104,7 +101,7 @@ public interface IIngredient {
/**
* Returns a new ingredient marked with the given name.
*
*
* @param mark mark to apply
* @return modified ingredient
*/
@@ -114,16 +111,27 @@ public interface IIngredient {
/**
* Checks if this ingredient matches the given item. For liquids, will match
* the item if it is a valid container.
*
*
* @param item item to check
* @return true if the item matches
*/
@ZenMethod
public boolean matches(IItemStack item);
/**
/**
* Checks if this ingredient matches the given item. For liquids, will match
* the item if it is a valid container.
*
* @param item item to check
* @return true if the item matches
*/
@ZenMethod
public boolean matchesExact(IItemStack item);
/**
* Checks if this ingredient matches the given liquid.
*
*
* @param liquid
* @return
*/
@@ -133,7 +141,7 @@ public interface IIngredient {
/**
* 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
*/
@@ -142,7 +150,7 @@ public interface IIngredient {
/**
* 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
@@ -152,7 +160,7 @@ public interface IIngredient {
/**
* Checks if this ingredient has (or could have) any transformatiosns.
*
*
* @return true if there are (or could be) any transformations false
* otherwise.
*/
@@ -161,11 +169,11 @@ public interface IIngredient {
/**
* Gets the internal item backing this ingredient.
*
*
* The value is implementation-dependent and should only be handled by the
* internal code. Don't use this value - instead, use the version-specific
* helper methods.
*
*
* @return internal item
*/
public Object getInternal();
@@ -1,101 +1,108 @@
package minetweaker.api.item;
import java.util.List;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import minetweaker.util.ArrayUtil;
import java.util.List;
/**
* Represents the wildcard ingredient (<*>).
*
*
* @author Stan Hebben
*/
public class IngredientAny implements IIngredient {
public static final IngredientAny INSTANCE = new IngredientAny();
public static final IngredientAny INSTANCE = new IngredientAny();
public static Object INTERNAL_ANY = null; // platforms supporting an "any"
// item should fill it here
public static Object INTERNAL_ANY = null; // platforms supporting an "any"
// item should fill it here
private IngredientAny() {
}
private IngredientAny() {
}
@Override
public String getMark() {
return null;
}
@Override
public String getMark() {
return null;
}
@Override
public int getAmount() {
return -1;
}
@Override
public int getAmount() {
return -1;
}
@Override
public List<IItemStack> getItems() {
return null;
}
@Override
public List<IItemStack> getItems() {
return null;
}
@Override
public List<ILiquidStack> getLiquids() {
return null;
}
@Override
public List<ILiquidStack> getLiquids() {
return null;
}
@Override
public IIngredient amount(int amount) {
return new IngredientStack(this, amount);
}
@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 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 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 marked(String mark) {
return new IngredientAnyAdvanced(mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
}
@Override
public IIngredient or(IIngredient ingredient) {
return this;
}
@Override
public IIngredient or(IIngredient ingredient) {
return this;
}
@Override
public boolean matches(IItemStack item) {
return true;
}
@Override
public boolean matches(IItemStack item) {
return true;
}
@Override
public boolean matches(ILiquidStack liquid) {
return true;
}
@Override
public boolean matchesExact(IItemStack item) {
return true;
}
@Override
public boolean contains(IIngredient ingredient) {
return true;
}
@Override
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
return item;
}
@Override
public boolean matches(ILiquidStack liquid) {
return true;
}
@Override
public boolean hasTransformers() {
return false;
}
@Override
public boolean contains(IIngredient ingredient) {
return true;
}
@Override
public Object getInternal() {
return INTERNAL_ANY;
}
@Override
public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) {
return item;
}
@Override
public String toString() {
return "<*>";
}
@Override
public boolean hasTransformers() {
return false;
}
@Override
public Object getInternal() {
return INTERNAL_ANY;
}
@Override
public String toString() {
return "<*>";
}
}
@@ -1,10 +1,11 @@
package minetweaker.api.item;
import java.util.List;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import minetweaker.util.ArrayUtil;
import java.util.List;
/**
* Represents the wildcard ingredient, with conditions and/or transformers
* applied to it.
@@ -81,6 +82,20 @@ public class IngredientAnyAdvanced implements IIngredient {
return true;
}
@Override
public boolean matchesExact(IItemStack item) {
// TODO: what is the point of this?
if (!item.matchesExact(item))
return false;
for (IItemCondition condition : conditions) {
if (!condition.matches(item))
return false;
}
return true;
}
@Override
public boolean matches(ILiquidStack liquid) {
// TODO: conditions on liquids?
@@ -1,11 +1,12 @@
package minetweaker.api.item;
import java.util.Collections;
import java.util.List;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import minetweaker.util.ArrayUtil;
import java.util.Collections;
import java.util.List;
/**
* Contains an item stack with modifiers applied to it.
*
@@ -85,6 +86,19 @@ public class IngredientItem implements IIngredient {
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;
@@ -6,12 +6,13 @@
package minetweaker.api.item;
import java.util.ArrayList;
import java.util.List;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import minetweaker.util.ArrayUtil;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Stan
@@ -106,6 +107,15 @@ public class IngredientOr implements IIngredient {
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) {
@@ -71,6 +71,10 @@ public class IngredientStack implements IIngredient {
public boolean matches(IItemStack item) {
return item.getAmount() == amount && ingredient.matches(item);
}
@Override
public boolean matchesExact(IItemStack item) {
return item.getAmount() == amount && ingredient.matchesExact(item);
}
@Override
public boolean matches(ILiquidStack liquid) {
@@ -6,11 +6,12 @@
package minetweaker.api.item;
import java.util.Collections;
import java.util.List;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import java.util.Collections;
import java.util.List;
/**
*
* @author Stan
@@ -85,6 +86,12 @@ public class IngredientUnknown implements IIngredient
{
return false;
}
@Override
public boolean matchesExact(IItemStack item)
{
return false;
}
@Override
public boolean matches(ILiquidStack liquid)
@@ -6,18 +6,14 @@
package minetweaker.api.oredict;
import java.util.Collections;
import java.util.List;
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.api.item.*;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.player.IPlayer;
import minetweaker.util.ArrayUtil;
import java.util.Collections;
import java.util.List;
/**
*
* @author Stan Hebben
@@ -97,6 +93,19 @@ public class IngredientOreDict implements IIngredient {
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;
@@ -42,7 +42,7 @@ public interface IRecipeManager {
* @return number of removed recipes
*/
@ZenMethod
public int remove(IIngredient output);
public int remove(IIngredient output, @Optional boolean nbtMatch);
/**
* Adds a shaped recipe.