Skip to content

Commit e462a9a

Browse files
authoredAug 7, 2019
Unify wield item handling (#8677)
This moves the wield item functions to Player and the tool utils for range calculation Also 'local_inventory' was removed due to redundancy in Client
1 parent 003af74 commit e462a9a

14 files changed

+154
-249
lines changed
 

Diff for: ‎src/client/client.cpp

+7-17
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ void Client::interact(u8 action, const PointedThing& pointed)
940940
NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0);
941941

942942
pkt << action;
943-
pkt << (u16)getPlayerItem();
943+
pkt << myplayer->getWieldIndex();
944944

945945
std::ostringstream tmp_os(std::ios::binary);
946946
pointed.serialize(tmp_os);
@@ -1277,19 +1277,6 @@ void Client::sendPlayerPos()
12771277
Send(&pkt);
12781278
}
12791279

1280-
void Client::sendPlayerItem(u16 item)
1281-
{
1282-
LocalPlayer *myplayer = m_env.getLocalPlayer();
1283-
if (!myplayer)
1284-
return;
1285-
1286-
NetworkPacket pkt(TOSERVER_PLAYERITEM, 2);
1287-
1288-
pkt << item;
1289-
1290-
Send(&pkt);
1291-
}
1292-
12931280
void Client::removeNode(v3s16 p)
12941281
{
12951282
std::map<v3s16, MapBlock*> modified_blocks;
@@ -1349,11 +1336,14 @@ void Client::setPlayerControl(PlayerControl &control)
13491336
player->control = control;
13501337
}
13511338

1352-
void Client::selectPlayerItem(u16 item)
1339+
void Client::setPlayerItem(u16 item)
13531340
{
1354-
m_playeritem = item;
1341+
m_env.getLocalPlayer()->setWieldIndex(item);
13551342
m_inventory_updated = true;
1356-
sendPlayerItem(item);
1343+
1344+
NetworkPacket pkt(TOSERVER_PLAYERITEM, 2);
1345+
pkt << item;
1346+
Send(&pkt);
13571347
}
13581348

13591349
// Returns true if the inventory of the local player has been

Diff for: ‎src/client/client.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
271271

272272
void setPlayerControl(PlayerControl &control);
273273

274-
void selectPlayerItem(u16 item);
275-
u16 getPlayerItem() const
276-
{ return m_playeritem; }
277-
278274
// Returns true if the inventory of the local player has been
279275
// updated from the server. If it is true, it is set to false.
280276
bool getLocalInventoryUpdated();
@@ -285,6 +281,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
285281
Inventory* getInventory(const InventoryLocation &loc) override;
286282
void inventoryAction(InventoryAction *a) override;
287283

284+
// Send the item number 'item' as player item to the server
285+
void setPlayerItem(u16 item);
286+
288287
const std::list<std::string> &getConnectedPlayerNames()
289288
{
290289
return m_env.getPlayerNames();
@@ -454,8 +453,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
454453
void Receive();
455454

456455
void sendPlayerPos();
457-
// Send the item number 'item' as player item to the server
458-
void sendPlayerItem(u16 item);
459456

460457
void deleteAuthData();
461458
// helper method shared with clientpackethandler
@@ -506,7 +503,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
506503
// If 0, server init hasn't been received yet.
507504
u16 m_proto_ver = 0;
508505

509-
u16 m_playeritem = 0;
510506
bool m_inventory_updated = false;
511507
Inventory *m_inventory_from_server = nullptr;
512508
float m_inventory_from_server_age = 0.0f;

0 commit comments

Comments
 (0)
Please sign in to comment.