add test ore (coal)

This commit is contained in:
MihailRis 2024-09-25 00:13:59 +03:00
parent 36eed38b4c
commit d534207deb
9 changed files with 31 additions and 10 deletions

View File

@ -0,0 +1,3 @@
{
"texture": "coal_ore"
}

View File

@ -1,8 +1,6 @@
{ {
"entities": [ "items": [
"drop", "bazalt_breaker"
"player",
"falling_block"
], ],
"blocks": [ "blocks": [
"dirt", "dirt",
@ -28,9 +26,12 @@
"pipe", "pipe",
"lightbulb", "lightbulb",
"torch", "torch",
"wooden_door" "wooden_door",
"coal_ore"
], ],
"items": [ "entities": [
"bazalt_breaker" "drop",
"player",
"falling_block"
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@ -8,6 +8,12 @@ biomes = json.parse(file.read("core:generators/default/biomes.json"))
function place_structures(x, z, w, d, seed, hmap) function place_structures(x, z, w, d, seed, hmap)
local placements = {} 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 return placements
end end

Binary file not shown.

View File

@ -2,5 +2,6 @@
"tree0": {}, "tree0": {},
"tree1": {}, "tree1": {},
"tree2": {}, "tree2": {},
"tower": {} "tower": {},
"coal_ore0": {}
} }

View File

@ -79,6 +79,7 @@ public:
} }
std::vector<StructurePlacement> placeStructures( std::vector<StructurePlacement> placeStructures(
const GeneratorDef& def,
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed,
const std::shared_ptr<Heightmap>& heightmap const std::shared_ptr<Heightmap>& heightmap
) override { ) override {
@ -98,7 +99,15 @@ public:
lua::rawgeti(L, i); lua::rawgeti(L, i);
lua::rawgeti(L, 1); 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::pop(L);
lua::rawgeti(L, 2); lua::rawgeti(L, 2);

View File

@ -135,6 +135,7 @@ public:
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0; const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
virtual std::vector<StructurePlacement> placeStructures( virtual std::vector<StructurePlacement> placeStructures(
const GeneratorDef& def,
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed,
const std::shared_ptr<Heightmap>& heightmap) = 0; const std::shared_ptr<Heightmap>& heightmap) = 0;

View File

@ -175,7 +175,7 @@ void WorldGenerator::generateStructures(
const auto& heightmap = prototype.heightmap; const auto& heightmap = prototype.heightmap;
util::concat(prototype.structures, def.script->placeStructures( 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 heightmap
)); ));
for (const auto& placement : prototype.structures) { for (const auto& placement : prototype.structures) {