Skip to content

Commit

Permalink
Unify wield item handling (#8677)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SmallJoker committed Aug 7, 2019
1 parent 003af74 commit e462a9a
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 249 deletions.
24 changes: 7 additions & 17 deletions src/client/client.cpp
Expand Up @@ -940,7 +940,7 @@ void Client::interact(u8 action, const PointedThing& pointed)
NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0);

pkt << action;
pkt << (u16)getPlayerItem();
pkt << myplayer->getWieldIndex();

std::ostringstream tmp_os(std::ios::binary);
pointed.serialize(tmp_os);
Expand Down Expand Up @@ -1277,19 +1277,6 @@ void Client::sendPlayerPos()
Send(&pkt);
}

void Client::sendPlayerItem(u16 item)
{
LocalPlayer *myplayer = m_env.getLocalPlayer();
if (!myplayer)
return;

NetworkPacket pkt(TOSERVER_PLAYERITEM, 2);

pkt << item;

Send(&pkt);
}

void Client::removeNode(v3s16 p)
{
std::map<v3s16, MapBlock*> modified_blocks;
Expand Down Expand Up @@ -1349,11 +1336,14 @@ void Client::setPlayerControl(PlayerControl &control)
player->control = control;
}

void Client::selectPlayerItem(u16 item)
void Client::setPlayerItem(u16 item)
{
m_playeritem = item;
m_env.getLocalPlayer()->setWieldIndex(item);
m_inventory_updated = true;
sendPlayerItem(item);

NetworkPacket pkt(TOSERVER_PLAYERITEM, 2);
pkt << item;
Send(&pkt);
}

// Returns true if the inventory of the local player has been
Expand Down
10 changes: 3 additions & 7 deletions src/client/client.h
Expand Up @@ -271,10 +271,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

void setPlayerControl(PlayerControl &control);

void selectPlayerItem(u16 item);
u16 getPlayerItem() const
{ return m_playeritem; }

// 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();
Expand All @@ -285,6 +281,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
Inventory* getInventory(const InventoryLocation &loc) override;
void inventoryAction(InventoryAction *a) override;

// Send the item number 'item' as player item to the server
void setPlayerItem(u16 item);

const std::list<std::string> &getConnectedPlayerNames()
{
return m_env.getPlayerNames();
Expand Down Expand Up @@ -454,8 +453,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void Receive();

void sendPlayerPos();
// Send the item number 'item' as player item to the server
void sendPlayerItem(u16 item);

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

u16 m_playeritem = 0;
bool m_inventory_updated = false;
Inventory *m_inventory_from_server = nullptr;
float m_inventory_from_server_age = 0.0f;
Expand Down

0 comments on commit e462a9a

Please sign in to comment.