add async env support for generating illumishrooms (thx Niklp)
This commit is contained in:
parent
01b82996ab
commit
8cf109392e
37
decor.lua
37
decor.lua
@ -757,34 +757,9 @@ if minetest.registered_nodes["default:coral_green"] then
|
||||
end
|
||||
|
||||
|
||||
local random = math.random
|
||||
|
||||
-- Generate Illumishroom in caves on top of coal
|
||||
minetest.register_on_generated(function(minp, maxp)
|
||||
|
||||
if minp.y > -30 or maxp.y < -3000 then
|
||||
return
|
||||
end
|
||||
|
||||
local bpos
|
||||
local coal = minetest.find_nodes_in_area_under_air(
|
||||
minp, maxp, "default:stone_with_coal")
|
||||
|
||||
for n = 1, #coal do
|
||||
|
||||
if random(2) == 1 then
|
||||
|
||||
bpos = {x = coal[n].x, y = coal[n].y + 1, z = coal[n].z}
|
||||
|
||||
if bpos.y > -3000 and bpos.y < -2000 then
|
||||
minetest.swap_node(bpos, {name = "ethereal:illumishroom3"})
|
||||
|
||||
elseif bpos.y > -2000 and bpos.y < -1000 then
|
||||
minetest.swap_node(bpos, {name = "ethereal:illumishroom2"})
|
||||
|
||||
elseif bpos.y > -1000 and bpos.y < -30 then
|
||||
minetest.swap_node(bpos, {name = "ethereal:illumishroom"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
-- register async mapgen script
|
||||
if minetest.register_mapgen_script then
|
||||
minetest.register_mapgen_script(minetest.get_modpath("ethereal") .. "/decor_on_generated.lua")
|
||||
else
|
||||
dofile(minetest.get_modpath("ethereal") .. "/decor_on_generated.lua")
|
||||
end
|
||||
|
39
decor_on_generated.lua
Normal file
39
decor_on_generated.lua
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
local random = math.random
|
||||
|
||||
-- Generate Illumishroom in caves on top of coal
|
||||
local function generate(minp, maxp)
|
||||
|
||||
if minp.y > -30 or maxp.y < -3000 then
|
||||
return
|
||||
end
|
||||
|
||||
local coal = minetest.find_nodes_in_area_under_air(
|
||||
minp, maxp, "default:stone_with_coal")
|
||||
|
||||
for n = 1, #coal do
|
||||
|
||||
if random(2) == 1 then
|
||||
|
||||
local bpos = {x = coal[n].x, y = coal[n].y + 1, z = coal[n].z}
|
||||
|
||||
if bpos.y > -3000 and bpos.y < -2000 then
|
||||
minetest.set_node(bpos, {name = "ethereal:illumishroom3"})
|
||||
elseif bpos.y > -2000 and bpos.y < -1000 then
|
||||
minetest.set_node(bpos, {name = "ethereal:illumishroom2"})
|
||||
elseif bpos.y > -1000 and bpos.y < -30 then
|
||||
minetest.set_node(bpos, {name = "ethereal:illumishroom"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.save_gen_notify then -- async env (5.9+)
|
||||
minetest.register_on_generated(function(vmanip, minp, maxp, blockseed)
|
||||
generate(minp, maxp)
|
||||
end)
|
||||
else -- main thread (5.8 and earlier)
|
||||
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||
generate(minp, maxp)
|
||||
end)
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user