Added new 'has-ingredients' condition

This commit is contained in:
Aria 2019-10-09 09:13:05 +02:00
parent 9e2a532cab
commit ef71f8d1bf
3 changed files with 44 additions and 7 deletions

View File

@ -0,0 +1,29 @@
package net.Indyuce.mmoitems.api.crafting.condition;
import net.Indyuce.mmoitems.api.player.PlayerData;
public class IngredientCondition extends Condition {
public IngredientCondition() {
super("has-ingredients");
}
@Override
public Condition load(String[] args) {
IngredientCondition condition = new IngredientCondition();
return condition;
}
@Override
public boolean isMet(PlayerData data) {
return false;
}
@Override
public String formatDisplay(String string) {
return "";
}
@Override
public void whenCrafting(PlayerData data) {
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.api.crafting.IngredientInventory;
import net.Indyuce.mmoitems.api.crafting.condition.Condition;
import net.Indyuce.mmoitems.api.crafting.condition.Condition.ConditionInfo;
import net.Indyuce.mmoitems.api.crafting.condition.IngredientCondition;
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient;
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient.IngredientInfo;
import net.Indyuce.mmoitems.api.player.PlayerData;
@ -26,13 +27,6 @@ public class RecipeInfo {
public RecipeInfo(Recipe recipe, PlayerData data, IngredientInventory inv) {
this.recipe = recipe;
for (Condition condition : recipe.getConditions()) {
ConditionInfo info = condition.newConditionInfo(data);
conditions.add(info);
if (!info.isMet())
conditionsMet = false;
}
for (Ingredient ingredient : recipe.getIngredients()) {
IngredientInfo info = ingredient.newIngredientInfo(inv);
@ -40,6 +34,18 @@ public class RecipeInfo {
if (!info.isHad())
ingredientsHad = false;
}
for (Condition condition : recipe.getConditions()) {
ConditionInfo info = condition.newConditionInfo(data);
conditions.add(info);
if (!info.isMet())
conditionsMet = false;
if (info.getCondition() instanceof IngredientCondition) {
if(ingredientsHad)
conditionsMet = true;
}
}
}
public Recipe getRecipe() {

View File

@ -18,6 +18,7 @@ import net.Indyuce.mmoitems.api.crafting.CraftingStation;
import net.Indyuce.mmoitems.api.crafting.condition.ClassCondition;
import net.Indyuce.mmoitems.api.crafting.condition.Condition;
import net.Indyuce.mmoitems.api.crafting.condition.FoodCondition;
import net.Indyuce.mmoitems.api.crafting.condition.IngredientCondition;
import net.Indyuce.mmoitems.api.crafting.condition.LevelCondition;
import net.Indyuce.mmoitems.api.crafting.condition.ManaCondition;
import net.Indyuce.mmoitems.api.crafting.condition.PermissionCondition;
@ -47,6 +48,7 @@ public class CraftingManager {
registerCondition(new StaminaCondition());
registerCondition(new FoodCondition());
registerCondition(new ClassCondition());
registerCondition(new IngredientCondition());
registerIngredient(new MMOItemIngredient());
registerIngredient(new VanillaIngredient());