net.morbz.minecraft.world
Class Region

java.lang.Object
  extended by net.morbz.minecraft.world.Region
All Implemented Interfaces:
IBlockContainer

public class Region
extends java.lang.Object
implements IBlockContainer

Defines a region. It consists of up to 32x32 chunks in XZ-dimension.

Author:
MorbZ

Field Summary
static int BLOCKS_PER_REGION_SIDE
          Blocks per region side
static int CHUNKS_PER_REGION_SIDE
          Chunks per region side
 
Constructor Summary
Region(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 maps for all chunks.
 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.
 int getX()
           
 int getZ()
           
 void setBlock(int x, int y, int z, IBlock block)
          Sets a block at the given position.
 void spreadSkyLight(byte light)
          Spreads the skylight.
 void writeToFile(java.io.File path)
          Writes this region to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHUNKS_PER_REGION_SIDE

public static final int CHUNKS_PER_REGION_SIDE
Chunks per region side

See Also:
Constant Field Values

BLOCKS_PER_REGION_SIDE

public static final int BLOCKS_PER_REGION_SIDE
Blocks per region side

See Also:
Constant Field Values
Constructor Detail

Region

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

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

getX

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

getZ

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

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 region
y - The Y-coordinate
z - The Z-coordinate within the region
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

calculateHeightMap

public void calculateHeightMap()
Calculates the height maps for all chunks.


writeToFile

public void writeToFile(java.io.File path)
                 throws java.io.IOException
Writes this region to a file.

Parameters:
path - The path to write the file
Throws:
java.io.IOException