Custom Enchantments - ShaneBeee/SkNMS GitHub Wiki

See Enchantment Definition on McWiki for further details.

Warning

  • Enchantments are not supposed to be created at runtime. This method is super hacky and I highly HIGHLY recommend just using a datapack instead.

  • You must ensure 1 of 2 things:

    • If your spawn keeps loaded in your world, you must make sure no items are in any chests or anything in that area that contain these enchantments.
    • Or just make sure to turn off your spawn chunk radius (set the gamerule spawnChunkRadius to 0 for all worlds).
  • This is due to the fact that these enchantments are registered to Minecraft via Skript AFTER your world/spawn chunks load.

  • Do not, I repeat... DO NOT save custom enchantments to variables (Skript will panic trying to load enchantments that aren't registered yet).

    • RAM/Memory and local variables are safe!

Important

  • Custom enchantments cannot be removed at runtime (a restart is the only way to get rid of them or change them after they're registered).
  • If you make a change to your custom enchantment, you'll have to restart your server (reloading the script just won't cut it).
  • I did not add an effects entry as it's super duper convoluted, and you can handle what your enchantment does via code.

Tip

Minecraft will automatically create enchantment books in the creative menu for your custom enchantments.

See example Screenshot 2025-01-24 at 5 09 27 PM

DEFINITION ENTRIES:

This represents entires that are found in the vanilla Enchantment Definition.
There are so many entries, so I will only go over ones that require special attention.
For more detailed information, please see the above mentioned wiki.

  • id = Takes in a string to identify your new enchantment, think vanilla "minecraft:sharpness".
  • description = Takes in a text component (from SkBee) or string, this is how your enchantment will show up in lore.
  • exclusive_set = The enchantments your enchantment will not work with. Either a single string (enchantment tag) or a list of enchantments.
  • supported_items/primary_items = See wiki for explanations. Either a single string (item tag) or a list of items.
  • slots = I don't think this is needed as it would be handled by the effects in Minecraft, which we aren't using here.

TAG ENTRIES:

This represents entires that aren't found in the vanilla Enchantment Definition, but are used to add your custom enchantment to certain enchantment tags.

  • is_cursed = Will add to the #minecraft:curse tag making your item a cursed item.
    These enchantments have red colored description and cannot be removed with a grindstone.
  • is_treasure = Will add to the #minecraft:treasure tag.
  • is_tradeable = Will add to the #minecraft:treasure and #minecraft:double_trade_price tags.
  • is_on_random_loot = Will add to the #minecraft:on_random_loot tag and can be found on naturally generated equipment from loot tables.
  • is_on_mob_spawn_equipment = If not a treasure, will add to the #minecraft:on_mob_spawn_equipment tag and can be found on spawned mobs' equipment.
  • is_on_traded_equipment = If not a treasure, will add to the #minecraft:on_traded_equipment tag and can be found on equipment sold by villagers.
  • is_discoverable = Will add to the #minecraft:in_enchanting_table tag if not cursed or a treasure.
    With this tag, the enchantment will show in the enchanting table.
Ingame example Screenshot 2025-01-24 at 4 55 38 PM

EXAMPLES:

Wither Enchantment

Will apply a wither effect to mobs hit by a sword/axe enchanted with this.
The level of the enchantment will determine how long to add the effect for (3 seconds * level).

Code
registry registration:
    register enchantment:
        id: "my_pack:wither"
        description: "<light red>Wither"
        supported_items: "#minecraft:enchantable/sharp_weapon"
        primary_items: "#minecraft:enchantable/sword"
        exclusive_set: "#minecraft:exclusive_set/damage"
        max_level: 5
        weight: 10
        min_cost_base: 1
        min_cost_per_level_above_first: 11
        max_cost_base: 21
        max_cost_per_level_above_first: 11
        is_discoverable: true

on damage of mob by player:
	set {_level} to enchantment level of my_pack:wither of attacker's tool
	if {_level} > 0:
		set {_time} to "%{_level} * 3% seconds" parsed as timespan
		apply wither to victim for {_time}

Green Thumb Enchantment

Replant a broken fully grown crop block when broken with a hoe with this enchantment.

Code
registry registration:
    register enchantment:
        id: "my_pack:green_thumb"
        description: "<light green>Green Thumb"
        max_level: 1
        supported_items: "#minecraft:hoes"

on break:
	if event-block is tagged as block tag "minecraft:crops":
		set {_level} to enchantment level of my_pack:green_thumb of player's tool
		if all:
			{_level} > 0
			age of event-block = max age of event-block
		then:
			set {_data} to blockdata of event-block
			set blockdata tag "age" of {_data} to 0
			wait 5 ticks
			set event-block to {_data}

Blinder Enchantment

Will apply a blindness effect to players hit by a sword/axe enchanted with this.
The level of the enchantment will determine how long to add the effect for (5 seconds * level).

Code
registry registration:
    register enchantment:
        id: "my_pack:blinder"
        description: "<#1277A4>Blinder"
        max_level: 5
        supported_items: "#minecraft:enchantable/sharp_weapon"
        weight: 5
        min_cost_base: 25
        min_cost_per_level_above_first: 11
        max_cost_base: 40
        max_cost_per_level_above_first: 11
        is_discoverable: true

on damage of player:
	set {_level} to enchantment level of my_pack:blinder of attacker's tool
	if {_level} > 0:
		set {_time} to "%{_level} * 5% seconds" parsed as timespan
		apply blindness to victim for {_time}

Explosion Enchantment

When breaking a block with a pickaxe with this enchantment, blocks in a radius of the level will explode.

Code
registry registration:
    register enchantment:
        id: "my_pack:explosion"
        description: "Explosion"
        max_level: 3
        supported_items: "#minecraft:pickaxes"
        exclusive_set: minecraft:efficiency
        weight: 5
        min_cost_base: 25
        min_cost_per_level_above_first: 11
        max_cost_base: 40
        max_cost_per_level_above_first: 11
        is_discoverable: true

on break:
	set {_level} to enchantment level of my_pack:explosion of player's tool
	if {_level} > 0:
		set {_loc} to location of event-block
		set {_v1} to vector({_level}, {_level}, {_level})
		set {_v2} to {_v1} * -1
		loop blocks within ({_loc} ~ {_v1}) and ({_loc} ~ {_v2}):
			if all:
				loop-block is not event-block
				loop-block is not air
			then:
				break loop-block with effects using player's tool
				create fake explosion at loop-block
				damage player's tool by 1
Video Example
Screen.Recording.2025-01-24.at.5.45.55.PM.mov
⚠️ **GitHub.com Fallback** ⚠️