Skip to content

Instantly share code, notes, and snippets.

@misode
Last active January 21, 2024 13:08
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save misode/66456e57372ce62cd9b65d1052521069 to your computer and use it in GitHub Desktop.
Save misode/66456e57372ce62cd9b65d1052521069 to your computer and use it in GitHub Desktop.

New Loot Table features in 1.14

This gist covers the changes to loot tables introduced in 18w43a, the first 1.14 snapshot. Check out this more in-depth loot table guide.

Last updated: 18w49a

Table of contents


Loot table types

Loot tables need a type associated with them, used to validate the structure. Some functions and conditions can only be used in certain types. There are currently 7 loot table types: empty, entity, chest, block, fishing, advancement_reward and generic.

Random integers

There are three ways to specify an integer: constant, uniform and binomial.

constant

To specify an exact number, simply declare the parameter as an integer. The following sets the count to exactly 2.

"count": 2

uniform

  • Parameters: min (float) and max (float)
  • Random value: uniform random value between min and max (inclusive) The type parameter is optional here as uniform is the default behavior. The following is a count object used in minecraft:blocks/glowstone. The count will randomly be set to 2, 3 or 4 with an equal chance for each of them.
"count": {
  "min": 2.0,
  "max": 4.0,
  "type": "minecraft:uniform"
}

binomial

  • Parameters: n (int) and p (float)
  • Random value: binomial distribution with n and p The following is a count object used in minecraft:blocks/melon.
"count": {
  "n": 3,
  "p": 0.06666667,
  "type": "minecraft:binomial"
}

Entry types

Entries are added to pools and specify what item(s) to add to the drop. Entries can have different types. minecraft:item drops a single item, minecraft:empty drops nothing and minecraft:loot_table includes a whole other loot table for that entry. With 1.14, a few new entry types got added.

Tag entry

The minecraft:tag type takes items from an item tag file. It can do two things depending on its expand tag. If expand is true, it chooses one item from the tag, all with same weight and quality. If expand is false, it drops all the items in that tag. This entry type is used in the creeper.json entity loot table to drop a random music disc.

{
  "type": "minecraft:tag",
  "name": "minecraft:music_discs",
  "expand": true
}

Group entry

The minecraft:group type has a children array. It executes all entries if its own condition passes. This can be used to avoid writing the same condition for multiple entries. A group without any condition is the same as applying the entries directly to the parent of that group. It is currently not used in vanilla.

{
  "type": "minecraft:group",
  "children": [
    {
      // an entry
    },
    {
      // another entry
    }
  ]
}

Alternatives entry

The minecraft:alternatives type is just like a group, except it only executes the first entry that is successful. Children are checked in order from top to bottom. This can be used if you want to check multiple conditions, but only return one item for that entry. It is used a lot in vanilla block loot tables.

{
  "type": "minecraft:alternatives",
  "children": [
    {
      // first entry
    },
    {
      // if the first entry succeed, this entry will not be executed
    }
  ]
}

Sequence entry

The minecraft:sequence type is again, just like a group, but this time it executes until the first entry fails. Children are checked in order from top to bottom. This entry type is currently not used in vanilla.

{
  "type": "minecraft:sequence",
  "children": [
    {
      // first entry
    },
    {
      // if this entry fails, no later entry will be executed
    },
    {
      // third entry
    }
  ]
}

Dynamic entry

The minecraft:dynamic type gets block specific drops. Currently implemented are minecraft:contents, which is used setting the contents of a shulker box. Following is the entry from a shulker box. (The copy_nbt function has been cut out for simplicity sake and will be explained later)

{
  "type": "minecraft:item",
  "name": "minecraft:white_shulker_box",
  "functions": [
    {
      "function": "minecraft:copy_name",
      "source": "block_entity"
    },
    {
      "function": "minecraft:set_contents",
      "entries": [
        {
          "type": "minecraft:dynamic",
          "name": "minecraft:contents"
        }
      ]
    }
  ]
}

New conditions

A lot of new conditions have been added. Some of them only apply to certain loot table functions! Each code example is only the condition compound.

Alternative condition

The minecraft:alternative condition has a terms array. the condition passes when one ore more of those terms succeeds. Every term is a condition. In vanilla, this is used for leaves dropping when the tool is either shears or a silk touch tool. The condition is available for all loot table types.

{
  "condition": "minecraft:alternative",
  "terms": [
    {
      // a condition
    },
    {
      // another condition
    }
  ]
}

Inverted condition

The minecraft:inverted condition passes when the condition in term fails and the other way around. The condition is available for all loot table types.

{
  "condition": "minecraft:inverted",
  "term": {
    // a condition
  }
}

Survives explosion

The minecraft:survives_explosion condition has no parameters and simply passes if the item would survive an explosion. If there was no explosion, this condition always passes. If there was an explosion, the chance of passing depends on the distance to the explosion and the explosion radius. The condition is only available for the block loot table type. It used in most blocks in vanilla.

{
  "condition": "minecraft:survives_explosion"
}

Block state property condition

