Add window slot packet and item info
This commit is contained in:
+61
-9
@@ -1,7 +1,8 @@
|
||||
import minecraft.networking.packets
|
||||
|
||||
from minecraft.networking.packets import Packet
|
||||
from minecraft.networking.types import BlockFace, VarInt, Position, Boolean, Byte
|
||||
from minecraft.networking.types import BlockFace, VarInt, Position, Boolean, Byte, UnsignedByte, Short, TrailingByteArray
|
||||
from minecraft.networking.types.basic import Type
|
||||
|
||||
#def qot(x):
|
||||
# print('qot.')
|
||||
@@ -11,10 +12,7 @@ from minecraft.networking.types import BlockFace, VarInt, Position, Boolean, Byt
|
||||
|
||||
|
||||
class AcknowledgePlayerDiggingPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x08
|
||||
|
||||
id = 0x08
|
||||
packet_name = 'acknowledge player digging'
|
||||
definition = [
|
||||
{'status': VarInt},
|
||||
@@ -24,10 +22,7 @@ class AcknowledgePlayerDiggingPacket(Packet):
|
||||
]
|
||||
|
||||
class BlockBreakAnimationPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x09
|
||||
|
||||
id = 0x09
|
||||
packet_name = 'block break animation'
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
@@ -35,12 +30,69 @@ class BlockBreakAnimationPacket(Packet):
|
||||
{'destroy_stage': Byte},
|
||||
]
|
||||
|
||||
#class WindowItemsPacket(Packet):
|
||||
# id = 0x15
|
||||
# packet_name = 'window items'
|
||||
# definition = [
|
||||
# {'window_id': UnsignedByte},
|
||||
# {'count': Short},
|
||||
# {'destroy_stage': Byte},
|
||||
# ]
|
||||
|
||||
|
||||
class Slot(Type):
|
||||
def __init__(self, present, item_id, item_count, nbt):
|
||||
self.present = present
|
||||
self.item_id = item_id
|
||||
self.item_count = item_count
|
||||
self.nbt = nbt
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dict__)
|
||||
def __repr__(self):
|
||||
return 'Slot(present={}, item_id={}, item_count={}, nbt={}'.format(
|
||||
self.present, self.item_id, self.item_count, self.nbt)
|
||||
|
||||
@staticmethod
|
||||
def read(file_object):
|
||||
present = Boolean.read(file_object)
|
||||
item_id = VarInt.read(file_object) if present else None
|
||||
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
|
||||
|
||||
|
||||
|
||||
class SetSlotPacket(Packet):
|
||||
id = 0x17
|
||||
packet_name = 'set slot'
|
||||
definition = [
|
||||
{'window_id': Byte},
|
||||
{'slot': Short},
|
||||
{'slot_data': Slot},
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
def get_packets(old_get_packets):
|
||||
def wrapper(func, context):
|
||||
print('Monkey-patched.')
|
||||
packets = func(context)
|
||||
packets.add(AcknowledgePlayerDiggingPacket)
|
||||
packets.add(BlockBreakAnimationPacket)
|
||||
packets.add(SetSlotPacket)
|
||||
return packets
|
||||
return lambda x: wrapper(old_get_packets, x)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user