blob: ee7ece9ab3178d6217d7553ceb1bdb841afd39cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "Generator.hpp"
#include "../Math/Noise.hpp"
namespace MC::World {
Chunk Generator::generate(int64_t chunk_x, int64_t chunk_y) {
Chunk chunk(chunk_x, chunk_y);
uint8_t extent = 60;
uint8_t base = 4;
for (int x = 0; x < CHUNK_WIDTH; x++) {
for (int z = 0; z < CHUNK_WIDTH; z++) {
float noise = Math::noise2d(
{(float)chunk_x * CHUNK_WIDTH + x, (float)chunk_y * CHUNK_WIDTH + z}
) * extent + base;
uint height = std::round(noise);
for (int y = 0; y < CHUNK_HEIGHT; y++) {
BlockType type = BlockType::Air;
if (y < height) {
type = BlockType::Dirt;
} else if (y == height) {
type = BlockType::Grass;
}
chunk.set(x, y, z, type);
}
}
}
return chunk;
}
}
|