Still not fully on track with the original event, but as we want them to see the potions we create, we can't be fully correct. However, correcting the behavior to decrement the ingredient after the event shouldn't harm anything. Fixes #2486

This commit is contained in:
t00thpick1 2015-03-18 16:23:07 -04:00
parent 4f1f10333f
commit 4aeda6e9e8

View File

@ -56,23 +56,29 @@ public final class AlchemyPotionBrewer {
return item == null || item.getType() == Material.AIR || item.getAmount() == 0; return item == null || item.getType() == Material.AIR || item.getAmount() == 0;
} }
private static boolean removeIngredient(BrewerInventory inventory, Player player) { private static void removeIngredient(BrewerInventory inventory, Player player) {
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone(); ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
if (isEmpty(ingredient) || !isValidIngredient(player, ingredient)) { if (isEmpty(ingredient) || !isValidIngredient(player, ingredient)) {
return false; return;
} }
else if (ingredient.getAmount() <= 1) { else if (ingredient.getAmount() <= 1) {
inventory.setIngredient(null); inventory.setIngredient(null);
return true; return;
} }
else { else {
ingredient.setAmount(ingredient.getAmount() - 1); ingredient.setAmount(ingredient.getAmount() - 1);
inventory.setIngredient(ingredient); inventory.setIngredient(ingredient);
return true; return;
} }
} }
private static boolean hasIngredient(BrewerInventory inventory, Player player) {
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
return !isEmpty(ingredient) && isValidIngredient(player, ingredient);
}
public static boolean isValidIngredient(Player player, ItemStack item) { public static boolean isValidIngredient(Player player, ItemStack item) {
if (isEmpty(item)) { if (isEmpty(item)) {
return false; return false;
@ -99,7 +105,7 @@ public final class AlchemyPotionBrewer {
BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory(); BrewerInventory inventory = ((BrewingStand) brewingStand).getInventory();
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone(); ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
if (!removeIngredient(inventory, player)) { if (!hasIngredient(inventory, player)) {
return; return;
} }
@ -129,6 +135,8 @@ public final class AlchemyPotionBrewer {
return; return;
} }
removeIngredient(inventory, player);
for (AlchemyPotion input : inputList) { for (AlchemyPotion input : inputList) {
AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient)); AlchemyPotion output = PotionConfig.getInstance().getPotion(input.getChildDataValue(ingredient));