Lua get_biome_data: calc heat and humidity only once (#15715)

This commit is contained in:
Erich Schubert 2025-01-26 19:17:02 +01:00 committed by GitHub
parent 45c5ef8798
commit bee541f378
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -552,24 +552,33 @@ int ModApiMapgen::l_get_biome_data(lua_State *L)
if (!biomegen)
return 0;
const Biome *biome = biomegen->calcBiomeAtPoint(pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
lua_newtable(L);
lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");
if (biomegen->getType() == BIOMEGEN_ORIGINAL) {
float heat = ((BiomeGenOriginal*) biomegen)->calcHeatAtPoint(pos);
float humidity = ((BiomeGenOriginal*) biomegen)->calcHumidityAtPoint(pos);
const Biome *biome = ((BiomeGenOriginal*) biomegen)->calcBiomeFromNoise(heat, humidity, pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
lua_newtable(L);
lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");
lua_pushnumber(L, heat);
lua_setfield(L, -2, "heat");
lua_pushnumber(L, humidity);
lua_setfield(L, -2, "humidity");
} else {
const Biome *biome = biomegen->calcBiomeAtPoint(pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;
lua_newtable(L);
lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");
}
return 1;