Minecraft – How to summon an object in motion where a player is looking

minecraft-commandsminecraft-java-edition

I have been trying to figure out throwing knives in Minecraft.

Is there an easy way (besides a ton of command blocks) to summon an object where the player is with motion according to where the player is looking, besides using an arrow?

I want to summon an armor stand and have the arrow break the armor stand, but if the armor stand is invulnerable the arrow should hit it and fall down. The same should happen with eye of ender, ender pearls and snowballs.

Best Answer

I got this to work:

In a repeating command block:

/execute @e[type=snowball,tag=!standSummoned] ~ ~ ~ summon armor_stand ~ ~0.1 ~ {Marker:1,Small:1b,CustomName:snowballStand,NoGravity:1}

In a conditional chain command block:

/scoreboard players tag @e[type=snowball,tag=!standSummoned] add standSummoned

In a regular chain command block:

/execute @e[type=snowball,tag=standSummoned] ~ ~ ~ /teleport @e[name=snowballStand] ~ ~-0.1 ~

The Marker:1 tag gives it a really tiny hitbox, so offsetting it slightly is enough to keep it from getting in the snowball's way. Note that this summons the armor stand with its feet at the snowball, you might want to offset it farther down to get the effect you want.

Edit

I may have misunderstood the problem. Were you trying to get a projectile to kill an existing invulnerable armor stand on hit? If so, this is what you want:

/execute @e[type=arrow] ~ ~ ~ scoreboard players tag @e[type=armor_stand,name=targetedArmorStandName,r=3] remove vulnerable
/execute @e[type=arrow] ~ ~ ~ scoreboard players tag @e[type=armor_stand,name=targetedArmorStandName,r=2] add vulnerable
/entitydata @e[tag=vulnerable] {Invulnerable:0}
/entitydata @e[tag=!vulnerable,type=armor_stand,name=targetedArmorStandName] {Invulnerable:1}