From 60d2ea03ad06b8429166bbe5493b833a64324b8c Mon Sep 17 00:00:00 2001 From: Bjarne Koll <LynxPlay101@gmail.com> Date: Tue, 22 Aug 2023 11:57:44 +0200 Subject: [PATCH] Prevent overfilled bundles from duplicating items (#9633) Bundles compute the amount to remove from an item based on the formula (64 - currentWeight) / itemWeight. An overfilled bundle however, with a currentWeight of > 64 ends up with a negative removal amount for the item. This can cause duplication issues on craftbukkit inventory implementations as they do currently not gracefully handle negative removal amounts in their remove methods. --- .../server/Fix-a-bunch-of-vanilla-bugs.patch | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/patches/server/Fix-a-bunch-of-vanilla-bugs.patch b/patches/server/Fix-a-bunch-of-vanilla-bugs.patch index e539ea6983..80fa4613ed 100644 --- a/patches/server/Fix-a-bunch-of-vanilla-bugs.patch +++ b/patches/server/Fix-a-bunch-of-vanilla-bugs.patch @@ -54,6 +54,9 @@ https://bugs.mojang.com/browse/MC-264285 https://bugs.mojang.com/browse/MC-84789 Fix wild wolves not considering bones interesting +https://bugs.mojang.com/browse/MC-225381 + Fix overfilled bundles duplicating items / being filled with air + Co-authored-by: William Blake Galbreath <blake.galbreath@gmail.com> diff --git a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java @@ -316,6 +319,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (!raid.hasFirstWaveSpawned()) { player.awardStat(Stats.RAID_TRIGGER); CriteriaTriggers.BAD_OMEN.trigger(player); +diff --git a/src/main/java/net/minecraft/world/item/BundleItem.java b/src/main/java/net/minecraft/world/item/BundleItem.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/item/BundleItem.java ++++ b/src/main/java/net/minecraft/world/item/BundleItem.java +@@ -0,0 +0,0 @@ public class BundleItem extends Item { + }); + } else if (itemStack.getItem().canFitInsideContainerItems()) { + int i = (64 - getContentWeight(stack)) / getWeight(itemStack); +- int j = add(stack, slot.safeTake(itemStack.getCount(), i, player)); ++ int j = add(stack, slot.safeTake(itemStack.getCount(), Math.max(0, i), player)); // Paper - prevent item addition on overfilled bundles - safeTake will yield EMPTY for amount == 0. + if (j > 0) { + this.playInsertSound(player); + } +@@ -0,0 +0,0 @@ public class BundleItem extends Item { + int i = getContentWeight(bundle); + int j = getWeight(stack); + int k = Math.min(stack.getCount(), (64 - i) / j); +- if (k == 0) { ++ if (k <= 0) { // Paper - prevent item addition on overfilled bundles + return 0; + } else { + ListTag listTag = compoundTag.getList("Items", 10); diff --git a/src/main/java/net/minecraft/world/item/SaddleItem.java b/src/main/java/net/minecraft/world/item/SaddleItem.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/SaddleItem.java