Skip to content
Permalink
Browse files

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
  • Loading branch information...
SmallJoker committed Aug 7, 2019
1 parent 003af74 commit e462a9a5ef46776d974203bb44e0b89e8c980b29
@@ -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);
@@ -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;
@@ -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
@@ -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();
@@ -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();
@@ -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
@@ -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;

0 comments on commit e462a9a

Please sign in to comment.
You can’t perform that action at this time.