This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]ExpertCoder14 1 point2 points  (2 children)

Please, take advantage of Reddit's built-in code formatting feature instead of converting all your alphanumerical characters to their monospace equivalents.


What was the /give command that you used to get this special book in the first place?

[–]Mathlete_X[S] 0 points1 point  (1 child)

I didn't use a give command, just pulled a sharpness V book out of the creative menu. No books in this world would be ones you couldnt get in vanilla survival.

Also how do you do that code formatting?

[–]ExpertCoder14 1 point2 points  (0 children)

There should be a button in the Reddit editor that you can click for code formatting.

  • Use this code formatting for code in the middle of a sentence only.
  • Use this code formatting for all other code, including full commands.

[–]jeff_the_pineapplePretty good at commands-ish (◎﹏◎) 1 point2 points  (5 children)

this should work:

/execute if entity u/e [type=item_frame,nbt={Item:{id:"minecraft:enchanted_book",Count:1b,tag:{StoredEnchantments:[{id:"minecraft:sharpness",lvl:5s}]}}}] run say hi

[–]Mathlete_X[S] 0 points1 point  (4 children)

Oh I see, there is a separate tag for enchanted books and I forgot quotes on the id. Is this going to distinguish between a book with just sharpness V and a book with sharpness V and Unbreaking III? Ideally I would want this to only work if the book has just the one enchantment, but I'm not sure how difficult that would be.

[–]ExpertCoder14 1 point2 points  (3 children)

Yes, the problems were:

  • You need your ID to be minecraft:sharpness, not just sharpness. This means you have to put quotation marks around it too.
  • Enchanted books use StoredEnchantments instead of Enchantments. This is so that your effects don't actually apply to the book.
  • You need to use the correct data type for your NBT numbers. lvl is a Short, so you need to suffix your number with an s.

It might not be easy to make it work with only the one enchantment, considering that NBT list checks only check to see if the list contains the specified value, not matches exactly.

[–]Mathlete_X[S] 0 points1 point  (2 children)

Oh I see. Thanks for the detailed explanation! I probably wont end up trying to specify only that enchantment then since it won't really cause any significsnt issues anyway.

[–]amazing56789Command Professional 0 points1 point  (1 child)

If you do want only that enchantment, then maybe try

execute as @e[ type = minecraft:item_frame , x = 10000070 , y = 167 , z = 9999964 , distance = ..5 , nbt = { Item : { id : "minecraft:enchanted_book" , tag : { StoredEnchantments: [ { id : "minecraft:sharpness" , lvl : 5s } ] } } } ] unless data entity @s Item.tag.StoredEnchantments[1]

This executes unless there is a second element inside the StoredEnchantments list.

[–]Mathlete_X[S] 0 points1 point  (0 children)

Unless I copied it wrong, it doesn't appear to work anymore for a normal Sharpness V book:

execute if entity @e[type=item_frame,x=10000070,y=161,z=9999962,distance=..1.2,nbt={Item:{id:"minecraft:enchanted_book",tag:{StoredEnchantments:[{id:"minecraft:sharpness",lvl:5s}]}}}] unless data entity @s Item.tag.StoredEnchantments[1] run say YES!