|
2 | 2 |
|
3 | 3 | local COORD = false -- Print tower co-ordinates to terminal (cheat)
|
4 | 4 |
|
5 |
| -local XMIN = 0 -- Area for random spawn |
6 |
| -local XMAX = 0 |
7 |
| -local ZMIN = 0 |
8 |
| -local ZMAX = 0 |
| 5 | +local XMIN = -1000 -- Area for random spawn |
| 6 | +local XMAX = 1000 |
| 7 | +local ZMIN = -1000 |
| 8 | +local ZMAX = 1000 |
9 | 9 |
|
10 | 10 | local BASRAD = 64 -- Average radius at y = -32
|
11 | 11 | local HEIGHT = 2048 -- Approximate height measured from y = -32
|
@@ -55,14 +55,18 @@ local np_biome = {
|
55 | 55 |
|
56 | 56 | -- Stuff
|
57 | 57 |
|
58 |
| -local cxmin = math.floor((XMIN + 32) / 80) -- limits in chunk co-ordinates |
59 |
| -local czmin = math.floor((ZMIN + 32) / 80) |
60 |
| -local cxmax = math.floor((XMAX + 32) / 80) |
61 |
| -local czmax = math.floor((ZMAX + 32) / 80) |
62 |
| -local cxav = (cxmin + cxmax) / 2 -- spawn area midpoint in chunk co-ordinates |
63 |
| -local czav = (czmin + czmax) / 2 |
64 |
| -local xnom = (cxmax - cxmin) / 4 -- noise multipliers |
65 |
| -local znom = (czmax - czmin) / 4 |
| 58 | +local xmid = (XMIN + XMAX) / 2 |
| 59 | +local zmid = (ZMIN + ZMAX) / 2 |
| 60 | +local xrad = xmid - XMIN |
| 61 | +local zrad = zmid - ZMIN |
| 62 | + |
| 63 | +local merux -- The position of the mountain is calculated on first mapgen |
| 64 | +local meruz |
| 65 | + |
| 66 | +local merux_min |
| 67 | +local merux_max |
| 68 | +local meruz_min |
| 69 | +local meruz_max |
66 | 70 |
|
67 | 71 | -- Nodes
|
68 | 72 |
|
@@ -93,24 +97,26 @@ local nobj_biome = nil
|
93 | 97 | -- On generated function
|
94 | 98 |
|
95 | 99 | minetest.register_on_generated(function(minp, maxp, seed)
|
96 |
| - if maxp.x < XMIN or minp.x > XMAX |
97 |
| - or maxp.z < ZMIN or minp.z > ZMAX then |
98 |
| - return |
| 100 | + if not merux and not meruz then -- on first mapgen |
| 101 | + local persist = math.sqrt(1.25) - 0.5 -- golden ratio - 1, solves the equation x²+x+1 = 2 |
| 102 | + |
| 103 | + local locnoise = minetest.get_perlin(5839090, 3, persist, 1) |
| 104 | + local noisex = locnoise:get2d({x = 31, y = 23}) / 2 |
| 105 | + local noisez = locnoise:get2d({x = 17, y = 11}) / 2 |
| 106 | + |
| 107 | + merux = math.floor(xmid + noisex * xrad + 0.5) |
| 108 | + meruz = math.floor(zmid + noisez * zrad + 0.5) |
| 109 | + merux_min = merux - BASRAD |
| 110 | + merux_max = merux + BASRAD |
| 111 | + meruz_min = meruz - BASRAD |
| 112 | + meruz_max = meruz + BASRAD |
| 113 | + |
| 114 | + if COORD then |
| 115 | + print ("[meru] at x " .. merux .. " z " .. meruz) |
| 116 | + end |
99 | 117 | end
|
100 | 118 |
|
101 |
| - local locnoise = minetest.get_perlin(5839090, 2, 0.5, 3) |
102 |
| - local noisex = locnoise:get2d({x = 31, y = 23}) |
103 |
| - local noisez = locnoise:get2d({x = 17, y = 11}) |
104 |
| - local cx = cxav + math.floor(noisex * xnom) -- chunk co ordinates |
105 |
| - local cz = czav + math.floor(noisez * znom) |
106 |
| - local merux = 80 * cx + 8 |
107 |
| - local meruz = 80 * cz + 8 |
108 |
| - if COORD then |
109 |
| - print ("[meru] at x " .. merux .. " z " .. meruz) |
110 |
| - end |
111 |
| - if minp.x < merux - 120 or minp.x > merux + 40 |
112 |
| - or minp.z < meruz - 120 or minp.z > meruz + 40 |
113 |
| - or minp.y < -32 or minp.y > HEIGHT * 1.2 then |
| 119 | + if minp.x > merux_max or maxp.x < merux_min or minp.z > meruz_max or maxp.z < meruz_min then |
114 | 120 | return
|
115 | 121 | end
|
116 | 122 |
|
|
0 commit comments