From c62e2cd49649109f0135e56ee8add0dab2254d01 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 20 Aug 2017 20:21:29 +0500 Subject: 2017-08-20 --- src/World.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 740c276..c79d1b7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -130,12 +130,16 @@ std::vector World::GetSectionsList() { return sectionsList; } +static Section fallbackSection = Section(PackedSection()); + const Section &World::GetSection(Vector sectionPos) { auto result = cachedSections.find(sectionPos); if (result == cachedSections.end()) { auto it = sections.find(sectionPos); - if (it == sections.end()) - LOG(ERROR) << "BAD"; + if (it == sections.end()) { + LOG(ERROR) << "Accessed not loaded section " << sectionPos; + return fallbackSection; + } Section section(it->second); auto result = cachedSections.insert(std::make_pair(sectionPos, section)); return result.first->second; @@ -216,7 +220,7 @@ void World::DeleteEntity(unsigned int EntityId) void World::ParseChunkData(std::shared_ptr packet) { Block& block = this->GetBlock(packet->Position); - block = Block(packet->BlockId >> 4, packet->BlockId & 15); + block = Block(packet->BlockId >> 4, packet->BlockId & 15, block.light, block.sky); Vector sectionPos(std::floor(packet->Position.x / 16.0), std::floor(packet->Position.y / 16.0), std::floor(packet->Position.z / 16.0)); EventAgregator::PushEvent(EventType::ChunkChanged, ChunkChangedData{ sectionPos }); } @@ -229,7 +233,7 @@ void World::ParseChunkData(std::shared_ptr packet) { int z = (it.HorizontalPosition & 15) + (packet->ChunkZ * 16); Vector worldPos(x, y, z); Block& block = GetBlock(worldPos); - block = Block(it.BlockId >> 4, it.BlockId & 15); + block = Block(it.BlockId >> 4, it.BlockId & 15, block.light, block.sky); Vector sectionPos(packet->ChunkX, std::floor(it.YCoordinate / 16.0), packet->ChunkZ); if (std::find(changedSections.begin(), changedSections.end(), sectionPos) == changedSections.end()) -- cgit v1.2.3