From 9f7aa76c4fc5b1e8d6cde5111b129eba3afef4c6 Mon Sep 17 00:00:00 2001 From: HeroOfTheWinds Date: Thu, 15 May 2014 14:38:14 -1000 Subject: [PATCH] Cause trees to spawn, set time to 4500 Single trees now spawn here and there . --- mods/mapgen/init.lua | 40 ++++++++++++++++++++++++++++++++++++++++ mods/sky/init.lua | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/mods/mapgen/init.lua b/mods/mapgen/init.lua index a1593a76..f8927c54 100644 --- a/mods/mapgen/init.lua +++ b/mods/mapgen/init.lua @@ -54,6 +54,27 @@ minetest.register_alias("mapgen_water_source", "moontest:hlsource") minetest.register_alias("mapgen_stone", "moontest:stone") minetest.register_alias("mapgen_dirt", "moontest:dust") +--treegen function +local function moontest_tree(x, y, z, area, data) + + local c_tree = minetest.get_content_id("default:tree") + local c_leaves = minetest.get_content_id("default:leaves") + for j = -2, 4 do + if j >= 1 then + for i = -2, 2 do + for k = -2, 2 do + local vi = area:index(x + i, y + j + 1, z + k) + if math.random(3) ~= 2 then + data[vi] = c_leaves + end + end + end + end + local vi = area:index(x, y + j, z) + data[vi] = c_tree + end +end + --Set everything to vacuum on generate minetest.register_on_generated(function(minp, maxp, seed) local x1 = maxp.x @@ -69,6 +90,7 @@ minetest.register_on_generated(function(minp, maxp, seed) --get the content ID #'s of air and vacuum local c_air = minetest.get_content_id("air") local c_vac = minetest.get_content_id("moontest:vacuum") + local c_dust = minetest.get_content_id("moontest:dust") --loop through every node of the chunk for z = z0, z1 do for x = x0, x1 do @@ -80,6 +102,24 @@ minetest.register_on_generated(function(minp, maxp, seed) data[vi] = c_vac end end + --gen trees + --find surface + local yasurf = false -- y of above surface node + for y = y1, 2, -1 do --decrement, not increment + local vi = area:index(x, y, z) + local c_node = data[vi] + if y == y1 and c_node ~= c_vac then -- if top node solid + break + elseif c_node == c_dust then --if first surface node + yasurf = y + 1 --set the position of the surface + break + end + end + if yasurf then --if surface was found + if math.random() <= 0.0001337 then --much LEET + moontest_tree(x, yasurf+1, z, area, data)--place a tree + end + end end end --write the voxel manipulator data back to world diff --git a/mods/sky/init.lua b/mods/sky/init.lua index 06ddafde..37f612c5 100644 --- a/mods/sky/init.lua +++ b/mods/sky/init.lua @@ -1,7 +1,7 @@ -- Set time to midnight. minetest.register_on_joinplayer(function(player) - minetest.set_timeofday(5000) + minetest.set_timeofday(4500) minetest.setting_set("time_speed", 0) end)