Minecraft – Custom Enchantment ID on Book That Can Be Combined In An Anvil

minecraft-commandsminecraft-java-edition

I have a command block system which checks if the user is holding a diamond pickaxe with a custom enchantment, and if so, performs some actions. I'm using a custom enchantment ID of 98 simply because unlike names, it can't be faked by a player without cheats, and because Minecraft ignores any non-standard properties rather than storing them. This part all works fine, and holding a diamond pick with enchantment 98 does what it's supposed to do.

Now, I'd like to give the player a way to actually obtain Enchantment 98. Obviously, it can't be added to the enchanting table's list (can it?), so instead, I'm making it a "treasure enchantment", obtainable in enchanted book form in loot chests. But that's become a problem. I can easily create an enchanted book with a StoredEnchantments ID of 98, but if I try to combine it with a pickaxe in an anvil, it won't let me combine it.

So how can I make an enchanted book that stores a custom enchantment ID (such as 98) but which can still be combined with tools in an anvil to apply that enchantment to it?

Best Answer

Here's an option. Make the enchanted books have an enchant that is applicable to the tool you want, but a high level that is possible to obtain in vanilla (i.e unbreaking 7), then after it's combined, check for any tool in a players hand with that enchant, and replace it with your 98.