Sync inventory snapshots from open containers
This commit is contained in:
1 parent
185cefced9
commit
5c6c08e3c0
2 files changed
+47
-5
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import io
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from munch import Munch
|
||||
from minecraft.networking.modern import (
|
||||
@@ -10,6 +11,7 @@ from minecraft.networking.packets import PacketBuffer
|
||||
from mosfet.game import (
|
||||
ContainerClickDropPacket, ContainerClickQuickMovePacket, Game,
|
||||
)
|
||||
from mosfet.protocol.managers import InventoryManager
|
||||
from mosfet.protocol.types import Slot
|
||||
|
||||
|
||||
@@ -22,6 +24,33 @@ class FakeConnection:
|
||||
|
||||
|
||||
class TestInventoryDrain(unittest.TestCase):
|
||||
def test_container_snapshot_refreshes_player_inventory_slots(self):
|
||||
stale = Slot(True, 123, 64)
|
||||
current = Slot(True, 456, 12)
|
||||
contents = [Slot(False) for _ in range(63)]
|
||||
contents[27] = current
|
||||
contents[28] = Slot(False)
|
||||
contents[62] = Slot(True, 789, 1)
|
||||
g = Munch(
|
||||
inv={9: stale, 10: stale},
|
||||
window=Munch(window_id=4, contents={}, container_slots=0),
|
||||
inventory_state_ids={}, item_lock=True,
|
||||
)
|
||||
manager = object.__new__(InventoryManager)
|
||||
manager.g = g
|
||||
|
||||
manager.handle_content(SimpleNamespace(
|
||||
container_id=4, state_id=9, items=contents,
|
||||
carried_item=Slot(False), partial=False,
|
||||
))
|
||||
|
||||
self.assertEqual(g.window.container_slots, 27)
|
||||
self.assertEqual(g.inv[9].item_id, 456)
|
||||
self.assertEqual(g.inv[9].item_count, 12)
|
||||
self.assertFalse(g.inv[10].present)
|
||||
self.assertEqual(g.inv[44].item_id, 789)
|
||||
self.assertFalse(g.item_lock)
|
||||
|
||||
def test_drop_packet_encodes_throw_whole_stack(self):
|
||||
packet = ContainerClickDropPacket(
|
||||
container_id=0, state_id=7, slot=45)
|
||||
|
||||
Reference in new issue
Block a user