superflat/init.lua

70 lines
2.0 KiB
Lua
Raw Normal View History

2014-07-17 15:17:36 +07:00
-- (Yet Another) Superflat Map Generator
2014-07-18 15:39:35 +07:00
-- Modify layers in parameter.lua !
2014-07-17 15:17:36 +07:00
--------------------
-- Internal stuff --
--------------------
2014-07-18 15:39:35 +07:00
sflat = sflat or {}
dofile(minetest.get_modpath("superflat").."/parsetext.lua")
dofile(minetest.get_modpath("superflat").."/parameter.lua")
2014-07-17 15:17:36 +07:00
minetest.register_on_mapgen_init(function(mgparams)
minetest.set_mapgen_params({mgname="singlenode"})
end)
-- Superflat's bedrock
minetest.register_node("superflat:bedrock", {
description = "SUPERFLAT'S BEDROCK",
tiles ={"default_cobble.png"},
groups = {unbreakable = 1, not_in_creative_inventory = 1},
sounds = default.node_sound_stone_defaults()
})
minetest.register_on_generated(function(minp, maxp, seed)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()
2014-07-18 15:39:35 +07:00
local pBLOCKS = sflat.parsetext(sflat.BLOCKS)
if minp.y > sflat.Y_ORIGIN + #pBLOCKS then
2014-07-17 15:17:36 +07:00
return
end
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
local yy = 1
for y = minp.y, maxp.y do
local vi = area:index(x, y, z)
2014-07-18 15:39:35 +07:00
if (y >= sflat.Y_ORIGIN and y < sflat.Y_ORIGIN + #pBLOCKS) then
data[vi] = minetest.get_content_id(pBLOCKS[yy])
2014-07-17 15:17:36 +07:00
yy = yy + 1
else
data[vi] = minetest.get_content_id("air")
end
end
end
end
vm:set_data(data)
vm:set_lighting({day=0, night=0})
vm:calc_lighting()
vm:write_to_map(data)
end)
2014-07-18 15:39:35 +07:00
sflat.bedrock_timer = 0
2014-07-17 15:17:36 +07:00
minetest.register_globalstep(function(dtime)
2014-07-18 15:39:35 +07:00
sflat.bedrock_timer = sflat.bedrock_timer - dtime
if sflat.bedrock_timer > 0 then return end
2014-07-17 15:17:36 +07:00
for k,player in ipairs(minetest.get_connected_players()) do
2014-07-18 15:39:35 +07:00
sflat.bedrock_timer = 1
2014-07-17 15:17:36 +07:00
local pos = player:getpos()
2014-07-18 15:39:35 +07:00
if pos.y < sflat.Y_ORIGIN-1 then
2014-07-17 15:17:36 +07:00
-- teleport them back to surface
2014-07-18 15:39:35 +07:00
player:setpos({x=pos.x,y=#pBLOCKS+2,z=pos.z})
2014-07-17 15:17:36 +07:00
-- build first layers under them
2014-07-18 15:39:35 +07:00
if minetest.env:get_node({x=pos.x,y=sflat.Y_ORIGIN,z=pos.z}).name == "air" then
minetest.env:set_node({x=pos.x,y=0,z=pos.z}, {name=pBLOCKS[1]})
2014-07-17 15:17:36 +07:00
end
end
end
end)