Package io.github.bakedlibs.dough.blocks
Class BlockPosition
java.lang.Object
io.github.bakedlibs.dough.blocks.BlockPosition
This is the position of a block in a World. Using this class as opposed to
This is 12 bytes in memory whereas
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 Summary
ConstructorsConstructorDescriptionThis creates a newBlockPositionfor the givenBlocks position.This creates a newBlockPositionfor the givenLocationBlockPosition(World world, int x, int y, int z) This creates a newBlockPositionfor the given position.BlockPosition(World world, long position) This creates a newBlockPositionfrom the given position andWorld. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic longgetAsLong(int x, int y, int z) This compacts the three provided integers into oneLong.static longThis compacts the three provided integers into oneLong.getBlock()Gets theBlockat this position.getChunk()Gets theChunkwhere this block is located.intGets the chunks x coordinate for this block.intGets the chunks z coordinate for this block.longGets the long position of this block.getWorld()Gets theWorldthis block is in.intgetX()Gets the x for this block.intgetY()Gets the y for this block.intgetZ()Gets the z for this block.inthashCode()Transform this BlockPosition into a standard BukkitLocation.toString()
-
Constructor Details
-
BlockPosition
This creates a newBlockPositionfrom the given position andWorld.- Parameters:
world- TheWorldposition- TheBlockPosition(as a long)
-
BlockPosition
This creates a newBlockPositionfor the given position.- Parameters:
world- TheWorldx- The x coordinatey- The y coordinatez- The z coordinate
-
BlockPosition
This creates a newBlockPositionfor the givenBlocks position.- Parameters:
b- TheBlock
-
BlockPosition
This creates a newBlockPositionfor the givenLocation- Parameters:
l- TheLocation
-
-
Method Details
-
getWorld
Gets theWorldthis block is in. If thisWorldhas been unloaded it will throw anIllegalStateException. This should be getting handled properly by yourself!
Note: This is held as a weak reference!- Returns:
- The
Worldfor 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
Gets theBlockat 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
Blockat this location.
-
getChunk
Gets theChunkwhere 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
Transform this BlockPosition into a standard BukkitLocation.- Returns:
- A Bukkit
Location.
-
getAsLong
public static long getAsLong(int x, int y, int z) This compacts the three provided integers into oneLong. This allows us to save a lot memory-wise.- Parameters:
x- The x componenty- The y componentz- The z component- Returns:
- The compacted
Long
-
getAsLong
This compacts the three provided integers into oneLong. This allows us to save a lot memory-wise. -
equals
-
hashCode
public int hashCode() -
toString
-