Skip to main content

Loot table reference (6/7)

This page excerpts the reference from MS Learn (MicrosoftDocs/minecraft-creator a9fd1c0, CC BY 4.0). Relative links in the original are removed.

(Source: ms-learn, creator/Reference/Content/LootTableReference/Examples/LootTableDefinitions/enchantingtables.md)

Loot Tables Documentation - Enchanting Tables​

These different enchanting functions let you set unique enchanting parameters for items in your world.

Enchantment Functions​

Use these functions to apply enchantment rules to your world so they work exactly the way you want them to:

  • enchant_book_for_trading (trade table only)​

    This function enchants a book using the algorithm for enchanting items sold by villagers.

    {
    "type": "item",
    "name": "minecraft:book",
    "quantity": 1,
    "functions": [
    {
    "function": "enchant_book_for_trading",
    "base_cost": 2,
    "base_random_cost": 5,
    "per_level_random_cost": 10,
    "per_level_cost": 3
    }
    ]
    }

    The total cost of an enchantment is calculated with this equation:

    base_cost + (base_random_cost + enchantmentLevel * per_level_random_cost) + enchantmentLevel * per_level_cost

  • enchant_random_gear​

    Enchants an item using the same algorithm used while enchanting equipment vanilla mobs spawn with. Takes a chance modifier to manipulate the algorithm.

    [!Note] A chance modifier of 1.0 doesn't mean a 100% chance that gear will become enchanted. Rather, the chance is modified based on the difficulty.

    On Peaceful and Easy difficulties, the chance will always be 0% no matter what. On Hard difficulty, a chance of 1.0 will be 100%, but the chance is roughly 2/3 that on Normal difficulty.

    {
    "type": "item",
    "name": "minecraft:chainmail_boots",
    "weight": 1,
    "functions": [
    {
    "function": "enchant_random_gear",
    "chance": 0.25
    }
    ]
    }

    Increasing chance to a number higher than 1.0 can help to bypass the decrease in chance with Normal difficulty. For example, setting chance to 2.0 will always enchant the item on both Normal and Hard difficulty.

  • enchant_randomly​

    Generates a random enchantment that is compatible with the item. Supports the optional treasure boolean (true/false) to allow treasure enchantments to be toggled on and off. Treasure enchantments are enchantments that cannot be obtained through the enchanting table, including Frost Walker, Mending, Soul Speed, Curse of Binding, and Curse of Vanishing.

    {
    "type": "item",
    "name": "minecraft:leather_helmet",
    "weight": 1,
    "functions": [
    {
    "function": "enchant_randomly",
    "treasure": true
    }
    ]
    }
  • enchant_with_levels​

    Applies an enchantment as if it were enchanted through an enchanting table using a minimum and maximum XP level defined through the levels parameter. The treasure boolean (true/false) will allow treasure-only enchantments to be used. Treasure enchantments are enchantments that cannot be obtained through the enchanting table, including Frost Walker, Mending, Soul Speed, Curse of Binding, and Curse of Vanishing.

    {
    "type": "item",
    "name": "minecraft:diamond_sword",
    "weight": 1,
    "functions": [
    {
    "function": "enchant_with_levels",
    "treasure": true,
    "levels": {
    "min": 20,
    "max": 39
    }
    }
    ]
    }
  • set_potion​

    This function sets the potion type of compatible items with a potion ID.

    {
    "type": "item",
    "name": "minecraft:potion",
    "weight": 1,
    "functions": [
    {
    "function": "set_potion",
    "id": "strong_regeneration"
    }
    ]
    }
  • specific_enchants​

    This function lets you set a list of specific enchantments on an item. It also lets you apply enchantments to items that wouldn't normally be enchantable in-game.

    {
    "type": "item",
    "name": "minecraft:stick",
    "weight": 1,
    "functions": [
    {
    "function": "specific_enchants",
    "enchants": [
    "knockback",
    "fire_aspect"
    ]
    }
    ]
    }

    You can also define the enchantments as objects to specifically define an enchantment level.

    {
    "type": "item",
    "name": "minecraft:stick",
    "weight": 1,
    "functions": [
    {
    "function": "specific_enchants",
    "enchants": [
    {
    "id": "knockback",
    "level": 1
    },
    {
    "id": "unbreaking",
    "level": 3
    }
    ]
    }
    ]
    }

    [!Note] Max enchantment levels are hard-coded and can't be overwritten.

