Added variant option to isViableStructurePos.

This commit is contained in:
Cubitect 2021-11-27 14:04:05 +01:00
parent a6f54b8d4f
commit e21f6c0f92
3 changed files with 19 additions and 15 deletions

View File

@ -173,7 +173,7 @@ int main()
{
uint64_t seed = lower48 | (upper16 << 48);
applySeed(&g, 0, seed);
if (isViableStructurePos(structType, &g, p.x, p.z))
if (isViableStructurePos(structType, &g, p.x, p.z, 0))
{
printf("Seed %" PRId64 " has a Pillager Outpost at (%d, %d).\n",
(int64_t) seed, p.x, p.z);
@ -250,10 +250,10 @@ int main()
uint64_t seed = s48 | (high << 48);
applySeed(&g, 0, seed);
if (isViableStructurePos(styp, &g, pos[0].x, pos[0].z) &&
isViableStructurePos(styp, &g, pos[1].x, pos[1].z) &&
isViableStructurePos(styp, &g, pos[2].x, pos[2].z) &&
isViableStructurePos(styp, &g, pos[3].x, pos[3].z))
if (isViableStructurePos(styp, &g, pos[0].x, pos[0].z, 0) &&
isViableStructurePos(styp, &g, pos[1].x, pos[1].z, 0) &&
isViableStructurePos(styp, &g, pos[2].x, pos[2].z, 0) &&
isViableStructurePos(styp, &g, pos[3].x, pos[3].z, 0))
{
printf("%" PRId64 "\n", (int64_t) seed);
}
@ -288,8 +288,6 @@ int main()
printf("Seed: %" PRId64 "\n", (int64_t) seed);
printf("Estimated position of first stronghold: (%d, %d)\n", pos.x, pos.z);
// The finders for the strongholds and spawn require that the seed is
// applied to the generator beforehand.
Generator g;
setupGenerator(&g, mc, 0);
applySeed(&g, 0, seed);

View File

@ -1771,7 +1771,7 @@ static int mapViableShore(const Layer * l, int * out, int x, int z, int w, int h
}
int isViableStructurePos(int structureType, Generator *g, int x, int z)
int isViableStructurePos(int structureType, Generator *g, int x, int z, uint32_t flags)
{
int approx = 0; // enables approximation levels
int viable = 0;
@ -1878,6 +1878,8 @@ L_feature:
id = getBiomeAt(g, 0, sampleX, 15, sampleZ);
if (id < 0 || !isViableFeatureBiome(g->mc, structureType, id))
goto L_not_viable;
if (flags && (uint32_t) id != flags)
goto L_not_viable;
viable = id; // biome for viablility, useful for further analysis
goto L_viable;
}
@ -1886,6 +1888,8 @@ L_feature:
const int vv[] = { plains, desert, savanna, taiga, snowy_tundra };
size_t i;
for (i = 0; i < sizeof(vv)/sizeof(int); i++) {
if (flags && flags != (uint32_t) vv[i])
continue;
VillageType vt = getVillageType(g->mc, g->seed, x, z, vv[i]);
switch (vt.rotation) {
case 0: sampleX = -1+vt.sx; sampleZ = -1+vt.sz; break;
@ -1897,7 +1901,7 @@ L_feature:
sampleX = ((chunkX << 5) + sampleX) / 2 >> 2;
sampleZ = ((chunkZ << 5) + sampleZ) / 2 >> 2;
id = getBiomeAt(g, 0, sampleX, 15, sampleZ);
if (id == vv[i]) {
if (id == vv[i] || (id == meadow && vv[i] == plains)) {
viable = id;
goto L_viable;
}
@ -1946,7 +1950,7 @@ L_feature:
{
if (g->mc >= MC_1_16)
goto L_not_viable;
if (isViableStructurePos(Village, g, p.x, p.z))
if (isViableStructurePos(Village, g, p.x, p.z, 0))
goto L_not_viable;
goto L_viable;
}

View File

@ -564,14 +564,16 @@ Pos estimateSpawn(const Generator *g);
// Validating Structure Positions
//==============================================================================
/* Performs a biome check at the specified block coordinates to determine
/* Performs a biome check near the specified block coordinates to determine
* whether a structure of the given type could spawn there. You can get the
* block positions using getStructurePos().
* The generator, 'g', should be initialized for a scale 1:1 generation of the
* correct MC version, dimension and seed. The generator may be temporarily
* modified during the function call, but will be restored upon return.
* The generator, 'g', should be initialized for the correct MC version,
* dimension and seed. The generator may be temporarily modified during the
* function call, but will be restored upon return.
* The 'flags' argument is optional structure specific information, such as the
* biome variant for villages.
*/
int isViableStructurePos(int structType, Generator *g, int blockX, int blockZ);
int isViableStructurePos(int structType, Generator *g, int blockX, int blockZ, uint32_t flags);
/* Checks if the specified structure type could generate in the given biome.
*/