mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
Chunk: refactor getTopLayer()
This commit is contained in:
parent
22b9cfcb8b
commit
1e5e315816
3 changed files with 26 additions and 24 deletions
|
@ -44,6 +44,8 @@ struct Block {
|
||||||
uint8_t biome;
|
uint8_t biome;
|
||||||
|
|
||||||
Block() : id(0), data(0), height(0), blockLight(0), skyLight(0), biome(0) {}
|
Block() : id(0), data(0), height(0), blockLight(0), skyLight(0), biome(0) {}
|
||||||
|
Block(uint8_t id0, uint8_t data0, unsigned height0, uint8_t blockLight0, uint8_t skyLight0, uint8_t biome0)
|
||||||
|
: id(id0), data(data0), height(height0), blockLight(blockLight0), skyLight(skyLight0), biome(biome0) {}
|
||||||
|
|
||||||
uint32_t getColor() const;
|
uint32_t getColor() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -138,6 +138,28 @@ void Chunk::analyzeChunk() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Block Chunk::getBlock(size_t x, size_t y, size_t z) const {
|
||||||
|
size_t y2 = y;
|
||||||
|
if (y2 < maxY-1)
|
||||||
|
y2++;
|
||||||
|
|
||||||
|
unsigned h;
|
||||||
|
for (h = y; h > 0; h--) {
|
||||||
|
uint8_t id2 = getBlockAt(x, h, z);
|
||||||
|
if (id2 != 8 && id2 != 9)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Block(
|
||||||
|
getBlockAt(x, y, z),
|
||||||
|
getDataAt(x, y, z),
|
||||||
|
h,
|
||||||
|
getBlockLightAt(x, y2, z),
|
||||||
|
getSkyLightAt(x, y2, z),
|
||||||
|
getBiomeAt(x, z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Chunk::Blocks Chunk::getTopLayer() const {
|
Chunk::Blocks Chunk::getTopLayer() const {
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
Blocks ret;
|
Blocks ret;
|
||||||
|
@ -155,30 +177,7 @@ Chunk::Blocks Chunk::getTopLayer() const {
|
||||||
if (!Resource::BLOCK_TYPES[id].opaque)
|
if (!Resource::BLOCK_TYPES[id].opaque)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Block &b = ret.blocks[x][z];
|
ret.blocks[x][z] = getBlock(x, y, z);
|
||||||
|
|
||||||
b.id = id;
|
|
||||||
b.data = getDataAt(x, y, z);
|
|
||||||
|
|
||||||
size_t y2 = y;
|
|
||||||
if (y2 < maxY-1)
|
|
||||||
y2++;
|
|
||||||
|
|
||||||
b.blockLight = getBlockLightAt(x, y2, z);
|
|
||||||
b.skyLight = getSkyLightAt(x, y2, z);
|
|
||||||
|
|
||||||
|
|
||||||
unsigned h;
|
|
||||||
for (h = y; h > 0; h--) {
|
|
||||||
uint8_t id2 = getBlockAt(x, h, z);
|
|
||||||
if (id2 != 8 && id2 != 9)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
b.height = h;
|
|
||||||
|
|
||||||
b.biome = getBiomeAt(x, z);
|
|
||||||
|
|
||||||
done++;
|
done++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,7 @@ public:
|
||||||
return *sections;
|
return *sections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Block getBlock(size_t x, size_t y, size_t z) const;
|
||||||
Blocks getTopLayer() const;
|
Blocks getTopLayer() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue