1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 02:00:37 +01:00
server-nalc/mods/lavatemple/mapgen.lua
LeMagnesium 27836d2835 Removing all the olds minetest.env calls
- All the minetest.env calls removed

It took me about 2 hours, but I did it, and it works!
2014-11-08 18:36:57 +01:00

58 lines
1.7 KiB
Lua
Executable File

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})
end end end
-- Deserialize the temple
--worldedit.deserialize(ltp, contents, minetest|.env)
worldedit.deserialize(ltp, contents, minetest)
end
end)