mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
Merge pull request 'Do not run kelp lbm every time' (#3612) from lbm_run_every_time_fixes into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3612
This commit is contained in:
commit
ed8953dfe3
1 changed files with 42 additions and 55 deletions
|
@ -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
|
||||||
|
@ -395,12 +386,11 @@ local function grow_kelp (pos)
|
||||||
else
|
else
|
||||||
--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,31 +499,15 @@ 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
|
||||||
|
|
||||||
minetest.register_lbm({
|
|
||||||
label = "Kelp initialise",
|
|
||||||
name = "mcl_ocean:kelp_init",
|
|
||||||
nodenames = { "group:kelp" },
|
|
||||||
run_at_every_load = true, -- so old kelps are also initialised
|
|
||||||
action = kelp.lbm_register,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Kelp registration API
|
-- Kelp registration API
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -725,6 +699,19 @@ minetest.register_craft({
|
||||||
burntime = 200,
|
burntime = 200,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- Kelp ABM + LBM's
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Kelp initialise",
|
||||||
|
name = "mcl_ocean:kelp_init_83",
|
||||||
|
nodenames = { "group:kelp" },
|
||||||
|
run_at_every_load = false, -- so old kelps are also initialised
|
||||||
|
action = kelp.lbm_register,
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
label = "Kelp drops",
|
label = "Kelp drops",
|
||||||
nodenames = { "group:kelp" },
|
nodenames = { "group:kelp" },
|
||||||
|
@ -745,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,
|
||||||
|
|
Loading…
Reference in a new issue