[BlockCursor] Fixed inventory update packet. [Client] Small optimization.

This commit is contained in:
Quentin Bazin 2019-04-07 15:40:37 +02:00
parent 58043344f1
commit 633233e57e
4 changed files with 15 additions and 9 deletions

6
TODO
View File

@ -1,5 +1,11 @@
TODO
# Multiplayer
• DONE: Fix right click on blocks
• DONE: Spltting a stack in the inventory causes a server crash
• TODO: Crafting only works for sticks
# General
• TODO: Use Faithful 32x for buttons, backgrounds and font (or use Minecraftia for the latter)

View File

@ -58,7 +58,7 @@ void InventoryWidget::onMouseEvent(const SDL_Event &event, MouseItemWidget &mous
packet << *m_inventory;
}
else {
packet << Network::Command::PlayerInvUpdate;
packet << Network::Command::PlayerInvUpdate << m_client.id();
packet << *m_inventory;
}
m_client.send(packet);
@ -75,7 +75,7 @@ void InventoryWidget::onMouseEvent(const SDL_Event &event, MouseItemWidget &mous
packet << *m_inventory;
}
else {
packet << Network::Command::PlayerInvUpdate;
packet << Network::Command::PlayerInvUpdate << m_client.id();
packet << *m_inventory;
}
m_client.send(packet);

View File

@ -108,8 +108,8 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
// FIXME
sf::Packet invPacket;
invPacket << Network::Command::PlayerInvUpdate;
m_player.serialize(invPacket);
invPacket << Network::Command::PlayerInvUpdate << m_client.id();
invPacket << m_player.inventory();
m_client.send(invPacket);
}
}
@ -157,8 +157,8 @@ void BlockCursor::update(const Hotbar &hotbar, bool useDepthBuffer) {
// FIXME
sf::Packet invPacket;
invPacket << Network::Command::PlayerInvUpdate;
m_player.serialize(invPacket);
invPacket << Network::Command::PlayerInvUpdate << m_client.id();
invPacket << m_player.inventory();
m_client.send(invPacket);
}
}

View File

@ -102,9 +102,9 @@ void Client::update() {
// DEBUG("TCP message received:", Network::commandToString(command));
for (auto &it : m_commands)
if (command == it.first)
it.second(packet);
auto it = m_commands.find(command);
if (it != m_commands.end())
it->second(packet);
}
}