package dk.thoerup.bukkit.waterworld; import java.util.*; import org.bukkit.block.*; import org.bukkit.generator.*; import org.bukkit.*; public class WaterGenerator extends ChunkGenerator { //This needs to be set to return true to override minecraft's default behaviour @Override public boolean canSpawn(World world, int x, int z) { return true; } //This converts relative chunk locations to bytes that can be written to the chunk public int xyzToByte(int x, int y, int z) { return (x * 16 + z) * 128 + y; } @Override public byte[] generate(World world, Random rand, int chunkx, int chunkz) { byte result[] = new byte[32768]; //This will set the floor of each chunk at bedrock level to bedrock for(int x=0; x<16; x++){ for(int z=0; z<16; z++) { int y=0; for (y=0; y<6; y++) { result[xyzToByte(x,y,z)] = (byte) Material.BEDROCK.getId(); } for (y=6; y<48; y++) { result[xyzToByte(x,y,z)] = (byte) Material.SAND.getId(); } for (y=48; y<65; y++) { result[xyzToByte(x,y,z)] = (byte) Material.WATER.getId(); } } } return result; } /* @Override public List getDefaultPopulators(World world) { return Arrays.asList((BlockPopulator) new ChessPopulator()); } class ChessPopulator extends BlockPopulator { @Override public void populate(World world, Random random, Chunk source) { for (int x=0; x<16; x++) { for (int z=0; z<16; z++) { Block b = source.getBlock(x,64,z); if ( ( (x+z) % 2) == 0) { b.setData( (byte)0 ); } else { b.setData( (byte)15 ); } } } } } */ }