Solved How to make a random, smoothed custom terrain?

Discussion in 'Plugin Development' started by leduyquang753, Dec 11, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    leduyquang753

    Look at this weird world I have just created:
    2017-12-11_21.23.06.png

    Each chunk is a small plains terrain and they are all seperated. But my first thought wasn't that. I wanted to make a custtom world generator which makes a simple, random plains just like Vanilla. So I made some code like this:
    Code:
    public class ChunkGen extends ChunkGenerator {
        public static Random r = new Random(System.nanoTime());
        private int roundup = 0;
        int[][] heightMap = new int[16][16];
    
        private int bilinearInterpolation(int x, int z) {
            float res = 1f / 255f * (
                    heightMap[0][0] * (15-x) * (15-z) +
                    heightMap[15][0] * x * (15-z) +
                    heightMap[0][15] * (15-x) * z +
                    heightMap[15][15] * x * z
            );
            return (int) res;
        }
    
        @Override
        public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
            ChunkData temp = createChunkData(world);
            PerlinNoiseGenerator gen = new PerlinNoiseGenerator(random);
            heightMap[0][0] = (int) Math.round(gen.noise(0, 0)*30+1);
            heightMap[15][0] = (int) Math.round(gen.noise(15, 0)*30+1);
            heightMap[0][15] = (int) Math.round(gen.noise(0, 15)*30+1);
            heightMap[15][15] = (int) Math.round(gen.noise(15, 15)*30+1);
            for (int i = 0; i < 16; i++)
                for (int j = 0; j < 16; j++) {
                    if (!((i==0 && j==0) || (i==0 && j==15) || (i==15 && j==0) || (i==15 && j==15)))
                        heightMap[i][j] = bilinearInterpolation(i,j);
                    temp.setBlock(i, heightMap[i][j], j, Material.GRASS);
                    temp.setBlock(i, heightMap[i][j]-1, j, Material.DIRT);
                    for (int k = heightMap[i][j]-2; (k>heightMap[i][j]-6 && k>0); k--) temp.setBlock(i, k, j, Material.STONE);
                    Material mt = null;
                    for (int k = heightMap[i][j]-6; k>0; k--) {
                        roundup = (int) (Math.round(gen.noise(i, j)+1)*9+1);
                        switch (roundup) {
                        case 9: mt = Material.DIAMOND_ORE;
                        case 1: mt = Material.STONE;
                        case 2: mt = Material.LAPIS_ORE;
                        case 3: mt = Material.STONE;
                        case 4: mt = Material.COAL_ORE;
                        case 5: mt = Material.IRON_ORE;
                        case 6: mt = Material.REDSTONE_ORE;
                        case 7: mt = Material.STONE;
                        case 8: mt = Material.IRON_ORE;
                        case 10: mt = Material.STONE;
                        default: mt = Material.STONE;
                        }
                        temp.setBlock(i, k, j, mt);
                    }
                    temp.setBlock(i, 0, j, Material.BEDROCK);
                }
            return temp;
        }
    }
    But I don't know to connect the chunks up to make a complete, smooth and infinite terrain.
    Any ideas for this please???

    SOLVED: I realized everything! :D I am so inspired now and I am writing a World Generator Plugin Tutorial for everyone wants to make a custom world... :)
     
    Last edited: Dec 13, 2017
Thread Status:
Not open for further replies.

Share This Page