Skip to content

Name Enchanted Item

Commoble edited this page Nov 19, 2020 · 4 revisions

The looot:name_enchanted_item function randomly generates a name for an enchanted itemstack and applies the name to the itemstack.

If the given itemstack has no enchantments, then no name is generated or applied.

If the given itemstack has one or two enchantments, a name is generated from the enchantments on the item, with cyan text.

Redeeming Fishing Rod of the Siren

If the given itemstack has three or more enchantments, a name is generated randomly from words defined in nameword datapacks, with purple text.

Grave King

Custom text formats are also supported:

Iron Sword of Maiming Alternative Fonts and Hexcode Colors

This loot function can be used in a standard loot table function block:

{
	"function": "looot:name_enchanted_item",  // tells the loot table loader which function this is
	"ignore_enchantments": boolean, // optional field, defaults to false
	"minor_style": {Formatting},  // optional field, sets the style of 1-2 enchantment names, or defaults to light blue text if not present
	"major_style": {Formatting},  // optional field, sets the style of 3+ enchantment names, or defaults to light purple text if not present
}

Where

An example of a full loot table json that uses this function:

{
	"type": "minecraft:block",
	"pools": 
	[
		{
			"rolls": 1,
			"entries": 
			[
				{
					"type": "minecraft:loot_table",
					"name": "loootexamplemod:subtables/weapons",
					"functions":
					[
						{
							"function": "minecraft:enchant_with_levels",
							"levels": 
							{
								"min": 1.0,
								"max": 50.0,
								"type": "minecraft:uniform"
							},
							"treasure": true
						},
						{
							"function": "looot:name_enchanted_item",
							"minor_style":
							{
								"color": "red",
								"bold": true,
								"italic": true,
								"underlined": true
							},
							"major_style":
							{
								"color": "#c7b989",
								"font": "minecraft:alt"
							}
						}
					]
				}
			]
		}
	]
}

Clone this wiki locally