(Source: ms-learn, creator/Reference/Content/LootTableReference/Examples/LootTableDefinitions/itemmodtables.md)

Loot Tables Documentation - Modifying Items​

There are loot/trade table functions you can use to set unique parameters for how tables handle items in your world.

Item Mod Functions​

The following functions let you modify loot table results in different ways, like how many of an item is returned, setting its data value, or even setting the name and lore of an item.

  • looting_enchant (loot table only)​

    This function lets you modify the count of how many items are returned when an entity is killed by an item with the looting enchantment.

    [!Note] The looting_enchant function only works with loot tables that are called by the death of an entity.

    {
    "type": "item",
    "name": "minecraft:stick",
    "weight": 1,
    "functions": [
    {
    "function": "looting_enchant",
    "count": {
    "min": 0,
    "max": 1
    }
    }
    ]
    }
  • random_aux_value​

    Similar to random_block_state, this function lets you pick a random auxiliary value for an item. The following example will result in a randomly-colored dye.

    {
    "type": "item",
    "name": "minecraft:dye",
    "weight": 1,
    "functions": [
    {
    "function": "random_aux_value",
    "values": {
    "min": 0,
    "max": 15
    }
    }
    ]
    }
  • random_block_state​

    This allows you to randomize the block state of the resulting item. This example is from the trade table for a shepherd to control what color wool they give.

    {
    "item": "minecraft:wool",
    "functions": [
    {
    "function": "random_block_state",
    "block_state": "color",
    "values": {
    "min": 0,
    "max": 15
    }
    }
    ]
    }
  • random_dye​

    This function affects the colors of the random leather items supplied by a leather worker.

    Example:

    "gives": [
    {
    "item": "minecraft:leather_helmet",
    "quantity": 1,
    "functions": [
    {
    "function": "random_dye"
    }
    ]
    }
    ]
  • set_actor_id​

    This function only works with a spawn egg and is used to set the entity ID of that spawn egg.

    {
    "type": "item",
    "name": "minecraft:stone",
    "weight": 1,
    "functions": [
    {
    "function": "set_actor_id",
    "id": "sample:cool_entity"
    }
    ]
    }

    You can also inherit the entity ID of the entity that's associated with that loot table (like making a rabbit drop a rabbit spawn egg) by omitting the id.

    {
    "type": "item",
    "name": "minecraft:spawn_egg",
    "weight": 1,
    "functions": [
    {
    "function": "set_actor_id"
    }
    ]
    }

    Be aware that if you use set_actor_id on a chest's loot table and omit the id value, it will generate the spawn egg of whatever opens the chest (the player). A player spawn egg will spawn a "player" that just stands around and throws up Molang errors (because it's trying to use the player's behavior file as well as the player's controllers).

    If you break a chest containing a loot table that uses an inherited ID from set_actor_id, it drops a default spawn egg that doesn't spawn anything.

  • set_banner_details​

    This function only works on banners and currently only supports a banner type of 1. A banner type of 1 results in a villager banner.

    {
    "type": "item",
    "name": "minecraft:banner",
    "weight": 1,
    "functions": [
    {
    "function": "set_banner_details",
    "type": 1
    }
    ]
    }
  • set_book_contents​

    This function sets the contents of a book.

    {
    "type": "item",
    "name": "minecraft:written_book",
    "functions": [
    {
    "function": "set_book_contents",
    "author": "Steve",
    "title": "Creator Woes",
    "pages": [
    "Once upon a time there were some marketplace partners that had to edit items using NBT. And it made them sad.",
    "Then the Bedrock team added the ability to customize items from JSON and everyone rejoiced!"
    ]
    }
    ]
    }

    You can also use rawtext to localize the content of the book. When using rawtext, remember to always escape (\) special characters like " and \.

    {
    "type": "item",
    "name": "minecraft:written_book",
    "functions": [
    {
    "function": "set_book_contents",
    "author": "Steve",
    "title": "Creator Woes",
    "pages": [
    "{\"rawtext\":[ {\"translate\":\"custom.book.page.1\"}]}",
    "{\"rawtext\":[ {\"translate\":\"custom.book.page.2\"}]}"
    ]
    }
    ]
    }

    [!Note] Be aware that you can only use rawtext on the book's contents (pages) at the timing of writing this — rawtext does not work for the author or title tags.

  • set_count​

    This function sets the quantity of items returned by setting the count value. It could either be an exact number like this example:

    {
    "type": "item",
    "name": "minecraft:stone",
    "weight": 1,
    "functions": [
    {
    "function": "set_count",
    "count": 5
    }
    ]
    }

    ... or it can be within a min/max range:

    {
    "type": "item",
    "name": "minecraft:stone",
    "weight": 1,
    "functions": [
    {
    "function": "set_count",
    "count": {
    "min": 1,
    "max": 6
    }
    }
    ]
    }
  • set_damage​

    This function sets the percentage of durability remaining for items that have durability by setting the damage value. 1.0 is 100% of durability remaining (undamaged) while 0.0 has no durability remaining.

    You can either set it to an exact durability like in the following example where we set the item to have 50% durability remaining.

    {
    "type": "item",
    "name": "minecraft:iron_leggings",
    "weight": 1,
    "functions": [
    {
    "function": "set_damage",
    "damage": 0.5
    }
    ]
    }

    You can also define a min/max range the game will use to pick a value.

    This example sets the durability to somewhere between 30% and 90% remaining.

    {
    "type": "item",
    "name": "minecraft:iron_leggings",
    "weight": 1,
    "functions": [
    {
    "function": "set_damage",
    "damage": {
    "min": 0.3,
    "max": 0.9
    }
    }
    ]
    }
  • set_data​

    This function sets the data value of a block or item to an exact ID. This is useful for things like returning a specific potion or an item of a specific color.

    The following example will result in a particular variant of suspicious stew.

    {
    "type": "item",
    "name": "minecraft:suspicious_stew",
    "weight": 1,
    "functions": [
    {
    "function": "set_data",
    "data": 3
    }
    ]
    }
  • set_data_from_color_index​

    This function inherits the data value of the resulting item from the associated entity's color index, like when a pink sheep drops pink wool when you kill or shear it. If the associated entity doesn't have a color index set (or if it's used inside a chest's loot table), it will always yield a data value of 0.

    {
    "type": "item",
    "name": "minecraft:wool",
    "weight": 1,
    "functions": [
    {
    "function": "set_data_from_color_index"
    }
    ]
    }
  • set_lore​

    This function defines the lore of an item. Each line within the lore object represents a single line of text. There's currently no support for rawtext.

    {
    "type": "item",
    "name": "minecraft:stick",
    "weight": 1,
    "functions": [
    {
    "function": "set_lore",
    "lore": [
    "Big Stick has been handed down",
    "for generations within the royal family",
    "until it went missing four score years ago..."
    ]
    }
    ]
    }
  • set_name​

    This function sets the name of an item. There's currently no support for rawtext.

    {
    "type": "item",
    "name": "minecraft:stick",
    "weight": 1,
    "functions": [
    {
    "function": "set_name",
    "name": "Big Stick"
    }
    ]
    }
Sources
idSourceLicenseCommitAccessed
ms-learnMinecraft Creator documentation (Microsoft Learn)CC BY 4.0 (documentation), MIT (code)a9fd1c02026-11-13