diff options
author | Mike Primm <mike@primmhome.com> | 2012-03-08 23:45:28 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-09 11:48:03 -0500 |
commit | 450b20bdc2f6fff2928f71a212eec9f3278a5288 (patch) | |
tree | 38aefe9a244efa26291a7a73df722be77a511a2a /src/main | |
parent | cb46f4b8fe3e8484c9343c9bd235a3fb322604c8 (diff) | |
download | bukkit-450b20bdc2f6fff2928f71a212eec9f3278a5288.tar bukkit-450b20bdc2f6fff2928f71a212eec9f3278a5288.tar.gz bukkit-450b20bdc2f6fff2928f71a212eec9f3278a5288.tar.lz bukkit-450b20bdc2f6fff2928f71a212eec9f3278a5288.tar.xz bukkit-450b20bdc2f6fff2928f71a212eec9f3278a5288.zip |
[Bleeding] Update generator interface for new generate methods. Addresses BUKKIT-874
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/generator/ChunkGenerator.java | 103 |
1 files changed, 102 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/generator/ChunkGenerator.java b/src/main/java/org/bukkit/generator/ChunkGenerator.java index 6847e3f5..db579cdc 100644 --- a/src/main/java/org/bukkit/generator/ChunkGenerator.java +++ b/src/main/java/org/bukkit/generator/ChunkGenerator.java @@ -6,6 +6,7 @@ import java.util.Random; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.block.Block; /** @@ -14,6 +15,29 @@ import org.bukkit.block.Block; */ public abstract class ChunkGenerator { /** + * Interface to biome data for chunk to be generated: initialized with default values for world type and seed. + * + * Custom generator is free to access and tailor values during generateBlockSections() or generateExtBlockSections(). + */ + public interface BiomeGrid { + /** + * Get biome at x, z within chunk being generated + * @param x - 0-15 + * @param z - 0-15 + * @return Biome value + */ + Biome getBiome(int x, int z); + /** + * Set biome at x, z within chunk being generated + * + * @param x - 0-15 + * @param z - 0-15 + * @param bio - Biome value + */ + void setBiome(int x, int z, Biome bio); + } + @Deprecated + /** * Shapes the chunk for the given coordinates.<br /> * <br /> * This method should return a byte[32768] in the following format: @@ -31,13 +55,90 @@ public abstract class ChunkGenerator { * Note that this method should <b>never</b> 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. + * @param world The world this chunk will be used for * @param random The random generator to use * @param x The X-coordinate of the chunk * @param z The Z-coordinate of the chunk * @return byte[] containing the types for each block created by this generator */ - public abstract byte[] generate(World world, Random random, int x, int z); + public byte[] generate(World world, Random random, int x, int z) { + throw new UnsupportedOperationException("Custom generator is missing required methods: generate(), generateBlockSections() and generateExtBlockSections()"); + } + + /** + * Shapes the chunk for the given coordinates.<br /> + * <br /> + * This method should return a short[][] array in the following format: + * + * <pre> + * result[y >> 4] = null IF the 16x16x16 section from y to y+15 is empty + * result[y >> 4] = new short[4096] if the section has any non-empty blocks + * + * within the section: + * + * for (int x = 0; x < 16; x++) { + * for (int z = 0; z < 16; z++) { + * for (int yy = y & 0xF; yy < 16; yy++) { + * result[(yy << 8) | (z << 4) | x] = ??; + * } + * } + * } + * </pre> + * + * Note that this method should <b>never</b> 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). + * + * @param world The world this chunk will be used for + * @param random The random generator to use + * @param x The X-coordinate of the chunk + * @param z The Z-coordinate of the chunk + * @param biomes Proposed biome values for chunk - can be updated by generator + * @return short[][] containing the types for each block created by this generator + */ + public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) { + return null; // Default - returns null, which drives call to generateBlockSections() + } + + /** + * Shapes the chunk for the given coordinates.<br /> + * <br /> + * This method should return a byte[][] array in the following format: + * + * <pre> + * result[y >> 4] = null IF the 16x16x16 section from y to y+15 is empty + * result[y >> 4] = new byte[4096] if the section has any non-empty blocks + * + * within the section: + * + * for (int x = 0; x < 16; x++) { + * for (int z = 0; z < 16; z++) { + * for (int yy = y & 0xF; yy < 16; yy++) { + * result[(yy << 8) | (z << 4) | x] = ??; + * } + * } + * } + * </pre> + * + * Note that this method should <b>never</b> attempt to get the Chunk at + * the passed coordinates, as doing so may cause an infinite loop + * + * @param world The world this chunk will be used for + * @param random The random generator to use + * @param x The X-coordinate of the chunk + * @param z The Z-coordinate of the chunk + * @param biomes Proposed biome values for chunk - can be updated by generator + * @return short[][] containing the types for each block created by this generator + */ + public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) { + return null; // Default - returns null, which drives call to generate() + } /** * Tests if the specified location is valid for a natural spawn position |