Project icon

Loot tables

Minecraft Version(s)
1.13-1.14.2
Loot tables

a loot table is .json file which tells the game what item to drop when a mob is killed, what items to generate inside of chests in naturally generated structures, what item a block should drop when it is broken or what item you get when you fish.

loot tables can be placed inside your data pack in the following directory: your_data_pack > data > namespace > loot_tables

loot table template: https://www.dropbox.com/s/d5wzg1cg5palas2/template_loot_table.json?dl=0

the code shown below is a loot table in its simplest form
JSON:
{

    "pools": [

        {
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:diamond"
                }

            ]

        }

    ]

}
let me explain what each element does.

"pools" - a pool is a collection of all the items your loot table can drop. A pool can depend on a condition if specified.

"rolls" - a roll is the number of times a pool will drop a random item from your entries once it is activated

if you want to randomize the number of rolls for a pool, you can do it like this:

this will specify a random roll between 1 and 10

"bonus_rolls" - increases the number of rolls on a pool based on players luck points.
example:
JSON:
{
    "pools": [

        {

            "rolls": 1,
            "bonus_rolls": {

                "min": 1,
                "max": 10
            },
            "entries": [

                {
                    "type": "item",
                    "name": "minecraft:diamond"
                }
            ]

        }

    ]

}
"entries" - every pool has an entry list with one or more entries in it. An entry specifies what should be dropped. and under what conditions (if a condition is specified)

"weight" - used to determine the chance of an item being picked up in comparison to the weight of other items.

"quality" - Optionally changes the weight of the entry based on player's generic.luck attribute value

Example of an entry:
JSON:
{
    "type": "item",
    "name": "minecraft:diamond"
}
"type" - when creating a new entry, you have to specify what type of entry this is. This is what the "type" tag is for.

Available entry types are:
  • item - the entry will drop an item
  • loot_table - the entry will drop an item from another loot table
example of an entry with a loot table instead of item:
JSON:
"entries":[

    {
        "type": "loot_table"
        "name": "namespace:loot_table_name"
    }
]
  • empty - the entry won't drop anything
"name" - the "name" tag specifies what item the entry will drop

you can have multiple entries in one pool by repeating the pattern:
JSON:
{

    "pools": [

        {

            "rolls": 1,
            "entries": [

                {
                    "type": "item",
                    "name": "minecraft:diamond"
                },

                {
                    "type": "item",
                    "name": "minecraft:stick"
                }
            ]
        }

    ]

}
in the above example, out loot table will randomly drop either a diamond or a stick.

you can also have multiple pools:
JSON:
{

    "pools": [

        {

            "rolls": 1,
            "entries": [

                {
                    "type": "item",
                    "name": "minecraft:diamond"
                }
            ]
        },

        {

            "rolls": 2,
            "entries": [

                {
                    "type": "item",
                    "name": "minecraft:stick"
                }
            ]
        }

    ]

}
In the example above, I created another pool and set its roll to 2 which means the 1st pool will drop only 1 item and my second pool will drop 2 items.

Note: both pools will drop a random item from their entries at the same time.

now that you know how a basic loot table works, let's move on to other things you can do with them.

Conditions

- you can specify a condition in a pool or entry to drop items only if the criteria is met.



a condition is placed in a list called "conditions" and it looks like this:

JSON:
"conditions":[

    {
        "condition": "minecraft:<condition_here>"
    }

]
let's add a condition to our previous example:

JSON:
{

    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:diamond"

                },

                {

                    "type": "item",

                    "name": "minecraft:stick",

                    "conditions":[

                        {
                            "condition": "minecraft:killed_by_player"
                        }
                    ]
                }
            ]
        }

    ]


}
so now the stick entry has a condition and will only drop a stick if the entity with this loot table is killed by a player. The diamond has no conditions so it will drop normally.



list of all available conditions:

