block.getX() in onPlayerInteract() - Bug?

Discussion in 'Plugin Development' started by V10lator, Nov 16, 2011.

Thread Status:
Not open for further replies.
  1. Hi,
    I'm using x, y and z coordinates very often but today was the first time I used (compared) them from onPlayerInteract() and another method (onBlockRedstoneChange()). That didn't work, so I wrote some debugging lines into my plugin that showed that the x coordinate of booth methods for the same block are different! I verified in-game that the coordinate from onBlockRedstoneChange() is valid.

    Can you confirm this bug?

    BTW: Here is the output from the debugging where the first value is from onBlockRedstoneChange and the second from onPlayerInteract(). The first line compares the worlds, second x, third y, last z:
    Code:
    16.11 07:46:12 [Server]16.11 07:46:12 [Server] INFO world vs world
    16.11 07:46:12 [Server] INFO -176 vs -177
    16.11 07:46:12 [Server] INFO 69 vs 69
    16.11 07:46:12 [Server] INFO 252 vs 252
     
  2. Offline

    ItsHarry

    -176 is X? o-o
    No idea.
     
  3. Offline

    Lolmewn

    Well, that's just weird.
     
  4. Yes, I already noticed that aswell. On the negative x-axis, the value seems to be off by one sometimes (I compared it using a minimap). I never had to compare values, so it wasn't a problem for me, but yeah, I did notice.
     
  5. @EvilSeph, @lukegb, @Dinnerbone, @sk89q, sorry for tagging you here but as leaky is down I need to get sure you read this as I need the bug to get fixed. :(
     
  6. Offline

    feildmaster

    I could understand if the Y was wrong... but the X? I could possibly look into it later. I have a ton of stuff I want to look into in bukkit. Could I have the code you're using for checking this as well?
     
  7. Offline

    halley

    When you find problems with an off-by-one result in negative integers, the usual cause is inconsistent ways of rounding floating point numbers to make integers.

    Math.floor(-176.4) gives -177.0
    Math.round(-176.4) gives -176.0
    (int)(-176.4) gives -176

    Math.floor(-176.6) gives -177.0
    Math.round(-176.6) gives -177.0
    (int)(-176.6) gives -176

    I believe all of the getBlockX() kinds of methods should be using Math.floor() but there may still be some cases where someone decides to do it a different way. Using Math.floor() gives a consistent block distance size regardless of sign. For example, a distance calculation should result in two meters between 1.2 and -0.8 and still 2.0 meters when using Math.floor(1.2) [1] and Math.floor(-0.8) [-1] for example.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
Thread Status:
Not open for further replies.

Share This Page