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:
committed by
peterbell10
parent
7b431bed51
commit
3e802932a6
@@ -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)
|
||||
{
|
||||
if (m_ClientHandle != nullptr)
|
||||
@@ -2212,6 +2224,10 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
|
||||
}
|
||||
|
||||
m_Inventory.LoadFromJson(root["inventory"]);
|
||||
|
||||
int equippedSlotNum = root.get("equippedItemSlot", 0).asInt();
|
||||
m_Inventory.SetEquippedSlotNum(equippedSlotNum);
|
||||
|
||||
cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents);
|
||||
|
||||
m_LoadedWorldName = root.get("world", "world").asString();
|
||||
@@ -2302,6 +2318,7 @@ bool cPlayer::SaveToDisk()
|
||||
root["position"] = JSON_PlayerPosition;
|
||||
root["rotation"] = JSON_PlayerRotation;
|
||||
root["inventory"] = JSON_Inventory;
|
||||
root["equippedItemSlot"] = m_Inventory.GetEquippedSlotNum();
|
||||
root["enderchestinventory"] = JSON_EnderChestInventory;
|
||||
root["health"] = m_Health;
|
||||
root["xpTotal"] = m_LifetimeTotalXp;
|
||||
|
||||
Reference in New Issue
Block a user