random_chance (range is from 0-1 where 0 is 0%, 0.5 is 50% and 1 is 100%)
random_chance_with_looting
killed_by_player
entity_properties
is_on_fire
entity_scores


the random_chance condition can be used like this:

JSON:
{

    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:diamond"

                },

                {

                    "type": "item",
                    "name": "minecraft:stick",
                    "conditions":[

                        {

                            "condition": "minecraft:random_chance",
                            "chance": 0.5

                        }

                    ]

                }

            ]

        }

    ]

}
this example will drop a diamond and it has a 50% chance to drop a stick as well



random_chance_with_looting does that same thing as random_chance but the chance increases based on the looting enchantment on the item in the killing entity's main hand. This condition also has one more additional parameter which is "looting_multiplier". The "looting_multiplier" is used to increase the chance even more by multiplying the "chance" parameter value with a given number.



when using the looting_multiplier, the chance of the item dropping is determined by this formula:

chance + (looting_level * looting_multiplier)



JSON:
{
    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:stick",
                    "conditions":[

                        {

                            "condition": "minecraft:random_chance_with_looting",
                            "chance": 0.5,
                            "looting_multiplier": 0.10

                        }

                    ]

                }

            ]

        }

    ]
}


we already went over "killed_by_player" in the previous examples, it triggers the condition is the entity which the loot table is on is killed by a player.



entity_properties is a little bit more complex but is easy to understand once you know how it works.

here is an example of this condition:

JSON:
{
    "pools": [

        {
            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:stick",
                    "conditions":[

                        {

                            "condition": "minecraft:entity_properties",
                            "entity": "this",
                            "predicate": {
                                "flags": {
                                    "is_on_fire": true

                                }

                            }

                        }

                    ]

                }

            ]

        }

    ]
}
let's go over what each parameter in this condition does.



"entity" - specifies which entity the condition is about



entity types for this condition are:

this - refers to the entity which the loot table is on
killer_player - refers to the player who killed the entity this loot table is on
killer - stores information about the final blow to the entity (cause and killer)
"predicate" - not much to say here, this is where your flags go



"flags" - the properties the specified entity must have for this condition to trigger



so for example, the code below will only drop a stick if the player killed the entity with this loot table while he/she was not on fire.

JSON:
{
    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:stick",
                    "conditions":[

                        {

                            "condition": "minecraft:entity_properties",
                            "entity": "killer_player",
                            "predicate": {
                                "flags": {
                                    "is_on_fire": false

                                }

                            }

                        }

                    ]

                }

            ]

        }



    ]



}
and last but not least, the final condition is "entity_scores" which I think is the most useful condition.

the syntax is as follows:

JSON:
{
    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:diamond"

                },

                {

                    "type": "item",
                    "name": "minecraft:stick",
                    "conditions":[

                        {

                            "condition": "minecraft:entity_scores",
                            "entity": "killer_player",
                            "scores": {

                                "myObjective": 1

                            }

                        }

                    ]

                }

            ]

        }

    ]
}
so this example will drop a stick only if the player who killed this entity has a score of 1 on "myObjetive". This is pretty useful but what if we want to test for scores between two values? well, there is a way to do that as well.



example of a score condition between two values:

JSON:
"conditions":[

                        {

                            "condition": "minecraft:entity_scores",
                            "entity": "killer_player",
                            "scores": {

                                "myObjective": 1,
                                "mySecondObjective": {

                                    "min": 1,
                                    "max": 10

                                }

                            }
            
                        }
                    ]
this condition will only trigger if the killer player has a score between 1-10 on his "mySecondObjective" objective.



you can also add multiple conditions to an entry by repeating the pattern:

JSON:
"conditions": [

    {
        "condition": "minecraft:<condision>"
    },

    {
        "condition": "minecraft:<another_condision>"
    }
]


one more thing I want to show you is hot to add a condition to an entire pool instead

of just the entry:

