From d534207debdd0a81f8e1ef5a1afd234abe9bcde9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 25 Sep 2024 00:13:59 +0300 Subject: [PATCH] add test ore (coal) --- res/content/base/blocks/coal_ore.json | 3 +++ res/content/base/content.json | 15 ++++++++------- res/content/base/textures/blocks/coal_ore.png | Bin 0 -> 7430 bytes res/generators/default.lua | 6 ++++++ res/generators/default/coal_ore0.vox | Bin 0 -> 339 bytes res/generators/default/structures.json | 3 ++- .../scripting/scripting_world_generation.cpp | 11 ++++++++++- src/world/generator/GeneratorDef.hpp | 1 + src/world/generator/WorldGenerator.cpp | 2 +- 9 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 res/content/base/blocks/coal_ore.json create mode 100644 res/content/base/textures/blocks/coal_ore.png create mode 100644 res/generators/default/coal_ore0.vox 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 0000000000000000000000000000000000000000..98f36abeaaff372d515aae486e3b1eb19ae9bd2e GIT binary patch literal 7430 zcmeHLX;>54(vB>GED9177sePDKxxw5=_H*DD6&aF7&axY*hzOFvLqy75pY8kL`6{) zcQz46#0^mt6hV~nDvP4vm1PtcL>N)If+*x9Y8`Q+3iC zJltpN>x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J*MybcpUs^Kf?2TL-8CAVrPPkTA3e#g|3P^&`A7dN)< zcCR#wPq<>IHQn?^;vpw%$MK%5{jb)|**>>w;l2X-j)Ldc{7impn|^&!4mVa~)JctD zbgGZ1-57S}>1PK8&No*!UY^yTI7+FimVI^>z!xKq^tuS0FB&;HXW#llUP^@Q0$}mwNp`-~3e@Tc9y|bu6^x-A5D^DB|MunKN{(BY7l1Frma~k-9FwbOr{B82eZ z??@5mU?>wr5P*qb8~|a%Ab@c>A^-=;JwgyTgmL~(iX0yh;*t4-pzoJOCYyy292_Mn z5(I!CLI@C|Ocp?nD<%SQQ6>%zwt~;w;4fv7>jQCl2#W{7-;W|!EJj3RzX5QVY;*|B zW&8;`{XFqn%2Y>0ykQ51tPocLQPA^->hAXh~Z zWRr#Y{U{R7$WX8XzQeFx=wrIRr?iJpO-2UXKfJ47mN zdmTlw9Hn~@T3^E7ra{T3dbz|I1WBbv8bdZaspqjODk>)P%bJ^ix@v;&In>zLczbK< zQjZCtGtv}cVUBwanP)${5rCAL*yrA{d;hLy%aY@>w@n^zYC19Ql8OEJihw-QK=FkO zp%D=kot=z7!uQV0b)-6)hzwd=Tki-@UgFL+&`|PBj~0+0&AUZfXqUj|OT4)0S40zF*}T`Yb*l4zcIq7L3$`P(TyifE30Fne!# zsNQOWSTyNm9X+qWGS&6Sk(T4PuHj`k{OcdeDo?6rYHDgsObocUQgFP!Jhb@b{npm_ z#s&gcO)|}oxS0-*$LF89 z+27G|R82dU(%HX$?0RR5A-gKY0eKdQYOUj|xZ&a9FPifgS@n*v=KWG>p@?uKi0*@p|sZ3 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..882afcb7e9288b7f55c4cf1281fc2d989f876fcd GIT binary patch literal 339 zcmZP!W@KO}%dbeyDP~||X21d&fnp#GgXnyiI6fL#4~z{n6Gr3Hk1j`!9&|IX@EMYF z@{_Z5^AdAYfuX^{!N9 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) {