Class BlockPosition

java.lang.Object
io.github.bakedlibs.dough.blocks.BlockPosition

public final class BlockPosition extends Object
This is the position of a block in a World. Using this class as opposed to Location is much better because it has a lower memory footprint and doesn't contain useless data such as yaw and pitch.
This is 12 bytes in memory whereas Location is 36 bytes. (Note, this is not accounting for things like object headers)
Author:
Walshy
  • Constructor Details

  • Method Details

    • getWorld

      @Nonnull public World getWorld()
      Gets the World this block is in. If this World has been unloaded it will throw an IllegalStateException. This should be getting handled properly by yourself!
      Note: This is held as a weak reference!
      Returns:
      The World for this block.
    • getPosition

      public long getPosition()
      Gets the long position of this block. This is constructed of the x, y and z.
      This is encoded as follows: ((x & 0x3FFFFFF) << 38) | ((z & 0x3FFFFFF) << 12) | (y & 0xFFF)
      Returns:
      The position of this block.
    • getX

      public int getX()
      Gets the x for this block.
      Returns:
      This blocks x coordinate.
    • getY

      public int getY()
      Gets the y for this block.
      Returns:
      This blocks y coordinate.
    • getZ

      public int getZ()
      Gets the z for this block.
      Returns:
      This blocks z coordinate.
    • getBlock

      @Nonnull public Block getBlock()
      Gets the Block at this position. Note, Bukkit will create a new instance so if you can avoid doing this then do as it is a bit costly.
      Returns:
      The Block at this location.
    • getChunk

      @Nonnull public Chunk getChunk()
      Gets the Chunk where this block is located.
      Returns:
      This blocks Chunk.
    • getChunkX

      public int getChunkX()
      Gets the chunks x coordinate for this block.
      Returns:
      The blocks chunks x coordinate.
    • getChunkZ

      public int getChunkZ()
      Gets the chunks z coordinate for this block.
      Returns:
      The blocks chunks z coordinate.
    • toLocation

      @Nonnull public Location toLocation()
      Transform this BlockPosition into a standard Bukkit Location.
      Returns:
      A Bukkit Location.
    • getAsLong

      public static long getAsLong(int x, int y, int z)
      This compacts the three provided integers into one Long. This allows us to save a lot memory-wise.
      Parameters:
      x - The x component
      y - The y component
      z - The z component
      Returns:
      The compacted Long
    • getAsLong

      public static long getAsLong(@Nonnull Location loc)
      This compacts the three provided integers into one Long. This allows us to save a lot memory-wise.
      Parameters:
      loc - The Location to simplify.
      Returns:
      The compacted Long, ignoring the World
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object