Update/add tree growing
parent
91dd03163b
commit
2e7f7824fa
|
@ -24,42 +24,14 @@ local np_snow = {
|
|||
}
|
||||
|
||||
-- Function
|
||||
|
||||
local function add_conifer(x, y, z, area, data)
|
||||
local top = math.random(12,16)
|
||||
local branch = math.floor(top * 0.5)
|
||||
local aaa = 1
|
||||
for j = 0, top do
|
||||
if j > branch and j <= top and aaa < 1 then -- öeaves
|
||||
aaa = 1
|
||||
local w = top-j-1
|
||||
if w > 3 then w = 3 end
|
||||
for i = -w, w do
|
||||
for k = -w, w do
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
--if math.random(5) ~= 2 then
|
||||
data[vi] = c_needles
|
||||
--end
|
||||
end
|
||||
end
|
||||
elseif aaa > 0 then
|
||||
aaa = 0
|
||||
end
|
||||
if j >= -1 and j <= top - 3 then -- trunk
|
||||
local vi = area:index(x, y + j, z)
|
||||
data[vi] = c_trunk
|
||||
end
|
||||
end
|
||||
local vi = area:index(x, y+top-2, z)
|
||||
data[vi] = c_needles
|
||||
end
|
||||
local grow_conifer = default.grow_conifer
|
||||
|
||||
-- On generated function
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
--[[if minp.y ~= -32 then
|
||||
if minp.y ~= -32 then
|
||||
return
|
||||
end]]
|
||||
end
|
||||
|
||||
if minp.y >= SNOW_START-5 then-- or maxp.y >= SNOW_START then
|
||||
return
|
||||
|
@ -103,7 +75,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||
end
|
||||
end
|
||||
if spawny and math.random(COTCHA) == 2 then
|
||||
add_conifer(x, spawny, z, area, data)
|
||||
grow_conifer(x, spawny, z, area, data)
|
||||
end
|
||||
end
|
||||
nixz = nixz + 1 -- increment 2D noise index
|
||||
|
|
|
@ -50,17 +50,34 @@ minetest.register_abm({
|
|||
interval = 10,
|
||||
chance = 50,
|
||||
action = function(pos, node)
|
||||
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
|
||||
if is_soil == nil or is_soil == 0 then return end
|
||||
print("A jungle sapling grows into a tree at "..minetest.pos_to_string(pos))
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y-1, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16})
|
||||
local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
|
||||
local data = vm:get_data()
|
||||
default.grow_jungletree(data, a, pos, math.random(1,100000))
|
||||
vm:set_data(data)
|
||||
vm:write_to_map(data)
|
||||
vm:update_map()
|
||||
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
|
||||
if is_soil == nil or is_soil == 0 then return end
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y-1, z=pos.z-16}, {x=pos.x+16, y=pos.y+24, z=pos.z+16})
|
||||
local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
|
||||
local data = vm:get_data()
|
||||
default.grow_jungletree(pos.x, pos.y, pos.z, a, data)--pos, math.random(1,100000))(x, y, z, area, data)--(data, a, pos, seed)
|
||||
vm:set_data(data)
|
||||
vm:write_to_map(data)
|
||||
vm:update_map()
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:conifer_sapling"},
|
||||
interval = 10,
|
||||
chance = 50,
|
||||
action = function(pos, node)
|
||||
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil
|
||||
if is_soil == nil or is_soil == 0 then return end
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y-1, z=pos.z-16}, {x=pos.x+16, y=pos.y+17, z=pos.z+16})
|
||||
local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
|
||||
local data = vm:get_data()
|
||||
default.grow_conifer(pos.x, pos.y, pos.z, a, data)
|
||||
vm:set_data(data)
|
||||
vm:write_to_map(data)
|
||||
vm:update_map()
|
||||
end
|
||||
})
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ dofile(minetest.get_modpath("default").."/growing.lua")
|
|||
dofile(minetest.get_modpath("default").."/intweak.lua")
|
||||
dofile(minetest.get_modpath("default").."/craftitems.lua")
|
||||
dofile(minetest.get_modpath("default").."/crafting.lua")
|
||||
dofile(minetest.get_modpath("default").."/trees.lua")
|
||||
dofile(minetest.get_modpath("default").."/jungle.lua")
|
||||
dofile(minetest.get_modpath("default").."/conifers.lua")
|
||||
dofile(minetest.get_modpath("default").."/mapgen.lua")
|
||||
|
@ -31,5 +32,4 @@ dofile(minetest.get_modpath("default").."/armor.lua")
|
|||
dofile(minetest.get_modpath("default").."/hud.lua")
|
||||
dofile(minetest.get_modpath("default").."/hunger.lua")
|
||||
dofile(minetest.get_modpath("default").."/torches.lua")
|
||||
dofile(minetest.get_modpath("default").."/trees.lua")
|
||||
|
||||
|
|
|
@ -41,55 +41,7 @@ rainforest = {}
|
|||
})]]
|
||||
|
||||
-- Function
|
||||
|
||||
local function watershed_jungletree(x, y, z, area, data)
|
||||
if y >= SNOW_START then
|
||||
return
|
||||
end
|
||||
local c_juntree = minetest.get_content_id("default:jungletree")
|
||||
local c_junleaf = minetest.get_content_id("default:jungleleaves")
|
||||
--local c_vine = minetest.get_content_id("rainforest:vine")
|
||||
local top = math.random(17,23)
|
||||
if y+top > SNOW_START then
|
||||
top = SNOW_START - y + math.random(-1,5)
|
||||
end
|
||||
local branch = math.floor(top * 0.6)
|
||||
for j = -5, top do
|
||||
if j == top or j == top - 1 or j == branch + 1 or j == branch + 2 then
|
||||
for i = -2, 2 do -- leaves
|
||||
for k = -2, 2 do
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
if math.random(5) ~= 2 then
|
||||
data[vi] = c_junleaf
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif j <= -1 or j == top - 2 or j == branch then -- branches, roots
|
||||
for i = -1, 1 do
|
||||
for k = -1, 1 do
|
||||
if math.abs(i) + math.abs(k) == 2 then
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
data[vi] = c_juntree
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if j >= 0 and j <= top - 3 then -- climbable nodes
|
||||
for i = -1, 1 do
|
||||
for k = -1, 1 do
|
||||
if math.abs(i) + math.abs(k) == 1 then
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
--data[vi] = c_vine
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if j >= -1 and j <= top - 3 then -- trunk
|
||||
local vi = area:index(x, y + j, z)
|
||||
data[vi] = c_juntree
|
||||
end
|
||||
end
|
||||
end
|
||||
local grow_jungletree = default.grow_jungletree
|
||||
|
||||
-- On generated function
|
||||
local snow_value = SNOW_START/2+3
|
||||
|
@ -151,7 +103,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||
end
|
||||
end
|
||||
if spawny and spawny < snow_value and math.random(JUTCHA) == 2 then
|
||||
watershed_jungletree(x, spawny, z, area, data)
|
||||
grow_jungletree(x, spawny, z, area, data)
|
||||
elseif spawny and spawny < snow_value and math.random(JUGCHA) == 2 then
|
||||
local visp = area:index(x, spawny, z)
|
||||
data[visp] = c_jgrass[math.random(1,2)]
|
||||
|
|
|
@ -287,7 +287,7 @@ minetest.register_node("default:needles", {
|
|||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'default:junglesapling'},
|
||||
items = {'default:conifer_sapling'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
|
@ -300,6 +300,23 @@ minetest.register_node("default:needles", {
|
|||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("default:conifer_sapling", {
|
||||
description = "Conifer Sapling",
|
||||
drawtype = "plantlike",
|
||||
visual_scale = 1.0,
|
||||
tiles = {"default_conifer_sapling.png"},
|
||||
inventory_image = "default_conifer_sapling.png",
|
||||
wield_image = "default_conifer_sapling.png",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
|
||||
},
|
||||
groups = {snappy=2,dig_immediate=3,flammable=2,attached_node=1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("default:junglesapling", {
|
||||
description = "Jungle Sapling",
|
||||
drawtype = "plantlike",
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 253 B |
|
@ -70,81 +70,87 @@ function default.grow_tree(data, a, pos, is_apple_tree, seed)
|
|||
end
|
||||
end
|
||||
|
||||
local c_jungletree = minetest.get_content_id("default:jungletree")
|
||||
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
|
||||
-- jungletree
|
||||
local c_juntree = minetest.get_content_id("default:jungletree")
|
||||
local c_junleaf = minetest.get_content_id("default:jungleleaves")
|
||||
|
||||
function default.grow_jungletree(x, y, z, area, data)
|
||||
if y >= SNOW_START then
|
||||
return
|
||||
end
|
||||
--local c_vine = minetest.get_content_id("rainforest:vine")
|
||||
local top = math.random(17,23)
|
||||
if y+top > SNOW_START then
|
||||
top = SNOW_START - y + math.random(-1,5)
|
||||
end
|
||||
local branch = math.floor(top * 0.6)
|
||||
for j = -5, top do
|
||||
if j == top or j == top - 1 or j == branch + 1 or j == branch + 2 then
|
||||
for i = -2, 2 do -- leaves
|
||||
for k = -2, 2 do
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
if math.random(5) ~= 2 then
|
||||
data[vi] = c_junleaf
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif j <= -1 or j == top - 2 or j == branch then -- branches, roots
|
||||
for i = -1, 1 do
|
||||
for k = -1, 1 do
|
||||
if math.abs(i) + math.abs(k) == 2 then
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
data[vi] = c_juntree
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if j >= 0 and j <= top - 3 then -- climbable nodes
|
||||
for i = -1, 1 do
|
||||
for k = -1, 1 do
|
||||
if math.abs(i) + math.abs(k) == 1 then
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
--data[vi] = c_vine
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if j >= -1 and j <= top - 3 then -- trunk
|
||||
local vi = area:index(x, y + j, z)
|
||||
data[vi] = c_juntree
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- conifer
|
||||
local c_trunk = minetest.get_content_id("default:conifer")
|
||||
local c_needles = minetest.get_content_id("default:needles")
|
||||
|
||||
function default.grow_conifer(x, y, z, area, data)
|
||||
local top = math.random(12,16)
|
||||
local branch = math.floor(top * 0.5)
|
||||
local aaa = 1
|
||||
for j = 0, top do
|
||||
if j > branch and j <= top and aaa < 1 then --leaves
|
||||
aaa = 1
|
||||
local w = top-j-1
|
||||
if w > 3 then w = 3 end
|
||||
for i = -w, w do
|
||||
for k = -w, w do
|
||||
local vi = area:index(x + i, y + j, z + k)
|
||||
--if math.random(5) ~= 2 then
|
||||
data[vi] = c_needles
|
||||
--end
|
||||
end
|
||||
end
|
||||
elseif aaa > 0 then
|
||||
aaa = 0
|
||||
end
|
||||
if j >= -1 and j <= top - 3 then -- trunk
|
||||
local vi = area:index(x, y + j, z)
|
||||
data[vi] = c_trunk
|
||||
end
|
||||
end
|
||||
local vi = area:index(x, y+top-2, z)
|
||||
data[vi] = c_needles
|
||||
end
|
||||
|
||||
function default.grow_jungletree(data, a, pos, seed)
|
||||
--[[
|
||||
NOTE: Tree-placing code is currently duplicated in the engine
|
||||
and in games that have saplings; both are deprecated but not
|
||||
replaced yet
|
||||
]]--
|
||||
local pr = PseudoRandom(seed)
|
||||
local x, y, z = pos.x, pos.y, pos.z
|
||||
for xi = -1, 1 do
|
||||
for zi = -1, 1 do
|
||||
if pr:next(1, 3) >= 2 then
|
||||
local vi1 = a:index(x+xi, y, z+zi)
|
||||
local vi2 = a:index(x+xi, y-1, z+zi)
|
||||
if a:contains(x+xi, y-1, z+zi) and data[vi2] == c_air then
|
||||
data[vi2] = c_jungletree
|
||||
elseif a:contains(x+xi, y, z+zi) and data[vi1] == c_air then
|
||||
data[vi1] = c_jungletree
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local th = pr:next(8, 12)
|
||||
for yy = y, y+th-1 do
|
||||
local vi = a:index(x, yy, z)
|
||||
if a:contains(x, yy, z) and (data[vi] == c_air or yy == y) then
|
||||
data[vi] = c_jungletree
|
||||
end
|
||||
end
|
||||
y = y+th-1 -- (x, y, z) is now last piece of trunk
|
||||
local leaves_a = VoxelArea:new{MinEdge={x=-3, y=-2, z=-3}, MaxEdge={x=3, y=2, z=3}}
|
||||
local leaves_buffer = {}
|
||||
|
||||
-- Force leaves near the trunk
|
||||
local d = 1
|
||||
for xi = -d, d do
|
||||
for yi = -d, d do
|
||||
for zi = -d, d do
|
||||
leaves_buffer[leaves_a:index(xi, yi, zi)] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add leaves randomly
|
||||
for iii = 1, 30 do
|
||||
local d = 1
|
||||
local xx = pr:next(leaves_a.MinEdge.x, leaves_a.MaxEdge.x - d)
|
||||
local yy = pr:next(leaves_a.MinEdge.y, leaves_a.MaxEdge.y - d)
|
||||
local zz = pr:next(leaves_a.MinEdge.z, leaves_a.MaxEdge.z - d)
|
||||
|
||||
for xi = 0, d do
|
||||
for yi = 0, d do
|
||||
for zi = 0, d do
|
||||
leaves_buffer[leaves_a:index(xx+xi, yy+yi, zz+zi)] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add the leaves
|
||||
for xi = leaves_a.MinEdge.x, leaves_a.MaxEdge.x do
|
||||
for yi = leaves_a.MinEdge.y, leaves_a.MaxEdge.y do
|
||||
for zi = leaves_a.MinEdge.z, leaves_a.MaxEdge.z do
|
||||
if a:contains(x+xi, y+yi, z+zi) then
|
||||
local vi = a:index(x+xi, y+yi, z+zi)
|
||||
if data[vi] == c_air or data[vi] == c_ignore then
|
||||
if leaves_buffer[leaves_a:index(xi, yi, zi)] then
|
||||
data[vi] = c_jungleleaves
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue