mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-17 07:50:29 +01:00
Updated plantlife
This commit is contained in:
parent
e88cf46770
commit
b9c5b1af5e
|
@ -30,35 +30,45 @@ minetest.register_craft({
|
||||||
-- these ABMs can get heavy, so just enqueue the nodes
|
-- these ABMs can get heavy, so just enqueue the nodes
|
||||||
|
|
||||||
-- Adding Blossoms
|
-- Adding Blossoms
|
||||||
|
-- Limit mass changes after block has not been loaded for some time:
|
||||||
|
-- Run ABM with higher frequency, but don't enqueue all blocks
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { nature.blossom_leaves },
|
nodenames = { nature.blossom_leaves },
|
||||||
interval = nature.blossom_delay,
|
interval = nature.blossom_delay / nature.leaves_blossom_chance,
|
||||||
chance = nature.blossom_chance,
|
chance = nature.leaves_blossom_chance,
|
||||||
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
nature.enqueue_node(pos, node, true)
|
if math.random(nature.leaves_blossom_chance) == 1 then
|
||||||
|
nature.enqueue_node(pos, node, nature.blossom_node)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Removing blossoms
|
-- Removing blossoms
|
||||||
|
-- Limit mass changes after block has not been loaded for some time:
|
||||||
|
-- Run ABM with higher frequency, but don't enqueue all blocks
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { nature.blossom_node },
|
nodenames = { nature.blossom_node },
|
||||||
interval = nature.blossom_delay,
|
interval = nature.blossom_delay / nature.blossom_leaves_chance,
|
||||||
chance = nature.blossom_chance,
|
chance = nature.blossom_leaves_chance,
|
||||||
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
nature.enqueue_node(pos, node, false)
|
if math.random(nature.blossom_leaves_chance) == 1 then
|
||||||
|
nature.enqueue_node(pos, node, nature.blossom_leaves)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Spawning apples
|
-- Spawning apples
|
||||||
|
-- Limit mass changes after block has not been loaded for some time:
|
||||||
|
-- spawn apples with 10% chance, but with 10 times higher frequency
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { nature.blossom_node },
|
nodenames = { nature.blossom_node },
|
||||||
interval = nature.blossom_delay,
|
interval = nature.blossom_delay / 10,
|
||||||
chance = nature.apple_chance,
|
chance = nature.apple_chance,
|
||||||
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
if nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then
|
if math.random(10) == 0 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then
|
||||||
spawn_apple_under(pos)
|
spawn_apple_under(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,44 +1,64 @@
|
||||||
-- helper functions
|
-- helper functions
|
||||||
|
|
||||||
|
local function process_blossom_queue_item()
|
||||||
|
local pos = nature.blossomqueue[1][1]
|
||||||
|
local node = nature.blossomqueue[1][2]
|
||||||
|
local replace = nature.blossomqueue[1][3]
|
||||||
|
if (nature.blossomqueue[1][3] == nature.blossom_node and not nature:is_near_water(pos)) then
|
||||||
|
table.remove(nature.blossomqueue, 1) -- don't grow if it's not near water, pop from queue.
|
||||||
|
return
|
||||||
|
end
|
||||||
|
nature:grow_node(pos, replace) -- now actually grow it.
|
||||||
|
table.remove(nature.blossomqueue, 1)
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
nature.dtime = dtime
|
nature.dtime = dtime
|
||||||
if #nature.blossomqueue > 0 and dtime < 0.2 then
|
if #nature.blossomqueue > 0 and dtime < 0.2 then
|
||||||
local pos = nature.blossomqueue[1][1]
|
local i = 1
|
||||||
local node = nature.blossomqueue[1][2]
|
if dtime < 0.1 then
|
||||||
if (nature.blossomqueue[1][3] and not nature:is_near_water(pos)) then
|
i = i + 4
|
||||||
table.remove(nature.blossomqueue, 1) -- don't grow if it's not near water, pop from queue.
|
end
|
||||||
return
|
if dtime < 0.05 then
|
||||||
|
i = i + 10
|
||||||
|
end
|
||||||
|
while #nature.blossomqueue > 0 and i > 0 do
|
||||||
|
process_blossom_queue_item()
|
||||||
|
i = i - 1
|
||||||
end
|
end
|
||||||
nature:grow_node(pos, nature.blossom_node) -- now actually grow it.
|
|
||||||
table.remove(nature.blossomqueue, 1)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function nature.enqueue_node(pos, node, fcn)
|
function nature.enqueue_node(pos, node, replace)
|
||||||
local idx = #nature.blossomqueue
|
local idx = #nature.blossomqueue
|
||||||
nature.blossomqueue[idx+1] = {}
|
if idx < nature.blossomqueue_max then
|
||||||
nature.blossomqueue[idx+1][1] = pos
|
local enqueue_prob = 0
|
||||||
nature.blossomqueue[idx+1][2] = node
|
if idx < nature.blossomqueue_max * 0.8 then
|
||||||
nature.blossomqueue[idx+1][3] = fcn
|
enqueue_prob = 1
|
||||||
|
else
|
||||||
|
-- Reduce queue growth as it gets closer to its max.
|
||||||
|
enqueue_prob = 1 - (idx - nature.blossomqueue_max * 0.8) / (nature.blossomqueue_max * 0.2)
|
||||||
|
end
|
||||||
|
if enqueue_prob == 1 or math.random(100) <= 100 * enqueue_prob then
|
||||||
|
nature.blossomqueue[idx+1] = {}
|
||||||
|
nature.blossomqueue[idx+1][1] = pos
|
||||||
|
nature.blossomqueue[idx+1][2] = node
|
||||||
|
nature.blossomqueue[idx+1][3] = replace
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_young_node(pos)
|
local function set_young_node(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
meta:set_string(nature.node_young, nature.setting_true)
|
meta:set_int(nature.meta_blossom_time, minetest.get_gametime())
|
||||||
minetest.after(nature.youth_delay,
|
|
||||||
function(pos)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string(nature.node_young, nature.setting_false)
|
|
||||||
end,
|
|
||||||
pos)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_not_young(pos)
|
local function is_not_young(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
local young = meta:get_string(nature.node_young)
|
local blossom_time = meta:get_int(nature.meta_blossom_time)
|
||||||
return young ~= nature.setting_true
|
return not (blossom_time and minetest.get_gametime() - blossom_time < nature.blossom_duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
function nature:grow_node(pos, nodename)
|
function nature:grow_node(pos, nodename)
|
||||||
|
@ -47,7 +67,6 @@ function nature:grow_node(pos, nodename)
|
||||||
>= nature.minimum_growth_light
|
>= nature.minimum_growth_light
|
||||||
|
|
||||||
if is_not_young(pos) and light_enough then
|
if is_not_young(pos) and light_enough then
|
||||||
minetest.remove_node(pos)
|
|
||||||
minetest.set_node(pos, { name = nodename })
|
minetest.set_node(pos, { name = nodename })
|
||||||
set_young_node(pos)
|
set_young_node(pos)
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ local current_mod_name = minetest.get_current_modname()
|
||||||
|
|
||||||
nature = {}
|
nature = {}
|
||||||
nature.blossomqueue = {}
|
nature.blossomqueue = {}
|
||||||
|
nature.blossomqueue_max = 1000
|
||||||
|
|
||||||
nature.blossom_node = "nature:blossom"
|
nature.blossom_node = "nature:blossom"
|
||||||
nature.blossom_leaves = "default:leaves"
|
nature.blossom_leaves = "default:leaves"
|
||||||
|
@ -19,15 +20,14 @@ if minetest.get_modpath("moretrees") then
|
||||||
minetest.register_alias("nature:blossom", "default:leaves")
|
minetest.register_alias("nature:blossom", "default:leaves")
|
||||||
end
|
end
|
||||||
|
|
||||||
nature.blossom_chance = 15
|
nature.leaves_blossom_chance = 15
|
||||||
|
nature.blossom_leaves_chance = 5
|
||||||
nature.blossom_delay = 3600
|
nature.blossom_delay = 3600
|
||||||
nature.apple_chance = 10
|
nature.apple_chance = 10
|
||||||
nature.apple_spread = 2
|
nature.apple_spread = 2
|
||||||
|
|
||||||
nature.node_young = "young"
|
nature.meta_blossom_time = "blossom_time"
|
||||||
nature.setting_true = "true"
|
nature.blossom_duration = nature.blossom_delay
|
||||||
nature.setting_false = "false"
|
|
||||||
nature.youth_delay = 5
|
|
||||||
|
|
||||||
function dumppos(pos)
|
function dumppos(pos)
|
||||||
return "("..pos.x..","..pos.y..","..pos.z..")"
|
return "("..pos.x..","..pos.y..","..pos.z..")"
|
||||||
|
|
0
mods/soundset/README.md
Normal file → Executable file
0
mods/soundset/README.md
Normal file → Executable file
0
mods/soundset/init.lua
Normal file → Executable file
0
mods/soundset/init.lua
Normal file → Executable file
Loading…
Reference in New Issue
Block a user