Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.generator.ChunkGenerator Class Referenceabstract

Classes

interface  BiomeGrid
 

Public Member Functions

byte[] generate (World world, Random random, int x, int z)
 
short[][] generateExtBlockSections (World world, Random random, int x, int z, BiomeGrid biomes)
 
byte[][] generateBlockSections (World world, Random random, int x, int z, BiomeGrid biomes)
 
boolean canSpawn (World world, int x, int z)
 
List< BlockPopulatorgetDefaultPopulators (World world)
 
Location getFixedSpawnLocation (World world, Random random)
 

Detailed Description

A chunk generator is responsible for the initial shaping of an entire chunk. For example, the nether chunk generator should shape netherrack and soulsand

Definition at line 17 of file ChunkGenerator.java.

Member Function Documentation

boolean org.bukkit.generator.ChunkGenerator.canSpawn ( World  world,
int  x,
int  z 
)

Tests if the specified location is valid for a natural spawn position

Parameters
worldThe world we're testing on
xX-coordinate of the block to test
zZ-coordinate of the block to test
Returns
true if the location is valid, otherwise false

Definition at line 230 of file ChunkGenerator.java.

References org.bukkit.World.getBlockAt(), org.bukkit.World.getEnvironment(), org.bukkit.World.getHighestBlockYAt(), and org.bukkit.block.Block.getType().

230  {
231  Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z);
232 
233  switch (world.getEnvironment()) {
234  case NETHER:
235  return true;
236  case THE_END:
237  return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA;
238  case NORMAL:
239  default:
240  return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL;
241  }
242  }
byte [] org.bukkit.generator.ChunkGenerator.generate ( World  world,
Random  random,
int  x,
int  z 
)

Shapes the chunk for the given coordinates.

This method should return a byte[32768] in the following format:

for (int x = 0; x < 16; x++) {
    for (int z = 0; z < 16; z++) {
        for (int y = 0; y < 128; y++) {
            // result[(x * 16 + z) * 128 + y] = ??;
        }
    }
}

Note that this method should never attempt to get the Chunk at the passed coordinates, as doing so may cause an infinite loop

Note this deprecated method will only be called when both generateExtBlockSections() and generateBlockSections() are unimplemented and return null.

Parameters
worldThe world this chunk will be used for
randomThe random generator to use
xThe X-coordinate of the chunk
zThe Z-coordinate of the chunk
Returns
byte[] containing the types for each block created by this generator

Definition at line 75 of file ChunkGenerator.java.

75  {
76  throw new UnsupportedOperationException("Custom generator is missing required methods: generate(), generateBlockSections() and generateExtBlockSections()");
77  }
byte [][] org.bukkit.generator.ChunkGenerator.generateBlockSections ( World  world,
Random  random,
int  x,
int  z,
BiomeGrid  biomes 
)

Shapes the chunk for the given coordinates.

As of 1.2, chunks are represented by a vertical array of chunk sections, each of which is 16 x 16 x 16 blocks. If a section is empty (all zero), the section does not need to be supplied, reducing memory usage.

This method must return a byte[][] array in the following format:

    byte[][] result = new byte[world-height / 16][];

Each section (sectionID = (Y>>4)) that has blocks needs to be allocated space for the 4096 blocks in that section:

    result[sectionID] = new byte[4096];

while sections that are not populated can be left null.

Setting a block at X, Y, Z within the chunk can be done with the following mapping function:

   void setBlock(byte[][] result, int x, int y, int z, byte blkid) {
       if (result[y >> 4) == null) {
           result[y >> 4] = new byte[4096];
       }
       result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
   }

while reading a block ID can be done with the following mapping function:

   byte getBlock(byte[][] result, int x, int y, int z) {
       if (result[y >> 4) == null) {
           return (byte)0;
       }
       return result[y >> 4][((y & 0xF) << 8) | (z << 4) | x];
   }

