From ce87e69d531c633eaafb12e9195a08514545a4ee Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 14 Dec 2024 10:24:21 -0800 Subject: [PATCH] net.minecraft.world.level.storage.loot --- .../storage/loot/LootDataType.java.patch | 20 +++++++++ .../level/storage/loot/LootTable.java.patch | 45 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootDataType.java.patch create mode 100644 paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootTable.java.patch diff --git a/paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootDataType.java.patch b/paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootDataType.java.patch new file mode 100644 index 0000000000..87eb699603 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootDataType.java.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/level/storage/loot/LootDataType.java ++++ b/net/minecraft/world/level/storage/loot/LootDataType.java +@@ -31,9 +_,14 @@ + } + + private static LootDataType.Validator createLootTableValidator() { +- return (context, key, value) -> value.validate( +- context.setContextKeySet(value.getParamSet()).enterElement("{" + key.registry() + "/" + key.location() + "}", key) +- ); ++ // CraftBukkit start ++ return (context, key, value) -> { ++ value.validate( ++ context.setContextKeySet(value.getParamSet()).enterElement("{" + key.registry() + "/" + key.location() + "}", key) ++ ); ++ value.craftLootTable = new org.bukkit.craftbukkit.CraftLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(key.location()), value); ++ // CraftBukkit end ++ }; + } + + @FunctionalInterface diff --git a/paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootTable.java.patch b/paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootTable.java.patch new file mode 100644 index 0000000000..21a8108d1a --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/storage/loot/LootTable.java.patch @@ -0,0 +1,45 @@ +--- a/net/minecraft/world/level/storage/loot/LootTable.java ++++ b/net/minecraft/world/level/storage/loot/LootTable.java +@@ -48,6 +_,7 @@ + private final List pools; + private final List functions; + private final BiFunction compositeFunction; ++ public org.bukkit.craftbukkit.CraftLootTable craftLootTable; // CraftBukkit + + LootTable(ContextKeySet paramSet, Optional randomSequence, List pools, List functions) { + this.paramSet = paramSet; +@@ -58,9 +_,10 @@ + } + + public static Consumer createStackSplitter(ServerLevel level, Consumer output) { ++ boolean skipSplitter = level != null && !level.paperConfig().fixes.splitOverstackedLoot; // Paper - preserve overstacked items + return itemStack -> { + if (itemStack.isItemEnabled(level.enabledFeatures())) { +- if (itemStack.getCount() < itemStack.getMaxStackSize()) { ++ if (skipSplitter || itemStack.getCount() < itemStack.getMaxStackSize()) { // Paper - preserve overstacked items + output.accept(itemStack); + } else { + int count = itemStack.getCount(); +@@ -141,9 +_,22 @@ + } + + public void fill(Container container, LootParams params, long seed) { ++ // CraftBukkit start ++ this.fillInventory(container, params, seed, false); ++ } ++ ++ public void fillInventory(Container container, LootParams params, long seed, boolean plugin) { ++ // CraftBukkit end + LootContext lootContext = new LootContext.Builder(params).withOptionalRandomSeed(seed).create(this.randomSequence); + ObjectArrayList randomItems = this.getRandomItems(lootContext); + RandomSource random = lootContext.getRandom(); ++ // CraftBukkit start ++ org.bukkit.event.world.LootGenerateEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLootGenerateEvent(container, this, lootContext, randomItems, plugin); ++ if (event.isCancelled()) { ++ return; ++ } ++ randomItems = event.getLoot().stream().map(org.bukkit.craftbukkit.inventory.CraftItemStack::asNMSCopy).collect(ObjectArrayList.toList()); ++ // CraftBukkit end + List availableSlots = this.getAvailableSlots(container, random); + this.shuffleAndSplitItems(randomItems, availableSlots.size(), random); +