3

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?

  • I've never looked into something like this myself, but are there tags for the book or enchantment that say what the enchantment can be applied to? – MBraedley Oct 20 '15 at 11:01
  • @MBraedley That was my first guess too, but such tag doesn't exist. Only the enchantment id and level are stored. I suppose the valid combinations are hardcoded. – Lars Oct 20 '15 at 11:22
  • @MBraedley Sadly, I couldn't find any tag like that. I assume they're all hardcoded, which is annoying, but I was hoping there was some way around it, or some way to fake it convincingly... – IceMetalPunk Oct 20 '15 at 11:48
  • I think you can now make enchanted books in enchanting tables, so you might be able to do something like /give @p book 1 0 {ench:[{id:98,lvl:1}]} (untested) – Riker Jun 24 '16 at 2:29
1

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.

0

I know of two ways to achieve this. Both make use of a Command Block.

The easiest way: You can give the enchanted pickaxe to the players

/give @p diamond_pickaxe 1 0 {ench:[{id:98,lvl:1}]}

or if they have (hold!) a normal pickaxe you can enchant it directly

/enchant @p 98 1

The 2nd way would require a separate /testfor command, though. Otherwise you could even enchant a bone. This is testable, too...

There are probably better ways for this, but this should do the trick.

/testfor @p {Inventory:[{Slot:0b,id:"minecraft:diamond_pickaxe"}],SelectedItemSlot:0}

(this would require to have a diamond pickaxe in your first item slot and also hold it.)

  • I know about those ways, but I was hoping to make the enchantment feel more like a real enchantment by allowing players to find the books and apply the enchantment in an anvil. At the very least, is there a way to detect the contents of an anvil for a given player so I can /give them the proper item when they combine the items in an anvil? – IceMetalPunk Oct 20 '15 at 11:47
  • I doubt there is. You could detect both items in the player inventory when the player is right at the anvil's location, but I don't know of a way to detect the anvil interaction itself. – dly Oct 20 '15 at 11:52
  • Oh, well. So in my efforts to work around this, I thought of having the player sneak-right-click with the enchanted book to apply it to the first diamond pick in their hotbar. Detecting the pick's hotbar position works fine, detecting sneaking works fine (using the stat.sneakTime)...the only thing I'm having trouble with is detecting if the player has right clicked on the book. The gamepedia Wiki says stat.useItem.enchanted_book is valid, but when I try to use it, the command block tells me it's invalid. How do I detect a right click with an enchanted book? – IceMetalPunk Oct 20 '15 at 12:46
  • 1
    Detecting Right clicking has always been a pain. As for the stat.useItem.enchanted_book I cannot confirm this, but I believe it fires when you really use it (put in anvil and forge the enchanted item out of it). But this could also be used, if you let the player forge an enchantment and replace it with yours. – dly Oct 21 '15 at 9:04
  • 1
    That depends on how you do it I guess... using /enchant on an existing item adds the new enchantment to the existing one(s). – dly Oct 24 '15 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.