Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit b40a199

Browse files
committed
Corrected hardcoded chunksizes in meru
and do not force meru mountain to spawn on chunk boundaries (it was dependant on chunksize = 5) Tested with chunksize = 3
1 parent 1f02cee commit b40a199

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

mods/meru/init.lua

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
local COORD = false -- Print tower co-ordinates to terminal (cheat)
44

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
99

1010
local BASRAD = 64 -- Average radius at y = -32
1111
local HEIGHT = 2048 -- Approximate height measured from y = -32
@@ -55,14 +55,18 @@ local np_biome = {
5555

5656
-- Stuff
5757

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
6670

6771
-- Nodes
6872

@@ -93,24 +97,26 @@ local nobj_biome = nil
9397
-- On generated function
9498

9599
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
99117
end
100118

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
114120
return
115121
end
116122

0 commit comments

Comments
 (0)