Never expect bukkit API to be intuitive

This commit is contained in:
nossr50 2021-03-02 15:17:55 -08:00
parent e38bc14e86
commit 4bd9ee0aa5
2 changed files with 16 additions and 8 deletions

View File

@ -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);
}
}
}

View File

@ -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;