Solved get exact ClickLocation of PlayerInteractEvent

Discussion in 'Plugin Development' started by Freahk, Aug 26, 2015.

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


    Hey there!

    I'm building my first bukkit/spiggot Plugin atm.
    I'm trying to build an automat using a wall sign as a "touchscreen" display So I need to know the exact Klick location instead of the integer coordinates of the clicked block coordinates that I get using

    evt.getClickedBlock().getX(); //returning e.g. 7
    evt.getClickedBlock().getX(); //returning e.g. 13
    evt.getClickedBlock().getZ(); //returning e.g. 42
    I need something like
    evt.getClickedLocation().getX(); //returning e.g. 7.5
    evt.getRelativeVector().getX();.//returning numbers between 0 and 1 e.g. 0.5
    I know how I could calculate the plane of the Sign using the signs coordinates and pitch and the straight of the players view direction using players exact Location, yaw and pitch.

    I also know that the exact click location is the location where the straight intersects the plane so I could calculate it.
    However this approach looks a bit complicated for me and I was wondering if there really is no such method in the bukkit API.

    Help would be appreciated.
    Thanks, Freahk
  2. Offline


    Cast X,Y,Z to double but for yaw and pitch keep them floats
  3. Offline


    @OhhPickles Sorry but I don't know what you mean.
    Do you mean something like
    double x = (double) evt.getClickedBlock().getX();

    That doesn't help me. I would just get for example '13.0' instead of '13'.
  4. Offline


    @Freahk Maybe you can calculate the exact point with the player's eye direction?
  5. Offline


  6. Offline


    First, you are not getting the location, so this method does not exist, and thus your code would not work. Get the block's location and THEN get the x,y,z. Secondly,this should never be the case(x equaling 7 and x equaling 13 miliseconds later). If it is, then there is something wrong with your version of Bukkit. Finally, to get Integetrs instead of Doubles, you should use getBlockX, getBlockY and GetBlockZ, or just cast getX to an int removing the decimal point.
  7. Offline


    @au2001 yeah that's what I mentioned above. I just have to calculate the point where the players vision intersects the pane containing the clicked sign.

    @chasechocolate Thanks. Didn't find that post when I was searching for it. So it seems that there is no way to get this information directly and I really have to calculate that point on my own or by using the code of ase34. Seems exactly like what I'm doing atm. Calculate the cartesian players view direction, ass

    @Zombie_Striker why doesn't that method exists? Assuming evt is a PlayerInteractEvent it defnetly has a method called getClickedBlock() returning a Block. So why can't I use the getX(), getY() and getZ() Methods on a block? The Javadoc tells me that the Block interface defines these methods...

    So the answer to my question is "you can't get the exact (float) location of the users click directly by using Bukkit API methods but you can calculate it using players Location, yaw, pitch and the blocks (integer) location and yaw (and pitch which is in my case always 0)"

    Thanks for the answers. Problem solved.
    If anyone wants to know how I calculate that location I will post the code here but I think ase34's Post explains it quite well.
Thread Status:
Not open for further replies.

Share This Page