TransWikia.com

How do I use the "SelectedItem" tag to check for a player in this command?

Arqade Asked by Dennez on May 27, 2021

I am trying to make this command work :

/execute as @a[nbt={SelectedItem:[{id:"minecraft:grass_block",tag:{display:{Name:"{"text":"GRASS3x3"}"}}}]}] run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1

It works when I leave the selected item part out, but I only want the command to execute when I’m holding a specific block with a specific name.

2 Answers

The main problem with your command is that you have an extra set of square brackets after SelectedItem; that is, ...SelectedItem:[{id:"mi... should really be ...SelectedItem:{id:"mi...

A square bracket [ tells Minecraft that the specified tag is a list (for example ArmorItems:[{},{},{},{}]), where as a curly bracket { tells Minecraft that the specified tag is a single item (with attributes).

I'm assuming that you should also use an at @s to tell Minecraft to run at the player's coordinates and specify the block you want to fill. This turns out as

/execute as @a[nbt={SelectedItem:{id:"minecraft:grass_block",tag:{display:{Name:"{"text":"GRASS3x3"}"}}}}] at @s run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 grass_block

Answered by Zach K on May 27, 2021

This solution should work on versions 1.16 and above. It hasn't been tested on any other versions.

Code in impulse command block: give @p blaze_rod{display:{Name:"{"text":"Fire Stuff"}"}}

Code in the repeating: execute as @a[nbt={SelectedItem:{id:"minecraft:blaze_rod",tag:{display:{Name:"{"text":"Fire Stuff"}"}}}}] at @s run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:magma_block

Chain On The Repeating: effect give @a[nbt={SelectedItem:{id:"blaze_rod",tag:{display:{Name:"{"text":"Fire Stuff"}"}}}}] minecraft:fire_resistance 50 100 true

Answered by Li-Shot on May 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP