Loot Tables
Loot tables are logic files which dictate what should happen when various actions or scenarios occur. Although the vanilla system deals purely with item generation, the system can be expanded to perform any number of defined actions.
Data-Driven Tables
Most loot tables within vanilla are data driven via JSON. This means that a mod is not necessary to create a new loot table, only a Data pack. A full list on how to create and put these loot tables within the mod's resources folder can be found on the Minecraft Wiki.
Using a Loot Table
A loot table is referenced by its ResourceKey<LootTable> which points to data/<namespace>/loot_tables/<path>.json. The LootTable associated with the reference can be obtained using ReloadableServerRegistries.Holder#getLootTable, where ReloadableServerRegistries.Holder can be obtained via MinecraftServer#reloadableRegistries.
A loot table is always generated with given parameters. The LootParams contains the level the table is generated in, luck for better generation, the LootContextParams which define scenario context, and any dynamic information that should occur on activation. The LootParams can be created using the constructor of the LootParams.Builder builder, and built via LootParams$Builder#create by passing in the LootContextParamSet.
A loot table may also have some context. The LootContext takes in the built LootParams and can set some random seeded instance. The context is created via the builder LootContext.Builder and built using LootContext$Builder#create by passing in a optional ResourceLocation representing the random instance to use.
A LootTable can be used to generate ItemStacks using one of the available methods which may take in a LootParams or a LootContext:
| Method | Description | 
|---|---|
getRandomItemsRaw | Consumes the items generated by the loot table. Do not use this method unless you don't want loot modifiers to apply. | 
getRandomItems | Returns the items generated by the loot table. | 
fill | Fills a container with the generated loot table. | 
Loot tables were built for generating items, so the methods expect some handling for the ItemStacks.