From 18a16f800033771898f884eac8d3e62bc776f433 Mon Sep 17 00:00:00 2001 From: Cubitect Date: Sun, 28 Nov 2021 12:39:43 +0100 Subject: [PATCH] Added rudimentary check for terrain, which should get slightly more accurate structure positions. --- finders.c | 43 +++++++++++++++++++++++++++++++++++++++++++ finders.h | 12 +++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/finders.c b/finders.c index 75a3b14..f9b5990 100644 --- a/finders.c +++ b/finders.c @@ -2063,6 +2063,49 @@ L_not_viable: } +int isViableStructureTerrain(int structType, Generator *g, int x, int z) +{ + int id, sx, sz; + if (g->mc < MC_1_18) + return 1; + if (structType == Desert_Pyramid || structType == Jungle_Temple) + { + sx = (structType == Desert_Pyramid ? 21 : 12); + sz = (structType == Desert_Pyramid ? 21 : 15); + } + else if (structType == Mansion) + { + int cx = x >> 4, cz = z >> 4; + uint64_t rng = chunkGenerateRnd(g->seed, cx, cz); + int rot = nextInt(&rng, 4); + sx = 5; + sz = 5; + if (rot == 0) { sx = -5; } + if (rot == 1) { sx = -5; sz = -5; } + if (rot == 2) { sz = -5; } + x = (cx << 4) + 7; + z = (cz << 4) + 7; + } + else + { + return 1; + } + + id = getBiomeAt(g, 4, (x+sx)>>2, 15, (z)>>2); + if (isOceanic(id) || id == river || id == frozen_river) + return 0; + id = getBiomeAt(g, 4, (x)>>2, 15, (z+sz)>>2); + if (isOceanic(id) || id == river || id == frozen_river) + return 0; + id = getBiomeAt(g, 4, (x+sx)>>2, 15, (z+sz)>>2); + if (isOceanic(id) || id == river || id == frozen_river) + return 0; + + return 1; +} + + + /* Given bordering noise columns and a fractional position between those, * determine the surface block height (i.e. where the interpolated noise > 0). * Note that the noise columns should be of size: ncolxz[ colheight+1 ] diff --git a/finders.h b/finders.h index 2ee66f7..a8efe95 100644 --- a/finders.h +++ b/finders.h @@ -35,7 +35,7 @@ enum StructureType { Feature, // for locations of temple generation attempts pre 1.13 Desert_Pyramid, - Jungle_Pyramid, + Jungle_Temple, Jungle_Pyramid = Jungle_Temple, Swamp_Hut, Igloo, Village, @@ -579,6 +579,16 @@ int isViableStructurePos(int structType, Generator *g, int blockX, int blockZ, u */ int isViableFeatureBiome(int mc, int structureType, int biomeID); +/* Some structures in 1.18 now only spawn if the surface is sufficiently high + * at all four bounding box corners. This affects primarily Desert_Pyramids, + * Jungle_Temples and Mansions. + * Currently cubiomes does not provide overworld surface height and cannot + * check it, but we can rule out some unlikely positions based biomes. + * + * This function is meant only for the 1.18 Overworld and is subject to change. + */ +int isViableStructureTerrain(int structType, Generator *g, int blockX, int blockZ); + /* End Cities require a sufficiently high surface in addition to a biome check. * The world seed should be applied to the EndNoise and SurfaceNoise before * calling this function. (Use initSurfaceNoiseEnd() for initialization.)