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.
This commit is contained in:
lexikiq 2021-06-21 23:21:58 -04:00
parent 37fa505050
commit 5c4d5afef1

View File

@ -22,7 +22,19 @@
LootTable(ContextKeySet type, Optional<ResourceLocation> randomSequenceId, List<LootPool> pools, List<LootItemFunction> functions) {
this.paramSet = type;
@@ -157,10 +165,23 @@
@@ -64,9 +72,10 @@
}
public static Consumer<ItemStack> createStackSplitter(ServerLevel world, Consumer<ItemStack> consumer) {
+ boolean skipSplitter = world != null && !world.paperConfig().fixes.splitOverstackedLoot; // Paper - preserve overstacked items
return (itemstack) -> {
if (itemstack.isItemEnabled(world.enabledFeatures())) {
- if (itemstack.getCount() < itemstack.getMaxStackSize()) {
+ if (skipSplitter || itemstack.getCount() < itemstack.getMaxStackSize()) { // Paper - preserve overstacked items
consumer.accept(itemstack);
} else {
int i = itemstack.getCount();
@@ -157,10 +166,23 @@
}
public void fill(Container inventory, LootParams parameters, long seed) {
@ -48,7 +60,7 @@
this.shuffleAndSplitItems(objectarraylist, list.size(), randomsource);
ObjectListIterator objectlistiterator = objectarraylist.iterator();
@@ -174,9 +195,9 @@
@@ -174,9 +196,9 @@
}
if (itemstack.isEmpty()) {
@ -60,7 +72,7 @@
}
}
@@ -238,8 +259,8 @@
@@ -238,8 +260,8 @@
public static class Builder implements FunctionUserBuilder<LootTable.Builder> {