SPIGOT-2304: Implement LootGenerateEvent
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
37
paper-server/nms-patches/LootTable.patch
Normal file
37
paper-server/nms-patches/LootTable.patch
Normal file
@@ -0,0 +1,37 @@
|
||||
--- 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);
|
||||
31
paper-server/nms-patches/LootTableRegistry.patch
Normal file
31
paper-server/nms-patches/LootTableRegistry.patch
Normal file
@@ -0,0 +1,31 @@
|
||||
--- a/net/minecraft/server/LootTableRegistry.java
|
||||
+++ b/net/minecraft/server/LootTableRegistry.java
|
||||
@@ -17,6 +17,7 @@
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Gson b = (new GsonBuilder()).registerTypeAdapter(LootValueBounds.class, new LootValueBounds.a()).registerTypeAdapter(LootValueBinomial.class, new LootValueBinomial.a()).registerTypeAdapter(LootValueConstant.class, new LootValueConstant.a()).registerTypeAdapter(LootIntegerLimit.class, new LootIntegerLimit.a()).registerTypeAdapter(LootSelector.class, new LootSelector.b()).registerTypeAdapter(LootTable.class, new LootTable.b()).registerTypeHierarchyAdapter(LootEntryAbstract.class, new LootEntries.a()).registerTypeHierarchyAdapter(LootItemFunction.class, new LootItemFunctions.a()).registerTypeHierarchyAdapter(LootItemCondition.class, new LootItemConditions.a()).registerTypeHierarchyAdapter(LootTableInfo.EntityTarget.class, new LootTableInfo.EntityTarget.a()).create();
|
||||
private Map<MinecraftKey, LootTable> c = ImmutableMap.of();
|
||||
+ public Map<LootTable, MinecraftKey> lootTableToKey = ImmutableMap.of(); // CraftBukkit
|
||||
private final LootPredicateManager d;
|
||||
|
||||
public LootTableRegistry(LootPredicateManager lootpredicatemanager) {
|
||||
@@ -52,7 +53,7 @@
|
||||
LootPredicateManager lootpredicatemanager = this.d;
|
||||
|
||||
this.d.getClass();
|
||||
- Function function = lootpredicatemanager::a;
|
||||
+ Function<MinecraftKey, LootItemCondition> function = lootpredicatemanager::a; // CraftBukkit - decompile error
|
||||
|
||||
immutablemap.getClass();
|
||||
LootCollector lootcollector = new LootCollector(lootcontextparameterset, function, immutablemap::get);
|
||||
@@ -64,6 +65,11 @@
|
||||
LootTableRegistry.LOGGER.warn("Found validation problem in " + s + ": " + s1);
|
||||
});
|
||||
this.c = immutablemap;
|
||||
+ // CraftBukkit start - build a reversed registry map
|
||||
+ ImmutableMap.Builder<LootTable, MinecraftKey> lootTableToKeyBuilder = ImmutableMap.builder();
|
||||
+ this.c.forEach((lootTable, key) -> lootTableToKeyBuilder.put(key, lootTable)); // PAIL rename keyToLootTable
|
||||
+ this.lootTableToKey = lootTableToKeyBuilder.build();
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
public static void a(LootCollector lootcollector, MinecraftKey minecraftkey, LootTable loottable) {
|
||||
Reference in New Issue
Block a user