Parcourir la source

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

t00thpick1 il y a 10 ans
Parent
commit
4aeda6e9e8

+ 13 - 5
src/main/java/com/gmail/nossr50/skills/alchemy/AlchemyPotionBrewer.java

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