diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java index 629d022bf9..a4ba7b4415 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/EntityTag.java @@ -10,6 +10,7 @@ import com.denizenscript.denizen.scripts.containers.core.EntityScriptContainer; import com.denizenscript.denizen.scripts.containers.core.EntityScriptHelper; import com.denizenscript.denizen.utilities.BukkitImplDeprecations; +import com.denizenscript.denizen.utilities.Utilities; import com.denizenscript.denizen.utilities.VanillaTagHelper; import com.denizenscript.denizen.utilities.depends.Depends; import com.denizenscript.denizen.utilities.entity.*; @@ -4114,6 +4115,27 @@ else if (getBukkitEntity() instanceof Creeper) { } } + // <--[mechanism] + // @object EntityTag + // @name loot_table + // @input ElementTag + // @description + // Sets the loot table of a lootable entity. + // This is the namespaced path of the loot table, provided by a datapack or Minecraft's default data. + // @tags + // + // @Example + // # Sets the nearest zombie's loot table to a phantom's + // - adjust loot_table:entities/phantom + // --> + if (mechanism.matches("loot_table_id")) { + if (!(getBukkitEntity() instanceof Lootable)) { + mechanism.echoError("'loot_table_id' is only valid for lootable entities."); + return; + } + ((Lootable) getBukkitEntity()).setLootTable(Bukkit.getLootTable(Utilities.parseNamespacedKey(mechanism.getValue().asString()))); + } + CoreUtilities.autoPropertyMechanism(this, mechanism); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java index 5936901e00..3ac0a421c7 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java @@ -5047,6 +5047,30 @@ else if (state instanceof Dropper) { } } + // <--[mechanism] + // @object LocationTag + // @name loot_table + // @input ElementTag + // @description + // Sets the loot table of a lootable container at this location. + // This is the namespaced path of the loot table, provided by a datapack or Minecraft's default data. + // @tags + // + // @Example + // # Sets the chest's loot table to a bonus chest + // - adjust <[location]> loot_table:chests/ancient_city + // --> + if (mechanism.matches("loot_table_id")) { + BlockState state = getBlockState(); + if (state instanceof Lootable) { + ((Lootable) state).setLootTable(Bukkit.getLootTable(Utilities.parseNamespacedKey(mechanism.getValue().asString()))); + state.update(); + } + else { + mechanism.echoError("'loot_table_id' mechanism can only be called on a lootable block (like a chest)."); + } + } + // <--[mechanism] // @object LocationTag // @name jukebox_record