Skip to content

Loot Crates ‐ 1.21

DaFuqs edited this page Jul 17, 2024 · 5 revisions

All Loot Crates, be it chests, barrels or Shulker Crates share the same component: lootcrates:loot_crate_loot. For examples see below.

lootcrates:loot_crate_loot Component Properties

Key Type Effect
loot_table loot table The loot table identifier to be used to fill the crate when it's interacted with
seed long Seed for generating the loot table. 0 or omitted uses a random seed. Setting a seed means that the generated loot will always be the same
tracked_per_player boolean; default: false If true all logic - besides the inventory - is ran on a per player basis
lock_mode string, see below; default: none Controls if the Crate should be locked and if it should relock when there is new loot for the player
trapped boolean; default: false When true, the Crate will output a Redstone signal when opened, similar to a Trapped Chest
replenish_time_scale string, see below; default: never Controls when and how often the Crate should generate new loot
replenish_time long; default: -1 Auxiliary data for ReplenishMode to specify the interval between new loot generation
inventory_deletion_mode string, see below; default: never Controls when the Crate should delete its inventory (to counter people cluttering the inventory with loot they do not want to take with them - preventing new loot to be generated for new players)
Items it's complicated Analog vanilla shulker chests. Defines the items stored in the crate. Can be used to define items that are always present in a crate at first opening.

Warning

Handle some combinations with care. Or do you really want players to have portable containers that generate new loot every minute?

Replenish Modes

  • "never" (default): The Crate will never generate new loot after the first time
  • "ticks": Ingame ticks that have to have passed, as specified by replenish_time
  • "seconds": Real-life milliseconds that have to have passed, as specified by replenish_time, measured by the computer clock
  • "hours": New loot each full new hour
  • "days": New loot each new day (0:00)
  • "weeks": New loot each new week (Mondays)
  • "months": New loot the first day of the month

Lock Modes

  • "lot_locked" (default): Crate is not locked
  • "require_key": Unlocking the Crate requires a matching Key. The key will not be consumed
  • "require_key_relock": Unlocking the Crate requires a matching Key. The key will not be consumed. Every time the Crate generates new loot it will require a key again
  • "consume_key": Unlocking the Crate requires a matching Key. The key will be consumed
  • "consume_key_relock": Unlocking the Crate requires a matching Key. The key will be consumed. Every time the Crate generates new loot it will require a key again

Inventory Deletion Modes

  • "never" (default): The inventory will never be deleted automatically
  • "on_open": The inventory will always be cleared when the inventory is opened
  • "when_replenished": The inventory will always be cleared when new loot is able to be generated

Examples

Following examples use a Rare Chest Loot Crate named "Bastion Treasure Crate" containing the vanilla bastion_treasure loot table, that is locked and will be restocked every 60 ticks (3 seconds).

You can find more examples, like a documented worldgen replacement config file and demo datapack under ./example_datapacks/

Give-Command for a Loot Crate

The example is a loot crate that replenishes every 20 ticks (1 second)

/give @p lootcrates:common_loot_barrel[lootcrates:loot_crate_loot={loot_table:"minecraft:chests/village/village_weaponsmith",replenish_time_scale:"ticks",replenish_time:20,inventory_deletion_mode:"never"}]

SetBlock-Command for a Loot Crate

/setblock ~ ~ ~ lootcrates:common_chest_loot_crate{components: {"lootcrates:loot_crate_loot": {replenish_time_scale: "ticks", replenish_time: 10L, loot_table: "minecraft:chests/village/village_weaponsmith"}, "lootcrates:loot_crate_player_data": {player_data: [{uuid: "00000000000000000000000000000000", replenish_time: 14091L, unlock_time: -1L}]}}}

Loot table for a Loot Crate

{
  "type": "minecraft:entity",
  "pools": [{
    "rolls": 1,
    "entries": [{
      "type": "item",
      "name": "lootcrates:rare_chest_loot_crate",
      "functions": [
        {
          "function": "minecraft:set_components",
          "components": {
            "lootcrates:loot_crate_loot": [
              {
                "loot_table": "minecraft:chests/village/village_weaponsmith",
                "replenish_time_scale": "ticks",
                "replenish_time":20
              }
            ]
          }
        }
      ]
    }]
  }]
}