mirror of
https://github.com/mt-mods/biome_lib.git
synced 2025-01-09 17:40:34 +01:00
make sure a listed block is indeed loaded before writing to it
(in case the mapgen takes long enough on a server that players have wandered off and the server has unloaded blocks) for each block queued, make sure it and all 6 of its neighbors are actually loaded before populating, else move the block to the end of the queue.
This commit is contained in:
parent
8ecb401309
commit
53f55cdb4d
33
init.lua
33
init.lua
@ -427,10 +427,22 @@ function biome_lib:populate_surfaces(biome, nodes_or_function_or_model, snodes,
|
|||||||
return items_added
|
return items_added
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- make sure the target block and all 6 neighbors are actually loaded.
|
||||||
|
|
||||||
|
local function confirm_block_surroundings(pos)
|
||||||
|
return minetest.get_node_or_nil(pos)
|
||||||
|
and minetest.get_node_or_nil({ x=pos.x-16, y=pos.y, z=pos.z })
|
||||||
|
and minetest.get_node_or_nil({ x=pos.x+16, y=pos.y, z=pos.z })
|
||||||
|
and minetest.get_node_or_nil({ x=pos.x, y=pos.y-16, z=pos.z })
|
||||||
|
and minetest.get_node_or_nil({ x=pos.x, y=pos.y+16, z=pos.z })
|
||||||
|
and minetest.get_node_or_nil({ x=pos.x, y=pos.y, z=pos.z-16 })
|
||||||
|
and minetest.get_node_or_nil({ x=pos.x, y=pos.y, z=pos.z+16 })
|
||||||
|
end
|
||||||
|
|
||||||
-- Primary mapgen spawner, for mods that can work with air checking enabled on
|
-- Primary mapgen spawner, for mods that can work with air checking enabled on
|
||||||
-- a surface during the initial map read stage.
|
-- a surface during the initial map read stage.
|
||||||
|
|
||||||
function biome_lib:generate_block_with_air_checking()
|
function biome_lib:generate_block_with_air_checking(shutdown)
|
||||||
if not biome_lib.blocklist_aircheck[1] then
|
if not biome_lib.blocklist_aircheck[1] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -450,7 +462,10 @@ function biome_lib:generate_block_with_air_checking()
|
|||||||
if #biome_lib.surface_nodes_aircheck.blockhash > 0 then
|
if #biome_lib.surface_nodes_aircheck.blockhash > 0 then
|
||||||
biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).." added, with "..#biome_lib.surface_nodes_aircheck.blockhash.." surface nodes detected.")
|
biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).." added, with "..#biome_lib.surface_nodes_aircheck.blockhash.." surface nodes detected.")
|
||||||
end
|
end
|
||||||
|
elseif not shutdown and not confirm_block_surroundings(minp) and #biome_lib.blocklist_aircheck > 1 then
|
||||||
|
biome_lib.blocklist_aircheck[#biome_lib.blocklist_aircheck+1] = biome_lib.blocklist_aircheck[1]
|
||||||
|
table.remove(biome_lib.blocklist_aircheck, 1)
|
||||||
|
biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).." had an unloaded neighbor, moved it to the end of the queue.")
|
||||||
else
|
else
|
||||||
if biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash] then
|
if biome_lib.actionslist_aircheck[biome_lib.actioncount_aircheck.blockhash] then
|
||||||
-- [1] is biome, [2] is node/function/model
|
-- [1] is biome, [2] is node/function/model
|
||||||
@ -474,7 +489,7 @@ end
|
|||||||
-- Secondary mapgen spawner, for mods that require disabling of
|
-- Secondary mapgen spawner, for mods that require disabling of
|
||||||
-- checking for air during the initial map read stage.
|
-- checking for air during the initial map read stage.
|
||||||
|
|
||||||
function biome_lib:generate_block_no_aircheck()
|
function biome_lib:generate_block_no_aircheck(shutdown)
|
||||||
if not biome_lib.blocklist_no_aircheck[1] then
|
if not biome_lib.blocklist_no_aircheck[1] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -488,7 +503,9 @@ function biome_lib:generate_block_no_aircheck()
|
|||||||
biome_lib.surface_nodes_no_aircheck.blockhash =
|
biome_lib.surface_nodes_no_aircheck.blockhash =
|
||||||
minetest.find_nodes_in_area(minp, maxp, biome_lib.surfaceslist_no_aircheck)
|
minetest.find_nodes_in_area(minp, maxp, biome_lib.surfaceslist_no_aircheck)
|
||||||
biome_lib.actioncount_no_aircheck.blockhash = 1
|
biome_lib.actioncount_no_aircheck.blockhash = 1
|
||||||
|
elseif not shutdown and not confirm_block_surroundings(minp) and #biome_lib.blocklist_no_aircheck > 1 then
|
||||||
|
biome_lib.blocklist_no_aircheck[#biome_lib.blocklist_no_aircheck+1] = biome_lib.blocklist_no_aircheck[1]
|
||||||
|
table.remove(biome_lib.blocklist_no_aircheck, 1)
|
||||||
else
|
else
|
||||||
if biome_lib.actionslist_no_aircheck[biome_lib.actioncount_no_aircheck.blockhash] then
|
if biome_lib.actionslist_no_aircheck[biome_lib.actioncount_no_aircheck.blockhash] then
|
||||||
biome_lib:populate_surfaces(
|
biome_lib:populate_surfaces(
|
||||||
@ -519,10 +536,10 @@ minetest.register_globalstep(function(dtime)
|
|||||||
while (#biome_lib.blocklist_aircheck > 0 or #biome_lib.blocklist_no_aircheck > 0)
|
while (#biome_lib.blocklist_aircheck > 0 or #biome_lib.blocklist_no_aircheck > 0)
|
||||||
and biome_lib.globalstep_runtime < 200000 do -- 0.2 seconds, in uS.
|
and biome_lib.globalstep_runtime < 200000 do -- 0.2 seconds, in uS.
|
||||||
if #biome_lib.blocklist_aircheck > 0 then
|
if #biome_lib.blocklist_aircheck > 0 then
|
||||||
biome_lib:generate_block_with_air_checking()
|
biome_lib:generate_block_with_air_checking(false)
|
||||||
end
|
end
|
||||||
if #biome_lib.blocklist_no_aircheck > 0 then
|
if #biome_lib.blocklist_no_aircheck > 0 then
|
||||||
biome_lib:generate_block_no_aircheck()
|
biome_lib:generate_block_no_aircheck(false)
|
||||||
end
|
end
|
||||||
biome_lib.globalstep_runtime = minetest.get_us_time() - biome_lib.globalstep_start_time
|
biome_lib.globalstep_runtime = minetest.get_us_time() - biome_lib.globalstep_start_time
|
||||||
end
|
end
|
||||||
@ -539,7 +556,7 @@ minetest.register_on_shutdown(function()
|
|||||||
print("[biome_lib] Stand by, playing out the rest of the aircheck mapblock log")
|
print("[biome_lib] Stand by, playing out the rest of the aircheck mapblock log")
|
||||||
print("(there are "..#biome_lib.blocklist_aircheck.." entries)...")
|
print("(there are "..#biome_lib.blocklist_aircheck.." entries)...")
|
||||||
while #biome_lib.blocklist_aircheck > 0 do
|
while #biome_lib.blocklist_aircheck > 0 do
|
||||||
biome_lib:generate_block_with_air_checking(0.1)
|
biome_lib:generate_block_with_air_checking(true)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -551,7 +568,7 @@ minetest.register_on_shutdown(function()
|
|||||||
print("[biome_lib] Stand by, playing out the rest of the no-aircheck mapblock log")
|
print("[biome_lib] Stand by, playing out the rest of the no-aircheck mapblock log")
|
||||||
print("(there are "..#biome_lib.blocklist_no_aircheck.." entries)...")
|
print("(there are "..#biome_lib.blocklist_no_aircheck.." entries)...")
|
||||||
while #biome_lib.blocklist_no_aircheck > 0 do
|
while #biome_lib.blocklist_no_aircheck > 0 do
|
||||||
biome_lib:generate_block_no_aircheck(0.1)
|
biome_lib:generate_block_no_aircheck(true)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user