Enchant System

Enchant System 1.1.0

Initially brought to my attention by Chaps79 on Discord a number of various bugs have been fixed:
* If you try to craft an item on the anvil but you don't have enough experience to do it, then the craft won't trigger.
* Items that aren't considered traditionally enchantable items will now default to an XP cost of 1, so that you don't get to enchant those for free.
* If you enchant a stack of items, then you a receive a stack of enchanted items. I thought about making it so that each item enchanted takes it's own enchanting book, but that seems unwieldy, and generally the items that stack aren't traditional tools and armor, so I figure it's fine. As always, feel free to change this behavior if it's unsuitable for you.
* At some point, formatting for enchantment names was broken, and started defaulting back to purple. This has been fixed, and you'll now get your regular gray enchantment lore lines again.
* Whenever you mixed vanilla and non vanilla enchants within any of the systems, things broke. From initial testing, this seems to have been fixed. So if you have an enchantment book with Protection 4 and "My Custom Helmet Enchant 5", then it should no longer be dropping Protection 4. This also goes the same for the enchantment table.
* Lore that already exists on the item should carry over to the newly enchanted item, although positioning on it might be a bit wonky. Ultimately the enchantment lore/regular lore needs to be tracked separately to avoid this issue, which will be a bit of a rewrite, but at least it's on there for now.
* Vanilla enchantments will now fire the relevant customevents, not just Denizen enchantments.
* When you cancel a customevent, it doesn't cancel the entire item from being enchanted, just that one enchantment. So if you decide to selectively cancel Protection enchantments, then someone using an anvil and enchanting book with Protection and Thorns will still get the Thorns on the item.

If you're using this and find any bugs, feel free to reach out to me on Discord!
When reading what an item can enchant using the can_enchant tag, Minecraft takes the category of the enchantment into consideration. In 85% of cases, that's fine, but there is no wildcard category, nor are there any categories for non tool/armor items. So if you wanted to put an enchantment onto a stick, it simply would not work, as the category would exclude the stick, and the tag would always read as false, regardless of what you put in the can_enchant key. This change now circumvents that entirely, so that the category is no longer taken into account when enchanting an item; only the can_enchant key is considered. This may mean that you will need to rewrite some enchantments, as they will suddenly be able to be applied to everything, but on the upside, this means your enchantments will now be able to be applied all items, not just tools and armor. This only applies to anvil enchantments, the enchanting table still uses categories

The second part of this update now has curses show up as expected in lore. This means an enchantment called "Roughness", if it had the is_curse key set to true, would be read as "Curse of Roughness", in red, instead of in grey.
  • Like
Reactions: Chaps79