planetoids/mapgen.lua

56 lines
1.2 KiB
Lua
Raw Normal View History

2019-05-09 05:04:21 -07:00
local has_vacuum_mod = minetest.get_modpath("vacuum")
2019-06-15 10:22:03 -07:00
local has_planetoidgen_mod = minetest.get_modpath("planetoidgen")
2018-10-31 02:47:44 -07:00
2019-05-08 12:16:23 -07:00
2019-05-09 05:04:21 -07:00
local get_corners = function(minp, maxp)
return {
minp,
maxp,
{ x=maxp.x, y=minp.y, z=minp.z },
{ x=minp.x, y=maxp.y, z=minp.z },
{ x=minp.x, y=minp.y, z=maxp.z },
{ x=maxp.x, y=maxp.y, z=minp.z },
{ x=minp.x, y=maxp.y, z=maxp.z },
{ x=maxp.x, y=minp.y, z=maxp.z },
}
end
local check_corners_in_space = function(minp, maxp)
for _, pos in ipairs(get_corners(minp, maxp)) do
if vacuum.is_pos_in_space(pos) then
return true
end
end
return false
end
2019-05-08 12:16:23 -07:00
2020-01-09 05:47:59 -08:00
minetest.register_on_generated(function(minp, maxp)
2018-06-20 09:06:48 -07:00
2018-08-23 04:58:35 -07:00
-- default from 6k to 10k
if minp.y < planetoids.miny or minp.y > planetoids.maxy then
2018-06-20 09:06:48 -07:00
return
end
2019-05-09 05:04:21 -07:00
if has_vacuum_mod and not check_corners_in_space(minp, maxp) then
2019-05-08 12:16:23 -07:00
-- no vacuum there, don't generate planetoids in non-vacuum
return
end
2022-01-17 00:51:43 -08:00
if has_planetoidgen_mod and type(planetoidgen.is_occupied) == "function" and planetoidgen.is_occupied(minp) then
2019-06-15 10:22:03 -07:00
-- here be planetoids, skip mapgen
return
end
2019-05-08 12:16:23 -07:00
2018-06-20 09:06:48 -07:00
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
2019-06-28 01:18:05 -07:00
planetoids.mapgen_oreplanet(minp, maxp, vm, area)
2018-06-20 09:06:48 -07:00
vm:write_to_map()
end)