Add state machine for caching items into chests
This commit is contained in:
		@@ -112,6 +112,8 @@ class ChatManager:
 | 
			
		||||
            return ''.join([self.translate_chat(x) for x in data['extra']])
 | 
			
		||||
        elif 'text' in data:
 | 
			
		||||
            return data['text']
 | 
			
		||||
        elif 'with' in data:
 | 
			
		||||
            return '<{}> {}'.format(*[self.translate_chat(x) for x in data['with']])
 | 
			
		||||
        elif 'translate' in data:
 | 
			
		||||
            return data['translate']
 | 
			
		||||
        else:
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ from minecraft.networking.packets import Packet, PacketBuffer
 | 
			
		||||
from minecraft.networking.types import (
 | 
			
		||||
    VarInt, Integer, UnsignedByte, Position, Vector, MutableRecord,
 | 
			
		||||
    attribute_alias, multi_attribute_alias, Long, Boolean, VarLong,
 | 
			
		||||
    Short, UnsignedLong, Byte, BlockFace,
 | 
			
		||||
    Short, UnsignedLong, Byte, BlockFace, String
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from protocol.types import Nbt, Slot
 | 
			
		||||
@@ -217,3 +217,45 @@ class HeldItemChangePacket(Packet):
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'slot': Short},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class OpenWindowPacket(Packet):
 | 
			
		||||
    # Sent to the client when it should open an inventory, such as a chest, workbench, or furnace
 | 
			
		||||
    # https://wiki.vg/Protocol#Open_Window
 | 
			
		||||
 | 
			
		||||
    id = 0x2D
 | 
			
		||||
    packet_name = 'open window'
 | 
			
		||||
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'window_id': VarInt},
 | 
			
		||||
        {'window_type': VarInt},
 | 
			
		||||
        {'window_title': String},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
class CloseWindowPacket(Packet):
 | 
			
		||||
    # Sent by the client when closing a window
 | 
			
		||||
    # https://wiki.vg/Protocol#Close_Window_.28serverbound.29
 | 
			
		||||
 | 
			
		||||
    id = 0x0A
 | 
			
		||||
    packet_name = 'close window'
 | 
			
		||||
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'window_id': UnsignedByte},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ClickWindowPacket(Packet):
 | 
			
		||||
    # Sent by the player when it clicks on a slot in a window
 | 
			
		||||
    # https://wiki.vg/Protocol#Click_Window
 | 
			
		||||
 | 
			
		||||
    id = 0x09
 | 
			
		||||
    packet_name = 'click window'
 | 
			
		||||
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'window_id': UnsignedByte},
 | 
			
		||||
        {'slot': Short},
 | 
			
		||||
        {'button': Byte},
 | 
			
		||||
        {'action_number': Short},
 | 
			
		||||
        {'mode': VarInt},
 | 
			
		||||
        {'clicked_item': Slot},
 | 
			
		||||
    ]
 | 
			
		||||
 
 | 
			
		||||
@@ -120,14 +120,10 @@ class Slot(Type):
 | 
			
		||||
        item_count = Byte.read(file_object) if present else None
 | 
			
		||||
        nbt = TrailingByteArray.read(file_object) if present else None
 | 
			
		||||
        return Slot(present, item_id, item_count, nbt)
 | 
			
		||||
        #a = {}
 | 
			
		||||
        #a['present'] = Boolean.read(file_object)
 | 
			
		||||
        #a['item_id'] = VarInt.read(file_object) if a['present'] else None
 | 
			
		||||
        #a['item_count'] = Byte.read(file_object) if a['present'] else None
 | 
			
		||||
        #a['nbt'] = TrailingByteArray.read(file_object) if a['present'] else None
 | 
			
		||||
        #return a
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def send(value, socket):
 | 
			
		||||
        # TODO
 | 
			
		||||
        pass
 | 
			
		||||
        Boolean.send(value.present, socket)
 | 
			
		||||
        VarInt.send(value.item_id, socket)
 | 
			
		||||
        Byte.send(value.item_count, socket)
 | 
			
		||||
        TrailingByteArray.send(value.nbt, socket)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user