feat: track container windows
This commit is contained in:
parent
d54fb380e9
commit
61811f542b
3 changed files with 70 additions and 1 deletions
|
@ -3,3 +3,4 @@ from .inventory import GameInventory
|
||||||
from .tablist import GameTablist
|
from .tablist import GameTablist
|
||||||
from .chat import GameChat
|
from .chat import GameChat
|
||||||
from .world import GameWorld
|
from .world import GameWorld
|
||||||
|
from .container import GameContainer
|
||||||
|
|
67
src/treepuncher/game/container.py
Normal file
67
src/treepuncher/game/container.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import asyncio
|
||||||
|
import datetime
|
||||||
|
from turtle import window_width
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
#from aiocraft.client import MinecraftClient
|
||||||
|
from aiocraft.mc.definitions import Item
|
||||||
|
from aiocraft.mc.proto import (
|
||||||
|
PacketOpenWindow, PacketCloseWindow, PacketSetSlot
|
||||||
|
)
|
||||||
|
|
||||||
|
from ..events import JoinGameEvent, DeathEvent, ConnectedEvent, DisconnectedEvent
|
||||||
|
from ..scaffold import Scaffold
|
||||||
|
|
||||||
|
class GameContainer(Scaffold):
|
||||||
|
window_id : int
|
||||||
|
window_title : str
|
||||||
|
window_inventory_type : str
|
||||||
|
window_entity_id : Optional[int]
|
||||||
|
window_transaction_id : int
|
||||||
|
window_inventory : List[Item]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_container_open(self) -> bool:
|
||||||
|
return self.window_id > 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def next_window_tid(self) -> int:
|
||||||
|
self.window_transaction_id += 1
|
||||||
|
return self.window_transaction_id
|
||||||
|
|
||||||
|
async def close_container(self):
|
||||||
|
await self.dispatcher.write(
|
||||||
|
PacketCloseWindow(
|
||||||
|
self.dispatcher.proto,
|
||||||
|
windowId=self.window_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.window_transaction_id = 0
|
||||||
|
self.window_id = -1
|
||||||
|
self.window_title = ""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.window_transaction_id = 0
|
||||||
|
self.window_id = -1
|
||||||
|
self.window_title = ""
|
||||||
|
|
||||||
|
@self.on(DisconnectedEvent)
|
||||||
|
async def disconnected_cb(_):
|
||||||
|
self.window_transaction_id = 0
|
||||||
|
self.window_id = -1
|
||||||
|
self.window_title = ""
|
||||||
|
|
||||||
|
@self.on_packet(PacketOpenWindow)
|
||||||
|
async def on_player_open_window(packet:PacketOpenWindow):
|
||||||
|
self.window_id = packet.windowId
|
||||||
|
self.window_title = packet.windowTitle
|
||||||
|
self.window_inventory_type = packet.inventoryType
|
||||||
|
self.window_entity_id = packet.entityId
|
||||||
|
self.window_inventory = [None] * packet.slotCount
|
||||||
|
|
||||||
|
@self.on_packet(PacketSetSlot)
|
||||||
|
async def on_set_slot(packet:PacketSetSlot):
|
||||||
|
if packet.windowId == self.window_id:
|
||||||
|
self.window_inventory[packet.slot] = packet.item
|
|
@ -14,7 +14,7 @@ from aiocraft.mc.packet import Packet
|
||||||
from aiocraft.mc.auth import AuthInterface, AuthException, MojangAuthenticator, MicrosoftAuthenticator, OfflineAuthenticator
|
from aiocraft.mc.auth import AuthInterface, AuthException, MojangAuthenticator, MicrosoftAuthenticator, OfflineAuthenticator
|
||||||
|
|
||||||
from .storage import Storage, SystemState, AuthenticatorState
|
from .storage import Storage, SystemState, AuthenticatorState
|
||||||
from .game import GameState, GameChat, GameInventory, GameTablist, GameWorld
|
from .game import GameState, GameChat, GameInventory, GameTablist, GameWorld, GameContainer
|
||||||
from .addon import Addon
|
from .addon import Addon
|
||||||
from .notifier import Notifier, Provider
|
from .notifier import Notifier, Provider
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ class Treepuncher(
|
||||||
GameState,
|
GameState,
|
||||||
GameChat,
|
GameChat,
|
||||||
GameInventory,
|
GameInventory,
|
||||||
|
GameContainer,
|
||||||
GameTablist,
|
GameTablist,
|
||||||
GameWorld
|
GameWorld
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in a new issue