Minecraft – How to swap a crafted Item for another one (in bedrock edition)

minecraft-bedrock-editionminecraft-commands

I am making an adventure map and am making it so that you craft a piece of tnt that should be placed on an observer. Though, when it is crafted it can't be placed on anything.
I have tried several times with different commands but none seem to work.

/replaceitem entity @p [name=tnt]slot.weapon.mainhand 1 tnt 1 0 {"minecraft:can_place_on":{"blocks":["observer"]}}

This is one command i've tried several times. It looks promising but says that "no targets matched selector". Even if the "[name=tnt]" is swapped by "[name=!tnt]" (that should make it so that everything exept tnt changes) the tnt changes.

I would be greatful if anyone could help me.

Best Answer

What your command is trying to do is replace the nearest player whose player name is tnt's mainhand slot. Because your Minecraft username isn't tnt, it is not finding you.

Unfortunately, it isn't possible to detect an item in a specific item slot in Minecraft Bedrock. You can, however, run /clear @p tnt -1 1 to clear a TNT from a player, and test whether it succeeds using a conditional chain command block.

Related Topic