Added jungle trees
This commit is contained in:
parent
83c43fb388
commit
ee4864faf8
21
mapgen.lua
21
mapgen.lua
@ -72,6 +72,19 @@ for i, n in ipairs(vmg.noises) do
|
||||
vmg.noises[i] = vmg.define("noise_" .. i, n)
|
||||
end
|
||||
|
||||
vmg.after_mapgen = {}
|
||||
|
||||
function vmg.register_after_mapgen(f, ...)
|
||||
table.insert(vmg.after_mapgen, {f = f, ...})
|
||||
end
|
||||
|
||||
function vmg.execute_after_mapgen()
|
||||
for i, params in ipairs(vmg.after_mapgen) do
|
||||
params.f(unpack(params))
|
||||
end
|
||||
vmg.after_mapgen = {}
|
||||
end
|
||||
|
||||
local average_stone_level = vmg.define("average_stone_level", 180)
|
||||
local dirt_thickness = math.sqrt(average_stone_level) / (vmg.noises[7].offset + 0.5)
|
||||
|
||||
@ -119,6 +132,8 @@ function vmg.generate(minp, maxp, seed)
|
||||
local c_tree = minetest.get_content_id("default:tree")
|
||||
local c_leaves = minetest.get_content_id("default:leaves")
|
||||
local c_apple = minetest.get_content_id("default:apple")
|
||||
local c_jungletree = minetest.get_content_id("default:jungletree")
|
||||
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
|
||||
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
@ -257,6 +272,11 @@ function vmg.generate(minp, maxp, seed)
|
||||
else
|
||||
vmg.grow_tree(pos, data, a, height, radius, c_tree, c_leaves, c_air, c_ignore)
|
||||
end
|
||||
elseif v15 < 0.7 and temp >= 2.5 and humidity > 2 and v16 > -0.1 then
|
||||
local rand = math.random()
|
||||
local height = math.floor(8 + 4 * rand)
|
||||
local radius = 5 + 3 * rand
|
||||
vmg.grow_jungle_tree(pos, data, a, height, radius, c_jungletree, c_jungleleaves, c_air, c_ignore)
|
||||
end
|
||||
y = y - 1
|
||||
end
|
||||
@ -287,6 +307,7 @@ function vmg.generate(minp, maxp, seed)
|
||||
i3d_a = i3d_a - 550399 -- i3d_a = 550401 after the first execution of this loop, it must be 2 before the second.
|
||||
i3d_b = i3d_b - 511999 -- i3d_b = 512001 after the first execution of this loop, it must be 2 before the second.
|
||||
end
|
||||
vmg.execute_after_mapgen()
|
||||
|
||||
local t3 = os.clock()
|
||||
if vmg.loglevel >= 2 then
|
||||
|
@ -98,3 +98,4 @@ register_dirts("Silty")
|
||||
register_dirts("Sandy")
|
||||
|
||||
minetest.add_group("default:leaves", {leafdecay = 5})
|
||||
minetest.add_group("default:jungleleaves", {leafdecay = 8})
|
||||
|
65
trees.lua
65
trees.lua
@ -8,7 +8,7 @@ function default.grow_tree(pos, is_apple_tree)
|
||||
local air = minetest.get_content_id("air")
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local emin, emax = vm:read_from_map({x = pos.x - 3, y = pos.y, z = pos.z - 3}, {x = pos.x + 3, y = pos.y + height + 3, z = pos.z + 3})
|
||||
local emin, emax = vm:read_from_map({x = pos.x - 4, y = pos.y, z = pos.z - 4}, {x = pos.x + 4, y = pos.y + height + 4, z = pos.z + 4})
|
||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||
local data = vm:get_data()
|
||||
if is_apple_tree then
|
||||
@ -21,6 +21,26 @@ function default.grow_tree(pos, is_apple_tree)
|
||||
vm:update_map()
|
||||
end
|
||||
|
||||
function default.grow_jungle_tree(pos)
|
||||
local rand = math.random()
|
||||
local height = math.floor(8 + 4 * rand)
|
||||
local radius = 5 + 3 * rand
|
||||
|
||||
local leaves = minetest.get_content_id("default:jungleleaves")
|
||||
local trunk = minetest.get_content_id("default:jungletree")
|
||||
local air = minetest.get_content_id("air")
|
||||
local ignore = minetest.get_content_id("ignore")
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local emin, emax = vm:read_from_map({x = pos.x - 8, y = pos.y - 1, z = pos.z - 8}, {x = pos.x + 8, y = pos.y + height + 5, z = pos.z + 8})
|
||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||
local data = vm:get_data()
|
||||
vmg.grow_jungle_tree(pos, data, area, height, radius, trunk, leaves, air, ignore)
|
||||
vmg.execute_after_mapgen()
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
vm:update_map()
|
||||
end
|
||||
|
||||
function vmg.grow_tree(pos, data, area, height, radius, trunk, leaves, air, ignore)
|
||||
if vmg.loglevel >= 3 then
|
||||
print("[Valleys Mapgen] Generating tree at " .. minetest.pos_to_string(pos) .. " ...")
|
||||
@ -29,9 +49,7 @@ function vmg.grow_tree(pos, data, area, height, radius, trunk, leaves, air, igno
|
||||
local iv = area:indexp(pos)
|
||||
data[iv] = air
|
||||
for i = 1, height do
|
||||
if data[iv] == air or data[iv] == ignore then
|
||||
data[iv] = trunk
|
||||
end
|
||||
iv = iv + ystride
|
||||
end
|
||||
local np = {offset = 0.8, scale = 0.4, spread = {x = 8, y = 4, z = 8}, octaves = 3, persist = 0.5}
|
||||
@ -47,9 +65,7 @@ function vmg.grow_apple_tree(pos, data, area, height, radius, trunk, leaves, fru
|
||||
local iv = area:indexp(pos)
|
||||
data[iv] = air
|
||||
for i = 1, height do
|
||||
if data[iv] == air or data[iv] == ignore then
|
||||
data[iv] = trunk
|
||||
end
|
||||
iv = iv + ystride
|
||||
end
|
||||
local np = {offset = 0.8, scale = 0.4, spread = {x = 8, y = 4, z = 8}, octaves = 3, persist = 0.5}
|
||||
@ -57,6 +73,45 @@ function vmg.grow_apple_tree(pos, data, area, height, radius, trunk, leaves, fru
|
||||
vmg.make_leavesblob(pos, data, area, leaves, air, ignore, {x = radius, y = radius, z = radius}, np, 0.06, fruit)
|
||||
end
|
||||
|
||||
local function make_jungle_root(x0, y0, z0, data, area, tree, air)
|
||||
local ystride = area.ystride
|
||||
local ybot = y0 - 1
|
||||
for x = x0 - 1, x0 + 1 do
|
||||
for z = z0 - 1, z0 + 1 do
|
||||
local iv = area:index(x, ybot, z)
|
||||
for i = 0, 5 do
|
||||
if data[iv] == air then
|
||||
if math.random() < 0.6 then
|
||||
data[iv-ystride] = tree -- make jungle tree below
|
||||
if math.random() < 0.6 then
|
||||
data[iv] = tree -- make jungle tree at this air node
|
||||
end
|
||||
end
|
||||
break
|
||||
end
|
||||
iv = iv + ystride
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vmg.grow_jungle_tree(pos, data, area, height, radius, trunk, leaves, air, ignore)
|
||||
if vmg.loglevel >= 3 then
|
||||
print("[Valleys Mapgen] Generating jungle tree at " .. minetest.pos_to_string(pos) .. " ...")
|
||||
end
|
||||
local ystride = area.ystride
|
||||
local iv = area:indexp(pos)
|
||||
data[iv] = air
|
||||
for i = 1, height do
|
||||
data[iv] = trunk
|
||||
iv = iv + ystride
|
||||
end
|
||||
vmg.register_after_mapgen(make_jungle_root, pos.x, pos.y, pos.z, data, area, trunk, air)
|
||||
local np = {offset = 0.8, scale = 0.4, spread = {x = 8, y = 4, z = 8}, octaves = 3, persist = 0.8}
|
||||
pos.y = pos.y + height
|
||||
vmg.make_leavesblob(pos, data, area, leaves, air, ignore, {x = radius, y = radius * 0.5, z = radius}, np)
|
||||
end
|
||||
|
||||
function vmg.make_leavesblob(pos, data, area, leaves, air, ignore, radius, np, fruit_chance, fruit)
|
||||
local count = 0
|
||||
fruit_chance = fruit_chance or 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user