3

I'm making a map where you have to craft items to destroy more items, and so on.
You need to craft this Stone Pickaxe and you are in Adventure Mode so it can't break anything. I want to swap it with another Stone Pickaxe which can actually destroy blocks. I know the /give <item>{CanDestroy:["<block>"]} 1.

Please help me swap items.

2

1 Answer 1

3

Put this command in an always active repeating command block:

execute as @a[nbt={SelectedItem:{id:"minecraft:stone_pickaxe"}}] run replaceitem entity @s weapon.mainhand minecraft:stone_pickaxe{CanDestroy:["minecraft:stone"]}

This will check if the player is holding a stone pickaxe, if so, it will change it so that it is able to break stone.

Also make sure that you turn of command block output like so:

/gamerule commandBlockOutput false

This is so your chat does not get spammed

2
  • Oh right, weapon.mainhand is also a slot, I forgot! Good solution. Commented Mar 16, 2020 at 12:43
  • 3
    You could also add unless data entity @s SelectedItem.tag.CanDestroy. That improves performance and prevents the output spam. Commented Mar 16, 2020 at 12:46

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