Skip to main content
Version: 1.20.x

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 ResourceLocation which points to data/<namespace>/loot_tables/<path>.json. The LootTable associated with the reference can be obtained using LootTables#get, where LootTables can be obtained via MinecraftServer#getLootTables.

A loot table is always generated within a given context. The LootContext defines the level the table is generated in, a specific randomizer and seed if desired, luck for better generation, the LootContextParams which define scenario context, and any dynamic information that should occur on activation. A loot context can be created using the constructor for LootContext$Builder and built using LootContext$Builder#create.

The created LootContext adheres to some LootContextParamSet. The param set defines which LootContextParams are required or optional in context for generation. A loot table generated within a given param set must only use contexts that are defined.

A LootTable can be used to generate ItemStacks using one of the available methods:

MethodDescription
getRandomItemsRawConsumes the items generated by the loot table.
getRandomItemsReturns the items generated by the loot table.
fillFills a container with the generated loot table.
note

Loot tables were built for generating items, so the methods expect some handling for the ItemStacks.

Additional Features

Forge provides some additional behavior to loot tables for greater control of the system.

LootTableLoadEvent

LootTableLoadEvent is an event fired on the Forge event bus which is fired whenever a loot table is loaded. If the event is canceled, then an empty loot table will be loaded instead.

info

Do not modify a loot table's drops through this event. Those modifications should be done using global loot modifiers.

Loot Pool Names

Loot pools can be named using the name key. Any non-named loot pool will be the hash code of the pool prefixed by custom#.

// For some loot pool
{
"name": "example_pool", // Pool will be named 'example_pool'
"rolls": {
// ...
},
"entries": {
// ...
}
}

Looting Modifiers

Loot tables are now affected by the LootingLevelEvent, on the Forge event bus, in addition to the looting enchantment.

Additional Context Parameters

Forge extends certain parameter sets to account for missing contexts which may be applicable. LootContextParamSets#CHEST now allows for a LootContextParams#KILLER_ENTITY as chest minecarts are entities which can be broken (or 'killed'). LootContextParamSets#FISHING also allows for a LootContextParams#KILLER_ENTITY since the fishing hook is also an entity which is retracted (or 'killed') when the player retrieves it.

Multiple Items on Smelting

When using the SmeltItemFunction, a smelted recipe will now return the actual number of items from the result instead of a single smelted item (e.g. if a smelting recipe returns 3 items and there are 3 drops, then the result would be 9 smelted items instead of 3).

Loot Table Id Condition

Forge adds an additional LootItemCondition which allows certain items to generate for a specific table. This is typically used within global loot modifiers.

// In some loot pool or pool entry
{
"conditions": [
{
"condition": "forge:loot_table_id",
// Will apply when the loot table is for dirt
"loot_table_id": "minecraft:blocks/dirt"
}
]
}

Can Tool Perform Action Condition

Forge adds an additional LootItemCondition which checks whether the given LootContextParams#TOOL can perform the specified ToolAction.

// In some loot pool or pool entry
{
"conditions": [
{
"condition": "forge:can_tool_perform_action",
// Will apply when the tool can strip a log like an axe
"action": "axe_strip"
}
]
}