Loot Functions
Loot functions can be used to modify the result of a loot entry, or the multiple results of a loot pool or loot table. In both cases, a list of functions is defined, which is run in order. During datagen, loot functions can be applied to LootPoolSingletonContainer.Builder<?>s, LootPool.Builders and LootTable.Builders by calling #apply. This article will outline the available loot functions. To create your own loot functions, see Custom Loot Functions.
Loot functions cannot be applied to composite loot entries (subclasses of CompositeEntryBase and their associated builder classes). They must be added to each singleton entry manually.
All vanilla loot functions except minecraft:sequence can specify loot conditions in a conditions block. If one of these conditions fails, the function will not be applied. On the code side, this is controlled by the LootItemConditionalFunction, which all loot functions except for SequenceFunction extend.
minecraft:set_item
Sets a different item to use in the result item stack.
{
"function": "minecraft:set_item",
// The item to use.
"item": "minecraft:dirt"
}
It is currently not possible to create this function during datagen.
minecraft:set_count
Sets an item count to use in the result item stack. Uses a number provider.
{
"function": "minecraft:set_count",
// The count to use.
"count": {
"type": "minecraft:uniform",
"min": 1,
"max": 3
},
// Whether to add to the existing value instead of setting it. Optional, defaults to false.
"add": true
}
During datagen, call SetItemCountFunction#setCount with the desired number provider and optionally an add boolean to construct a builder for this function.