Advertisement
Guest User

CustomChunkGenerator

a guest
Jun 9th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.61 KB | None | 0 0
  1. public class CustomChunkGenerator extends ChunkGenerator {
  2.  
  3.     @Override
  4.     public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
  5.  
  6.         int currentHeight;
  7.  
  8.         int heightDifference = 30;
  9.         int minHeight = 40;
  10.  
  11.         ChunkData chunk = createChunkData(world);
  12.  
  13.         SimplexOctaveGenerator generator = new SimplexOctaveGenerator(new Random(world.getSeed()), 8);
  14.  
  15.         //How steep the terrain should be
  16.         generator.setScale(0.008D);
  17.  
  18.  
  19.         if (biomeGrid.getBiome(7, minHeight, 7) == Biome.MOUNTAINS) {
  20.             generator.setScale(0.01D);
  21.         }
  22.  
  23.         //Generate blocks
  24.         for (int x = 0; x < 16; x++) {
  25.             for (int z = 0; z < 16; z++) {
  26.  
  27.                 Biome biome = biomeGrid.getBiome(x, minHeight, z);
  28.  
  29.                 //Set bottom to bedrock
  30.                 chunk.setBlock(x, 0, z, Material.BEDROCK);
  31.  
  32.                 currentHeight = (int) ((generator.noise(chunkX * 16 + x, chunkZ * 16 + z, 0.5D, 0.5D, true) + 1) * heightDifference + minHeight);
  33.  
  34.                 //Replace ocean biomes with plains
  35.                 if (biome == Biome.OCEAN || biome == Biome.DEEP_OCEAN || biome == Biome.FROZEN_OCEAN || biome == Biome.DEEP_FROZEN_OCEAN
  36.                         || biome == Biome.WARM_OCEAN || biome == Biome.DEEP_WARM_OCEAN || biome == Biome.COLD_OCEAN || biome == Biome.DEEP_COLD_OCEAN
  37.                         || biome == Biome.LUKEWARM_OCEAN || biome == Biome.DEEP_LUKEWARM_OCEAN) {
  38.  
  39.                     biomeGrid.setBiome(x, z, Biome.PLAINS);
  40.                 }
  41.  
  42.                 //Set water below water level and set biome to ocean
  43.                 if (currentHeight < 62) {
  44.                     for (int i = currentHeight + 1; i < 63; i++) {
  45.                         chunk.setBlock(x, i, z, Material.WATER);
  46.                     }
  47.  
  48.                     biomeGrid.setBiome(x, z, Biome.OCEAN);
  49.  
  50.                     chunk.setBlock(x, currentHeight, z, Material.SAND);
  51.                     chunk.setBlock(x, currentHeight - 1, z, Material.SAND);
  52.                 }
  53.  
  54.                 else if (biome == Biome.DESERT || biome == Biome.DESERT_HILLS || biome == Biome.DESERT_LAKES) {
  55.                     chunk.setBlock(x, currentHeight, z, Material.SAND);
  56.                     chunk.setBlock(x, currentHeight - 1, z, Material.SANDSTONE);
  57.  
  58.                     if (random.nextBoolean()) {
  59.                         chunk.setBlock(x, currentHeight - 2, z, Material.SANDSTONE);
  60.                     }
  61.  
  62.                 } else {
  63.                     chunk.setBlock(x, currentHeight, z, Material.GRASS_BLOCK);
  64.                     chunk.setBlock(x, currentHeight - 1, z, Material.DIRT);
  65.                 }
  66.  
  67.                 //Set all blocks under ground to stone
  68.                 for (int i = currentHeight - 2; i > 0; i--) {
  69.                     if (chunk.getType(x, i, z) == Material.AIR) {
  70.                         chunk.setBlock(x, i, z, Material.STONE);
  71.                     }
  72.                 }
  73.  
  74.             }
  75.         }
  76.  
  77.         return chunk;
  78.  
  79.     }
  80.  
  81.     @Override
  82.     public List<BlockPopulator> getDefaultPopulators(World world) {
  83.         return Arrays.asList(new LakePopulator(),
  84.                 new GrassPopulator(), new TreePopulator(),
  85.                 new OrePopulator(), new CavePopulator(),
  86.                 new DesertPopulator());
  87.     }
  88.  
  89.  
  90.     @Override
  91.     public Location getFixedSpawnLocation(World world, Random random) {
  92.         int x = random.nextInt(200) - 100;
  93.         int z = random.nextInt(200) - 100;
  94.         int y = world.getHighestBlockYAt(x, z);
  95.         return new Location(world, x, y, z);
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement