1 local stone = BlockSystem:get_def("game:stone")
2 local dirt = BlockSystem:get_def("game:dirt")
3 local grass = BlockSystem:get_def("game:grass")
4 local leaves = BlockSystem:get_def("game:leaves")
5 local tree = BlockSystem:get_def("game:tree")
7 math.randomseed(os.time())
9 function MapGen:generate(chunk)
10 local grass_layer_table, old_grass_layer_table
13 grass_layer_table, old_grass_layer_table = {}, grass_layer_table
14 grass_layer = old_grass_layer_table and old_grass_layer_table[1] or 8 + math.random(5)
16 local old_grass_layer = old_grass_layer_table and old_grass_layer_table[z] or grass_layer
17 grass_layer = math.floor((grass_layer + old_grass_layer) / 2)
18 if math.random(3) == 1 then
19 grass_layer = grass_layer + math.random(3) - 2
21 grass_layer = glm.clamp(grass_layer, 0, 15)
22 grass_layer_table[z] = grass_layer
23 if math.random(25) == 1 then
24 chunk:add_block(glm.vec3(x, grass_layer, z), dirt)
25 self:add_tree(chunk, glm.vec3(x, grass_layer + 1, z))
27 chunk:add_block(glm.vec3(x, grass_layer, z), grass)
29 local dirt_start, dirt_end = grass_layer - 1, math.max(grass_layer - 5, 0)
30 local stone_start, stone_end = grass_layer - 6, 0
31 if dirt_start >= 0 then
32 for y = dirt_start, dirt_end, -1 do
33 chunk:add_block(glm.vec3(x, y, z), dirt)
36 if stone_start >= 0 then
37 for y = stone_start, stone_end, -1 do
38 chunk:add_block(glm.vec3(x, y, z), stone)
77 function MapGen:add_tree(chunk, tree_pos)
78 for i, p in ipairs(tree_blocks) do
83 local pos = tree_pos + p
84 if chunk:get_pos_hash(pos) then
85 chunk:add_block(pos, block)