Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 87 lines 3.1 kB view raw
1package org.bukkit.generator; 2 3import org.bukkit.Location; 4import org.bukkit.Material; 5import org.bukkit.World; 6import org.bukkit.block.Block; 7 8import java.util.ArrayList; 9import java.util.List; 10import java.util.Random; 11 12/** 13 * A chunk generator is responsible for the initial shaping of an entire chunk. 14 * For example, the nether chunk generator should shape netherrack and soulsand 15 */ 16public abstract class ChunkGenerator { 17 /** 18 * Shapes the chunk for the given coordinates.<br /> 19 * <br /> 20 * This method should return a byte[32768] in the following format: 21 * <pre> 22 * for (int x = 0; x < 16; x++) { 23 * for (int z = 0; z < 16; z++) { 24 * for (int y = 0; y < 128; y++) { 25 * // result[(x * 16 + z) * 128 + y] = ??; 26 * } 27 * } 28 * } 29 * </pre> 30 * <p> 31 * Note that this method should <b>never</b> attempt to get the Chunk at 32 * the passed coordinates, as doing so may cause an infinite loop 33 * 34 * @param world The world this chunk will be used for 35 * @param random The random generator to use 36 * @param x The X-coordinate of the chunk 37 * @param z The Z-coordinate of the chunk 38 * @return byte[] containing the types for each block created by this generator 39 */ 40 public abstract byte[] generate(World world, Random random, int x, int z); 41 42 /** 43 * Tests if the specified location is valid for a natural spawn position 44 * 45 * @param world The world we're testing on 46 * @param x X-coordinate of the block to test 47 * @param z Z-coordinate of the block to test 48 * @return true if the location is valid, otherwise false 49 */ 50 public boolean canSpawn(World world, int x, int z) { 51 Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z); 52 53 switch (world.getEnvironment()) { 54 case NETHER: 55 return true; 56 case SKYLANDS: 57 return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA; 58 case NORMAL: 59 default: 60 return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL; 61 } 62 } 63 64 /** 65 * Gets a list of default {@link BlockPopulator}s to apply to a given world 66 * 67 * @param world World to apply to 68 * @return List containing any amount of BlockPopulators 69 */ 70 public List<BlockPopulator> getDefaultPopulators(World world) { 71 return new ArrayList<BlockPopulator>(); 72 } 73 74 /** 75 * Gets a fixed spawn location to use for a given world. 76 * <p> 77 * A null value is returned if a world should not use a fixed spawn point, 78 * and will instead attempt to find one randomly. 79 * 80 * @param world The world to locate a spawn point for 81 * @param random Random generator to use in the calculation 82 * @return Location containing a new spawn point, otherwise null 83 */ 84 public Location getFixedSpawnLocation(World world, Random random) { 85 return null; 86 } 87}