Wiki 9Minecraft Wiki 9Minecraft

Loot Table and Trade Item Functions

Modify item counts, durability, enchantments, and lore inside Bedrock loot and trade tables.

5Sections
5Code examples
4Known errors

Item functions are JSON objects attached to entries inside loot tables and villager trade tables that modify an item stack right as the game generates it. You reach for them whenever a plain item identifier is not enough, such as when dropping a damaged sword from a mob, placing a custom-named key in a dungeon chest, or scaling drop counts with the Looting enchantment.

How item functions are applied

Every item entry inside a loot table pool or a trade tier can hold a "functions" array. When the game selects that entry, it creates a base item stack of one item with default data and then runs each function object in the array from top to bottom.

Order matters when functions interact. For example, if you set an item's stack size and then apply a smelting function, the entire stack is smelted. If two functions modify the same property, such as setting the item count twice, the second function overwrites the result of the first.

Each object in the array requires a "function" string key that names the operation, alongside whatever parameters that specific function expects. You can also attach a "conditions" array to individual functions inside a loot table so that a modification only happens when a predicate passes, such as only enchanting a bow if the mob was killed by a player.

BP/loot_tables/entities/custom_skeleton.json
{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:bow",
          "weight": 1,
          "functions": [
            {
              "function": "set_damage",
              "damage": {
                "min": 0.1,
                "max": 0.6
              }
            },
            {
              "function": "enchant_with_levels",
              "levels": {
                "min": 5,
                "max": 15
              },
              "treasure": false
            }
          ]
        }
      ]
    }
  ]
}

Stack size, data values, and durability

The most common function in any pack is "set_count", which defines how many items appear in the stack. Its "count" field accepts either a fixed integer or an object with "min" and "max" integers for a random range. For mob drops, pairing "set_count" with "looting_enchant" lets the stack grow based on the level of Looting on the killer's weapon.

For items with durability, "set_damage" controls how worn the item is when it drops. Note that Bedrock's "set_damage" counterintuitively defines the fraction of durability remaining on the item, where 1.0 is brand new and 0.0 is completely broken. Always test your min and max range in-game to confirm the durability bar lands where you expect.

The "set_data" function sets the auxiliary data value on an item. While most modern vanilla items have been split into flat identifiers (like "minecraft:red_wool" instead of wool with data 14), "set_data" is still used for potions, tipped arrows, and certain legacy blocks or items that have not yet been flattened.

FunctionWhat it doesNotes
set_countSets stack size to a fixed number or min/max range.Clamped automatically to the item's max stack size.
looting_enchantAdds bonus count per level of Looting on the killer's tool.Only triggers when an entity is killed; ignored in chests.
set_damageSets durability using a float range between 0.0 and 1.0.Only works on items with a durability component or vanilla durability.
set_dataAssigns an integer data value (aux value) to the item.Used for potion variants; does nothing on flattened items.
furnace_smeltConverts the item into its smelted result if a recipe exists.Commonly paired with an entity_properties on_fire condition.
BP/loot_tables/entities/custom_beast.json
{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:leather",
          "functions": [
            {
              "function": "set_count",
              "count": {
                "min": 1,
                "max": 3
              }
            },
            {
              "function": "looting_enchant",
              "count": {
                "min": 0,
                "max": 2
              }
            }
          ]
        }
      ]
    }
  ]
}

Applying enchantments

Bedrock provides four distinct functions for enchanting items. If you want to mimic the enchanting table, use "enchant_with_levels", which spends a number of XP levels on the item and picks valid enchantments by weight. Setting its boolean "treasure" field to true allows enchantments like Mending or Frost Walker to be chosen.

When you want a random assortment of enchantments without level calculations, "enchant_randomly" picks one random enchantment compatible with the item, while "enchant_book_for_trading" is tailored for villager trades and enchanted books.

When you need exact control over which enchantments appear and at what level, use "specific_enchants". It accepts an "enchants" array where you can pass either plain enchantment identifier strings (which apply at level 1) or objects specifying the "id" and an exact "level" integer or min/max range. Using "specific_enchants" on an "minecraft:enchanted_book" is the standard way to drop custom-curated enchanted books.

FunctionWhat it doesNotes
enchant_with_levelsEnchants the item as if at an enchanting table at a given level.Accepts a "levels" integer/range and a "treasure" boolean.
enchant_randomlyApplies one random compatible enchantment at a random valid level.Accepts an optional "treasure" boolean.
enchant_book_for_tradingGenerates trade-style enchantments, primarily for books.Used heavily in vanilla librarian trade tables.
specific_enchantsApplies an explicit list of enchantment IDs and levels.Can apply enchantments above normal survival level caps up to the hard cap.
BP/loot_tables/chests/dungeon_reward.json
{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:diamond_sword",
          "functions": [
            {
              "function": "specific_enchants",
              "enchants": [
                {
                  "id": "sharpness",
                  "level": 4
                },
                {
                  "id": "unbreaking",
                  "level": {
                    "min": 1,
                    "max": 3
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Names, lore, books, and container contents

To customize how an item reads in the player's inventory, combine "set_name" and "set_lore". The "set_name" function takes a "name" string and overrides the item's display name (rendering in italics just like an anvil rename unless reset with formatting codes). The "set_lore" function takes a "lore" array of strings, adding each entry as a separate line beneath the item's stats in the tooltip.

For "minecraft:written_book" items, the "set_book_contents" function populates the book's metadata and text. You can specify the "title", "author", and a "pages" array of strings so players find pre-written lore books in chests without needing script hooks.

Two other specialized functions populate complex items: "fill_container" takes a "loot_table" path string (such as "loot_tables/chests/simple_dungeon.json") and populates a chest or shulker box item with the results of that table when placed, while "exploration_map" converts an empty map into a locator map pointing to a structure identifier passed in its "destination" field.

BP/loot_tables/chests/crypt_key.json
{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:tripwire_hook",
          "functions": [
            {
              "function": "set_name",
              "name": "§r§6Crypt Key"
            },
            {
              "function": "set_lore",
              "lore": [
                "§7Opens the iron door in the lower chamber.",
                "§8Single use"
              ]
            }
          ]
        }
      ]
    }
  ]
}

Using item functions in trade tables

Villager and wandering trader tables under "BP/trading/" support the exact same item function syntax on both the "wants" items and the "gives" items, with one important difference: you do not need the "type": "item" key that loot tables use. Instead, a trade item object specifies an "item" string (for example, "minecraft:emerald") and an optional "functions" array.

While you can set a simple stack size in a trade using the "quantity" field directly on the item object, you still reach for the "functions" array whenever the traded item needs enchantments, custom names, lore, durability damage, or suspicious stew effects.

BP/trading/custom_smith_trades.json
{
  "tiers": [
    {
      "total_exp_required": 0,
      "groups": [
        {
          "num_to_select": 1,
          "trades": [
            {
              "max_uses": 3,
              "reward_exp": true,
              "trader_exp": 5,
              "wants": [
                {
                  "item": "minecraft:emerald",
                  "quantity": 12
                }
              ],
              "gives": [
                {
                  "item": "minecraft:iron_pickaxe",
                  "quantity": 1,
                  "functions": [
                    {
                      "function": "set_name",
                      "name": "§rMiner's Pick"
                    },
                    {
                      "function": "specific_enchants",
                      "enchants": [
                        {
                          "id": "efficiency",
                          "level": 2
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Which versions this applies to

Applies to Minecraft Bedrock 1.16.0 through 1.21+. All core item functions shown here are stable and require no experimental toggles.

When it does not work

What you seeWhyThe fix
Item drops at 1 count, unenchanted, or unnamed without a crash, and the Content Log prints an unknown function warning.You included the "minecraft:" namespace prefix on a Java-only function or misspelled the function name (for example writing "set_nbt", which does not exist in Bedrock).Use only supported Bedrock function names such as "set_count", "set_name", "set_lore", and "specific_enchants". The "minecraft:" prefix is optional on function names in Bedrock, so omitting it is safest.
specific_enchants produces an unenchanted item even though the JSON is valid.The enchantment identifier inside the "enchants" list includes the "minecraft:" prefix (which older and current Bedrock parsers often reject inside this specific function) or uses a Java Edition enchantment name like "sweeping".Write plain Bedrock enchantment identifiers without a namespace, such as "sharpness", "unbreaking", or "fire_aspect".
Enchanted books drop as regular books with a purple glint instead of usable enchanted books.The entry's item "name" was set to "minecraft:book" instead of "minecraft:enchanted_book" when using "specific_enchants". Unlike "enchant_with_levels", "specific_enchants" does not automatically convert a normal book into an enchanted book.Change the entry's item "name" to "minecraft:enchanted_book" whenever applying "specific_enchants".
fill_container produces an empty chest or shulker box when placed by the player.The "loot_table" path inside the function is missing the "loot_tables/" root folder or omits the ".json" file extension.Provide the full behaviour-pack-relative path including the extension, such as "loot_tables/chests/simple_dungeon.json".

Reference, straight from the game files

Read out of the game itself, so the ids match the version you are building for.