diff --git a/res/generators/default.lua b/res/generators/default.lua index 789569e1..3560f706 100644 --- a/res/generators/default.lua +++ b/res/generators/default.lua @@ -21,7 +21,8 @@ biomes = { }, plant_chance = 0.5, plants = { - {block="base:grass", weight=1} + {block="base:grass", weight=1}, + {block="base:flower", weight=0.03}, } }, desert = { diff --git a/src/logic/scripting/scripting_world_generation.cpp b/src/logic/scripting/scripting_world_generation.cpp index 2b500cbd..0f704e7e 100644 --- a/src/logic/scripting/scripting_world_generation.cpp +++ b/src/logic/scripting/scripting_world_generation.cpp @@ -1,5 +1,8 @@ #include "scripting.hpp" +#include +#include + #include "scripting_commons.hpp" #include "typedefs.hpp" #include "lua/lua_engine.hpp" @@ -188,7 +191,7 @@ static inline Biome load_biome( } lua::pop(L); } - // TODO: sort by weight descending + std::sort(plants.begin(), plants.end(), std::greater()); BlocksLayers groundLayers = load_layers(L, "layers"); BlocksLayers seaLayers = load_layers(L, "sea_layers"); diff --git a/src/world/generator/GeneratorDef.hpp b/src/world/generator/GeneratorDef.hpp index b424b636..4824a39e 100644 --- a/src/world/generator/GeneratorDef.hpp +++ b/src/world/generator/GeneratorDef.hpp @@ -41,6 +41,7 @@ struct BiomeParameter { float weight; }; +/// @brief Plant is a single-block structure randomly generating in world struct PlantEntry { /// @brief Plant block id std::string block; @@ -50,6 +51,10 @@ struct PlantEntry { struct { blockid_t id; } rt; + + bool operator>(const PlantEntry& other) const { + return weight > other.weight; + } }; struct BiomePlants {