Started by
DarkParty
on
Topic category: Help with Minecraft modding (Java Edition)
So I am trying to make an enchantments mod, but when an enchantment is a treasure enchantment, you can apply the book to like literally anything, which I do not want to be the case. But it seems like you can only specify what items are enchantable on an enchanting table.
I realize that the question may be a little unclear XD. I am wonder how to make it so that you can only apply an enchante book of a custom enchantment to certain items.
I think that enchantments can normally only be applied to certain items in an anvil. However I'm also pretty sure that creative mode bypasses that limit. If your testing has been in creative mode, try it in survival, it might work as intended (not applying to the wrong items) in survival mode.
I could be mistaken though.
Here are some "creative" solutions I could think of from the top of my head, They may not be ideal but they'll "work":
Don't use the anvil to enchant the item
Make a procedure that when a player R-clicks with the book in off hand, it checks (with an if-statement) if the player is holding the particular book; it'll apply the enchantment to the item while removing some of the players XP
Make sure that when the player clicks the anvil it will cancel the event.
Use a temporary fake anvil, that transfers an amount of damage
Have it so that when the player R-clicks the anvil with the book, it'll replace the anvil with a block that looks similar to it (possibly with the book visually on it)
When you R-Click the fake anvil with the sword it takes some XP, enchants the sword, and places back the old anvil with some additional damage added onto it.
Its fine if you don't like these ideas but hopefully they'll help you come up with a better one.
It was the creative mode @catnip. Thx!
I'm glad I was able to help.