How do I get entities to spawn at a Player's Crosshairs?

Discussion in 'Plugin Development' started by cheer60823, Jun 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    cheer60823

    I have recently been working on a plugin, and I would like to add a feature called "ArrowStorm" All I need to know is how do I get 50 arrows to spawn at a player's (Who typed the command) crosshairs.
    Please Help!
    Thanks
    ~Cheer60823
     
  2. Offline

    chasechocolate

    Assuming you want the arrow entity, use this:
    Code:java
    1. Block targetBlock = player.getTargetBlock(null, 100); //100 is the max distance away
    2. Location loc = targetBlock.getLocation();
    3.  
    4. for(int i = 0; i < 50; i++){
    5. loc.getWorld().spawn(loc, Arrow.class);
    6. }

    If you mean arrow drop, then just replace the line in the for loop to:
    Code:java
    1. loc.getWorld().dropItem(loc, new ItemStack(Material.ARROW))
     
Thread Status:
Not open for further replies.

Share This Page