Move 1.15.2 code into old/
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
import minecraft.networking.packets
|
||||
|
||||
from minecraft.networking.packets import Packet
|
||||
from minecraft.networking.types import BlockFace, VarInt, Position, Boolean, Byte, UnsignedByte, Short, TrailingByteArray, Long
|
||||
from minecraft.networking.types.basic import Type
|
||||
|
||||
#def qot(x):
|
||||
# print('qot.')
|
||||
# return set()
|
||||
#
|
||||
#minecraft.networking.packets.clientbound.play.get_packets = qot
|
||||
|
||||
|
||||
class AcknowledgePlayerDiggingPacket(Packet):
|
||||
id = 0x08
|
||||
packet_name = 'acknowledge player digging'
|
||||
definition = [
|
||||
{'location': Position},
|
||||
{'block': VarInt},
|
||||
{'status': VarInt},
|
||||
{'successful': Boolean},
|
||||
]
|
||||
|
||||
class BlockBreakAnimationPacket(Packet):
|
||||
id = 0x09
|
||||
packet_name = 'block break animation'
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'location': Position},
|
||||
{'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},
|
||||
]
|
||||
|
||||
class TimeUpdatePacket(Packet):
|
||||
id = 0x4F
|
||||
packet_name = 'time update'
|
||||
definition = [
|
||||
{'world_age': Long},
|
||||
{'time_of_day': Long},
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
packets.add(TimeUpdatePacket)
|
||||
return packets
|
||||
return lambda x: wrapper(old_get_packets, x)
|
||||
|
||||
minecraft.networking.packets.clientbound.play.get_packets = get_packets(minecraft.networking.packets.clientbound.play.get_packets)
|
||||
|
||||
class PlayerDiggingPacket(Packet):
|
||||
# used when player mines / breaks blocks
|
||||
# https://wiki.vg/Protocol#Player_Digging
|
||||
|
||||
id = 0x1A
|
||||
packet_name = 'player digging'
|
||||
|
||||
definition = [
|
||||
{'status': VarInt},
|
||||
{'location': Position},
|
||||
{'face': VarInt},
|
||||
]
|
||||
|
||||
STARTED = 0
|
||||
CANCELLED = 1
|
||||
FINISHED = 2
|
||||
|
||||
# PlayerBlockPlacementPacket.Face is an alias for BlockFace.
|
||||
Face = BlockFace
|
||||
|
||||
|
||||
class PickItemPacket(Packet):
|
||||
# used when player picks item (middle click)
|
||||
# https://wiki.vg/Protocol#Pick_Item
|
||||
|
||||
id = 0x17
|
||||
packet_name = 'pick item'
|
||||
|
||||
definition = [
|
||||
{'slot_to_use': VarInt},
|
||||
]
|
||||
|
||||
class HeldItemChangePacket(Packet):
|
||||
# Sent when the player changes the slot selection
|
||||
# https://wiki.vg/Protocol#Held_Item_Change_.28serverbound.29
|
||||
|
||||
id = 0x23
|
||||
packet_name = 'held item change'
|
||||
|
||||
definition = [
|
||||
{'slot': Short},
|
||||
]
|
||||
Reference in New Issue
Block a user