0

I am trying to do a command on when you throw a snowball named "Lightning", it spawns lightning bolt at it every second. I ran into a slight problem which I cannot solve! Here is the command:

/execute @e[type=Snowball,name=Lightning] ~ ~ ~ /summon LightningBolt
3

I assume by "a snowball named "Lightning"" you mean that the item is named "Lightning" (like if you renamed it with an anvil).

Unfortunately, this information does not pass over to the thrown snowball entity (the item name doesn't become the entity name, for example), so what you want is a bit more complicated to achieve.

You should create a new objective to keep track of when a player throws a snowball:

/scoreboard objectives add ThrownSnowball stat.useItem.minecraft.snowball

Then, on a clock, run the following commands in this order:

/execute @a[tag=HoldingLightning,score_ThrownSnowball_min=1] ~ ~ ~ /scoreboard players tag @e[type=Snowball,c=1] add LightningBall
/scoreboard players set @a[score_ThrownSnowball_min=1] ThrownSnowball 0
/execute @e[type=Snowball,tag=LightningBall] ~ ~ ~ /summon LightningBolt
/scoreboard players tag @a[tag=HoldingLightning] remove HoldingLightning
/scoreboard players tag @a add HoldingLightning {SelectedItem:{id:"minecraft:snowball",tag:{display:{Name:"Lightning"}}}}

This should tag all players holding the snowball renamed to "Lightning" with HoldingLightning. If that player then has a ThrownSnowball score of at least one (meaning they've thrown a snowball in this tick, as this score resets at the end of the commands), they give the closest snowball the LightningBall tag. You can then use @e[type=Snowball,tag=LightningBall] to run the summon command as often as you want (you can put the summon command on a separate, slower clock).

| improve this answer | |
  • 1
    Be aware that this will not work if the player has only one snowball remaining before they throw it, since then they won't be given the "HoldingLightning" tag. The solution is to move the commands tagging the player to the end of the sequence so that the next tick depends on what the player was holding the tick prior to throwing the snowball. – Skylinerw Jul 14 '16 at 17:10
  • 1
    @Skylinerw Woops, should be fixed now. – SirBenet Jul 14 '16 at 17:22
  • @colorfusion Can you show me a picture of the clock because i got confused – user144609 Jul 15 '16 at 18:07
  • Here's a picture of the clock. Which part are you getting confused on? – SirBenet Jul 15 '16 at 18:42
-1

If you're looking to select a specific type of mob, try

@e[type=Mobtype].

Hope this helps :D

| improve this answer | |
  • They are already quite aware of that considering that, in their question, they correctly make use of the type parameter. – Skylinerw Jul 14 '16 at 20:01
  • I am trying to say the name of the mob – user144609 Jul 15 '16 at 18:01

Your Answer

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