Bukkit's getBlock().getLocation.getBlockX|Z() is incorrect

Discussion in 'Plugin Development' started by x2nec, Aug 13, 2012.

Thread Status:
Not open for further replies.
  1. Hey, I'm trying to use the said method above when a block is destroyed:

    Code:
    Block b = e.getBlock();
            int x = b.getLocation().getBlockX();
            int y = b.getLocation().getBlockY();
            int z = b.getLocation().getBlockZ();
    When doing this, I should get -26, 22, -9 but instead I'm getting -27, 22 -10. Could someone confirm or help me with this?
     
  2. Offline

    Firefly

    How are you testing the "should get" coordinates?
     
  3. Offline

    VoidWhisperer

    That's because it has to round it to the next real integer if you want it to be an int. My recommendation would be, if possible, to turn x/y/z into doubles and change it to getX/getY/getZ so that it gets a more exact amount.
     
  4. I'm saving these to files, and then recalling them on restart. The values should point to the location of a block, but they're just off


    I'll try that now thanks :)
     
  5. Offline

    VoidWhisperer

    No problem :p I've had the same issue before.
     
  6. Hmmm... it's still selecting the next blocks so I presume it is still rounding up and not down. The block in question is a Sign by the way.
     
  7. Offline

    VoidWhisperer

    erm..... are you sure your not trying to convert it from a double to an int? that would also be rounding it.
     
  8. Offline

    Jnorr44

    why don't you get JUST the location... that would be the exact coords on the block i believe.
     
  9. Offline

    Crast

    why not use b.getX() / getY() / getZ()? (instead of b.getLocation().getBlockX() et al) Those also return ints to begin with, rather than changing to a float location and then converting back.
     
Thread Status:
Not open for further replies.

Share This Page