From f7d6ad53eeb1ad3a4372cc73fe77eac4e01a9470 Mon Sep 17 00:00:00 2001 From: konsolas Date: Wed, 8 Apr 2020 17:11:22 +1000 Subject: [PATCH] SPIGOT-5603: Use LootContext#lootingModifier in CraftLootTable --- .../bukkit/craftbukkit/CraftLootTable.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java index 90b227cce1..396a78b9da 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java @@ -9,7 +9,8 @@ import net.minecraft.server.DamageSource; import net.minecraft.server.Entity; import net.minecraft.server.EntityHuman; import net.minecraft.server.IInventory; -import net.minecraft.server.LootContextParameterSets; +import net.minecraft.server.LootContextParameter; +import net.minecraft.server.LootContextParameterSet; import net.minecraft.server.LootContextParameters; import net.minecraft.server.LootTable; import net.minecraft.server.LootTableInfo; @@ -89,10 +90,28 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { builder.set(LootContextParameters.KILLER_ENTITY, nmsKiller); // If there is a player killer, damage source should reflect that in case loot tables use that information builder.set(LootContextParameters.DAMAGE_SOURCE, DamageSource.playerAttack(nmsKiller)); + builder.set(LootContextParameters.LAST_DAMAGE_PLAYER, nmsKiller); // SPIGOT-5603 - Set minecraft:killed_by_player + } + + // SPIGOT-5603 - Use LootContext#lootingModifier + if (context.getLootingModifier() != LootContext.DEFAULT_LOOT_MODIFIER) { + builder.set(LootContextParameters.LOOTING_MOD, context.getLootingModifier()); } } - return builder.build(getHandle().getLootContextParameterSet()); + // SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build() + LootContextParameterSet.a nmsBuilder = new LootContextParameterSet.a(); // PAIL rename Builder + for (LootContextParameter param : getHandle().getLootContextParameterSet().a()) { // PAIL rename required + nmsBuilder.a(param); // PAIL rename addRequired + } + for (LootContextParameter param : getHandle().getLootContextParameterSet().b()) { // PAIL rename optional + if (!getHandle().getLootContextParameterSet().a().contains(param)) { // PAIL rename required + nmsBuilder.b(param); // PAIL rename addOptional + } + } + nmsBuilder.b(LootContextParameters.LOOTING_MOD); // PAIL rename addOptional + + return builder.build(nmsBuilder.a()); // PAIL rename build } @Override