From 4c024e72f9dd1571ce880d42643ae50a11fa2f3f Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 17 Jan 2022 10:09:52 +1100 Subject: [PATCH] SPIGOT-6901: Add Support for Random in methods for LootTable By: Doc --- .../main/java/org/bukkit/craftbukkit/CraftLootTable.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java index b250f644cc..86868f8fd8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java @@ -41,7 +41,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { @Override public Collection populateLoot(Random random, LootContext context) { - LootTableInfo nmsContext = convertContext(context); + LootTableInfo nmsContext = convertContext(context, random); List nmsItems = handle.getRandomItems(nmsContext); Collection bukkit = new ArrayList<>(nmsItems.size()); @@ -57,7 +57,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { @Override public void fillInventory(Inventory inventory, Random random, LootContext context) { - LootTableInfo nmsContext = convertContext(context); + LootTableInfo nmsContext = convertContext(context, random); CraftInventory craftInventory = (CraftInventory) inventory; IInventory handle = craftInventory.getInventory(); @@ -70,11 +70,14 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { return key; } - private LootTableInfo convertContext(LootContext context) { + private LootTableInfo convertContext(LootContext context, Random random) { Location loc = context.getLocation(); WorldServer handle = ((CraftWorld) loc.getWorld()).getHandle(); LootTableInfo.Builder builder = new LootTableInfo.Builder(handle); + if (random != null) { + builder = builder.withRandom(random); + } setMaybe(builder, LootContextParameters.ORIGIN, new Vec3D(loc.getX(), loc.getY(), loc.getZ())); if (getHandle() != LootTable.EMPTY) { // builder.luck(context.getLuck());