diff --git a/doc/en/world-generator.md b/doc/en/world-generator.md index 47f46b80..2112bce2 100644 --- a/doc/en/world-generator.md +++ b/doc/en/world-generator.md @@ -72,17 +72,20 @@ Fragments used by the generator must present in the directory: ## Structures -A structure is a set of rules for inserting a fragment into the world by the generator. It currently has no properties, being created as empty objects in the `generators/generator_name.files/structures.toml` file. Example: +A structure is a set of rules for inserting a fragment into the world by the generator. Structures are declared as objects in the file `generators/generator_name.files/structures.toml`. Example: ```toml tree0 = {} tree1 = {} tree2 = {} -tower = {} +tower = {lowering=2} coal_ore0 = {} ``` Currently, the name of the structure must match the name of the fragment used. +Available properties: +- lowering - depth of structure lowering. + ## Biomes A biome defines what blocks and layers the terrain is generated from, as well as a set of plants and structures. diff --git a/doc/ru/world-generator.md b/doc/ru/world-generator.md index 284ea067..1523f94a 100644 --- a/doc/ru/world-generator.md +++ b/doc/ru/world-generator.md @@ -72,17 +72,20 @@ ## Структуры -Структура - набор правил по вставке фрагмента в мир генератором. На данный момент не имеет свойств, создаваясь в виде пустых объектов в файле `generators/имя_генератора.files/structures.toml`. Пример: +Структура - набор правил по вставке фрагмента в мир генератором. Структуры объявляются в виде объектов в файле `generators/имя_генератора.files/structures.toml`. Пример: ```toml tree0 = {} tree1 = {} tree2 = {} -tower = {} +tower = {lowering=-2} coal_ore0 = {} ``` На данный момент, имя структуры должно совпадать с именем использованного фрагмента. +Доступные свойства: +- lowering - глубина погружения структуры под поверхность. + ## Биомы Биом определяет то, из каких блоков и какими слоями генерируется ландшафт, а так же набор растений, структур. diff --git a/res/content/base/generators/demo.files/structures.toml b/res/content/base/generators/demo.files/structures.toml index 3dcf3cda..12edb165 100644 --- a/res/content/base/generators/demo.files/structures.toml +++ b/res/content/base/generators/demo.files/structures.toml @@ -1,5 +1,5 @@ tree0 = {} tree1 = {} tree2 = {} -tower = {} +tower = {lowering=2} coal_ore0 = {} diff --git a/src/content/loading/GeneratorLoader.cpp b/src/content/loading/GeneratorLoader.cpp index ebae9118..8aef7f7b 100644 --- a/src/content/loading/GeneratorLoader.cpp +++ b/src/content/loading/GeneratorLoader.cpp @@ -127,7 +127,7 @@ static VoxelStructureMeta load_structure_meta( ) { VoxelStructureMeta meta; meta.name = name; - + config.at("lowering").get(meta.lowering); return meta; } diff --git a/src/world/generator/GeneratorDef.hpp b/src/world/generator/GeneratorDef.hpp index b21a2425..75ad8813 100644 --- a/src/world/generator/GeneratorDef.hpp +++ b/src/world/generator/GeneratorDef.hpp @@ -15,7 +15,10 @@ class VoxelFragment; struct GeneratorDef; struct VoxelStructureMeta { + /// @brief Structure name std::string name; + /// @brief Structure lowering on placement + int lowering = 0; }; struct BlocksLayer { diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index c0084df4..bc851a07 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -270,10 +270,11 @@ void WorldGenerator::generateStructures( if (height < def.seaLevel) { continue; } - auto& structure = *def.structures[structureId]->fragments[rotation]; - glm::ivec3 position {x, height, z}; - position.x -= structure.getSize().x / 2; - position.z -= structure.getSize().z / 2; + auto& structure = *def.structures[structureId]; + auto& fragment = *structure.fragments[rotation]; + glm::ivec3 position {x, height-structure.meta.lowering, z}; + position.x -= fragment.getSize().x / 2; + position.z -= fragment.getSize().z / 2; placeStructure( StructurePlacement { structureId,