Creating a tool that can break certain blocks as a command in Bedrock 1.14 [duplicate]
Java Edition has the CanPlaceOn
and CanDestroy
NBT tags, which are used to restrict the blocks an item can be placed on and destroy respectively (in adventure mode). For example, the following commands give the player a stone block that can only be placed on grass and dirt, and a netherite axe that can only destroy pumpkins:
give @s stone{CanPlaceOn:["minecraft:grass","minecraft:dirt"]}
give @s netherite_axe{CanDestroy:["minecraft:pumpkin"]}
How can I do this in Bedrock Edition?
Browse more workarounds for getting/setting NBT in Bedrock Edition
Solution 1:
The BE equivalents of these tags are minecraft:can_place_on
and minecraft:can_destroy
respectively. You can use these in the /give
and /replaceitem
commands using the final [components: json]
argument. For example, the syntax of /give
is:
give <player: target> <itemName: Item> [amount: int] [data: int] [components: json]
Note that unlike Java Edition, block names go inside an array named blocks
that goes inside minecraft:can_place_on
and minecraft:can_destroy
. Like so:
give @s stone 1 0 {"minecraft:can_place_on":{"blocks":["grass","dirt"]}}
give @s netherite_axe 1 0 {"minecraft:can_destroy":{"blocks":["pumpkin"]}}
You can also combine both minecraft:can_place_on
and minecraft:can_destroy
:
give @s iron_block 1 0 {"minecraft:can_place_on":{"blocks":["iron_block"]},"minecraft:can_destroy":{"blocks":["grass","dirt"]}}
* The namespace value minecraft:
is optional and can be omitted.
This syntax is called JavaScript Object Notation (JSON), which is a format similar to the NBT used in JE commands (technically SNBT). Objects are surrounded by braces ({
and }
), have keys and values separated by colons (:
), and have key-value pairs separated by commas (,
). Keys and strings are surrounded by double quotes ("
); arrays are surrounded by brackets ([
and ]
) and contain items delimited by commas (,
).