Skip to content

Loot Crates ‐ 1.20.1

DaFuqs edited this page Jul 17, 2024 · 1 revision

All Loot Crates, be it chests, barrels or Shulker Crates share the same NBT tags.

Available Tags

These are set directly on the block. When using these Tags on a Loot Crate Item those have to be set under the tag "BlockEntityTag" to have an effect (analog to vanilla items). For examples see below

Tag NBT Type Effect
LootTable loot table The loot table identifier to be used to fill the crate when it's interacted with
LootTableSeed 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
TrackedPerPlayer boolean; default: false If true all logic - besides the inventory - is ran on a per player basis
LockMode 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
ReplenishMode string, see below; default: never Controls when and how often the Crate should generate new loot
ReplenishTimeTicks long; default: -1 Auxiliary data for ReplenishMode to specify the interval between new loot generation
InventoryDeletionMode 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
  • "game_time": Ingame-Ticks that have to have passed, as specified by ReplenishTimeTicks
  • "real_time": Real-Life Milliseconds that have to have passed, as specified by ReplenishTimeTicks, measured by the computer clock
  • "hourly": New loot each full new hour
  • "daily": New loot each new day (0:00)
  • "weekly": New loot each new week (Mondays)
  • "monthly": New loot the first day of the month

Lock Modes

  • "none" (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

/give @p lootcrates:rare_chest_loot_crate{BlockEntityTag:{TrackedPerPlayer:1,LockMode:"NONE",ReplenishMode:"DAILY",InventoryDeletionMode:"WHEN_REPLENISHED",LootTable:"minecraft:chests/village/village_weaponsmith"}, display: {Name: '{"text":"My Crate"}'}}

Give-Command for a simple Loot Crate with preset loot

/give @p lootcrates:blaze_chest_loot_crate{BlockEntityTag: {Items: [{Slot: 4b, id: "minecraft:iron_leggings", Count: 1b, tag: {Damage: 0}}]}}

SetBlock-Command for a Loot Crate

/setblock ~ ~ ~ lootcrates:rare_chest_loot_crate{TrackedPerPlayer:1,LockMode:"NONE",ReplenishMode:"DAILY",InventoryDeletionMode:"WHEN_REPLENISHED",LootTable:"minecraft:chests/village/village_weaponsmith"}

Loot table for a Loot Crate

{
  "type": "minecraft:entity",
  "pools": [{
    "rolls": 1,
    "entries": [{
      "type": "item",
      "name": "lootcrates:rare_chest_loot_crate",
      "functions": [{
        "function": "set_nbt",
        "tag": "{BlockEntityTag:{TrackedPerPlayer:1,LockMode:\"NONE\",ReplenishMode:\"DAILY\",InventoryDeletionMode:\"WHEN_REPLENISHED\",LootTable:\"minecraft:chests/village/village_weaponsmith\"}, display: {Name: '{\"text\":\"My Crate\"}'}}"
      }]
    }]
  }]
}