From a01108411944e8060540ff7887e0adf514eb6a41 Mon Sep 17 00:00:00 2001 From: DemiPixel Date: Fri, 9 Oct 2015 09:15:57 -0700 Subject: [PATCH 1/2] Added waterline + dirt/bedrock height --- src/lib/worldGenerations/diamond_square.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/worldGenerations/diamond_square.js b/src/lib/worldGenerations/diamond_square.js index 4417bbc..7c7cc22 100644 --- a/src/lib/worldGenerations/diamond_square.js +++ b/src/lib/worldGenerations/diamond_square.js @@ -97,6 +97,7 @@ function generation({seed,worldHeight=80}={}) { // Selected empirically var size = 10000000; var space = new DiamondSquare(size, size / 1000, seed); + var waterline = 20; function generateSimpleChunk(chunkX, chunkZ) { var chunk = new Chunk(); @@ -107,15 +108,19 @@ function generation({seed,worldHeight=80}={}) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { var level = Math.floor(space.value(worldX + x, worldZ + z) * worldHeight); + var dirtheight = level - 4 + Math.round(Math.random()*2); + var bedrockheight = 1 + Math.round(Math.random()*3) for (var y = 0; y < 256; y++) { let block; - if (y == 0) block = 7; - else if (y < level) block = 3; - else if (y == level) block = 2; - else if (y < 20) block = 9; + var surfaceblock = level < waterline ? 12 : 2; // Sand below water, grass + var belowblock = level < waterline ? 12 : 3; // 3-5 blocks below surface - if (block) chunk.setBlockType(new Vec3(x, y, z), block); + if (y < bedrockheight) block = 7; // Solid bedrock at bottom + else if (y < level && y >= dirtheight) block = belowblock; // Dirt/sand below surface + else if (y < level) block = 1; // Set stone inbetween + else if (y == level) block = surfaceblock; // Set surface sand/grass + else if (y <= waterline) block = 9; // Set the water chunk.setSkyLight(new Vec3(x, y, z), 15); } From 075fb7332fa690d7c420495e09f1c0ee40628641 Mon Sep 17 00:00:00 2001 From: DemiPixel Date: Fri, 9 Oct 2015 09:31:34 -0700 Subject: [PATCH 2/2] Added grass, fixed waterline to match the other commit --- src/lib/worldGenerations/diamond_square.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/worldGenerations/diamond_square.js b/src/lib/worldGenerations/diamond_square.js index 7c7cc22..f00c570 100644 --- a/src/lib/worldGenerations/diamond_square.js +++ b/src/lib/worldGenerations/diamond_square.js @@ -93,11 +93,10 @@ function DiamondSquare(size, roughness, seed) { } } -function generation({seed,worldHeight=80}={}) { +function generation({seed,worldHeight=80,waterline=20}={}) { // Selected empirically var size = 10000000; var space = new DiamondSquare(size, size / 1000, seed); - var waterline = 20; function generateSimpleChunk(chunkX, chunkZ) { var chunk = new Chunk(); @@ -112,6 +111,7 @@ function generation({seed,worldHeight=80}={}) { var bedrockheight = 1 + Math.round(Math.random()*3) for (var y = 0; y < 256; y++) { let block; + let data; var surfaceblock = level < waterline ? 12 : 2; // Sand below water, grass var belowblock = level < waterline ? 12 : 3; // 3-5 blocks below surface @@ -121,8 +121,16 @@ function generation({seed,worldHeight=80}={}) { else if (y < level) block = 1; // Set stone inbetween else if (y == level) block = surfaceblock; // Set surface sand/grass else if (y <= waterline) block = 9; // Set the water + else if (y == level + 1 && level >= waterline && Math.random() < 0.1) { + block = 31; + data = 1; + } + // Add grass/more flowers/changes later - chunk.setSkyLight(new Vec3(x, y, z), 15); + var pos = new Vec3(x, y, z); + chunk.setBlockType(pos, block) + if (data) chunk.setBlockData(pos, data); + chunk.setSkyLight(pos, 15); } } }