Don't set smelt stacks to above item's max stack size

This commit is contained in:
nossr50 2021-02-26 15:28:50 -08:00
parent 06e38c991a
commit 82b0304091
3 changed files with 24 additions and 10 deletions

View File

@ -1,4 +1,5 @@
Version 2.1.175 Version 2.1.175
Fixed a bug where mcMMO would occasionally give a 65 item stack from a double smelt on a furnace
Version 2.1.174 Version 2.1.174
Some legacy color codes in our locale file were swapped to &-code equivalents (thanks ViaSnake) Some legacy color codes in our locale file were swapped to &-code equivalents (thanks ViaSnake)

View File

@ -116,7 +116,8 @@ public class InventoryListener implements Listener {
//Profile doesn't exist //Profile doesn't exist
if(offlineProfile != null) { if(offlineProfile != null) {
event.setResult(offlineProfile.getSmeltingManager().smeltProcessing(smelting, event.getResult())); //Process smelting
offlineProfile.getSmeltingManager().smeltProcessing(event);
} }
} }
} }

View File

@ -12,7 +12,9 @@ import com.gmail.nossr50.util.random.RandomChanceUtil;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillActivationType;
import org.bukkit.event.inventory.FurnaceBurnEvent; import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class SmeltingManager extends SkillManager { public class SmeltingManager extends SkillManager {
public SmeltingManager(McMMOPlayer mcMMOPlayer) { public SmeltingManager(McMMOPlayer mcMMOPlayer) {
@ -108,19 +110,29 @@ public class SmeltingManager extends SkillManager {
} }
} }
public ItemStack smeltProcessing(ItemStack smelting, ItemStack result) { public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) {
ItemStack sourceItemStack = furnaceSmeltEvent.getSource();
ItemStack resultItemStack = furnaceSmeltEvent.getResult();
applyXpGain(Smelting.getResourceXp(smelting), XPGainReason.PVE, XPGainSource.PASSIVE); applyXpGain(Smelting.getResourceXp(sourceItemStack), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP
int itemLimit = resultItemStack.getMaxStackSize();
if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, result.getType()) processDoubleSmelt(furnaceSmeltEvent, resultItemStack, itemLimit);
&& isSecondSmeltSuccessful() && result.getAmount() < 64) {
ItemStack newResult = result.clone();
newResult.setAmount(result.getAmount() + 1);
return newResult;
} }
return result; private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull ItemStack resultItemStack, int itemLimit) {
//TODO: Permission check work around, could store it as NBT on the furnace
//We don't do permission checks because this can be for an offline player and Bukkit has nothing to grab permissions for offline players
//Process double smelt
if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType())
&& resultItemStack.getAmount() < itemLimit
&& isSecondSmeltSuccessful()) {
ItemStack newResult = resultItemStack.clone();
newResult.setAmount(Math.min(resultItemStack.getAmount() + 1, itemLimit)); //Don't go over max stack limits
furnaceSmeltEvent.setResult(newResult);
}
} }
public int vanillaXPBoost(int experience) { public int vanillaXPBoost(int experience) {