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

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

  1. Offline

    GeekPlaya

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This might help if you are wanting what block they are looking at.

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


    This post has been edited 1 time. It was last edited by Father Of Time Dec 19, 2011.
  3. Offline

    GeekPlaya

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  4. Offline

    Father Of Time

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    just use player.getTargetBlock();
  6. Offline

    nkrecklow

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Following what @[user]se1by[/user] 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
    }
    LemonLake and hammale like this.
  7. Offline

    1poseidon3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

Share This Page