Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix skipped section when all blocks are identical #380

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Chunk::~Chunk() {
}
}

const unsigned int Chunk::air_hid = qHash(QString("minecraft:air"));


void Chunk::findHighestBlock()
{
// loop over all Sections in reverse order
Expand All @@ -59,7 +62,10 @@ void Chunk::findHighestBlock()
it.previous();
if (it.value()) {
for (int j = 4095; j >= 0; j--) {
if (it.value()->blocks[j]) {
const ChunkSection* cs = it.value();
auto blockid = cs->blocks[j];
auto hid = cs->blockPalette[blockid].hid;
if (hid != air_hid) {
// found first non-air Block
highest = it.key() * 16 + (j >> 8);
return;
Expand Down Expand Up @@ -494,8 +500,11 @@ bool Chunk::loadSection1519(ChunkSection *cs, const Tag *section) {
loadSection_loadBlockStates(cs, section->at("BlockStates"));
sectionContainsData = true;
} else {
// set everything to 0 (minecraft:air)
// data tag is missing -> invent empty data
memset(cs->blocks, 0, sizeof(cs->blocks));
if ((cs->blockPaletteLength > 0) && (cs->blockPalette[0].name != "minecraft:air" )) {
sectionContainsData = true;
}
}

// copy Light data
Expand Down Expand Up @@ -527,16 +536,18 @@ bool Chunk::loadSection2844(ChunkSection * cs, const Tag * section) {
loadSection_loadBlockStates(cs, section->at("block_states")->at("data"));
sectionContainsData = true;
} else {
// set everything to 0 (minecraft:air)
// data tag is missing -> invent empty data
memset(cs->blocks, 0, sizeof(cs->blocks));
if ((cs->blockPaletteLength > 0) && (cs->blockPalette[0].name != "minecraft:air" )) {
sectionContainsData = true;
}
}

// decode Biomes-Palette to be able to map Biome
if (section->has("biomes") && section->at("biomes")->has("palette")) {
loadSection_decodeBiomePalette(cs, section->at("biomes"));
sectionContainsData = true;
} else {
// never observed in real live
// observed for unused Y == 20 section
// probably we should create some default Biome in this case
sectionContainsData = false;
}
Expand Down Expand Up @@ -605,7 +616,8 @@ void Chunk::loadSection_createDummyPalette(ChunkSection *cs) {
// create a dummy palette
cs->blockPalette = new PaletteEntry[1];
cs->blockPalette[0].name = "minecraft:air";
cs->blockPalette[0].hid = 0;
cs->blockPalette[0].hid = air_hid;
cs->blockPaletteLength = 1;
}


Expand Down
10 changes: 5 additions & 5 deletions chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ class Chunk : public QObject {
short depth[16 * 16]; // cached depth map to create shadow
EntityMap entities;

/** Specifies whether the chunk is locked by the ChunkLock resourcepack. */
bool isChunkLocked;
// ChunkLocked feature:
bool isChunkLocked; // flag specifies whether the chunk is locked by the ChunkLock resourcepack
QString chunkLockItemName; // the name of the item needed for unlocking the chunk

/** The name of the item needed for unlocking the chunk.
Only valid if isChunkLocked is true. */
QString chunkLockItemName;
// HID used for minecraft:air
static const unsigned int air_hid;

friend class MapView;
friend class ChunkRenderer;
Expand Down
Loading