diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/client.cpp | 30 | ||||
-rw-r--r-- | src/client/client.h | 6 | ||||
-rw-r--r-- | src/client/game.cpp | 12 |
3 files changed, 19 insertions, 29 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index e78b9bb8a..4c5485325 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -557,8 +557,8 @@ void Client::step(float dtime) if (count_after != count_before) { // Do this every <interval> seconds after TOCLIENT_INVENTORY // Reset the locally changed inventory to the authoritative inventory - m_env.getLocalPlayer()->inventory = *m_inventory_from_server; - m_inventory_updated = true; + player->inventory = *m_inventory_from_server; + m_update_wielded_item = true; } } @@ -1331,28 +1331,30 @@ void Client::setPlayerControl(PlayerControl &control) void Client::setPlayerItem(u16 item) { m_env.getLocalPlayer()->setWieldIndex(item); - m_inventory_updated = true; + m_update_wielded_item = true; NetworkPacket pkt(TOSERVER_PLAYERITEM, 2); pkt << item; Send(&pkt); } -// Returns true if the inventory of the local player has been -// updated from the server. If it is true, it is set to false. -bool Client::getLocalInventoryUpdated() +// Returns true once after the inventory of the local player +// has been updated from the server. +bool Client::updateWieldedItem() { - bool updated = m_inventory_updated; - m_inventory_updated = false; - return updated; -} + if (!m_update_wielded_item) + return false; + + m_update_wielded_item = false; -// Copies the inventory of the local player to parameter -void Client::getLocalInventory(Inventory &dst) -{ LocalPlayer *player = m_env.getLocalPlayer(); assert(player); - dst = player->inventory; + if (auto *list = player->inventory.getList("main")) + list->setModified(false); + if (auto *list = player->inventory.getList("hand")) + list->setModified(false); + + return true; } Inventory* Client::getInventory(const InventoryLocation &loc) diff --git a/src/client/client.h b/src/client/client.h index 3bfb1631e..85456fe4d 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -274,9 +274,7 @@ public: // Returns true if the inventory of the local player has been // updated from the server. If it is true, it is set to false. - bool getLocalInventoryUpdated(); - // Copies the inventory of the local player to parameter - void getLocalInventory(Inventory &dst); + bool updateWieldedItem(); /* InventoryManager interface */ Inventory* getInventory(const InventoryLocation &loc) override; @@ -504,7 +502,7 @@ private: // If 0, server init hasn't been received yet. u16 m_proto_ver = 0; - bool m_inventory_updated = false; + bool m_update_wielded_item = false; Inventory *m_inventory_from_server = nullptr; float m_inventory_from_server_age = 0.0f; PacketCounter m_packetcounter; diff --git a/src/client/game.cpp b/src/client/game.cpp index 4d5fbfb97..5bf41bcd6 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -599,7 +599,6 @@ struct GameRunData { bool dig_instantly; bool digging_blocked; bool left_punch; - bool update_wielded_item_trigger; bool reset_jump_timer; float nodig_delay_timer; float dig_time; @@ -1018,7 +1017,6 @@ bool Game::startup(bool *kill, // Reinit runData runData = GameRunData(); runData.time_from_last_punch = 10.0; - runData.update_wielded_item_trigger = true; m_game_ui->initFlags(); @@ -3736,19 +3734,11 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, if (player->getWieldIndex() != runData.new_playeritem) client->setPlayerItem(runData.new_playeritem); - // Update local inventory if it has changed - if (client->getLocalInventoryUpdated()) { - //infostream<<"Updating local inventory"<<std::endl; - runData.update_wielded_item_trigger = true; - } - - if (runData.update_wielded_item_trigger) { + if (client->updateWieldedItem()) { // Update wielded tool ItemStack selected_item, hand_item; ItemStack &tool_item = player->getWieldedItem(&selected_item, &hand_item); camera->wield(tool_item); - - runData.update_wielded_item_trigger = false; } /* |