X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=91d6aed6992e7327fc23116fcea59c9f902c8c00;hb=933ca0fe6c660e482edd45742d981f2de59a32df;hp=524454b43e31a70310f9b0fa377c3a29ec3d8071;hpb=c1da86ebab41895bf49ed747c75ecf722e8c5586;p=blank.git diff --git a/src/client/client.cpp b/src/client/client.cpp index 524454b..91d6aed 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -8,6 +8,7 @@ #include "../app/TextureIndex.hpp" #include "../model/CompositeModel.hpp" #include "../io/WorldSave.hpp" +#include "../world/ChunkIndex.hpp" #include "../world/ChunkStore.hpp" #include @@ -214,6 +215,27 @@ void InteractiveState::MergePlayerCorrection(std::uint16_t pack, const EntitySta input.MergePlayerCorrection(pack, state); } +void InteractiveState::Handle(const Packet::BlockUpdate &pack) { + glm::ivec3 pos; + pack.ReadChunkCoords(pos); + Chunk *chunk = player.GetChunks().Get(pos); + if (!chunk) { + // this change doesn't concern us + return; + } + uint32_t count = 0; + pack.ReadBlockCount(count); + for (uint32_t i = 0; i < count; ++i) { + uint16_t index; + Block block; + pack.ReadIndex(index, i); + pack.ReadBlock(block, i); + if (index < Chunk::size && block.type < block_types.Size()) { + manip.SetBlock(*chunk, index, block); + } + } +} + void InteractiveState::SetAudio(bool b) { master.GetConfig().audio.enabled = b; if (b) { @@ -476,5 +498,13 @@ void MasterState::On(const Packet::ChunkData &pack) { state->GetChunkReceiver().Handle(pack); } +void MasterState::On(const Packet::BlockUpdate &pack) { + if (!state) { + cout << "received block update, but the world has not been created yet" << endl; + return; + } + state->Handle(pack); +} + } }