I know how to make things spawn as they follow an object, but is there any way to make them spawn once lets say a snowball hits its target?

I am working on a way to make snowballs that spawn tnt upon hitting their target.

  • 1
    While this question is bumped, can minecraft command-savvy people go and downvote the answers that are straight-up wrong? – MrLemon Oct 22 '15 at 15:58

I have found a solution that works relatively well. The main issue is that when a snowball lands, the entity disappears immediately. To counteract this, we can use an armor stand marker to track the last known location of the snowball. This is not exactly where the snowball hits, but close enough for practical purposes.

First, you need to set up a scoreboard objective to track the snowball's lifetime, and another to detect a lonely armorstand.

/scoreboard objectives add snowballTime dummy
/scoreboard objectives add hasSnowball dummy

Now, create a fill clock (or use 1.9's repeat/chain command blocks), and run the following commands:

/scoreboard players add @e[type=Snowball] snowballTime 1

/execute @e[type=Snowball,score_snowballTime=1] ~ ~ ~ summon ArmorStand ~ ~ ~ {NoGravity:1b,CustomName:"SnowballMarker",Marker:1b,Invisible:1b}
/execute @e[type=Snowball,score_snowballTime_min=2] ~ ~ ~ tp @e[type=ArmorStand,name=SnowballMarker,c=1] @e[type=Snowball,r=1]

/scoreboard players set @e[type=ArmorStand,name=SnowballMarker] hasSnowball 0
/execute @e[type=Snowball] ~ ~ ~ scoreboard players set @e[type=ArmorStand,name=SnowballMarker,r=1] hasSnowball 1

/execute @e[type=ArmorStand,name=SnowballMarker,score_hasSnowball=0] ~ ~ ~ summon PrimedTnt ~ ~ ~ {Fuse:0}
/kill @e[type=ArmorStand,name=SnowballMarker,score_hasSnowball=0]

The first command will assign an ever-increasing score to every snowball entity in the world. The second and third commands will either create a new (invisible, hitboxless) armor stand (called "SnowballMarker") at the location of the snowball, or teleport an existing one to the snowball.

The fourth and fifth commands will set the hasSnowball score on the armor stand to 0 or 1, depending on whether or not there is a snowball within a radius of 1 block.

Command 6 summons TNT at every armor stand that does not have a snowball, and the last command removes these armor stands afterwards. Set the Fuse to whatever you like.

(I you are curious about the way this works, I suggest removing Invisible:1b from the summon command of the armor stand, so you can see them in action)

| improve this answer | |

I would take a different approach: When the snowball is thrown, summon an ArmorStand at its location. (using execute on the snowball). And use it to track the snowball. When the snowball hits something, it disappears and the ArmorStands SBB score starts to increase. You can use this to summon a TNT at the Spot where the snowball "died":

execute @e[type=Snowball,score_SBB_min=1,score_SBB=1] ~ ~ ~ summon ArmorStand ~ ~ ~ {CustomName:"SBTracker",Marker:1b,NoGravity:1b,Invisible:1b} (SBB=Snowballbomb, you have to create this objective first)

Teleport every ArmorStand to "its" Snowball: execute @e[type=ArmorStand,name=SBTracker] ~ ~ ~ /tp @e[c=1] @e[type=Snowball,r=2]

At every gametick, increase every snowballs SBB score by one: scoreboard players add @e[type=Snowball] SBB 1

Do the same to the ArmorStands: scoreboard players add @e[type=ArmorStand] SBB 1

Reset every ArmorStands SBB to 0 when there is a snowball nearby: execute @e[type=Snowball] ~ ~ ~ /scoreboard players set @e[type=ArmorStand,r=2] SBB 0

Summon a TNT at every ArmorStand with a SBB score of more than one: execute @e[type=ArmorStand,score_SBB_min=2,score_SBB=2] ~ ~ ~ /summon PrimedTNT ~ ~ ~

Kill every ArmorStand with a SBB score of at least 3: kill @e[type=ArmorStand,score_SBB_min=3]

| improve this answer | |
  • You talk about "(taking) a different approach", but this answer is functionally identical to mine, with the only difference being that you use the same scoreboard objective for the armor stands and the snowballs. – MrLemon Oct 22 '15 at 15:53
  • Strange, I somehow didnt see your answer... But why do you use 2 objectives? – Mystery Oct 22 '15 at 16:38
  • Keeping things a bit more sorted and clear, I guess. I just didn't think about using the same objective for both. – MrLemon Oct 22 '15 at 16:57

Fixed! Fully functional 1.8/1.8.x

Enter in a command block

/testfor @e[type=Snowball]

Then, power this with a clock. To make a clock, type

/gamerule dotiledrops false

and then set a Redstone Block on top of a command block that has this command:

/setblock ~0 ~1 ~0 minecraft:redstone_block 0 destroy

Then set two comparators on two sides of the original /testfor command block. Then, place a command block on the ends of both of the comparators pointing away from the /testfor command block. In one, place the command

/summon PrimedTnt ~20 ~-20 ~ {Fuse:whateveryouwant30reccomended} ~ ~ ~

In the other, place the command

/tp @e[type=PrimedTnt,c=-1] @e[type=Snowball,c=-1]
| improve this answer | |
  • 2
    This is outright horrible. 1) There is no need to turn off tile drops to make a clock. 2) The summon command has syntax errors, and could be summoning to the snowballs directly using execute. 3) the tp command teleports every Tnt to every snowball (Which I don't even know how the game will handle it). – MrLemon Sep 1 '15 at 15:30
  • 2
    the answer has not answered his question, and he raises very valid points. Why do you say "we are making a clock" and then call the line to disable tiles dropping? I do not play minecraft and even I can tell this is very incorrect. There is no reason to vandalise the question, just because your answer was not accepted. We expect a certain level of quality, here, and accuracy is one of the biggest factors that trumps all. – user106385 Sep 4 '15 at 21:35
/scoreboard objectives add lifetime dummy 
/scoreboard players add @e[type=Snowball] lifetime 0

the screboard is so the tnt doesnt explode in ur face then do

/execute @e[type=Snowball] ~ ~ ~ /testfor @a[r=2]

so it tests for a player in a range of 2 blocks

/execute @e[type=Snowball,score_lifetime_min=4] ~ ~ ~ /summon PrimedTnt 

also do /gamerule commandblockoutput false or it'll spam the chat

| improve this answer | |
  • 1
    Apart from the missing formatting and largely missing explanation, this doesn't even make sense (potentially because of the latter): 1) Your lifetime score will always be at 0, since you are adding 0. 2) Your execute/testfor doesn't do anything. Is is supposed to be hooked up to a comparator running into the third command? – MrLemon Sep 1 '15 at 15:24

I may have an idea (Either bad or good) Score Command:`

/scoreboard objectives add snowballtime dummy

So this is how I think that this can work. Hook this command to a clock:

/execute @e[type=Snowball] ~ ~ ~ detect ~1 ~ ~ [block] scoreboard players add @e[type=Snowball] snowballtime 1

You will need to copy this command a lot of times and change the "detect ~ ~1 ~", "detect ~ ~-1 ~",etc. so it will detect a block in any direction in a 1 block radius.

Then add a redstone comparator pointing to this command:

/execute @e[type=Snowball,score_snowballtime=1] ~ ~ ~ summon PrimedTnt ~ ~ ~ {Fuse:0}

and a command behind that:

/execute @e[type=Snowball] ~ ~ ~ detect [~? ~? ~?] [block] scoreboard players set @e[type=Snowball] snowballtime 0

I hope that can help, plus I am just getting some ideas for commands for maps and minigames.

| improve this answer | |
  • 1
    I see multiple issues here. The detect syntax of the execute command requires you to specify a specific block. Meaning you'd need about 6 times the number of blocks in the game command blocks for this. Also, the snowball would blow up in your face if you throw it while adjacent to a wall (or ceiling) – MrLemon Sep 6 '15 at 20:37

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