switch from ABM to node timer for mapgen mycelium growth

This commit is contained in:
FaceDeer 2020-02-09 14:40:08 -07:00
parent 7877f2cb4b
commit bf507c3177
2 changed files with 41 additions and 32 deletions

View File

@ -60,7 +60,9 @@ local mushroom_cavern_floor = function(abs_cracks, humidity, vi, area, data, dat
local rand = math.random() * math.min(abs_cracks, 1) * humidityfactor
if rand < 0.0005 then
data[vi+ystride] = c_giant_mycelium
local mycelium_index = vi+ystride
data[mycelium_index] = c_giant_mycelium
minetest.get_node_timer(area:position(mycelium_index)):start(math.random(1,10))
elseif rand < 0.003 then
local schematic = df_primordial_items.get_primordial_mushroom()
local rotation = (math.random(1,4)-1)*90
@ -80,7 +82,9 @@ local mushroom_cavern_ceiling = function(abs_cracks, humidity, vi, area, data, d
if abs_cracks < 0.3 then
local rand = math.random() * humidityfactor
if rand < 0.002 then
data[vi-ystride] = c_giant_mycelium
local mycelium_index = vi-ystride
data[mycelium_index] = c_giant_mycelium
minetest.get_node_timer(area:position(mycelium_index)):start(math.random(1,10))
elseif rand < 0.03 then
df_primordial_items.spawn_ceiling_spire_vm(vi, area, data)
elseif rand < 0.2 then
@ -99,7 +103,9 @@ local mushroom_warren_ceiling = function(abs_cracks, vi, area, data, data_param2
if abs_cracks < 0.2 then
local rand = math.random()
if rand < 0.002 then
data[vi-ystride] = c_giant_mycelium
local mycelium_index = vi-ystride
data[mycelium_index] = c_giant_mycelium
minetest.get_node_timer(area:position(mycelium_index)):start(math.random(1,10))
elseif rand < 0.2 then
data[vi-ystride] = c_orb
data_param2[vi-ystride] = math.random(0,179)
@ -117,7 +123,9 @@ local mushroom_warren_floor = function(abs_cracks, vi, area, data, data_param2)
end
local rand = math.random() * math.min(abs_cracks, 1)
if rand < 0.001 then
data[vi+ystride] = c_giant_mycelium
local mycelium_index = vi+ystride
data[mycelium_index] = c_giant_mycelium
minetest.get_node_timer(area:position(mycelium_index)):start(math.random(1,10))
elseif rand < 0.03 then
data[vi+ystride] = fungal_plants[math.random(1,5)]
end
@ -348,6 +356,7 @@ local decorate_primordial = function(minp, maxp, seed, vm, node_arrays, area, da
local rand_vi = vi + random_dir[math.random(1,4)]
if data[rand_vi] == c_air then
data[rand_vi] = c_giant_mycelium
minetest.get_node_timer(area:position(rand_vi)):start(math.random(1,10))
end
end
end

View File

@ -363,9 +363,25 @@ minetest.register_node("df_primordial_items:giant_hypha_apical_meristem", {
end,
})
-- this version grows instantly via ABM, it is meant for mapgen usage.
-- An ABM is used so that it will trigger only after the surrounding map chunks have
-- also been generated, in case it wants to grow into them.
-- this version grows instantly, it is meant for mapgen usage.
local grow_mycelium_immediately = function(pos)
local stack = {pos}
while #stack > 0 do
local pos = table.remove(stack)
if not (df_farming and df_farming.kill_if_sunlit(pos)) then
local new_poses = grow_mycelium(pos, "df_primordial_items:giant_hypha_apical_mapgen")
if new_poses then -- if we hit the end of the world, just stop. There'll be a mapgen meristem left here, re-trigger it.
for _, new_pos in ipairs(new_poses) do
table.insert(stack, new_pos)
end
else
minetest.get_node_timer(pos):start(math.random(10,60))
end
end
end
end
minetest.register_node("df_primordial_items:giant_hypha_apical_mapgen", {
description = S("Giant Hypha Apical Meristem"),
tiles = {
@ -382,29 +398,13 @@ minetest.register_node("df_primordial_items:giant_hypha_apical_mapgen", {
is_ground_content = false,
groups = {oddly_breakable_by_hand = 1, choppy = 2, hypha = 1, not_in_creative_inventory = 1, light_sensitive_fungus = 13},
sounds = df_trees.node_sound_tree_soft_fungus_defaults(),
})
local grow_mycelium_immediately = function(pos)
local stack = {pos}
while #stack > 0 do
local pos = table.remove(stack)
if not (df_farming and df_farming.kill_if_sunlit(pos)) then
local new_poses = grow_mycelium(pos, "df_primordial_items:giant_hypha_apical_mapgen")
if new_poses then -- if we hit the end of the world, just stop. There'll be a mapgen meristem left here, the abm will re-trigger it when the player gets close.
for _, new_pos in ipairs(new_poses) do
table.insert(stack, new_pos)
end
end
end
end
end
minetest.register_abm({
label = "Mycelium mapgen growth",
nodenames = {"df_primordial_items:giant_hypha_apical_mapgen"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
on_timer = function(pos, elapsed)
grow_mycelium_immediately(pos)
end
})
end,
on_construct = function(pos)
minetest.get_node_timer(pos):start(1)
end,
on_destruct = function(pos)
minetest.get_node_timer(pos):stop()
end,
})