Skip to content

Commit 5c1edc5

Browse files
authoredMay 24, 2018
Vein ore: Fix bug caused by changing perlinmap Y size (#7371)
Because vein ore uses 3D noise (all the other ores use 2D noise) the perlinmap Y size can be different in different mapchunks when close to the ore Y limits. Previously this caused bugs in the vein structure because changes in perlinmap Y size did not recreate the noise objects. Delete and recreate the noise objects with the new Y size if Y size has changed.
1 parent d6a6d31 commit 5c1edc5

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed
 

‎src/mapgen/mg_ore.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,23 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
371371
PcgRandom pr(blockseed + 520);
372372
MapNode n_ore(c_ore, 0, ore_param2);
373373

374-
u32 sizex = (nmax.X - nmin.X + 1);
375-
376-
if (!noise) {
377-
int sx = nmax.X - nmin.X + 1;
378-
int sy = nmax.Y - nmin.Y + 1;
379-
int sz = nmax.Z - nmin.Z + 1;
380-
noise = new Noise(&np, mapseed, sx, sy, sz);
381-
noise2 = new Noise(&np, mapseed + 436, sx, sy, sz);
374+
int sizex = nmax.X - nmin.X + 1;
375+
int sizey = nmax.Y - nmin.Y + 1;
376+
// Because this ore uses 3D noise the perlinmap Y size can be different in
377+
// different mapchunks due to ore Y limits. So recreate the noise objects
378+
// if Y size has changed.
379+
// Because these noise objects are created multiple times for this ore type
380+
// it is necessary to 'delete' them here.
381+
if (!noise || sizey != sizey_prev) {
382+
delete noise;
383+
delete noise2;
384+
int sizez = nmax.Z - nmin.Z + 1;
385+
noise = new Noise(&np, mapseed, sizex, sizey, sizez);
386+
noise2 = new Noise(&np, mapseed + 436, sizex, sizey, sizez);
387+
sizey_prev = sizey;
382388
}
383-
bool noise_generated = false;
384389

390+
bool noise_generated = false;
385391
size_t index = 0;
386392
for (int z = nmin.Z; z <= nmax.Z; z++)
387393
for (int y = nmin.Y; y <= nmax.Y; y++)

‎src/mapgen/mg_ore.h

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class OreVein : public Ore {
126126

127127
float random_factor;
128128
Noise *noise2 = nullptr;
129+
int sizey_prev = 0;
129130

130131
OreVein() = default;
131132
virtual ~OreVein();

0 commit comments

Comments
 (0)
Please sign in to comment.