Minecraft – Spawning mobs a few feet away in the direction you are looking at

minecraft-commandsminecraft-java-edition

I'll be straight here. I have tried various stupid things, but none seem to be working. What I have for now with a Mob-Spawning kit:

  • Set a command block that tests for any zombie with the name ZombieMaker.

  • Set up command block that kills named zombie.

  • Set it up so that ZombieMinion spawns when ZombieMaker spawns, just before it dies.

    That was background info, because then people start complaining that I haven't tried it out myself. And yes, I have searched for help. The question is:

How do I spawn that Zombie (ZombieMinion) a few blocks away to the direction I, or any player with that kit, is looking at (if possible, where the player was pointing at can also help)?

Best Answer

First, set a row of Command blocks plugged into a clock, testing for the Player approximate roation:

rotation can be tested for using the target selector arguments ry, rym, rx, and rxm, denoting the maximum and minimum view angle in the horizontal (east, south, etc.) and vertical (up, down) direction, respectively.

For example, to test for someone looking South (=0±22), use

testfor @a[ry=22,rym=-22]

(source here)

Then, for each command block set a command to be triggered if the output is true:

/execute @a[SomeSelector] ~ ~ ~ summon Zombie x y z {YourNBTTag}

Instead of x y z put the relative coordinates you want (for each CMD block pair a different set).
That would be, 4 * 2 or 8 * 2 CMD blocks altogether, depending on the accuracy you want.