diff --git a/source/common/world/Chunk.hpp b/source/common/world/Chunk.hpp index e30205d86..573f920e6 100644 --- a/source/common/world/Chunk.hpp +++ b/source/common/world/Chunk.hpp @@ -64,8 +64,8 @@ class Chunk : public gk::NonCopyable { void setBlockRaw(int x, int y, int z, u16 block); - virtual void onBlockPlaced(int, int, int, const Block &) const {} - virtual void onBlockDestroyed(int, int, int, const Block &) const {} + virtual void onBlockPlaced(int, int, int, const Block &) {} + virtual void onBlockDestroyed(int, int, int, const Block &) {} BlockData *getBlockData(int x, int y, int z) const; BlockData *addBlockData(int x, int y, int z, int inventoryWidth = 0, int inventoryHeight = 0); diff --git a/source/server/world/ServerChunk.cpp b/source/server/world/ServerChunk.cpp index b5988cb8f..7bda3287d 100644 --- a/source/server/world/ServerChunk.cpp +++ b/source/server/world/ServerChunk.cpp @@ -37,14 +37,18 @@ void ServerChunk::updateLights() { } } -void ServerChunk::onBlockPlaced(int x, int y, int z, const Block &block) const { +void ServerChunk::onBlockPlaced(int x, int y, int z, const Block &block) { const ServerBlock &serverBlock = (ServerBlock &)block; serverBlock.onBlockPlaced(glm::ivec3{x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH, z + m_z * CHUNK_HEIGHT}, m_world); + + m_hasBeenModified = true; } -void ServerChunk::onBlockDestroyed(int x, int y, int z, const Block &block) const { +void ServerChunk::onBlockDestroyed(int x, int y, int z, const Block &block) { const ServerBlock &serverBlock = (ServerBlock &)block; serverBlock.onBlockDestroyed(glm::ivec3{x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH, z + m_z * CHUNK_HEIGHT}, m_world); + + m_hasBeenModified = true; } void ServerChunk::tick(World &world, ServerCommandHandler &server) { diff --git a/source/server/world/ServerChunk.hpp b/source/server/world/ServerChunk.hpp index 614f17bc3..4e242fbe4 100644 --- a/source/server/world/ServerChunk.hpp +++ b/source/server/world/ServerChunk.hpp @@ -42,16 +42,19 @@ class ServerChunk : public Chunk { void updateLights(); - void onBlockPlaced(int x, int y, int z, const Block &block) const; - void onBlockDestroyed(int x, int y, int z, const Block &block) const; + void onBlockPlaced(int x, int y, int z, const Block &block) override; + void onBlockDestroyed(int x, int y, int z, const Block &block) override; void tick(World &world, ServerCommandHandler &server); bool isSent() const { return m_isSent; } void setSent(bool isSent) { m_isSent = isSent; } + bool hasBeenModified() const { return m_hasBeenModified; } + private: std::atomic_bool m_isSent{false}; + std::atomic_bool m_hasBeenModified{false}; }; #endif // SERVERCHUNK_HPP_ diff --git a/source/server/world/WorldController.cpp b/source/server/world/WorldController.cpp index e62252577..900d597b9 100644 --- a/source/server/world/WorldController.cpp +++ b/source/server/world/WorldController.cpp @@ -110,18 +110,18 @@ void WorldController::save(const std::string &name) { for (auto &world : m_worldList) { Network::Packet chunks; unsigned int chunkCount = 0; - for (auto &chunk : world.chunks()) { - if (!chunk.second->isInitialized()) continue; + for (auto &it : world.chunks()) { + if (!it.second->isInitialized() || !it.second->hasBeenModified()) continue; - const gk::Vector3i &chunkpos = chunk.first; - const Chunk::DataArray &data = chunk.second->data(); + const gk::Vector3i &chunkpos = it.first; + const Chunk::DataArray &data = it.second->data(); chunks << chunkpos.x << chunkpos.y << chunkpos.z; for (u8 z = 0 ; z < Chunk::height ; ++z) { for (u8 y = 0 ; y < Chunk::depth ; ++y) { for (u8 x = 0 ; x < Chunk::width ; ++x) { chunks << u32(data[z][y][x]) - << u8(chunk.second->lightmap().getLightData(x, y, z)); + << u8(it.second->lightmap().getLightData(x, y, z)); } } }