14

How do you add NBT tags to commands? I’ve tried commands that normally work in Java Edition like:

give @s minecraft:planks 30 1 {display:{Lore:["Wooden planks"]}}
give @s potion 1 0 {Potion:"minecraft:night_vision"}
give @s diamond_sword{ench:[{id:16,lvl:5}]}
give @s minecraft:stone{CanPlaceOn:["minecraft:grass","minecraft:dirt"]} 3
give @s chest{BlockEntityTag:{Items:[{id:"diamond",count:10b}]}}
summon creeper ~ ~ ~ {powered:1b,CustomName:"Powered Creeper"}
summon villager ~ ~ ~ {Offers:{Recipes:[{buy:{id:"emerald",count:5b},sell:{id:"diamond_sword"}}]}}
  • I'm beginning to wonder whether it would be better to create separate canonical questions for things that are possible and only close questions that are actually impossible as duplicates of this one. – pppery Jul 5 at 2:27
  • @pppery I think that's a good idea. This question is a bit broad and it might become a megathread for all NBT-related things in Bedrock Edition. – cherryblossom Jul 5 at 4:11
13

Unfortunately, this is not possible in PE or BE (Bedrock Edition) except for the "can_place_on" or "can_destroy" tag:

/give @s stone 1 0 {"can_place_on":{"blocks":["grass","dirt"]}}

This gives yourself 1 stone that can be placed on grass and dirt.

/give @s iron_shovel 1 0 {"can_destroy":{"blocks":["grass","dirt"]}}

This gives yourself 1 iron shovel that can destroy grass and dirt.

Note: The can_place_on and can_destroy tags only have an effect in Adventure Mode (like Java Edition).


1.13 Update

You can now summon entities with a name using this syntax:

summon <entityType: EntityType> [spawnPos: x y z] [spawnEvent: string] [nameTag: string]
summon <entityType: EntityType> <nameTag: string> [spawnPos: x y z]

For example, to summon a chicken named "testing":

summon chicken testing

To summon entities with names including spaces or special characters, or starting with numbers, you'll need to put the name in double quotation marks. To include " escape it: \".

The below command summons a chicken with the name "some name with spaces and "quotation marks"".

summon chicken "some name with spaces and \"quotation marks\""

Workarounds

For some NBT tags, spawn events can be used. However, this may permanently change the mob's behaviour or corrupt it.

| improve this answer | |
  • 6
    Hm, nice self-answered question. I usually close these questions as duplicate of some random alike question of that category, now I can use this. Thanks! – Fabian Röling Jun 22 '18 at 22:10
  • Someone said (if I understand it right) that this answer does not work anymore in the latest versions. Can you please check that and update the answer, if necessary? – Fabian Röling Feb 9 at 23:19
  • @FabianRöling I tested the above commands in 1.14.2, the latest version, and they still worked. I haven't heard of any new JSON components and I can't find anything other than that comment about them. – cherryblossom Feb 10 at 5:57
  • According to the wiki, it's "1.14.20" for some reason. And this will get pretty confusing sometimes now that the MCJava and MCBE version numbers are so similar. – Fabian Röling Feb 10 at 14:05
  • @FabianRöling I meant 1.14.20, sorry. Thanks for pointing that out. – cherryblossom Feb 10 at 20:02
5

This is only possible for giving potions, using CanPlaceOn and CanDestroy, and the {powered:1} section of the creeper, although the syntax is slightly different. Based on other answers here, we know that it is impossible to add NBT tags in Bedrock Edition. However, there are loopholes for the items above.

For the potion, we'll use the data integer of 5, meaning Night Vision for 3 minutes. Link here: https://www.digminecraft.com/generators/give_potion_pe.php

/give @p potion 1 5

Here is a table of the possible values: Potion Table

For the stone, we can use JSON components for the abilities to place on certain items. This only works in adventure mode.

/give @s minecraft:stone 1 0 {"minecraft:can_place_on":{"blocks":["minecraft:grass","minecraft:dirt"]}}

Finally, for the powered creeper, we can utilize spawn events to make this possible in Bedrock Edition.

/summon creeper ~ ~ ~ minecraft:become_charged

I hope this helps!

| improve this answer | |
3

Here is another handy trick to summon an item entity with custom name, coloured name using section sign §, and even with enchantments!

  1. Manually prepare your item. If you need to enchant, do it with enchanted books and an anvil. If you need to rename, do it with an anvil. Use the section sign § in your item name to colour it.

  2. Place a chest on the ground. Insert your item into the chest. Note the coordinates of this chest.

  3. You will need to create a command chain to make this work. See this post for details on how to place command blocks correctly to chain them together. The command chain you are about to make will consist of 3 command blocks. (2 chain command blocks linked to an impulse command block)

  4. In the 1st (impulse) command block, insert this command:

    clone <templateX> <templateY> <templateZ> <templateX> <templateY> <templateZ> <destinationX> <destinationY> <destinationZ>
    

Clones the template chest to the location of your choosing.
You will need to replace the placeholders in the command with the actual coordinates of your template chest and destination location (without the angle brackets <>) 5. In the 2nd block of the chain, insert this command:

    setblock <destinationX> <destinationY> <destinationZ> air 0 destroy

Again, you will need to replace the coordinates without the angle brackets. 6. In the 3rd block of the chain, insert this command:

    kill @e[type=item,name=chest,x=<yourX>,y=<yourY>,z=<yourZ>,r=1]

Replace <yourX>,<yourY>, and <yourZ> with the X, Y, and Z of your location.

And you're done! Try it out by placing a button on the 1st command block and giving it a press. You should see that the item you put in the chest will appear at the location you specified.

How It Works

  1. When a player breaks a chest, it drops all its contents.
  2. Using /setblock in destroy mode will act like the player broke the block, except the block does not drop itself. However, it will drop all its contents.
  3. The chest is cloned and deleted so quickly that we do not see the chest appear, or if we do, we only see it for about a millisecond. Otherwise, we just see an item drop appear out of nowhere!
  4. The last command deletes the chest. Because /setblock in destroy mode acts as if it is broken in Survival, it means the chest will drop too along with its items. This last command quickly deletes the chest before the player has a chance to pick it up.

Final Notes

  • If one of the items placed inside the template chest is another chest, it will be deleted along with the template chest dropping itself. To combat this, use another storage device like a trapped chest.

Next Steps

Here are some ideas that could come next. Try them out!

  • Now try putting more than one item in the chest. What happens?
| improve this answer | |
2

Detecting whether a player has an item in their inventory

You can use the /clear command:

/clear <player> <item> <data> 0

The 0 specifies the maximum number of items to clear (so none will be cleared in this command). If the player has at least 1 <item> in their inventory (with the data value <data>), the command will output a success. To match all data values, use -1for <data>.

The success can be detected using a chain command block. Put the /clear any command block facing a conditional, always active, chain command block with the command that you want to execute if the player has the item.

| improve this answer | |

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