Skip to content

Commit

Permalink
loot_table mechs for locations and entities (#2345)
Browse files Browse the repository at this point in the history
* loot_table mechs for locations/entities

* fixes

* example comment fix
  • Loading branch information
acikek committed Jun 24, 2022
1 parent 53da888 commit 725632b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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
// <EntityTag.loot_table_id>
// @Example
// # Sets the nearest zombie's loot table to a phantom's
// - adjust <player.location.find_entities[zombie].within[5].first> 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);
}

Expand Down
Expand Up @@ -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
// <LocationTag.has_loot_table>
// @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
Expand Down

0 comments on commit 725632b

Please sign in to comment.