Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomChunkGenerator extends ChunkGenerator {
- @Override
- public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
- int currentHeight;
- int heightDifference = 30;
- int minHeight = 40;
- ChunkData chunk = createChunkData(world);
- SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
- //How steep the terrain should be
- generator.setScale(0.008D);
- if (biomeGrid.getBiome(7, minHeight, 7) == Biome.MOUNTAINS) {
- generator.setScale(0.01D);
- }
- //Generate blocks
- for (int x = 0; x < 16; x++) {
- for (int z = 0; z < 16; z++) {
- Biome biome = biomeGrid.getBiome(x, minHeight, z);
- //Set bottom to bedrock
- chunk.setBlock(x, 0, z, Material.BEDROCK);
- currentHeight = (int) ((generator.noise(chunkX * 16 + x, chunkZ * 16 + z, 0.5D, 0.5D, true) + 1) * heightDifference + minHeight);
- //Replace ocean biomes with plains
- if (biome == Biome.OCEAN || biome == Biome.DEEP_OCEAN || biome == Biome.FROZEN_OCEAN || biome == Biome.DEEP_FROZEN_OCEAN
- || biome == Biome.WARM_OCEAN || biome == Biome.DEEP_WARM_OCEAN || biome == Biome.COLD_OCEAN || biome == Biome.DEEP_COLD_OCEAN
- || biome == Biome.LUKEWARM_OCEAN || biome == Biome.DEEP_LUKEWARM_OCEAN) {
- biomeGrid.setBiome(x, z, Biome.PLAINS);
- }
- //Set water below water level and set biome to ocean
- if (currentHeight < 62) {
- for (int i = currentHeight + 1; i < 63; i++) {
- chunk.setBlock(x, i, z, Material.WATER);
- }
- biomeGrid.setBiome(x, z, Biome.OCEAN);
- chunk.setBlock(x, currentHeight, z, Material.SAND);
- chunk.setBlock(x, currentHeight - 1, z, Material.SAND);
- }
- else if (biome == Biome.DESERT || biome == Biome.DESERT_HILLS || biome == Biome.DESERT_LAKES) {
- chunk.setBlock(x, currentHeight, z, Material.SAND);
- chunk.setBlock(x, currentHeight - 1, z, Material.SANDSTONE);
- if (random.nextBoolean()) {
- chunk.setBlock(x, currentHeight - 2, z, Material.SANDSTONE);
- }
- } else {
- chunk.setBlock(x, currentHeight, z, Material.GRASS_BLOCK);
- chunk.setBlock(x, currentHeight - 1, z, Material.DIRT);
- }
- //Set all blocks under ground to stone
- for (int i = currentHeight - 2; i > 0; i--) {
- if (chunk.getType(x, i, z) == Material.AIR) {
- chunk.setBlock(x, i, z, Material.STONE);
- }
- }
- }
- }
- return chunk;
- }
- @Override
- public List<BlockPopulator> getDefaultPopulators(World world) {
- return Arrays.asList(new LakePopulator(),
- new GrassPopulator(), new TreePopulator(),
- new OrePopulator(), new CavePopulator(),
- new DesertPopulator());
- }
- @Override
- public Location getFixedSpawnLocation(World world, Random random) {
- int x = random.nextInt(200) - 100;
- int z = random.nextInt(200) - 100;
- int y = world.getHighestBlockYAt(x, z);
- return new Location(world, x, y, z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement