From 4bd9ee0aa5698a21d5f6da9a58c0de254962f4b2 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 2 Mar 2021 15:17:55 -0800 Subject: [PATCH] Never expect bukkit API to be intuitive --- .../nossr50/listeners/InventoryListener.java | 2 +- .../skills/smelting/SmeltingManager.java | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index c3a0aa838..c110de94c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -117,7 +117,7 @@ public class InventoryListener implements Listener { //Profile doesn't exist if(offlineProfile != null) { //Process smelting - offlineProfile.getSmeltingManager().smeltProcessing(event); + offlineProfile.getSmeltingManager().smeltProcessing(event, furnace); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java index f6b52646b..ddda94ba1 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java @@ -11,8 +11,10 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.SkillActivationType; +import org.bukkit.block.Furnace; import org.bukkit.event.inventory.FurnaceBurnEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; +import org.bukkit.inventory.FurnaceInventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -110,13 +112,13 @@ public class SmeltingManager extends SkillManager { } } - public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) { applyXpGain(Smelting.getResourceXp(furnaceSmeltEvent.getSource()), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP - processDoubleSmelt(furnaceSmeltEvent); + processDoubleSmelt(furnaceSmeltEvent, furnace); } - private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) { + private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) { ItemStack resultItemStack = furnaceSmeltEvent.getResult(); /* doubleSmeltCondition should be equal to the max @@ -124,7 +126,7 @@ public class SmeltingManager extends SkillManager { //Process double smelt if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType()) - && canDoubleSmeltItemStack(resultItemStack) //Effectively two less than max stack size + && canDoubleSmeltItemStack(furnace) //Effectively two less than max stack size && isSecondSmeltSuccessful()) { ItemStack doubleSmeltStack = resultItemStack.clone(); //TODO: Necessary? @@ -133,9 +135,15 @@ public class SmeltingManager extends SkillManager { } } - private boolean canDoubleSmeltItemStack(@NotNull ItemStack itemStack) { - int resultAmount = itemStack.getAmount(); //Amount before double smelt - int itemLimit = itemStack.getMaxStackSize(); + private boolean canDoubleSmeltItemStack(@NotNull Furnace furnace) { + FurnaceInventory furnaceInventory = furnace.getInventory(); + ItemStack furnaceResult = furnaceInventory.getResult(); + + if(furnaceResult == null) + return false; + + int resultAmount = furnaceResult.getAmount(); //Amount before double smelt + int itemLimit = furnaceResult.getMaxStackSize(); int doubleSmeltCondition = itemLimit - 2; //Don't double smelt if it would cause an illegal stack size return resultAmount <= doubleSmeltCondition;