#How to detect item on the ground with components?
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
💬 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
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
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}}]
no wait actually you are using two different values for the "cubic" custom data
next, a small improvement would be to change container.* to container.0 as this is the only slot an items has.
Here a better performant version of the command
[35mexecute [34mas [36m@e[33m[[37mtype[34m=[33mminecraft:item] [34mif items entity [36m@s [0mcontainer.0 player_head[33m[[37mminecraft:custom_data~[35m{[37mcubic[34m:[32m1b[35m}[33m] [34mat [36m@s [34mrun [35mgive [36m@p [0mdiamond
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.
Thank you for the help!
This command works perfect!