How would I make something spawn when and where a snowball hits something? [duplicate]

How would I make something spawn when and where a snowball hits something? [duplicate] - Crop faceless informal woman with opened notebook

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.



Best Answer

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)




Pictures about "How would I make something spawn when and where a snowball hits something? [duplicate]"

How would I make something spawn when and where a snowball hits something? [duplicate] - Man in Pink Crew Neck T-shirt
How would I make something spawn when and where a snowball hits something? [duplicate] - Man in Pink Crew Neck T-shirt
How would I make something spawn when and where a snowball hits something? [duplicate] - Diverse Group of People in Swimwear Looking for Something in Sandy Beach



How do you get infinite snowball in Minecraft?

Use a Shovel to dig up the Snow Dig up the snow with your shovel. Each time you dig up the snow, it creates a snowball. Make as many snowballs as you like. Add the snowballs to your inventory and never run out of snowballs again!



7 fun Snowball commands




More answers regarding how would I make something spawn when and where a snowball hits something? [duplicate]

Answer 2

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]

Answer 3

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]

Answer 4

/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

Answer 5

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.

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Skylar Kang, MART PRODUCTION, MART PRODUCTION, Ron Lach