How do I get the Location of where the player is looking

Discussion in 'Plugin Development' started by GeekPlaya, Dec 19, 2011.

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

    GeekPlaya

    I am trying to get the location of where the player was looking. I thought it was getEyeLocation() but apparently that's just where they are standing..
     
  2. Offline

    Father Of Time

    This might help if you are wanting what block they are looking at.

    http://jd.bukkit.org/doxygen/d4/d7b...Entity.html#a03e2192e3c89529d1f59ec5ce04370ba

     
  3. Offline

    GeekPlaya

  4. Offline

    Father Of Time

    Do a block iteration trace, find the first block the trace comes in contact with that isn't air and return the location of the block; same principle, different execution. :D

    Check out block iterators, I'm pretty sure they can assist you.
     
  5. Offline

    se1by

    just use player.getTargetBlock();
     
  6. Offline

    user_43347

    Following what @se1by said, heres the code...
    Code:
    public Block getSelectedBlock(Player p) {
       Block b = p.getTargetBlock(200, null);
       return b;
    }
    So using that, I could just do something like this...
    Code:
    if (getSelectedBlock(p).equals(Material.TNT)) {
       //The block is tnt
    }
     
    kalicat, LemonLake and hammale like this.
  7. Offline

    1poseidon3

    I know this is n old post but for everyone who couldnt figure this out the code would be this:
    Code:java
    1. Player player = (Player) sender;
    2. Block block = player.getTargetBlock(null, 100);
    3. Location bl = block.getLocation();


    That is all you need. What you would need to do (to spawn a mob maybe) is this:
    Code:java
    1. if(args[0].equalsIgnoreCase("Wolf")){
    2. world.spawnCreature(bl,EntityType.WOLF);
     
    Captain Dory likes this.
  8. Offline

    MordorKing78

    But how do i setType ?
     
  9. Offline

    kalicat

    Code:java
    1. private staredAtBlock(Player player){
    2. return player.getTargetBlock(null, 200);
    3. }
    4. private setStaredBlock(Block block){
    5. staredAtBlock.setType(Material.TNT);
    6. }


    that should do the trick
     
Thread Status:
Not open for further replies.

Share This Page