summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2020-07-27 06:05:53 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2020-07-27 06:05:53 +0200
commitd899b21504c02cae99eb3688e561cf9bad4120c4 (patch)
treebfa380e1b81ab848766becff8322e783e4dcde1a /src/World.cpp
parentMerge pull request #40 from LaG1924/lua-scripting (diff)
downloadAltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.tar
AltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.tar.gz
AltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.tar.bz2
AltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.tar.lz
AltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.tar.xz
AltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.tar.zst
AltCraft-d899b21504c02cae99eb3688e561cf9bad4120c4.zip
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 00a1a19..d767871 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -9,6 +9,16 @@
#include "Packet.hpp"
#include "Collision.hpp"
+std::map<int, Dimension> registeredDimensions;
+
+void RegisterNewDimension(int dimensionId, Dimension newDimension) {
+ registeredDimensions[dimensionId] = newDimension;
+}
+
+World::World(int dimensionId) : dimension(dimensionId) {
+
+}
+
void World::ParseChunkData(std::shared_ptr<PacketChunkData> packet) {
StreamBuffer chunkData(packet->Data.data(), packet->Data.size());
std::bitset<16> bitmask(packet->PrimaryBitMask);
@@ -24,7 +34,13 @@ void World::ParseChunkData(std::shared_ptr<PacketChunkData> packet) {
UpdateSectionsList();
} else {
- std::swap(sections.at(chunkPosition), section);
+ auto it = sections.find(chunkPosition);
+ if (it == sections.end()) {
+ LOG(WARNING) << "Chunk updating empty chunk";
+ sections.insert(std::make_pair(chunkPosition, section));
+ }
+ else
+ std::swap(sections.at(chunkPosition), section);
}
PUSH_EVENT("ChunkChanged", chunkPosition);
@@ -44,7 +60,7 @@ Section World::ParseSection(StreamInput *data, Vector position) {
auto dataArray = data->ReadByteArray(dataArrayLength * 8);
auto blockLight = data->ReadByteArray(2048);
std::vector<unsigned char> skyLight;
- if (dimension == 0)
+ if (registeredDimensions[dimension].skylight)
skyLight = data->ReadByteArray(2048);
long long *blockData = reinterpret_cast<long long*>(dataArray.data());