Note that this method should never attempt to get the Chunk at the passed coordinates, as doing so may cause an infinite loop

Parameters
worldThe world this chunk will be used for
randomThe random generator to use
xThe X-coordinate of the chunk
zThe Z-coordinate of the chunk
biomesProposed biome values for chunk - can be updated by generator
Returns
short[][] containing the types for each block created by this generator
Deprecated:
Magic value

Definition at line 218 of file ChunkGenerator.java.

218  {
219  return null; // Default - returns null, which drives call to generate()
220  }
short [][] org.bukkit.generator.ChunkGenerator.generateExtBlockSections ( World  world,
Random  random,
int  x,
int  z,
BiomeGrid  biomes 
)

Shapes the chunk for the given coordinates, with extended block IDs supported (0-4095).

As of 1.2, chunks are represented by a vertical array of chunk sections, each of which is 16 x 16 x 16 blocks. If a section is empty (all zero), the section does not need to be supplied, reducing memory usage.

This method must return a short[][] array in the following format:

    short[][] result = new short[world-height / 16][];

Each section (sectionID = (Y>>4)) that has blocks needs to be allocated space for the 4096 blocks in that section:

    result[sectionID] = new short[4096];

while sections that are not populated can be left null.

Setting a block at X, Y, Z within the chunk can be done with the following mapping function:

   void setBlock(short[][] result, int x, int y, int z, short blkid) {
       if (result[y >> 4] == null) {
           result[y >> 4] = new short[4096];
       }
       result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
   }

while reading a block ID can be done with the following mapping function:

   short getBlock(short[][] result, int x, int y, int z) {
       if (result[y >> 4] == null) {
           return (short)0;
       }
       return result[y >> 4][((y & 0xF) << 8) | (z << 4) | x];
   }

while sections that are not populated can be left null.

Setting a block at X, Y, Z within the chunk can be done with the following mapping function:

   void setBlock(short[][] result, int x, int y, int z, short blkid) {
       if (result[y >> 4) == null) {
           result[y >> 4] = new short[4096];
       }
       result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
   }

while reading a block ID can be done with the following mapping function:

   short getBlock(short[][] result, int x, int y, int z) {
       if (result[y >> 4) == null) {
           return (short)0;
       }
       return result[y >> 4][((y & 0xF) << 8) | (z << 4) | x];
   }

Note that this method should never attempt to get the Chunk at the passed coordinates, as doing so may cause an infinite loop

Note generators that do not return block IDs above 255 should not implement this method, or should have it return null (which will result in the generateBlockSections() method being called).

Parameters
worldThe world this chunk will be used for
randomThe random generator to use
xThe X-coordinate of the chunk
zThe Z-coordinate of the chunk
biomesProposed biome values for chunk - can be updated by generator
Returns
short[][] containing the types for each block created by this generator
Deprecated:
Magic value

Definition at line 160 of file ChunkGenerator.java.

160  {
161  return null; // Default - returns null, which drives call to generateBlockSections()
162  }
List<BlockPopulator> org.bukkit.generator.ChunkGenerator.getDefaultPopulators ( World  world)

Gets a list of default BlockPopulators to apply to a given world

Parameters
worldWorld to apply to
Returns
List containing any amount of BlockPopulators

Definition at line 251 of file ChunkGenerator.java.

251  {
252  return new ArrayList<BlockPopulator>();
253  }
Location org.bukkit.generator.ChunkGenerator.getFixedSpawnLocation ( World  world,
Random  random 
)

Gets a fixed spawn location to use for a given world.

A null value is returned if a world should not use a fixed spawn point, and will instead attempt to find one randomly.

Parameters
worldThe world to locate a spawn point for
randomRandom generator to use in the calculation
Returns
Location containing a new spawn point, otherwise null

Definition at line 265 of file ChunkGenerator.java.

265  {
266  return null;
267  }

The documentation for this class was generated from the following file: