PaperMC/nms-patches/LootTable.patch
2020-04-30 19:15:58 +10:00

37 lines
1.4 KiB
Diff

--- a/net/minecraft/server/LootTable.java
+++ b/net/minecraft/server/LootTable.java
@@ -18,6 +18,12 @@
import org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import java.util.stream.Collectors;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.world.LootGenerateEvent;
+// CraftBukkit end
public class LootTable {
@@ -103,8 +109,21 @@
}
public void fillInventory(IInventory iinventory, LootTableInfo loottableinfo) {
+ // CraftBukkit start
+ this.fillInventory(iinventory, loottableinfo, false);
+ }
+
+ public void fillInventory(IInventory iinventory, LootTableInfo loottableinfo, boolean plugin) {
+ // CraftBukkit end
List<ItemStack> list = this.populateLoot(loottableinfo);
Random random = loottableinfo.a();
+ // CraftBukkit start
+ LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(iinventory, this, loottableinfo, list, plugin);
+ if (event.isCancelled()) {
+ return;
+ }
+ list = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList());
+ // CraftBukkit end
List<Integer> list1 = this.a(iinventory, random);
this.a(list, list1.size(), random);