diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch index d39a8088d6..5683c08491 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch @@ -1,14 +1,15 @@ --- a/net/minecraft/world/level/storage/loot/LootDataManager.java +++ b/net/minecraft/world/level/storage/loot/LootDataManager.java -@@ -30,6 +30,7 @@ - public static final LootDataId EMPTY_LOOT_TABLE_KEY = new LootDataId<>(LootDataType.TABLE, LootTables.EMPTY); - private Map, ?> elements = Map.of(); - private Multimap, MinecraftKey> typeKeys = ImmutableMultimap.of(); -+ public Map lootTableToKey = ImmutableMap.of(); // CraftBukkit +@@ -21,6 +21,8 @@ + import net.minecraft.server.packs.resources.ResourceDataJson; + import net.minecraft.util.profiling.GameProfilerFiller; + import net.minecraft.world.level.storage.loot.parameters.LootContextParameterSets; ++import org.bukkit.craftbukkit.CraftLootTable; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; + import org.slf4j.Logger; - public LootDataManager() {} - -@@ -87,7 +88,7 @@ + public class LootDataManager implements IReloadListener, LootDataResolver { +@@ -87,7 +89,7 @@ @Nullable @Override public T getElement(LootDataId lootdataid) { @@ -17,15 +18,19 @@ } }); -@@ -99,16 +100,21 @@ +@@ -97,18 +99,25 @@ + lootcollector.getProblems().forEach((s, s1) -> { + LootDataManager.LOGGER.warn("Found loot table element validation problem in {}: {}", s, s1); }); ++ // CraftBukkit start ++ map1.forEach((key, lootTable) -> { ++ if (object instanceof LootTable table) { ++ table.craftLootTable = new CraftLootTable(CraftNamespacedKey.fromMinecraft(key.location()), table); ++ } ++ }); ++ // CraftBukkit end this.elements = map1; this.typeKeys = com_google_common_collect_immutablemultimap_builder.build(); -+ // CraftBukkit start - build a reversed registry map -+ ImmutableMap.Builder lootTableToKeyBuilder = ImmutableMap.builder(); -+ this.elements.forEach((key, lootTable) -> lootTableToKeyBuilder.put((Object) lootTable, key.location())); -+ this.lootTableToKey = lootTableToKeyBuilder.build(); -+ // CraftBukkit end } private static void castAndValidate(LootCollector lootcollector, LootDataId lootdataid, Object object) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch index 9c212fb69c..57ca9b550b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch @@ -5,7 +5,7 @@ import org.slf4j.Logger; +// CraftBukkit start -+import java.util.stream.Collectors; ++import org.bukkit.craftbukkit.CraftLootTable; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.world.LootGenerateEvent; @@ -14,7 +14,15 @@ public class LootTable { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -149,9 +156,22 @@ +@@ -50,6 +57,7 @@ + private final List pools; + private final List functions; + private final BiFunction compositeFunction; ++ public CraftLootTable craftLootTable; // CraftBukkit + + LootTable(LootContextParameterSet lootcontextparameterset, Optional optional, List list, List list1) { + this.paramSet = lootcontextparameterset; +@@ -149,9 +157,22 @@ } public void fill(IInventory iinventory, LootParams lootparams, long i) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 2fd27f5289..f3fedf149a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -1741,11 +1741,9 @@ public class CraftEventFactory { public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootTableInfo lootInfo, List loot, boolean plugin) { CraftWorld world = lootInfo.getLevel().getWorld(); Entity entity = lootInfo.getParamOrNull(LootContextParameters.THIS_ENTITY); - NamespacedKey key = CraftNamespacedKey.fromMinecraft(world.getHandle().getServer().getLootData().lootTableToKey.get(lootTable)); - CraftLootTable craftLootTable = new CraftLootTable(key, lootTable); List bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new)); - LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), inventory.getOwner(), craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin); + LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), inventory.getOwner(), lootTable.craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin); Bukkit.getPluginManager().callEvent(event); return event; }