Sync inventory snapshots from open containers

This commit is contained in:
Tanner committed 2026-11-10 18:39:02 +00:00
1 parent 185cefced9
commit 5c6c08e3c0
2 files changed
+47 -5

No files matched your search

+18 -5
View File
@@ -625,6 +625,15 @@ class InventoryManager:
state_id=self.g.inventory_state_ids.get(packet.window_id, 0),
)
@staticmethod
def _player_inventory_slot(window_slot, container_slots):
offset = window_slot - container_slots
if 0 <= offset < 27:
return 9 + offset
if 27 <= offset < 36:
return 36 + offset - 27
return None
def handle_content(self, packet):
slots = {index: self.to_slot(item)
for index, item in enumerate(packet.items)}
@@ -640,6 +649,11 @@ class InventoryManager:
# Player inventory contributes 36 slots to chest menus.
self.g.window.container_slots = max(0, len(slots) - 36)
self.g.window.state_id = packet.state_id
for window_slot, item in slots.items():
inventory_slot = self._player_inventory_slot(
window_slot, self.g.window.container_slots)
if inventory_slot is not None:
self.g.inv[inventory_slot] = item
self.g.cursor = self.to_slot(packet.carried_item)
self.g.item_lock = False
@@ -660,11 +674,10 @@ class InventoryManager:
packet.container_id == self.g.window.window_id):
self.g.window.contents[packet.slot] = item
self.g.window.state_id = packet.state_id
offset = packet.slot - self.g.window.container_slots
if 0 <= offset < 27:
self.g.inv[9 + offset] = item
elif 27 <= offset < 36:
self.g.inv[36 + offset - 27] = item
inventory_slot = self._player_inventory_slot(
packet.slot, self.g.window.container_slots)
if inventory_slot is not None:
self.g.inv[inventory_slot] = item
self.g.item_lock = False
def _sync_held_item(self):