1

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 reapeat 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. Thanks.

2

In your NBT, item should be Item and firework_star should be minecraft:firework_star, since NBT matching is case-sensitive and needs to exactly match how it's stored.

@e[nbt={Item:{id:"minecraft:firework_star"}}]

Next, it's important to understand the difference between the as and at 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 everyone
  • as 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 name

In 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 execute at the player so that ^ ^ ^4 uses their position/rotation.

The following commands should work:

execute at @e[type=item,nbt={Item:{id:"minecraft:firework_star"}}] at @p run summon minecraft:evoker_fangs ^ ^ ^4

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:

/scoreboard objectives add DroppedFWStar dropped:firework_star

Then you can use the following to activate the ability:

execute at @a[scores={DroppedFWStar=1..}] run summon minecraft:evoker_fangs ^ ^ ^4

And set the score back to 0 afterwards.

  • Thank You SOO much! This explains a lot of problems I've had with the execute command. this ha been really helpful. – 4AC11 Jul 27 '18 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.