recover hotbar selected slot after reconnect (#4249)
1. implement protocol message SendHeldItemChange 2. add save / load inventory equipped item slot in JSON 3. send held item slot message after player connect to server Fixes #4189
This commit is contained in:
parent
7b431bed51
commit
3e802932a6
@ -417,6 +417,9 @@ void cClientHandle::FinishAuthenticate(const AString & a_Name, const cUUID & a_U
|
|||||||
// Send experience
|
// Send experience
|
||||||
m_Player->SendExperience();
|
m_Player->SendExperience();
|
||||||
|
|
||||||
|
// Send hotbar active slot
|
||||||
|
m_Player->SendHotbarActiveSlot();
|
||||||
|
|
||||||
// Send player list items
|
// Send player list items
|
||||||
SendPlayerListAddPlayer(*m_Player);
|
SendPlayerListAddPlayer(*m_Player);
|
||||||
cRoot::Get()->BroadcastPlayerListsAddPlayer(*m_Player);
|
cRoot::Get()->BroadcastPlayerListsAddPlayer(*m_Player);
|
||||||
@ -2635,6 +2638,15 @@ void cClientHandle::SendHealth(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cClientHandle::SendHeldItemChange(int a_ItemIndex)
|
||||||
|
{
|
||||||
|
m_Protocol->SendHeldItemChange(a_ItemIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cClientHandle::SendHideTitle(void)
|
void cClientHandle::SendHideTitle(void)
|
||||||
{
|
{
|
||||||
m_Protocol->SendHideTitle();
|
m_Protocol->SendHideTitle();
|
||||||
|
@ -176,6 +176,7 @@ public: // tolua_export
|
|||||||
void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion);
|
void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion);
|
||||||
void SendGameMode (eGameMode a_GameMode);
|
void SendGameMode (eGameMode a_GameMode);
|
||||||
void SendHealth (void);
|
void SendHealth (void);
|
||||||
|
void SendHeldItemChange (int a_ItemIndex);
|
||||||
void SendHideTitle (void); // tolua_export
|
void SendHideTitle (void); // tolua_export
|
||||||
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
|
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
|
||||||
void SendLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo);
|
void SendLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo);
|
||||||
|
@ -743,6 +743,18 @@ void cPlayer::SendHealth(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cPlayer::SendHotbarActiveSlot(void)
|
||||||
|
{
|
||||||
|
if (m_ClientHandle != nullptr)
|
||||||
|
{
|
||||||
|
m_ClientHandle->SendHeldItemChange(m_Inventory.GetEquippedSlotNum());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::SendExperience(void)
|
void cPlayer::SendExperience(void)
|
||||||
{
|
{
|
||||||
if (m_ClientHandle != nullptr)
|
if (m_ClientHandle != nullptr)
|
||||||
@ -2212,6 +2224,10 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Inventory.LoadFromJson(root["inventory"]);
|
m_Inventory.LoadFromJson(root["inventory"]);
|
||||||
|
|
||||||
|
int equippedSlotNum = root.get("equippedItemSlot", 0).asInt();
|
||||||
|
m_Inventory.SetEquippedSlotNum(equippedSlotNum);
|
||||||
|
|
||||||
cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents);
|
cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents);
|
||||||
|
|
||||||
m_LoadedWorldName = root.get("world", "world").asString();
|
m_LoadedWorldName = root.get("world", "world").asString();
|
||||||
@ -2302,6 +2318,7 @@ bool cPlayer::SaveToDisk()
|
|||||||
root["position"] = JSON_PlayerPosition;
|
root["position"] = JSON_PlayerPosition;
|
||||||
root["rotation"] = JSON_PlayerRotation;
|
root["rotation"] = JSON_PlayerRotation;
|
||||||
root["inventory"] = JSON_Inventory;
|
root["inventory"] = JSON_Inventory;
|
||||||
|
root["equippedItemSlot"] = m_Inventory.GetEquippedSlotNum();
|
||||||
root["enderchestinventory"] = JSON_EnderChestInventory;
|
root["enderchestinventory"] = JSON_EnderChestInventory;
|
||||||
root["health"] = m_Health;
|
root["health"] = m_Health;
|
||||||
root["xpTotal"] = m_LifetimeTotalXp;
|
root["xpTotal"] = m_LifetimeTotalXp;
|
||||||
|
@ -431,6 +431,9 @@ public:
|
|||||||
|
|
||||||
void SendHealth(void);
|
void SendHealth(void);
|
||||||
|
|
||||||
|
// Send current active hotbar slot
|
||||||
|
void SendHotbarActiveSlot(void);
|
||||||
|
|
||||||
void SendExperience(void);
|
void SendExperience(void);
|
||||||
|
|
||||||
/** In UI windows, get the item that the player is dragging */
|
/** In UI windows, get the item that the player is dragging */
|
||||||
|
@ -41,6 +41,7 @@ UInt32 cProtocol_1_9_0::GetPacketId(eOutgoingPackets a_Packet)
|
|||||||
case sendExplosion: return 0x1c;
|
case sendExplosion: return 0x1c;
|
||||||
case sendGameMode: return 0x1e;
|
case sendGameMode: return 0x1e;
|
||||||
case sendHealth: return 0x3e;
|
case sendHealth: return 0x3e;
|
||||||
|
case sendHeldItemChange: return 0x37;
|
||||||
case sendInventorySlot: return 0x16;
|
case sendInventorySlot: return 0x16;
|
||||||
case sendJoinGame: return 0x23;
|
case sendJoinGame: return 0x23;
|
||||||
case sendKeepAlive: return 0x1f;
|
case sendKeepAlive: return 0x1f;
|
||||||
@ -124,6 +125,7 @@ UInt32 cProtocol_1_12::GetPacketId(eOutgoingPackets a_Packet)
|
|||||||
case sendEntityVelocity: return 0x3d;
|
case sendEntityVelocity: return 0x3d;
|
||||||
case sendExperience: return 0x3f;
|
case sendExperience: return 0x3f;
|
||||||
case sendHealth: return 0x40;
|
case sendHealth: return 0x40;
|
||||||
|
case sendHeldItemChange: return 0x39;
|
||||||
case sendLeashEntity: return 0x3c;
|
case sendLeashEntity: return 0x3c;
|
||||||
case sendPlayerMaxSpeed: return 0x4d;
|
case sendPlayerMaxSpeed: return 0x4d;
|
||||||
case sendRemoveEntityEffect: return 0x32;
|
case sendRemoveEntityEffect: return 0x32;
|
||||||
@ -161,6 +163,7 @@ UInt32 cProtocol_1_12_1::GetPacketId(eOutgoingPackets a_Packet)
|
|||||||
case sendEntityVelocity: return 0x3e;
|
case sendEntityVelocity: return 0x3e;
|
||||||
case sendExperience: return 0x40;
|
case sendExperience: return 0x40;
|
||||||
case sendHealth: return 0x41;
|
case sendHealth: return 0x41;
|
||||||
|
case sendHeldItemChange: return 0x3a;
|
||||||
case sendLeashEntity: return 0x3d;
|
case sendLeashEntity: return 0x3d;
|
||||||
case sendPlayerList: return 0x2e;
|
case sendPlayerList: return 0x2e;
|
||||||
case sendPlayerAbilities: return 0x2c;
|
case sendPlayerAbilities: return 0x2c;
|
||||||
|
@ -89,6 +89,7 @@ public:
|
|||||||
sendExplosion,
|
sendExplosion,
|
||||||
sendGameMode,
|
sendGameMode,
|
||||||
sendHealth,
|
sendHealth,
|
||||||
|
sendHeldItemChange,
|
||||||
sendInventorySlot,
|
sendInventorySlot,
|
||||||
sendJoinGame,
|
sendJoinGame,
|
||||||
sendKeepAlive,
|
sendKeepAlive,
|
||||||
@ -160,6 +161,7 @@ public:
|
|||||||
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0;
|
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0;
|
||||||
virtual void SendGameMode (eGameMode a_GameMode) = 0;
|
virtual void SendGameMode (eGameMode a_GameMode) = 0;
|
||||||
virtual void SendHealth (void) = 0;
|
virtual void SendHealth (void) = 0;
|
||||||
|
virtual void SendHeldItemChange (int a_ItemIndex) = 0;
|
||||||
virtual void SendHideTitle (void) = 0;
|
virtual void SendHideTitle (void) = 0;
|
||||||
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
|
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0;
|
||||||
virtual void SendKeepAlive (UInt32 a_PingID) = 0;
|
virtual void SendKeepAlive (UInt32 a_PingID) = 0;
|
||||||
|
@ -428,6 +428,17 @@ void cProtocolRecognizer::SendHealth(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cProtocolRecognizer::SendHeldItemChange(int a_ItemIndex)
|
||||||
|
{
|
||||||
|
ASSERT(m_Protocol != nullptr);
|
||||||
|
m_Protocol->SendHeldItemChange(a_ItemIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cProtocolRecognizer::SendHideTitle(void)
|
void cProtocolRecognizer::SendHideTitle(void)
|
||||||
{
|
{
|
||||||
ASSERT(m_Protocol != nullptr);
|
ASSERT(m_Protocol != nullptr);
|
||||||
|
@ -85,6 +85,7 @@ public:
|
|||||||
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
|
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
|
||||||
virtual void SendGameMode (eGameMode a_GameMode) override;
|
virtual void SendGameMode (eGameMode a_GameMode) override;
|
||||||
virtual void SendHealth (void) override;
|
virtual void SendHealth (void) override;
|
||||||
|
virtual void SendHeldItemChange (int a_ItemIndex) override;
|
||||||
virtual void SendHideTitle (void) override;
|
virtual void SendHideTitle (void) override;
|
||||||
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
|
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
|
||||||
virtual void SendKeepAlive (UInt32 a_PingID) override;
|
virtual void SendKeepAlive (UInt32 a_PingID) override;
|
||||||
|
@ -592,6 +592,19 @@ void cProtocol_1_8_0::SendHealth(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cProtocol_1_8_0::SendHeldItemChange(int a_ItemIndex)
|
||||||
|
{
|
||||||
|
ASSERT((a_ItemIndex >= 0) && (a_ItemIndex <= 8)); // Valid check
|
||||||
|
|
||||||
|
cPacketizer Pkt(*this, 0x09); // Held item change
|
||||||
|
cPlayer * Player = m_Client->GetPlayer();
|
||||||
|
Pkt.WriteBEInt8(static_cast<Int8>(Player->GetInventory().GetEquippedSlotNum()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cProtocol_1_8_0::SendHideTitle(void)
|
void cProtocol_1_8_0::SendHideTitle(void)
|
||||||
{
|
{
|
||||||
ASSERT(m_State == 3); // In game mode?
|
ASSERT(m_State == 3); // In game mode?
|
||||||
|
@ -77,6 +77,7 @@ public:
|
|||||||
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
|
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
|
||||||
virtual void SendGameMode (eGameMode a_GameMode) override;
|
virtual void SendGameMode (eGameMode a_GameMode) override;
|
||||||
virtual void SendHealth (void) override;
|
virtual void SendHealth (void) override;
|
||||||
|
virtual void SendHeldItemChange (int a_ItemIndex) override;
|
||||||
virtual void SendHideTitle (void) override;
|
virtual void SendHideTitle (void) override;
|
||||||
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
|
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
|
||||||
virtual void SendKeepAlive (UInt32 a_PingID) override;
|
virtual void SendKeepAlive (UInt32 a_PingID) override;
|
||||||
|
@ -636,6 +636,20 @@ void cProtocol_1_9_0::SendHealth(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cProtocol_1_9_0::SendHeldItemChange(int a_ItemIndex)
|
||||||
|
{
|
||||||
|
ASSERT((a_ItemIndex >= 0) && (a_ItemIndex <= 8)); // Valid check
|
||||||
|
|
||||||
|
cPacketizer Pkt(*this, GetPacketId(sendHeldItemChange)); // Held item change
|
||||||
|
cPlayer * Player = m_Client->GetPlayer();
|
||||||
|
Pkt.WriteBEInt8(static_cast<Int8>(Player->GetInventory().GetEquippedSlotNum()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cProtocol_1_9_0::SendHideTitle(void)
|
void cProtocol_1_9_0::SendHideTitle(void)
|
||||||
{
|
{
|
||||||
ASSERT(m_State == 3); // In game mode?
|
ASSERT(m_State == 3); // In game mode?
|
||||||
|
@ -83,6 +83,7 @@ public:
|
|||||||
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
|
virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override;
|
||||||
virtual void SendGameMode (eGameMode a_GameMode) override;
|
virtual void SendGameMode (eGameMode a_GameMode) override;
|
||||||
virtual void SendHealth (void) override;
|
virtual void SendHealth (void) override;
|
||||||
|
virtual void SendHeldItemChange (int a_ItemIndex) override;
|
||||||
virtual void SendHideTitle (void) override;
|
virtual void SendHideTitle (void) override;
|
||||||
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
|
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;
|
||||||
virtual void SendKeepAlive (UInt32 a_PingID) override;
|
virtual void SendKeepAlive (UInt32 a_PingID) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user