]> git.lizzy.rs Git - elidragon_v2.git/blob - mods/elidragon_plot/init.lua
Add plot mapgen + plot mapgen config for creative & survival
[elidragon_v2.git] / mods / elidragon_plot / init.lua
1 local plot = {}
2
3 minetest.register_on_generated(function(minp, maxp)
4         local mgconfig = plot.config.mapgen
5
6         if not mgconfig.enable then
7                 return
8         end
9
10         local min_y, max_y = mgconfig.min_y, mgconfig.max_y
11
12         if maxp.y < min_y or minp.y > max_y then
13                 return
14         end
15
16         local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
17         local data = vm:get_data()
18         local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
19
20         local void_layer = mgconfig.void_layer
21
22         if void_layer then
23                 for idx in area:iter(minp.x, math.max(minp.y, void_layer.min_y), minp.z, maxp.x, math.min(maxp.y, void_layer.max_y), mapx.z) do
24                         data[idx] = void_layer.c_void
25                 end
26         end
27
28         local function do_multiples(low, high, base, add, func)
29                 for p = math.ceil(low / base), math.floor(high / base) do
30                         func(p * base + add)
31                 end
32         end
33
34         local function do_borders(low, high, base, road, func)
35                 local r = road / 2
36                 do_multiples(low - r, high - r, base,  r, func)
37                 do_multiples(low + r, high + r, base, -r, func)
38         end
39
40         do_borders(minp.x, maxp.x, mgconfig.gap, mgconfig.road_width, function(x)
41                 for idx in area:iter(x, math.max(minp.y, min_y), minp.z, x, math.min(maxp.y, max_y), mapx.z) do
42                         data[idx] = mgconfig.c_border
43                 end
44         end)
45
46         do_borders(minp.z, maxp.z, mgconfig.gap, mgconfig.road_width, function(z)
47                 for idx in area:iter(minp.x, math.max(minp.y, min_y), z, maxp.x, math.min(maxp.y, max_y), z) do
48                         data[idx] = mgconfig.c_border
49                 end
50         end)
51
52         vm:set_data(data)
53         vm:calc_lighting()
54         vm:update_liquids()
55         vm:write_to_map()
56 end)
57
58 elidragon.plot = plot