ok so I'm just working to understand the new command system. before, (1.12)
I would have done a /testfor
command to detect a specific item.
now, the command has been removed. so, i tried this:
/execute as @e[nbt={item:{id:firework_star}}] run execute as @p run summon minecraft:evoker_fangs ^ ^ ^4
in a repeating command block. I dropped the item and nothing happened. is there and easy solution to this? I'd also like some insight on WHY this doesn't work.
Best Answer
In your NBT,
item
should beItem
andfirework_star
should beminecraft:firework_star
, since NBT matching is case-sensitive and needs to exactly match how it's stored.Next, it's important to understand the difference between the
as
andat
execute subcommands:at
runs the command where an entity is, with its rotation, and in its dimension.E.G:
execute at @a run setblock ~ ~ ~ stone
sets a stone block at everyoneas
doesn't change the position/rotation/dimension, just who's running the command.E.G:
execute as @a run say @s
makes everyone say their own nameIn general you'll only need one or the other, depending on whether you need to change the command position or executor.
In your case, you want to get the closest player to the firework star, so you should be executing
at
it (since you're finding the closest player to its position), and then you want to executeat
the player so that^ ^ ^4
uses their position/rotation.The following commands should work:
I also added a
type=item
for performance, since NBT-checking every entity in the world (presumably every tick) is laggy. If this is some kind of throw-ability, it would be even more efficient to add an objective that keeps track of when a player drops the firework star:Then you can use the following to activate the ability:
And set the score back to 0 afterwards.