advanced plants test

This commit is contained in:
MihailRis 2024-08-20 20:58:36 +03:00
parent 5bdabaea42
commit a81555b979
3 changed files with 11 additions and 2 deletions

View File

@ -21,7 +21,8 @@ biomes = {
}, },
plant_chance = 0.5, plant_chance = 0.5,
plants = { plants = {
{block="base:grass", weight=1} {block="base:grass", weight=1},
{block="base:flower", weight=0.03},
} }
}, },
desert = { desert = {

View File

@ -1,5 +1,8 @@
#include "scripting.hpp" #include "scripting.hpp"
#include <algorithm>
#include <functional>
#include "scripting_commons.hpp" #include "scripting_commons.hpp"
#include "typedefs.hpp" #include "typedefs.hpp"
#include "lua/lua_engine.hpp" #include "lua/lua_engine.hpp"
@ -188,7 +191,7 @@ static inline Biome load_biome(
} }
lua::pop(L); lua::pop(L);
} }
// TODO: sort by weight descending std::sort(plants.begin(), plants.end(), std::greater<PlantEntry>());
BlocksLayers groundLayers = load_layers(L, "layers"); BlocksLayers groundLayers = load_layers(L, "layers");
BlocksLayers seaLayers = load_layers(L, "sea_layers"); BlocksLayers seaLayers = load_layers(L, "sea_layers");

View File

@ -41,6 +41,7 @@ struct BiomeParameter {
float weight; float weight;
}; };
/// @brief Plant is a single-block structure randomly generating in world
struct PlantEntry { struct PlantEntry {
/// @brief Plant block id /// @brief Plant block id
std::string block; std::string block;
@ -50,6 +51,10 @@ struct PlantEntry {
struct { struct {
blockid_t id; blockid_t id;
} rt; } rt;
bool operator>(const PlantEntry& other) const {
return weight > other.weight;
}
}; };
struct BiomePlants { struct BiomePlants {