Tons of changes:

- Added interface to game, client and server
- Added transformations
- Made ingredient conditions more practical to use, no longer requires imports
- Started implementation of event handling
- Moved commands and logic to the common API code
- Added common interface to MineTweaker recipes
- Added string methods
- Moved the logger from static value to static getter
- Fixed crashes on dedicated servers
- Fixed bracket resolution for <id:meta> values in 1.6.4
- Fixed scripts not being sent to multiplayer clients in 1.6.4
This commit is contained in:
Stan Hebben committed 2014-07-04 22:03:03 +02:00
1 parent 7f6235f30d
commit 115593efa5
131 files changed
+3215 -1930

No files matched your search

@@ -115,6 +115,9 @@ public interface IIngredient {
@ZenMethod
public IItemStack applyTransform(IItemStack item);
@ZenGetter("hasTransformations")
public boolean hasTransformers();
/**
* Gets the internal item backing this ingredient.
*
@@ -6,7 +6,11 @@
package minetweaker.api.item;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenSetter;
/**
*
@@ -14,5 +18,12 @@ import stanhebben.zenscript.annotations.ZenClass;
*/
@ZenClass("minetweaker.item.IItemDefinition")
public interface IItemDefinition {
@ZenGetter("id")
public String getId();
@ZenGetter("name")
public String getName();
@ZenMethod
public IItemStack makeStack(@Optional int meta);
}
@@ -70,6 +70,11 @@ public class IngredientAny implements IIngredient {
return item;
}
@Override
public boolean hasTransformers() {
return false;
}
@Override
public Object getInternal() {
return INTERNAL_ANY;
@@ -89,6 +89,11 @@ public class IngredientAnyAdvanced implements IIngredient {
return item;
}
@Override
public boolean hasTransformers() {
return transformers.length > 0;
}
@Override
public Object getInternal() {
return IngredientAny.INTERNAL_ANY;
@@ -7,8 +7,7 @@
package minetweaker.api.item;
import minetweaker.api.data.IData;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenExpansion;
import stanhebben.zenscript.annotations.ZenMethod;
/**
@@ -18,104 +17,110 @@ import stanhebben.zenscript.annotations.ZenMethod;
*
* @author Stan Hebben
*/
@ZenClass("minetweaker.item.Condition")
public class Condition {
@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
*/
@ZenGetter
public static IItemCondition damaged() {
return new IItemCondition() {
@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 IItemCondition damageAtLeast(final int minDamage) {
return new IItemCondition() {
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 IItemCondition damageAtMost(final int maxDamage) {
return new IItemCondition() {
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 IItemCondition damageBetween(final int minDamage, final int maxDamage) {
return new IItemCondition() {
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 IItemCondition data(final IData data) {
return new IItemCondition() {
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 IItemCondition stack(final int amount) {
return new IItemCondition() {
public static IIngredient onlyStack(IIngredient ingredient, final int amount) {
return ingredient.only(new IItemCondition() {
@Override
public boolean matches(IItemStack stack) {
return stack.getAmount() >= amount;
}
};
});
}
}
@@ -67,7 +67,7 @@ public class IngredientItem implements IIngredient {
@Override
public boolean matches(IItemStack item) {
if (!item.matches(item)) return false;
if (!this.item.matches(item)) return false;
for (IItemCondition condition : conditions) {
if (!condition.matches(item)) return false;
@@ -95,6 +95,11 @@ public class IngredientItem implements IIngredient {
return item;
}
@Override
public boolean hasTransformers() {
return transformers.length > 0;
}
@Override
public Object getInternal() {
return item.getInternal();
@@ -75,4 +75,9 @@ public class IngredientStack implements IIngredient {
public Object getInternal() {
return null;
}
@Override
public boolean hasTransformers() {
return ingredient.hasTransformers();
}
}
@@ -6,49 +6,51 @@
package minetweaker.api.item;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenExpansion;
import stanhebben.zenscript.annotations.ZenMethod;
/**
*
* @author Stan
*/
@ZenClass("minetweaker.item.Transform")
public class Transform {
@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 IItemTransformer reuse() {
return new IItemTransformer() {
public static IIngredient reuse(IIngredient ingredient) {
return ingredient.transform(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.
*
* @param ingredient target value
* @return damage transformer
*/
@ZenMethod
public static IItemTransformer damage() {
return new IItemTransformer() {
public static IIngredient transformDamage(IIngredient ingredient) {
return ingredient.transform(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);
return item.withAmount(item.getAmount()).withDamage(0);
} else {
return item.withDamage(newDamage);
return item.withAmount(item.getAmount() + 1).withDamage(newDamage);
}
}
};
});
}
/**
@@ -57,12 +59,13 @@ public class Transform {
* 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 IItemTransformer damage(final int damage) {
return new IItemTransformer() {
public static IIngredient transformDamage(IIngredient ingredient, final int damage) {
return ingredient.transform(new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
int newDamage = item.getDamage() + damage;
@@ -72,26 +75,25 @@ public class Transform {
return item.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 IItemTransformer replaceWith(IItemStack withItem) {
final IItemStack result = withItem.withAmount(withItem.getAmount() + 1);
return new IItemTransformer() {
public static IIngredient transformReplace(IIngredient ingredient, final IItemStack withItem) {
return ingredient.transform(new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
return result;
return withItem.withAmount(withItem.getAmount() + 1);
}
};
});
}
/**
@@ -99,16 +101,17 @@ public class Transform {
* 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 IItemTransformer consume(final int amount) {
return new IItemTransformer() {
public static IIngredient transformConsume(IIngredient ingredient, final int amount) {
return ingredient.transform(new IItemTransformer() {
@Override
public IItemStack transform(IItemStack item) {
return item.withAmount(Math.max(item.getAmount() - amount, 0) + 1);
}
};
});
}
}