fork update #10

Merged
chmodsayshello merged 220 commits from VoxeLibre/VoxeLibre:master into master 2023-06-04 12:44:03 +02:00
1 changed files with 29 additions and 46 deletions
Showing only changes of commit 8edffeb40d - Show all commits

View File

@ -216,41 +216,34 @@ local function store_age (pos, age)
end end
end end
local function retrieve_age (pos, include_nil) local function retrieve_age (pos)
local meta = mt_get_meta(pos) local meta = mt_get_meta(pos)
if include_nil then
local age_set = meta:contains("mcl_ocean:kelp_age") local age_set = meta:contains("mcl_ocean:kelp_age")
if not age_set then if not age_set then
return nil return nil
end end
end
return meta:get_int("mcl_ocean:kelp_age") local age = meta:get_int("mcl_ocean:kelp_age")
--minetest.log("age: " .. tostring(age))
return age
end end
-- Initialise a kelp's age. -- Initialise a kelp's age.
function kelp.init_age(pos, age, from_lbm) function kelp.init_age(pos)
-- Watched params: pos -- Watched params: pos
-- Optional params: age, from_lbm -- Optional params: age, from_lbm
local new_age local age = retrieve_age(pos)
local stored_age = retrieve_age(pos, from_lbm) if not age then
age = kelp.roll_init_age()
if age then
--minetest.log("age: " .. tostring(age))
store_age(pos, age)
new_age = age
elseif not stored_age then
new_age = kelp.roll_init_age()
--minetest.log("no kelp age set so init with: " .. tostring(new_age)) --minetest.log("no kelp age set so init with: " .. tostring(new_age))
store_age(pos, new_age) store_age(pos, age)
else else
--minetest.log("stored_age: " .. tostring(stored_age)) --minetest.log("stored_age: " .. tostring(age))
new_age = stored_age
end end
return new_age return age
end end
-- Apply next kelp height. The surface is swapped. so on_construct is skipped. -- Apply next kelp height. The surface is swapped. so on_construct is skipped.
@ -380,13 +373,11 @@ end
local function grow_kelp (pos) local function grow_kelp (pos)
local node = mt_get_node(pos) local node = mt_get_node(pos)
if kelp.roll_growth() then
local age = retrieve_age(pos) local age = retrieve_age(pos)
if not age then if not age then
--minetest.log("init a new age as not set: " .. mt_pos_to_string(pos)) --minetest.log("init a new age as not set: " .. mt_pos_to_string(pos))
kelp.init_age(pos, nil) age = kelp.init_age(pos)
end end
if kelp.is_age_growable(age) then if kelp.is_age_growable(age) then
@ -396,11 +387,10 @@ local function grow_kelp (pos)
--minetest.log("age not: ".. tostring(age) .. ", pos: ".. mt_pos_to_string(pos)) --minetest.log("age not: ".. tostring(age) .. ", pos: ".. mt_pos_to_string(pos))
end end
end end
end
function kelp.surface_on_construct(pos) function kelp.surface_on_construct(pos)
--minetest.log("on construct kelp called") --minetest.log("on construct kelp called")
kelp.init_age(pos, nil) kelp.init_age(pos)
end end
@ -509,20 +499,13 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing)
itemstack:take_item() itemstack:take_item()
end end
-- Initialize age and timer when it's planted on a new surface. kelp.init_age(pos_under)
local init_age = kelp.roll_init_age()
if new_surface then
kelp.init_age(pos_under, init_age)
else
store_age(pos_under, init_age)
end
return itemstack return itemstack
end end
function kelp.lbm_register(pos) function kelp.lbm_register(pos)
kelp.init_age(pos, nil, true) kelp.init_age(pos)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -749,7 +732,7 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
label = "Kelp growth", label = "Kelp growth",
nodenames = { "group:kelp" }, nodenames = { "group:kelp" },
interval = 17, --17 interval = 17,
chance = 28, chance = 28,
catch_up = false, catch_up = false,
action = grow_kelp, action = grow_kelp,