net.morbz.minecraft.world
Class Chunk

java.lang.Object
  extended by net.morbz.minecraft.world.Chunk
All Implemented Interfaces:
ITagProvider, IBlockContainer

public class Chunk
extends java.lang.Object
implements ITagProvider, IBlockContainer

Defines a chunk. It consists of 16x16 blocks in XZ-dimension and up to 16 sections for the height.

Author:
MorbZ

Field Summary
static int BLOCKS_PER_CHUNK_SIDE
          Blocks per chunk side
static int SECTIONS_PER_CHUNK
          Sections per chunk
 
Constructor Summary
Chunk(IBlockContainer parent, int xPos, int zPos, DefaultLayers layers)
          Creates a new instance.
 
Method Summary
 void addSkyLight()
          Adds the sky light.
 void calculateHeightMap()
          Calculates the height map.
 int getHighestBlock(int x, int z)
          Returns the highest non transparent block. calculateHeightMap() has to be invoked before calling this method to get actual results.
 byte getSkyLight(int x, int y, int z)
          Returns the sky light level of the block at given position.
 byte getSkyLightFromParent(IBlockContainer child, int childX, int childY, int childZ)
          Returns the sky light level of a block that is out of bounds of the child block container.
 org.jnbt.Tag getTag()
          Returns an instance of a subclass of the NBT-Tag class.
 int getX()
           
 int getZ()
           
 boolean hasBlocks()
          Has at least 1 block that is not air.
 void setBlock(int x, int y, int z, IBlock block)
          Sets a block at the given position.
 void spreadSkyLight(byte light)
          Spreads the skylight.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECTIONS_PER_CHUNK

public static final int SECTIONS_PER_CHUNK
Sections per chunk

See Also:
Constant Field Values

BLOCKS_PER_CHUNK_SIDE

public static final int BLOCKS_PER_CHUNK_SIDE
Blocks per chunk side

See Also:
Constant Field Values
Constructor Detail

Chunk

public Chunk(IBlockContainer parent,
             int xPos,
             int zPos,
             DefaultLayers layers)
Creates a new instance.

Parameters:
parent - The parent block container
xPos - The X-coordinate within the region
zPos - The Z-coordinate within the region
layers - The default layers. Can be 'null'
Method Detail

getX

public int getX()
Returns:
The X-coordinate within the region

getZ

public int getZ()
Returns:
The Z-coordinate within the region

setBlock

public void setBlock(int x,
                     int y,
                     int z,
                     IBlock block)
Sets a block at the given position.

Parameters:
x - The X-coordinate within the chunk
y - The Y-coordinate
z - The Z-coordinate within the chunk
block - The block

getSkyLight

public byte getSkyLight(int x,
                        int y,
                        int z)
Returns the sky light level of the block at given position. If there is no block World.DEFAULT_SKY_LIGHT will be returned.

Specified by:
getSkyLight in interface IBlockContainer
Parameters:
x - The local X-coordinate
y - The local Y-coordinate
z - The local Z-coordinate
Returns:
The sky light level

getSkyLightFromParent

public byte getSkyLightFromParent(IBlockContainer child,
                                  int childX,
                                  int childY,
                                  int childZ)
Returns the sky light level of a block that is out of bounds of the child block container.

Specified by:
getSkyLightFromParent in interface IBlockContainer
Parameters:
child - The child block container
childX - The local X-coordinate
childY - The local Y-coordinate
childZ - The local Z-coordinate
Returns:
The sky light level

spreadSkyLight

public void spreadSkyLight(byte light)
Spreads the skylight. For each block that has the given light level it's adjacent blocks will be lit if their current light level is lower.

Specified by:
spreadSkyLight in interface IBlockContainer
Parameters:
light - The light level

addSkyLight

public void addSkyLight()
Adds the sky light. Starts from top the top of each column and sets sky light to full, up to the first non-transparent block.


getHighestBlock

public int getHighestBlock(int x,
                           int z)
Returns the highest non transparent block. calculateHeightMap() has to be invoked before calling this method to get actual results.

Parameters:
x - The X-coordinate
z - The Z-coordinate
Returns:
The Y-coordinate of the highest block

hasBlocks

public boolean hasBlocks()
Has at least 1 block that is not air.

Returns:
True if there is a block

calculateHeightMap

public void calculateHeightMap()
Calculates the height map.


getTag

public org.jnbt.Tag getTag()
Returns an instance of a subclass of the NBT-Tag class.

Specified by:
getTag in interface ITagProvider
Returns:
The Tag representation of this class