#How to detect item on the ground with components?

1 messages · Page 1 of 1 (latest)

valid agate
#

I cant detect item on the ground with component.
Command:
execute as @e[type=minecraft:item,nbt={custom_data:"cubic"}] if items entity @e[type=item] container.* player_head[minecraft:custom_data={cubic:1b}] run give @p diamond

deft lagoonBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

calm fractal
#

execute as @e[type=minecraft:item,components={"minecraft:custom_data":"cubic"}] if items entity @s container.* player_head[minecraft:custom_data={cubic:1b}] run give @p diamond should work

faint nymph
#

This command is not correct.
First of all, components are never a single string, they are part of a compound execute as @e[type=minecraft:item,nbt={custom_data:{cubic:1b}}]

calm fractal
#

no wait actually you are using two different values for the "cubic" custom data

faint nymph
#

next, a small improvement would be to change container.* to container.0 as this is the only slot an items has.

rapid kettleBOT
#

Here a better performant version of the command

execute as @e[type=minecraft:item] if items entity @s container.0 player_head[minecraft:custom_data~{cubic:1b}] at @s run give @p diamond
faint nymph
#

I removed the nbt check as it will greatly increase lag if you have many items in your world.

#

If possible always avoid nbt checks (especially entity nbt checks)

#

Another thing is the ~ in the if items part. If you use = it will fail if there is any other data than the one tag you're testing for. ~ on the other hand only checks if the specified tag is present and has the correct value regardless of the other data in custom_data tag.

valid agate
#

Thank you for the help!
This command works perfect!