From 6e761857bc67503616613ad4f80156809c41f8d4 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Tue, 16 Jun 2020 03:41:49 -0400 Subject: [PATCH] Fix shift-click crafting recipe with result greater than 1, fixes #1235 --- .../blackvein/quests/listeners/ItemListener.java | 15 +++++---------- .../quests/listeners/PlayerListener.java | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/listeners/ItemListener.java b/main/src/main/java/me/blackvein/quests/listeners/ItemListener.java index 96dae30d3..d70349b59 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/ItemListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/ItemListener.java @@ -62,21 +62,16 @@ public class ItemListener implements Listener { @SuppressWarnings("deprecation") private ItemStack getCraftedItem(CraftItemEvent evt) { if (evt.isShiftClick()) { - ItemStack result = evt.getRecipe().getResult(); - int numberOfItems = result.getAmount(); - int itemsChecked = 0; + ItemStack recipeResult = evt.getRecipe().getResult(); + int resultAmt = recipeResult.getAmount(); // Bread = 1, Cookie = 8, etc. + int leastIngredient = 1; for (ItemStack item : evt.getInventory().getMatrix()) { if (item != null && !item.getType().equals(Material.AIR)) { - if (itemsChecked == 0) { - numberOfItems = item.getAmount(); - } else { - numberOfItems = Math.min(numberOfItems, item.getAmount()); - itemsChecked++; - } + leastIngredient = Math.min(leastIngredient * resultAmt, item.getAmount() * resultAmt); } } - return new ItemStack(result.getType(), numberOfItems, result.getDurability()); + return new ItemStack(recipeResult.getType(), leastIngredient, recipeResult.getDurability()); } return evt.getCurrentItem(); } diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index c0cefa1e8..a085efcfb 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -167,7 +167,7 @@ public class PlayerListener implements Listener { } catch (NoSuchMethodError err) { // Do nothing, getHand() not present pre-1.9 } - if (e == null || e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand) + if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand) if (evt.hasBlock() && ItemUtil.isJournal(evt.getPlayer().getItemInHand())) { if (evt.getClickedBlock().getType().name().contains("PORTAL") && plugin.getSettings().canAllowPranks()) {