Introduction to Loot Tables
Loot tables are a new feature in Minecraft 1.9. In vanilla they are JSON files that represent how loot is distributed and generated in the game. The loot table system is now the recommended way to handle dungeon loot, mob drops and fishing results. The intended way for mod authors to interact with the loot table system is through a new event called LootTableLoadEvent. This event is called when the loot tables are loaded into the game, which is also when a world is loaded. This event is fired for every single loot table that is loaded into the game, so please keep that in mind when writing code using this event. Through the LootTableLoadEvent mod authors can add or remove loot entries.
The event gives the mod author access to a LootTable object, this object is a representation of the json file loaded into code. A LootTable holds a list of LootPool objects. Loot pools are used to separate loot into different groups. This is mostly used to separate loot into different rarity groups. For example, the vanilla dungeon has three pools, one holds basic loot like rotten flesh, another holds uncommon loot such as bread and buckets, and a third group for rare loot such as golden apples and name tags. Each pool is given a random number of roles, with each role resulting in an item that will be added to the output. This is what allows Dungeon Chests to have a distribution of loot from various rarities. LootPool objects hold a list of LootEntry objects. Each LootEntry defines a possible outcome. There are several different types of LootEntry objects added by vanilla. The first is LootEntryEmpty, this entry is self explanatory, it is empty, and add adds no loot to the result. The second is LootEntryItem which is also self explanatory, it adds an item to the result. The third type is LootEntryTable and it is a bit more complex. The Table entry basically adds an entire LootTable as a possible entry, and if it gets selected, it will add loot from the table it represents. LootEntryTable can allow for in infinite loop to happen when generating loot, so please be cautious when using it. Mods can create their own entry types as well.
Loot tables also have something known as functions. A function is a special piece of code that is applied to an item when it is added to the loot results. Vanilla provides you with a lot of premade functions. For example, enchant_randomly which enchants the item with a random amount of enchantments.Another function is furnace_smelt which smelts the item as if it were in a furnace, this is used when mobs die from fire damage, to get cooked drops. Some of the more useful function examples are set_count and set_damage. Because a LootEntry only holds an Item and not an ItemStack you will need to use functions to set things like the amount in the stack and the meta value. Mods can create their own functions as well, which opens up an entire range of new possibilities. You can find a complete list of the vanilla functions here.
Another aspect to loot tables are conditions. Loot tables use conditions to add requirements to certain drops. A vanilla example of this is the random_chance condition which can be used to make a drop happen only X% of the time. There is also the killed_by_player condition which is used for item drops and checks to see if the mob was killed by a player, there is also an inverse flag which can be used to allow the drop if the mob was not killed by a player instead. There is also the entity_properties condition which is a bit more complex. It has an entity value which can be set to this to specify the entity that died, killer to specify the killer or killer_player to specify a killer that is also a player. There is then a sub value called properties which holds all the properties you want to check. The only known property right now is on_fire which checks if the entity specified was on fire or not. Mod authors can also write their own conditions. You can find a complete list of vanilla conditions here.
The event gives the mod author access to a LootTable object, this object is a representation of the json file loaded into code. A LootTable holds a list of LootPool objects. Loot pools are used to separate loot into different groups. This is mostly used to separate loot into different rarity groups. For example, the vanilla dungeon has three pools, one holds basic loot like rotten flesh, another holds uncommon loot such as bread and buckets, and a third group for rare loot such as golden apples and name tags. Each pool is given a random number of roles, with each role resulting in an item that will be added to the output. This is what allows Dungeon Chests to have a distribution of loot from various rarities. LootPool objects hold a list of LootEntry objects. Each LootEntry defines a possible outcome. There are several different types of LootEntry objects added by vanilla. The first is LootEntryEmpty, this entry is self explanatory, it is empty, and add adds no loot to the result. The second is LootEntryItem which is also self explanatory, it adds an item to the result. The third type is LootEntryTable and it is a bit more complex. The Table entry basically adds an entire LootTable as a possible entry, and if it gets selected, it will add loot from the table it represents. LootEntryTable can allow for in infinite loop to happen when generating loot, so please be cautious when using it. Mods can create their own entry types as well.
Loot tables also have something known as functions. A function is a special piece of code that is applied to an item when it is added to the loot results. Vanilla provides you with a lot of premade functions. For example, enchant_randomly which enchants the item with a random amount of enchantments.Another function is furnace_smelt which smelts the item as if it were in a furnace, this is used when mobs die from fire damage, to get cooked drops. Some of the more useful function examples are set_count and set_damage. Because a LootEntry only holds an Item and not an ItemStack you will need to use functions to set things like the amount in the stack and the meta value. Mods can create their own functions as well, which opens up an entire range of new possibilities. You can find a complete list of the vanilla functions here.
Another aspect to loot tables are conditions. Loot tables use conditions to add requirements to certain drops. A vanilla example of this is the random_chance condition which can be used to make a drop happen only X% of the time. There is also the killed_by_player condition which is used for item drops and checks to see if the mob was killed by a player, there is also an inverse flag which can be used to allow the drop if the mob was not killed by a player instead. There is also the entity_properties condition which is a bit more complex. It has an entity value which can be set to this to specify the entity that died, killer to specify the killer or killer_player to specify a killer that is also a player. There is then a sub value called properties which holds all the properties you want to check. The only known property right now is on_fire which checks if the entity specified was on fire or not. Mod authors can also write their own conditions. You can find a complete list of vanilla conditions here.