The minecraft:blockstate_property condition checks for blockstates of the block. It has a block parameter to check for the block id and it has a properties parameter, which is a map of properties and their values. The condition is only available for the block loot table type. It is currently not used in vanilla. Following is an example of how to use this condition to check for a downwards facing hopper. If you apply this to the minecraft:blocks/hopper loot table, this would make hoppers only drop when they are facing downwards.

{
  "condition": "minecraft:block_state_property",
  "block": "minecraft:hopper",
  "properties": {
    "facing": "down"
  }
}

Location check condition

The minecraft:location_check condition has a predicate parameter. It uses the same structure as the location object for advancements. This condition is available for all loot table types. In vanilla, this is used to add bamboo as possible item when fishing in a jungle biome.

{
  "condition": "minecraft:location_check",
  "predicate": {
    "biome": "minecraft:jungle"
  }
}

Weather check condtion

The minecraft:weather_check condition has two boolean parameters, raining and thundering. This condition is available for all loot table types. It is currently not used in vanilla. The following is a condition that checks if it is raining.

{
  "condition": "minecraft:weather_check",
  "raining": true
}

Match tool condition

The minecraft:match_tool condition has a predicate parameter. It uses the same structure as the item object for advancements. This condition is only available for block and fishing loot table types. The following is a condition that tests for a silk touch tool.

{
  "condition": "minecraft:match_tool",
  "predicate": {
    "enchantments": [
      {
        "enchantment": "minecraft:silk_touch",
        "levels": {
          "min": 1
        }
      }
    ]
  }
}

Entity properties condition

The minecraft:entity_properties was modified. It has a predicate tag which uses the same structure as the entity_object for advancements. If the predicate tag is empty, any entity is accepted, but an entity still has to be present. This can be used to check if blocks were broken by an entity. It also has an entity parameter. The following checks if the killer entity is a skeleton.

{
  "condition": "minecraft:entity_properties",
  "predicate": {
    "type": "#minecraft:skeletons"
  },
  "entity": "killer"
}

Damage source properties condition

The minecraft:damage_source_properties condition has a predicate parameter, which matches the source of the damage. It uses the same structure as the damage object for advancements. This condition is only available for the entity loot table type. In vanilla, this is used to make turtles drop a bowl when killed by lightning.

{
  "condition": "minecraft:damage_source_properties",
  "predicate": {
    "is_lightning": true
  }
}

Table bonus condition

The minecraft:table_bonus condition defines the chances of passing based on an enchantment level. It has two parameters, enchantment for the enchantment id and chances for a list of probabilities for each enchantment level, starting with 0 (not enchanted with the given enchantment id). This condition is only available for the block loot table type. In vanilla, this is used for leaves having a higher chance of dropping a sapling with a higher fortune enchantment.

{
  "condition": "minecraft:table_bonus",
  "enchantment": "minecraft:fortune",
  "chances": [
    0.05,
    0.0625,
    0.083333336,
    0.1
  ]
}

New functions

A lot of new functions were added. Similar to conditions, some of them are only available for certain loot table types. Each code example is only the function.

Copy name function

The minecraft:copy_name function copies the CustomName tags to the display.Name tag of the item. The source tag needs to be set to block_entity. This function is only available for the block loot table type. In vanilla, this is used to copy the name of most container blocks and some other blocks to their dropped item.

{
  "function": "minecraft:copy_name",
  "source": "block_entity"
}

Set name function

The minecraft:set_name was modified. It now allows an entity parameter. If present, the name will be resolved with that entity. It allows using selector and score components. The following sets the name of the item to the killer's name.

{
  "function": "minecraft:set_name",
  "entity": "killer"
}

Explosion decay function

The minecraft:explosion_decay function is related to the minecraft:survives_explosion condition, but instead of canceling the entry completely, it removes some items from the item stack. Each item in the stack is processed separately. This function is only available for the block loot table type.

{
  "function": "minecraft:explosion_decay"
}

Limit count function

The minecraft:limit_count function limits the count of every item stack to a range. This function is available for all loot table types. In vanilla, this is used in blocks like glowstone and melon to prevent them from dropping more items than required to craft the block.

{
  "function": "minecraft:limit_count",
  "limit": {
    "max": 9
  }
}

Set contents function

The minecraft:set_contents function sets the contents of the item to an entry. It has an entries parameter which specifies which items get put in the contents of the item. The the entry can be a dynamic type causing the contents to be copied. This function is only available for the block tool table type and only for containers. In vanilla, this is used for shulker boxes to copy the contents to the dropped item.

{
  "function": "minecraft:set_contents",
  "entries": [
    {
      "type": "minecraft:dynamic",
      "name": "minecraft:contents"
    }
  ]
}

Set lore function

The minecraft:set_lore function sets the lore of the item. It has 3 tags. lore is a list of text components, one for each line. A line of lore can also include a json list itself. selector, score and nbt tag can be used as well, using the entity tag context. This tag can be set to this, killer and direct_killer. It also has a replace tag. If true, it will replace any existing lore, from other functions like set_contents. If false, it will append to the lore list.

{
  "function": "minecraft:set_lore",
  "lore": [
    {"text":"Lore textcomponents!","color":"red"},
    [{"text":"My name is ","color":"gold"}, {"selector":"@s"}]
  ],
  "entity": "this",
  "replace": "true"
}

