Class ChunkGenerator

java.lang.Object
org.bukkit.generator.ChunkGenerator

public abstract class ChunkGenerator
extends java.lang.Object
A chunk generator is responsible for the initial shaping of an entire chunk. For example, the nether chunk generator should shape netherrack and soulsand
  • Constructor Details

  • Method Details

    • generate

      @Deprecated public byte[] generate​(World world, java.util.Random random, int x, int z)
      Deprecated.
    • generateExtBlockSections

      @Deprecated public short[][] generateExtBlockSections​(World world, java.util.Random random, int x, int z, ChunkGenerator.BiomeGrid biomes)
      Deprecated.
      Magic value
      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) {}
                  {@code 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) {}
                  {@code 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:
      world - The world this chunk will be used for
      random - The random generator to use
      x - The X-coordinate of the chunk
      z - The Z-coordinate of the chunk
      biomes - Proposed biome values for chunk - can be updated by generator
      Returns:
      short[][] containing the types for each block created by this generator
    • generateBlockSections

      @Deprecated public byte[][] generateBlockSections​(World world, java.util.Random random, int x, int z, ChunkGenerator.BiomeGrid biomes)
      Deprecated.
      Magic value
      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) {}
                  {@code 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:
      world - The world this chunk will be used for
      random - The random generator to use
      x - The X-coordinate of the chunk
      z - The Z-coordinate of the chunk
      biomes - Proposed biome values for chunk - can be updated by generator
      Returns:
      short[][] containing the types for each block created by this generator
    • generateChunkData

      public ChunkGenerator.ChunkData generateChunkData​(World world, java.util.Random random, int x, int z, ChunkGenerator.BiomeGrid biome)
      Shapes the chunk for the given coordinates. This method must return a ChunkData.

      Notes:

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

      This method should never modify a ChunkData after it has been returned.

      This method must return a ChunkData returned by createChunkData(org.bukkit.World)

      Parameters:
      world - The world this chunk will be used for
      random - The random generator to use
      x - The X-coordinate of the chunk
      z - The Z-coordinate of the chunk
      biome - Proposed biome values for chunk - can be updated by generator
      Returns:
      ChunkData containing the types for each block created by this generator
    • createChunkData

      protected final ChunkGenerator.ChunkData createChunkData​(World world)
      Create a ChunkData for a world.
      Parameters:
      world - the world the ChunkData is for
      Returns:
      a new ChunkData for world
    • canSpawn

      public boolean canSpawn​(World world, int x, int z)
      Tests if the specified location is valid for a natural spawn position
      Parameters:
      world - The world we're testing on
      x - X-coordinate of the block to test
      z - Z-coordinate of the block to test
      Returns:
      true if the location is valid, otherwise false
    • getDefaultPopulators

      public java.util.List<BlockPopulator> getDefaultPopulators​(World world)
      Gets a list of default BlockPopulators to apply to a given world
      Parameters:
      world - World to apply to
      Returns:
      List containing any amount of BlockPopulators
    • getFixedSpawnLocation

      public Location getFixedSpawnLocation​(World world, java.util.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:
      world - The world to locate a spawn point for
      random - Random generator to use in the calculation
      Returns:
      Location containing a new spawn point, otherwise null