mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Sometimes I hate being dyslexic, fixing illegal stack sizes in smelting.. again
This commit is contained in:
parent
afd2b50900
commit
e38bc14e86
@ -117,7 +117,7 @@ public class InventoryListener implements Listener {
|
||||
//Profile doesn't exist
|
||||
if(offlineProfile != null) {
|
||||
//Process smelting
|
||||
offlineProfile.getSmeltingManager().smeltProcessing(event, furnace);
|
||||
offlineProfile.getSmeltingManager().smeltProcessing(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ 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.ItemStack;
|
||||
@ -111,48 +110,37 @@ public class SmeltingManager extends SkillManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull Furnace furnace) {
|
||||
ItemStack sourceItemStack = furnaceSmeltEvent.getSource();
|
||||
ItemStack resultItemStack = furnaceSmeltEvent.getResult();
|
||||
public void smeltProcessing(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) {
|
||||
applyXpGain(Smelting.getResourceXp(furnaceSmeltEvent.getSource()), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP
|
||||
|
||||
applyXpGain(Smelting.getResourceXp(sourceItemStack), XPGainReason.PVE, XPGainSource.PASSIVE); //Add XP
|
||||
|
||||
|
||||
processDoubleSmelt(furnaceSmeltEvent, resultItemStack, furnace);
|
||||
processDoubleSmelt(furnaceSmeltEvent);
|
||||
}
|
||||
|
||||
private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent, @NotNull ItemStack resultItemStack, @NotNull Furnace furnace) {
|
||||
int itemLimit = resultItemStack.getMaxStackSize();
|
||||
|
||||
//Check for viewers
|
||||
if(furnace.getInventory().getViewers().size() > 0) {
|
||||
itemLimit = itemLimit - 1; //Lower max size to prevent exploit, the exploit involves an open window and a stack at 63 which is about to double smelt, instructions to replicate below
|
||||
/*
|
||||
Momshroom02/26/2021
|
||||
1) have max (or close to it) smelting.
|
||||
2) put more than half a stack of an ore in a furnace and wait for it to smelt.
|
||||
3) have your inv full except for one items worth of whatever the furnace product is. (so like a stack of 63 iron and the rest of your inv is full).
|
||||
4) shift click on the furnace output to remove only one item-- leaving 63.
|
||||
5) let one more item smelt so the furnace appears to have 64
|
||||
6) manually drag (don't shift click) the stack of product out of the furnace- it'll be 65 items
|
||||
when you drop that and pick it up with only one free space in your inv, it'll look like there's more than one left on the ground, but for me, there was only one, and the "dupe" was visual only-- idk about VK's player.
|
||||
*/
|
||||
}
|
||||
|
||||
//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
|
||||
private void processDoubleSmelt(@NotNull FurnaceSmeltEvent furnaceSmeltEvent) {
|
||||
ItemStack resultItemStack = furnaceSmeltEvent.getResult();
|
||||
/*
|
||||
doubleSmeltCondition should be equal to the max
|
||||
*/
|
||||
|
||||
//Process double smelt
|
||||
if (Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.SMELTING, resultItemStack.getType())
|
||||
&& resultItemStack.getAmount() < itemLimit
|
||||
&& canDoubleSmeltItemStack(resultItemStack) //Effectively two less than max stack size
|
||||
&& isSecondSmeltSuccessful()) {
|
||||
|
||||
ItemStack newResult = resultItemStack.clone();
|
||||
newResult.setAmount(Math.min(resultItemStack.getAmount() + 1, itemLimit)); //Don't go over max stack limits
|
||||
furnaceSmeltEvent.setResult(newResult);
|
||||
ItemStack doubleSmeltStack = resultItemStack.clone(); //TODO: Necessary?
|
||||
doubleSmeltStack.setAmount(resultItemStack.getAmount() + 1); //Add one
|
||||
furnaceSmeltEvent.setResult(doubleSmeltStack); //Set result
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canDoubleSmeltItemStack(@NotNull ItemStack itemStack) {
|
||||
int resultAmount = itemStack.getAmount(); //Amount before double smelt
|
||||
int itemLimit = itemStack.getMaxStackSize();
|
||||
int doubleSmeltCondition = itemLimit - 2; //Don't double smelt if it would cause an illegal stack size
|
||||
|
||||
return resultAmount <= doubleSmeltCondition;
|
||||
}
|
||||
|
||||
public int vanillaXPBoost(int experience) {
|
||||
return experience * getVanillaXpMultiplier();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user