diff --git a/src/files/WorldRegions.cpp b/src/files/WorldRegions.cpp index 6d2485d7..92feacda 100644 --- a/src/files/WorldRegions.cpp +++ b/src/files/WorldRegions.cpp @@ -360,7 +360,7 @@ void WorldRegions::put(Chunk* chunk, std::vector entitiesData){ return; } bool lightsUnsaved = !chunk->flags.loadedLights && doWriteLights; - if (!chunk->flags.unsaved && !lightsUnsaved) { + if (!chunk->flags.unsaved && !lightsUnsaved && !chunk->flags.entities) { return; } @@ -441,7 +441,11 @@ chunk_inventories_map WorldRegions::fetchInventories(int x, int z) { if (data == nullptr) { return nullptr; } - return json::from_binary(data, bytesSize); + auto map = json::from_binary(data, bytesSize); + if (map->size() == 0) { + return nullptr; + } + return map; } void WorldRegions::processRegionVoxels(int x, int z, const regionproc& func) { diff --git a/src/voxels/Chunk.hpp b/src/voxels/Chunk.hpp index a0157763..b04accc6 100644 --- a/src/voxels/Chunk.hpp +++ b/src/voxels/Chunk.hpp @@ -35,6 +35,7 @@ public: bool lighted: 1; bool unsaved: 1; bool loadedLights: 1; + bool entities: 1; } flags {}; /// @brief Block inventories map where key is index of block in voxels array diff --git a/src/voxels/Chunks.cpp b/src/voxels/Chunks.cpp index ca35c798..6f365c44 100644 --- a/src/voxels/Chunks.cpp +++ b/src/voxels/Chunks.cpp @@ -717,7 +717,7 @@ void Chunks::save(Chunk* chunk) { list.put(level->entities->serialize(entity)); } if (!entities.empty()) { - chunk->flags.unsaved = true; + chunk->flags.entities = true; } worldFiles->getRegions().put(chunk, json::to_binary(root, true)); } diff --git a/src/voxels/ChunksStorage.cpp b/src/voxels/ChunksStorage.cpp index bac62015..3231ce35 100644 --- a/src/voxels/ChunksStorage.cpp +++ b/src/voxels/ChunksStorage.cpp @@ -66,6 +66,7 @@ std::shared_ptr ChunksStorage::create(int x, int z) { if (auto map = regions.fetchEntities(chunk->x, chunk->z)) { level->entities->loadEntities(std::move(map)); + chunk->flags.entities = true; } chunk->flags.loaded = true;