Solved Get the block player looking at

Discussion in 'Spigot Plugin Development' started by dexelOK, Apr 20, 2017.

Thread Status:
Not open for further replies.
  1. Hi Spigot.
    I use 1.11.2.

    How can I get the Location of the block player looking at?
    I thought it is getEyeLocation(), but it's not.
  2. Thought i ask this first: What have you tryed so far?
    Because this is just a simple line, i'm going to spoonfeed you,

    Code (Text):

         Location location = player.getTargetBlock((HashSet<Byte>) null, distance).getLocation();
    • Like Like x 2
  3. I'm quite a noob. How can I get distance?
  4. *Facepalm* its just an integer like "20"
  5. Ahah, I can just set it to any integer, right?
  6. sure, but notice: if you set it to like 1 the distance may don't find the target block if you are too far away from the block

    Distance = playerLocation to Block Location

    Can also be simply calculated by using (Pseudo Code: block.distance(block); )
  7. Thanks. Theme is closed.
  8. (Open)
    Hey, getTargetBlock method is deprecated and it just doesn't work! Nothing is in console. Here is my code:
    Code (Text):
    list.add(name.toLowerCase() + ":" + Source.makeLocation(p.getTargetBlock((HashSet<Byte>) null, 20).getLocation()) + ":" + percent);
    UPD: Method works, but location is still setting up to player eye location.

    UPD1: Something happend, and it works now. Thanks, the theme is closed.
    #8 dexelOK, Apr 20, 2017
    Last edited: Apr 20, 2017
Thread Status:
Not open for further replies.