I decided to make a Snowball that summons lightning bolts along. Well I already did one half - With the @e[type=Snowball] (or Arrow, depending if I use a bow). But with @e I will target all the snowballs. So I wondered if a snowball could shoot named snowballs so I can use @e[name=RandomName]. Can anyone help?
-
The name property isn't used on projectiles, it's on scoreboards.– user114997Commented Aug 10, 2015 at 19:24
-
Hello there and sorry for the confusion! I have brought your post back from the dead because it's actually on-topic, and I may be able to come up with some stuff. First of all, selectors can't select based on a custom name, so you're going to need to use a scoreboard. Secondly, I'm not sure it's possible to differentiate this sort of thing. There may be some tricks that can be done by checking for a player within x radius of a snowball having a named snowball in their hand, and applying a score to that snowball, but that's the best I can come up with. I'll look into these things though.– Unionhawk ♦Commented Aug 11, 2015 at 0:34
3 Answers
Snowballs are a lot of fun aren't they? Well, this is simpler, since your requirements are that a particular sort of snowball will have an arc of lightning bolts across its trajectory, but the principal is the same.
For this, I used a series of 4 commands and 1 setup command. (well, and also /gamerule commandBlockOutput false
) It works by setting a lightning
score for snowball entities holding customly named snowballs, and then summoning a lightningbolt at each of those snowballs. And it's actually a neat little set of commands.
First, we need our scoreboard. You can set one up using /scoreboard objectives add lightning dummy
. From here, we want to be able to perform commands on players holding customly named snowballs:
scoreboard players set @a lightning 1 {SelectedItem:{id:minecraft:snowball,tag:{display:{Name:"KABOOM"}}}}
Unfortunately there's no really clean way to invert this sort of command to reset this score, and resetting it for all items would also cause the last snowball in a stack to stop working, so I just reset it for players holding snowballs. As long as the commands execute at the same time, you shouldn't run into any problems, unless you're trying to build a PvP game around this, then you may want to reset this score for everyone just to be safe:
scoreboard players set @a lightning 0 {SelectedItem:{id:minecraft:snowball}}
From here, we can set the score of the snowball entities near these players using execute
:
execute @a[score_lightning_min=1] ~ ~ ~ scoreboard players add @e[type=Snowball,r=10] lightning 0
Now you have a marked snowball. Just what we need! The final step to this equation is to slap a score_lightning_min=0
in the original "make lightning at every snowball entity" command, hook all 4 command blocks up to a clock of some sort (I recommend a /fill
clock, but it's not entirely necessary as long as all of your commands are on the same line of redstone) and we should be set:
execute @e[type=Snowball,score_lightning_min=0] ~ ~ ~ summon LightningBolt ~ ~ ~
The results: Wholly satisfying:
-
There is a problem with this in that if a player is holding a KABOOM snowball, any thrown snowball withing 10 blocks gets converted, including those not thrown by the player.– MrLemonCommented Aug 11, 2015 at 8:56
-
@MrLemon That is correct. Unfortunately, since there is not a clean way to name snowballs as they're thrown, that becomes a side effect.– Unionhawk ♦Commented Aug 11, 2015 at 11:25
It is possible to name arrows or snowballs. However, any arrow shot from a bow will spawn a default arrow entity, and any snowball thrown by a player will spawn the default snowball entity. Currently there is no way to change this, but there are a few workarounds if you're doing something specific.
1.) You can tag only snowballs/arrows that are in a certain area around certain players. For instance, you could make a character class called the 'Archer' with scoreboard commands. and you could make all the arrows that this class fires have some special effect by tagging all the arrows that travel very close to 'Archer' players.
2.) You can tag only snowballs/arrows that are travelling certain speeds, heights, or directions with minecraft's new /scorebord players tag command (this will only work in the snapshots). You may also be able to tag only arrows that are on fire (but this depends on whether or not arrows use the {Fire:x} NBT tag.
3.) If players are not going to be throwing the special snowballs/arrows (e.g. you are only summoning them) it is easy enough to just summon arrows/snowballs with names.
4.) This one only applies to arrows. In the most recent snapshots Mojang has added new arrow types that involve 2 new entities. Spectral arrows and arrows with potion effects both have their own unique entities so you could modify what these arrows do without affecting default arrows (although this method would affect ALL spectral arrows and/or ALL tipped arrows.
If one of these methods sounds like it would help you reply to this comment and I will elaborate said method (writing out 4 tutorials is a bit too much sorry).
Just put this on a Command block on a super fast clock
/Kill @e[type=Snowball]
Then another command block with this in it:
/execute @e[type=Snowball] ~ ~ ~ /summon Arrow {CustomName:"(Name)"}
There you go and just copy and paste these commands in Minecraft.
How to get command block:
/give @p minecraft:command_block
How to copy and paste:
Highlight the command you want to copy
Open up the command block
Press CTRL+v at the same time
How to make clock:
/fill ~ ~1 ~ ~ ~1 ~ minecraft:air
Then another command block 2 blocks above that with the command:
/fill ~ ~-1 ~ ~ ~-1 ~ minecraft:redstone_block
Yay you did it whooooooo!
-
You've not quite specified how to add custom names to the snowball and arrow entities.– user114997Commented Aug 15, 2015 at 19:33
-
-
I have no way of doing so for the time being, but I'll let you know in a few days. ;)– user114997Commented Aug 15, 2015 at 19:51
-
-