Adding Loot Tables, Spawn Rules & Crafting Recipes
Next, we'll enhance the custom Ghost entity by adding some more basic mechanics to it:
Loot Tables
First, we'll make the ghost drop Ectoplasm upon death: create the following file:
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "wiki:ectoplasm",
"weight": 1,
"functions": [
{
"function": "set_count",
"count": {
"min": 1,
"max": 3
}
}
]
}
]
}
]
}Loot tables consist of
pools. Each pool defines a different set of loot that will be dropped. A pool consists of 3 parts,rolls,entriesandconditions. Theconditionsare optional and won't be covered in this guide.The
rollssection defines how many times a random entry will be chosen from the followingentriesobject.The
entriespart defines the items from which the loot table can choose. Each roll a new item will be chosen.typedefines what will be chosen. You can set it toitemorloot_tableto either chose an item or an different loot table.namedefines the identifier of the item (with its namespace) that will be selected.weightis optional and defines how likely it is, that this item will be selected. If there is more than one item in theentriessection, theweightattribute can be used to make the probability of one item more or less likely. If it isn't set, it defaults to 1.functionsprovide a powerful way of customizing the item that will be returned. They can add enchantments to an item, set an item's name or simply setting the number of items that will be dropped. To define the number of items, we useset_count. It takes thecountattribute, which sets the maximum and minimum amount of items that will be dropped.
For more information on loot tables, see our extended guide: Loot Tables!
Spawn Rules
Next, we'll make the ghost spawn in deserts at night:
{
"format_version": "1.8.0",
"minecraft:spawn_rules": {
"description": {
"identifier": "wiki:ghost",
"population_control": "monster"
},
"conditions": [
{
"minecraft:spawns_on_surface": {},
"minecraft:brightness_filter": {
"min": 0,
"max": 7,
"adjust_for_weather": true
},
"minecraft:difficulty_filter": {
"min": "easy",
"max": "hard"
},
"minecraft:weight": {
"default": 80
},
"minecraft:herd": {
"min_size": 1,
"max_size": 3
},
"minecraft:biome_filter": {
"test": "has_biome_tag",
"operator": "==",
"value": "desert"
}
}
]
}
}- You already know what
format_versiondoes. - Inside the
minecraft:spawn_rulespart we define our spawn rules. - The
descriptiondefines the basic properties of the file.- The
identifieris used to define which entity these spawn rules apply to. population_controlis used to limit the amount of entities that will be spawned. Once the pool that is defined inside ofpopulation_controlis full, no more entities will be spawned.
- The
- With
conditionswe can define rules that limit the spawning of this entity to special cases. We will shortly describe each condition used here, but you can learn more conditions and how to use them here.spawns_on_surfaceallows the mob to only spawn on surfaces.minecraft:brightness_filterlimits the spawning to areas with a lighting level thats between the defined values. Ifadjust_for_weatheristrue, the light level decrease during rain and storms will be ignored.minecraft:difficulty_filterdefines the difficulty level needed to spawn the entity.weightdefines how often this entity will spawn. The higher this value, the more often the mob will spawn.minecraft:herddefines how many entities will be spawned at once.- With
minecraft:biome_filterwe define the biomes in which the entity is able to spawn.
To learn more about spawn rules, take a look at our list of vanilla spawn rules.
Crafting Recipes
And finally, as an introduction to recipes, we'll make the Ectoplasm craftable into Ectoplasm Blocks:
{
"format_version": "1.20.10",
"minecraft:recipe_shaped": {
"description": {
"identifier": "wiki:ectoplasm_block"
},
"tags": ["crafting_table"],
"pattern": [
// 3×3 grid of Ectoplasm items
"###",
"###",
"###"
],
"key": {
"#": {
"item": "wiki:ectoplasm"
}
},
"unlock": [
{
"item": "wiki:ectoplasm" // Unlock this recipe when the player acquires an Ectoplasm item
}
],
"result": {
"item": "wiki:ectoplasm_block"
}
}
}format_versionis already known.- With
recipe_shapedwe define, that each ingredient has a set place in the crafting grid. There are some other types that can be used, you can find more information here. - Inside
descriptionwe define theidentifierof this recipe, which is the name of the recipe. tagsis a list of crafting tags which determine the blocks (crafting table, furnace, etc) that are able to use this recipe.patterndefines the arrangement of the items inside the crafting grid. Each#represents the item that is set underkey. In this case, the whole 3x3 grid has to be filled with"wiki:ectoplasm", our own item. It is possible to define more items, just add an entry tokeyand set the key to a character, that you can use insidepattern.resultcontains anitem, which is set to the item that will be the output of this recipe.
For more information on this topic, visit our page about recipes!
What You Have Learned
What you have learned:
- How to create a loot table and define which items a mob is able to drop
- How to set the rules for a mob to spawn
- How to create new crafting recipes
Your Progress So Far
What you've done:
- Setup your pack
- Create a custom item
- Create a custom entity
- Create the entity's loot, spawn rules, and a custom recipe
Congratulations! you have finished the Guide and created your first Add-on. 🎉










