Enchantment Definition Registration (Section) — SkNMS
Addon: SkNMS · Category: Section · Since: 1.0.0
Syntax
register [new] [custom] enchantmentDescription
Register a new custom enchantment. There are a LOT of entries for this, so please refer to the [**Enchantment Definition**](https://minecraft.wiki/w/Enchantment_definition) page on McWiki for all the details. More examples and detailed information provided in the [**SkNMS Wiki**](https://github.com/ShaneBeee/SkNMS/wiki/Custom-Enchantments).
**NOTES**: - 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.
**DEFINITION ENTRIES**: These entries are directly related to the Enchantment Definition in Minecraft (as seen in the above mentioned wiki). I'm only going to touch on a few here, as there are so many to type out, see the above mentioned wiki for full details. - `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**: These entries are related to the Minecraft Enchantment tags that this enchantment will be added to (all default to false). - `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_discoverable` = Will add to the `#minecraft:in_enchanting_table` tag if not cursed or a treasure. - `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.
**WARNINGS**: - 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 these enchantments will register 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 arent registered yet). RAM/Memory variables are safe! That said, enjoy your new custom enchantments.
Examples
# Wither Sword Enchantment
registry registration:
register enchantment:
id: "my_pack:wither"
description: mini message from "<red>Wither"
supported_items: "minecraft:swords"
max_level: 5
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}