fix global errors, remove the leaves remove stuff and delay the growing of coonifers by default
|
@ -0,0 +1,4 @@
|
||||||
|
## Generic ignorable patterns and files
|
||||||
|
*~
|
||||||
|
.*.swp
|
||||||
|
debug.txt
|
|
@ -1 +1,2 @@
|
||||||
default
|
default
|
||||||
|
function_delayer?
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
local load_time_start = os.clock()
|
||||||
|
|
||||||
|
local maxdelay = 1
|
||||||
|
|
||||||
|
|
||||||
|
-- used for the table.sort function
|
||||||
|
local function sort_times(a,b)
|
||||||
|
return a[1] < b[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
local todo = {}
|
||||||
|
function minetest.delay_function(time, func, ...)
|
||||||
|
table.insert(todo, {time, func, {...}})
|
||||||
|
|
||||||
|
-- execute the functions with lower delays earlier
|
||||||
|
table.sort(todo, sort_times)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
local count = #todo
|
||||||
|
|
||||||
|
-- abort if nothing is todo
|
||||||
|
if count == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get the start time
|
||||||
|
local ts = tonumber(os.clock())
|
||||||
|
|
||||||
|
-- execute expired functions
|
||||||
|
local n = 1
|
||||||
|
while n <= count do
|
||||||
|
local time = todo[n][1]
|
||||||
|
time = time-dtime
|
||||||
|
if time <= 0 then
|
||||||
|
local params = todo[n][3]
|
||||||
|
params[#params+1] = time
|
||||||
|
todo[n][2](unpack(params or {}))
|
||||||
|
table.remove(todo, n)
|
||||||
|
count = count-1
|
||||||
|
else
|
||||||
|
todo[n][1] = time
|
||||||
|
n = n+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- abort if too much time is used already
|
||||||
|
if tonumber(os.clock())-ts > maxdelay then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- execute functions until the time limit is reached
|
||||||
|
n = 1
|
||||||
|
while n <= count do
|
||||||
|
local params = todo[n][3]
|
||||||
|
params[#params+1] = todo[n][1]
|
||||||
|
todo[n][2](unpack(params or {}))
|
||||||
|
table.remove(todo, n)
|
||||||
|
count = count-1
|
||||||
|
if tonumber(os.clock())-ts > maxdelay then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
local time = math.floor(tonumber(os.clock()-load_time_start)*100+0.5)/100
|
||||||
|
local msg = "[function_delayer] loaded after ca. "..time
|
||||||
|
if time > 0.05 then
|
||||||
|
print(msg)
|
||||||
|
else
|
||||||
|
minetest.log("info", msg)
|
||||||
|
end
|
79
init.lua
|
@ -11,8 +11,6 @@ local LEAVES_NARROWRADIUS = 3 -- For narrow typed conifers.
|
||||||
local CONIFERS_DISTANCE = 4
|
local CONIFERS_DISTANCE = 4
|
||||||
local CONIFERS_ALTITUDE = 30
|
local CONIFERS_ALTITUDE = 30
|
||||||
|
|
||||||
local REMOVE_TREES = false -- Remove trees above CONIFERS_ALTITUDE? It kills default trees from the top.
|
|
||||||
|
|
||||||
local SAPLING_CHANCE = 100 -- 1/x chances to grow a sapling.
|
local SAPLING_CHANCE = 100 -- 1/x chances to grow a sapling.
|
||||||
|
|
||||||
local INTERVAL = 3600
|
local INTERVAL = 3600
|
||||||
|
@ -22,6 +20,10 @@ local conifers_seed = 1435
|
||||||
-- End of structure definitions.
|
-- End of structure definitions.
|
||||||
|
|
||||||
|
|
||||||
|
if not minetest.delay_function then
|
||||||
|
dofile(minetest.get_modpath("conifers").."/function_delayer.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
conifers = {}
|
conifers = {}
|
||||||
|
|
||||||
|
@ -212,58 +214,65 @@ minetest.register_craft({
|
||||||
-- ABM definitions
|
-- ABM definitions
|
||||||
--
|
--
|
||||||
-- Spawn random conifers.
|
-- Spawn random conifers.
|
||||||
|
|
||||||
local function get_conifers_random(pos)
|
local function get_conifers_random(pos)
|
||||||
return PseudoRandom(math.abs(pos.x+pos.y*3+pos.z*5)+conifers_seed)
|
return PseudoRandom(math.abs(pos.x+pos.y*3+pos.z*5)+conifers_seed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function conifer_abm_rand(pos)
|
||||||
|
local pr = get_conifers_random(pos)
|
||||||
|
local p = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
|
if pr:next(1,23) == 1
|
||||||
|
and minetest.get_node(p).name == "air"
|
||||||
|
and pos.y >= CONIFERS_ALTITUDE
|
||||||
|
and (not conifers:is_node_in_cube({"conifers:trunk"}, pos, CONIFERS_DISTANCE)) then
|
||||||
|
conifers:make_conifer(p, math.random(0, 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function conifer_abm_rand_delay(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if node.name == "default:dirt_with_grass" then
|
||||||
|
conifer_abm_rand(pos, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = "default:dirt_with_grass",
|
nodenames = "default:dirt_with_grass",
|
||||||
interval = INTERVAL,
|
interval = INTERVAL,
|
||||||
chance = 9.1,
|
chance = 9.1,
|
||||||
|
|
||||||
action = function(pos)
|
action = function(pos)
|
||||||
local pr = get_conifers_random(pos)
|
minetest.delay_function(INTERVAL-1, conifer_abm_rand_delay, pos)
|
||||||
local p = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
||||||
if pr:next(1,23) == 1
|
|
||||||
and minetest.get_node(p).name == "air"
|
|
||||||
and pos.y >= CONIFERS_ALTITUDE
|
|
||||||
and (not conifers:is_node_in_cube({"conifers:trunk"}, pos, CONIFERS_DISTANCE)) then
|
|
||||||
conifers:make_conifer(p, math.random(0, 1))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- Saplings.
|
-- Saplings.
|
||||||
|
|
||||||
|
local function conifer_abm_sapling(pos)
|
||||||
|
if minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
||||||
|
conifers:make_conifer(pos, math.random(0, 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function conifer_abm_sapling_delay(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if node.name == "conifers:sapling" then
|
||||||
|
conifer_abm_sapling(pos, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = "conifers:sapling",
|
nodenames = "conifers:sapling",
|
||||||
interval = INTERVAL,
|
interval = INTERVAL,
|
||||||
chance = SAPLING_CHANCE,
|
chance = SAPLING_CHANCE,
|
||||||
|
|
||||||
action = function(pos, node)
|
action = function(pos)
|
||||||
if minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
minetest.delay_function(INTERVAL-1, conifer_abm_sapling_delay, pos)
|
||||||
conifers:make_conifer(pos, math.random(0, 1))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Should we remove all the trees above the conifers altitude?
|
|
||||||
if REMOVE_TREES == true then
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {
|
|
||||||
"default:tree",
|
|
||||||
"default:leaves"
|
|
||||||
},
|
|
||||||
interval = INTERVAL/100,
|
|
||||||
chance = 1,
|
|
||||||
|
|
||||||
action = function(pos, node)
|
|
||||||
if minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air"
|
|
||||||
and pos.y >= CONIFERS_ALTITUDE then
|
|
||||||
minetest.add_node(pos , {name = "air"})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -296,7 +305,7 @@ function conifers:is_node_in_cube(nodenames, pos, size)
|
||||||
for x = pos.x-size, pos.x+size do
|
for x = pos.x-size, pos.x+size do
|
||||||
for y = pos.y-hs, pos.y+hs do
|
for y = pos.y-hs, pos.y+hs do
|
||||||
for z = pos.z-size, pos.z+size do
|
for z = pos.z-size, pos.z+size do
|
||||||
n = minetest.get_node_or_nil({x=x, y=y, z=z})
|
local n = minetest.get_node_or_nil({x=x, y=y, z=z})
|
||||||
if n == nil
|
if n == nil
|
||||||
or n.name == 'ignore'
|
or n.name == 'ignore'
|
||||||
or conifers:table_contains(nodenames, n.name) then
|
or conifers:table_contains(nodenames, n.name) then
|
||||||
|
@ -308,6 +317,8 @@ function conifers:is_node_in_cube(nodenames, pos, size)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local area, nodes
|
||||||
|
|
||||||
--
|
--
|
||||||
-- are_leaves_surrounded(position)
|
-- are_leaves_surrounded(position)
|
||||||
--
|
--
|
||||||
|
|
After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 333 B After Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 367 B After Width: | Height: | Size: 198 B |
Before Width: | Height: | Size: 454 B After Width: | Height: | Size: 230 B |
After Width: | Height: | Size: 498 B |
Before Width: | Height: | Size: 768 B After Width: | Height: | Size: 687 B |
After Width: | Height: | Size: 487 B |