1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-16 07:20:31 +01:00
server-nalc/mods/lavatemple/mapgen.lua

58 lines
1.7 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
lavatemple.mapgen_data = {}
lavatemple.file = minetest.get_worldpath()..'/lavatemple.mt'
-- try to load the data from file
local f = io.open(lavatemple.file, "r")
if f then
local contents = f:read()
io.close(f)
if contents ~= nil then
lavatemple.mapgen_data = minetest.deserialize(contents)
end
end
-- generate position of the temple (if not done already)
if type (lavatemple.mapgen_data) ~= "table" or
lavatemple.mapgen_data.pos == nil or
lavatemple.mapgen_data.pos.x == nil or
lavatemple.mapgen_data.pos.y == nil or
lavatemple.mapgen_data.pos.z == nil then
-- generate the temple position
math.randomseed(os.time())
lavatemple.mapgen_data.pos = {
x=math.random(-2000,2000),
y=math.random(-500,-50),
z=math.random(-2000,2000)
}
-- save data
local f = io.open(lavatemple.file, "w")
f:write(minetest.serialize(lavatemple.mapgen_data))
io.close(f)
end
minetest.register_on_generated(function(minp,maxp,seed)
local ltp = lavatemple.mapgen_data.pos
if ltp.x > minp.x and ltp.x < maxp.x and
ltp.y > minp.y and ltp.y < maxp.y and
ltp.z > minp.z and ltp.z < maxp.z then
local f = io.open(minetest.get_modpath("lavatemple").."/schems/lavatemple.we", "r")
if not f then return end
local contents = f:read()
io.close(f)
if not contents then return end
-- Clear the area since worldedit doesn't save "air" nodes
pos1, pos2, count = worldedit.allocate(ltp, contents)
for x=pos1.x,pos2.x do
for y=pos1.y,pos2.y do
for z=pos1.z,pos2.z do
minetest.remove_node({x=x,y=y,z=z})
2014-10-28 18:01:32 +01:00
end end end
-- Deserialize the temple
--worldedit.deserialize(ltp, contents, minetest|.env)
worldedit.deserialize(ltp, contents, minetest)
2014-10-28 18:01:32 +01:00
end
end)