diff --git a/res/content/base/blocks/coal_ore.json b/res/content/base/blocks/coal_ore.json new file mode 100644 index 00000000..23c050c6 --- /dev/null +++ b/res/content/base/blocks/coal_ore.json @@ -0,0 +1,3 @@ +{ + "texture": "coal_ore" +} diff --git a/res/content/base/content.json b/res/content/base/content.json index 9b696dfd..cec825a8 100644 --- a/res/content/base/content.json +++ b/res/content/base/content.json @@ -1,8 +1,6 @@ { - "entities": [ - "drop", - "player", - "falling_block" + "items": [ + "bazalt_breaker" ], "blocks": [ "dirt", @@ -28,9 +26,12 @@ "pipe", "lightbulb", "torch", - "wooden_door" + "wooden_door", + "coal_ore" ], - "items": [ - "bazalt_breaker" + "entities": [ + "drop", + "player", + "falling_block" ] } \ No newline at end of file diff --git a/res/content/base/textures/blocks/coal_ore.png b/res/content/base/textures/blocks/coal_ore.png new file mode 100644 index 00000000..98f36abe Binary files /dev/null and b/res/content/base/textures/blocks/coal_ore.png differ diff --git a/res/generators/default.lua b/res/generators/default.lua index 6eeee14a..a5bd50bf 100644 --- a/res/generators/default.lua +++ b/res/generators/default.lua @@ -8,6 +8,12 @@ biomes = json.parse(file.read("core:generators/default/biomes.json")) function place_structures(x, z, w, d, seed, hmap) local placements = {} + for i=1,10 do + local sx = math.random() * w + local sz = math.random() * d + local sy = math.random() * hmap:at(sx, sz)*256 - 6 + table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4}) + end return placements end diff --git a/res/generators/default/coal_ore0.vox b/res/generators/default/coal_ore0.vox new file mode 100644 index 00000000..882afcb7 Binary files /dev/null and b/res/generators/default/coal_ore0.vox differ diff --git a/res/generators/default/structures.json b/res/generators/default/structures.json index 109ca95f..18f22b26 100644 --- a/res/generators/default/structures.json +++ b/res/generators/default/structures.json @@ -2,5 +2,6 @@ "tree0": {}, "tree1": {}, "tree2": {}, - "tower": {} + "tower": {}, + "coal_ore0": {} } diff --git a/src/logic/scripting/scripting_world_generation.cpp b/src/logic/scripting/scripting_world_generation.cpp index a05dade8..eeeeb1c5 100644 --- a/src/logic/scripting/scripting_world_generation.cpp +++ b/src/logic/scripting/scripting_world_generation.cpp @@ -79,6 +79,7 @@ public: } std::vector placeStructures( + const GeneratorDef& def, const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, const std::shared_ptr& heightmap ) override { @@ -98,7 +99,15 @@ public: lua::rawgeti(L, i); lua::rawgeti(L, 1); - int structIndex = lua::tointeger(L, -1); + int structIndex = 0; + if (lua::isstring(L, -1)) { + const auto& found = def.structuresIndices.find(lua::require_string(L, -1)); + if (found != def.structuresIndices.end()) { + structIndex = found->second; + } + } else { + structIndex = lua::tointeger(L, -1); + } lua::pop(L); lua::rawgeti(L, 2); diff --git a/src/world/generator/GeneratorDef.hpp b/src/world/generator/GeneratorDef.hpp index be429173..bf6934b0 100644 --- a/src/world/generator/GeneratorDef.hpp +++ b/src/world/generator/GeneratorDef.hpp @@ -135,6 +135,7 @@ public: const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0; virtual std::vector placeStructures( + const GeneratorDef& def, const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, const std::shared_ptr& heightmap) = 0; diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index 27c6753c..596a66fc 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -175,7 +175,7 @@ void WorldGenerator::generateStructures( const auto& heightmap = prototype.heightmap; util::concat(prototype.structures, def.script->placeStructures( - {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed, + def, {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed, heightmap )); for (const auto& placement : prototype.structures) {