-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapgen.lua
55 lines (40 loc) · 1.24 KB
/
mapgen.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local has_vacuum_mod = minetest.get_modpath("vacuum")
local has_planetoidgen_mod = minetest.get_modpath("planetoidgen")
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
minetest.register_on_generated(function(minp, maxp)
-- default from 6k to 10k
if minp.y < planetoids.miny or minp.y > planetoids.maxy then
return
end
if has_vacuum_mod and not check_corners_in_space(minp, maxp) then
-- no vacuum there, don't generate planetoids in non-vacuum
return
end
if has_planetoidgen_mod and type(planetoidgen.is_occupied) == "function" and planetoidgen.is_occupied(minp) then
-- here be planetoids, skip mapgen
return
end
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
planetoids.mapgen_oreplanet(minp, maxp, vm, area)
vm:write_to_map()
end)