JSON:
{
    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:diamond"

                }

            ],

            "conditions": [

                {
                    "condition": "minecraft:killed_by_player"
                }

            ]

        }

    ]
}
simply put the conditions list in the outer score where your pool parameters are (entries, rolls...)

you can also have multiple conditions both in your pool and your entries.



That's it for conditions, next up is functions (not to be confused with .mcfunctions, these are loot_table functions)



Functions

- loot table functions are pieces of code which we can use to manipulate our items in our entries.

you can use them to change the item count, add enchantments and other data to the items.



a function looks like this:

JSON:
"functions": [

                        {
                            "function": "minecraft:<function_name>",
                            <function_paramaters>
                        }
]
list of available functions:

set_count - specifies the amount of items an entry will hold
set_data - used to set the item variation (example: player heads)
set_damage - sets the item's durability (range from 0-1 where 0 is 0%, 0.5 is 50% and 1 is 100%)
set_nbt - sets the NBT value of the item
set_attributes - applies attribute modifiers to the item
enchant_randomly - the item will receive a random enchantment from the specified enchantment list. If no list is specified, it will receive a random compatible enchantment.
enchant_with_levels - enchants the item with a random enchantment just like you would do with an enchantment table.
looting_enchant - the number of extra items to drop if the entity has the Looting enchantment on the item in their main hand.
furnace_smelt - smelts the item as if you put it in a furnace and replaces it with the output item (only if the item has a smelting recipe).
for example, if we wanted to increase the amount of items dropped by an entry, we would use the "set_count" function like this:

JSON:
{
    "pools": [

        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:diamond"

                },

                {

                    "type": "item",
                    "name": "minecraft:stick",
                    "functions": [

                        {

                            "function": "minecraft:set_count",
                            "count": 10

                        }

                    ]

                }

            ]

        }

    ]
}
this entry will now drop 10 sticks.



"set_data" - this is the one I don't see the use for as there are no more item variations. Every item variation like "wool 1,2,3..." is now split into separate items (white_wool, red_wool, blue_wool...). Anyway, the syntax goes like this:



JSON:
"functions":[

    {

        "function": "minecraft:set_data",
        "data": <number>

    }
]


next up is "set_damage" which I think you all know what it does. It sets the durability of the item to the specified amount. The range goes from 0 to 1 where 0 is 0%, 0.5 is 50% and 1 is 100%

example:
JSON:
{
    "pools": [

      
        {

            "rolls": 1,
            "entries": [

                {

                    "type": "item",
                    "name": "minecraft:diamond_sword",
                    "functions": [

                        {

                            "function": "minecraft:set_damage",
                            "damage": 0.5

                        }

                    ]

                }

            ]

        }

    ]
}
this result in a diamond sword with half of its durability.

you can also set the durability to be randomly chosen between values like this:

JSON:
"functions": [

                        {

                            "function": "minecraft:set_damage",
                            "damage": {    
                 
                                "min": 0.20
                                "max": 1

                            }

                        }
                    ]


to apply a loot table to an entity:

Code:
/summon sheep ~ ~ ~ {DeathLootTable:"namespace:loot_table_name"}
or

Code:
/data merge entity @e[...] {DeathLootTable:"namespace:loot_table_name"}
or you can overwrite the default minecraft loot tables for an entity type and use your own. To do this, place your loot table into the minecraft namespace.



For example, if I wanted to replace the zombie loot table with my own, I would rename my table to "zombie.json" and place it inside:

data pack > data > minecraft > loot_tables > entities



and if I wanted to replace the loot table for the blue sheep, then I would rename my table to "blue.json" and put it inside: data pack > data > minecraft > loot_tables > entities > sheep



you can find a list of all default loot tables you can overwrite on the wiki page


the same concept works for blocks, just replace the block's loot table with your own.
Author
MegaCrafter10
Views
189
First release
Last update
Rating
0.00 star(s) 0 ratings

More projects from MegaCrafter10

Top