From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Mon, 21 Jun 2021 23:21:58 -0400 Subject: [PATCH] Preserve overstacked loot Preserves overstacked items in loot tables, such as shulker box drops, to prevent the items from being deleted (as they'd overflow past the bounds of the container)-- or worse, causing chunk bans via the large amount of NBT created by unstacking the items. Fixes GH-5140 and GH-4748. diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java index d549455e893a2e65fb6f4a529cc9685420190da9..6dc4c20464783c021104f5f20e76eca48323e81f 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -901,6 +901,11 @@ public class PaperWorldConfig { allowPlayerCrammingDamage = getBoolean("allow-player-cramming-damage", allowPlayerCrammingDamage); } + public boolean splitOverstackedLoot = true; + private void splitOverstackedLoot() { + splitOverstackedLoot = getBoolean("split-overstacked-loot", splitOverstackedLoot); + } + private com.google.common.collect.Table sensorTickRates; private com.google.common.collect.Table behaviorTickRates; private void tickRates() { diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java b/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java index 276c444a0fddb6962818635d5fc7721a56b30784..4f240fc74fb9551d752855dcdf2a376ff30f536b 100644 --- a/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java +++ b/src/main/java/net/minecraft/world/level/storage/loot/LootTable.java @@ -54,9 +54,17 @@ public class LootTable { this.compositeFunction = LootItemFunctions.compose(functions); } + @Deprecated // Paper - preserve overstacked items public static Consumer createStackSplitter(Consumer lootConsumer) { + // Paper start - preserve overstacked items + return createStackSplitter(lootConsumer, null); + } + + public static Consumer createStackSplitter(Consumer lootConsumer, @org.jetbrains.annotations.Nullable net.minecraft.server.level.ServerLevel world) { + boolean skipSplitter = world != null && !world.paperConfig.splitOverstackedLoot; + // Paper end return (itemstack) -> { - if (itemstack.getCount() < itemstack.getMaxStackSize()) { + if (skipSplitter || itemstack.getCount() < itemstack.getMaxStackSize()) { // Paper - preserve overstacked items lootConsumer.accept(itemstack); } else { int i = itemstack.getCount(); @@ -93,7 +101,7 @@ public class LootTable { } public void getRandomItems(LootContext context, Consumer lootConsumer) { - this.getRandomItemsRaw(context, LootTable.createStackSplitter(lootConsumer)); + this.getRandomItemsRaw(context, LootTable.createStackSplitter(lootConsumer, context.getLevel())); // Paper - preserve overstacked items } public List getRandomItems(LootContext context) { diff --git a/src/main/java/net/minecraft/world/level/storage/loot/functions/SetContainerContents.java b/src/main/java/net/minecraft/world/level/storage/loot/functions/SetContainerContents.java index 057676201aa2d19032537832849f3857425d357a..b5c6b7280a9c6964e2ad4aa9bd4517146c98e727 100644 --- a/src/main/java/net/minecraft/world/level/storage/loot/functions/SetContainerContents.java +++ b/src/main/java/net/minecraft/world/level/storage/loot/functions/SetContainerContents.java @@ -46,7 +46,7 @@ public class SetContainerContents extends LootItemConditionalFunction { NonNullList nonNullList = NonNullList.create(); this.entries.forEach((entry) -> { entry.expand(context, (choice) -> { - choice.createItemStack(LootTable.createStackSplitter(nonNullList::add), context); + choice.createItemStack(LootTable.createStackSplitter(nonNullList::add, context.getLevel()), context); // Paper - preserve overstacked items }); }); CompoundTag compoundTag = new CompoundTag();