How do I edit NBT tags of inventory items?

I'm trying to make an adventure map in Minecraft Java with blanket permission to place anything on certain block types, and break certain others, by appropriate tool. I'm currently trying to clock command blocks to run a /tag command on everything in a hotbar, but i can't figure out the syntax, and the wiki page for /tag has all of 23 lines of text, assuming a user can figure out the name field with no examples or reference links. My test command block, reading, as of now, "tag @e[nbt={Item:{slot:0}}] add {CanDestroy:["stone"]}", is flagging "{CanDestroy:["stone"]}" as red(error), because "Expected whitespace to end one argument, but found trailing data at position32: ...:0}" How do i format this for the tag command? Or am i going about this all wrong? I want to allow players to place/break with crafted items, so i can't very well just regulate inventoty with /give, which seems to be the standard approach for these NBT tags.

PS: The name field, for what it's worth, was angle bracketed, but that wouldn't display here.

6

1 Answer

Apparently, i was trying to use the wrong command, to do something the game doesn't allow. For what it's worth, i ended up using the /execute command to run data on dropped items. My thanks to Mr. Röling for his help.

Ex: execute as @e[type=item,scores={tool=3}] run data merge entity @s {Item:{tag:{CanDestroy:["coarse_dirt","gravel","sand","snow","snow_block"]}}}

You Might Also Like