Fill player head function

The minecraft:fill_player_head function adds the item tags for a player_head given an entity, which is most likely set to this.

{
  "function": "minecraft:fill_player_head",
  "entity": "this"
}

Copy nbt function

The minecraft:copy_nbt function copies nbt from a source to the item. It has 2 parameters, source, where to get the nbt from, one of block_entity, this, killer, killer_player and ops, a list op copy operations. A copy operation itself has 3 parameters, source and target are nbt paths similar to nbt paths used in /data. op is the third parameter and can be replace, append (for lists) and merge (for compounds). In vanilla, this function is used for banners, player heads and shulker boxes to keep their nbt data when dropped.

{
  "function": "minecraft:copy_nbt",
  "source": "block_entity",
  "ops": [
    {
      "source": "Patterns",
      "target": "BlockEntityTag.Patterns",
      "op": "replace"
    }
  ]
}

Apply bonus function

The minecraft:apply_bonus function applies one of predefined bonus formulas. It has 3 parameters, enchantment: an enchantment id used for level calculation, formula: type of used bonus formula and parameters: values required for the formula, which depend on the formula type.

binomial_with_bonus_count

  • Parameters: extra (int) and probability (float)
  • Random value: binomial distribution with n = level + extra and p = probability

uniform_bonus_count

  • Parameters: bonusMultiplier (float)
  • Random value: uniform distribution from 0 to level * bonusMultiplier

ore_drops

  • Parameters: none
  • Random value: not known

Examples

  • This loot table will drop a player head of the player that died with the name of the killer in the lore if the player was killed by another player.
{
  "type": "minecraft:entity",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:player_head",
          "functions": [
            {
              "function": "minecraft:fill_player_head",
              "entity": "this"
            },
            {
              "function": "set_lore",
              "lore": [{"text": "Killer: "}, {"selector": "@s"}],
              "entity": "killer"
            }
          ],
          "conditions": [
            {
              "condition": "damage_source_properties",
              "predicate": {
                "source_entity": {
                  "type": "minecraft:player"
                }
              }
            }
          ]
        }
      ]
    }
  ]
}
@simon511000
Copy link

OMG thank you !!

@Oskyyr
Copy link

Oskyyr commented Jan 12, 2019

thank you

@FlamedDogo
Copy link

Sorry if this is a bit complicated, but how would I set up a loot table that makes shulker box's drop their contents, and not the box? I already know how to specify nbt values, but cant get contents to copy to the items nbt

@Synthestra
Copy link

Synthestra commented Aug 2, 2019

Sorry if this is a bit complicated, but how would I set up a loot table that makes shulker box's drop their contents, and not the box? I already know how to specify nbt values, but cant get contents to copy to the items nbt

{
	"type": "minecraft:block",
	"pools": [
		{
			"rolls": 1,
			"entries": [
				{
					"type": "minecraft:alternatives",
					"children": [
						{
							"type": "minecraft:dynamic",
							"name": "minecraft:contents",
							"conditions": [
								{
									"condition": "minecraft:match_tool",
									"predicate": {
										"nbt": "{drop_contents:true}"
									}
								}
							]
						},
						{
							"type": "minecraft:item",
							"functions": [
								{
									"function": "minecraft:copy_name",
									"source": "block_entity"
								},
								{
									"function": "minecraft:copy_nbt",
									"source": "block_entity",
									"ops": [
										{
											"source": "Lock",
											"target": "BlockEntityTag.Lock",
											"op": "replace"
										},
										{
											"source": "LootTable",
											"target": "BlockEntityTag.LootTable",
											"op": "replace"
										},
										{
											"source": "LootTableSeed",
											"target": "BlockEntityTag.LootTableSeed",
											"op": "replace"
										}
									]
								},
								{
									"function": "minecraft:set_contents",
									"entries": [
										{
											"type": "minecraft:dynamic",
											"name": "minecraft:contents"
										}
									]
								}
							],
							"name": "minecraft:shulker_box"
						}
					]
				}
			]
		}
	]
}

Then use the mine subcommand of the /loot command, specifying minecraft:air{drop_contents:true}

@OktayYeniTR
Copy link

OktayYeniTR commented Aug 26, 2019

i made this but i need to make higher chance to drop items and higher chance to drop chorus_flower(with {display:{Lore:['[{"text":"You can only plant to ","color":"white","italic":false},{"text":"soil","color":"dark_gray","italic":false}]']}} tag)
https://pastebin.com/WUthib2P
btw im trying to make dynamic trees datapack

@misode
Copy link
Author

misode commented Aug 27, 2019

@OktayYeniTR To increase the drop chance, put a higher value in weight. More info on that here

To add custom nbt to the item, you use the set_nbt function.

@SPGoding
Copy link

SPGoding commented Sep 5, 2019

Is there any plans to add the copy_state function? XD

@misode
Copy link
Author

misode commented Sep 5, 2019

@SPGoding Good call! This was initially intended for 1.14 additions, but I guess I can add the 1.15 ones too, with an additional note saying it's only available in 1.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment