From bee541f378d946e71cfcfe3da2a1a61ce3ab62b9 Mon Sep 17 00:00:00 2001 From: Erich Schubert Date: Sun, 26 Jan 2025 19:17:02 +0100 Subject: [PATCH] Lua get_biome_data: calc heat and humidity only once (#15715) --- src/script/lua_api/l_mapgen.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index aa017a0ea..3b547f5da 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -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;