Loot Tables are a technical feature that were added in Update 0.16.0.
The best way to understand Loot Tables is to read the
json files from the Vanilla Behavior Pack. Especially interesting are the files in the folder
loot_tables/chests. These files, as most behavior and resource pack file are in json format, which is too much to explain here.
The overall structure of each of these files are:
pools– A table of each of the various loot groups
- Each loot group has:
rolls– To indicate how many times they pick items from the entries
entries– The weighted list of possible items to include
- Each entry has:
name– An identificator
weight– Used for randomisation
functions– One or more functions used for specifying count (other than a single item), specify data variation, or to enchant the item in question.
Some specific functions which are often seen are:
set_count– Defines the
maxamount of that particular item
set_data– Used to set which variant, using
data, of the item to include. Often used to distinguish which wood or sapling to include
enchant_with_levels– Indicates that enchantments are to be applied, and which corresponding
levelsto use for these.
To generate loot the game goes through each of the loot groups, and repeats the choosing of items the number of times specified by the
rolls parameter. To actually choose an item, it chooses a random number with a maximum of the summed
weight's, and picks the corresponding item. Finally it applies the functions of that chosen item, and adds it to the loot.
For an in-depth example see Tutorial:Loot Table Example.