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
|
2015-06-10 17:14:58 +02:00
|
|
|
local f = io.open(lavatemple.file, "r")
|
2014-10-28 18:01:32 +01:00
|
|
|
if f then
|
|
|
|
local contents = f:read()
|
|
|
|
io.close(f)
|
2015-06-10 17:14:58 +02:00
|
|
|
if contents ~= nil then
|
2014-10-28 18:01:32 +01:00
|
|
|
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)
|
|
|
|
}
|
2015-06-10 17:14:58 +02:00
|
|
|
|
2014-10-28 18:01:32 +01:00
|
|
|
-- 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
|
2014-11-08 18:36:57 +01:00
|
|
|
minetest.remove_node({x=x,y=y,z=z})
|
2014-10-28 18:01:32 +01:00
|
|
|
end end end
|
|
|
|
-- Deserialize the temple
|
2014-11-08 18:36:57 +01:00
|
|
|
--worldedit.deserialize(ltp, contents, minetest|.env)
|
|
|
|
worldedit.deserialize(ltp, contents, minetest)
|
2014-10-28 18:01:32 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|