80 lines
1.9 KiB
Python
80 lines
1.9 KiB
Python
|
import minecraft.networking.packets
|
||
|
|
||
|
from minecraft.networking.packets import Packet
|
||
|
from minecraft.networking.types import BlockFace, VarInt, Position, Boolean, Byte
|
||
|
|
||
|
#def qot(x):
|
||
|
# print('qot.')
|
||
|
# return set()
|
||
|
#
|
||
|
#minecraft.networking.packets.clientbound.play.get_packets = qot
|
||
|
|
||
|
|
||
|
class AcknowledgePlayerDiggingPacket(Packet):
|
||
|
@staticmethod
|
||
|
def get_id(context):
|
||
|
return 0x08
|
||
|
|
||
|
packet_name = 'acknowledge player digging'
|
||
|
definition = [
|
||
|
{'status': VarInt},
|
||
|
{'location': Position},
|
||
|
{'face': VarInt},
|
||
|
{'successful': Boolean},
|
||
|
]
|
||
|
|
||
|
class BlockBreakAnimationPacket(Packet):
|
||
|
@staticmethod
|
||
|
def get_id(context):
|
||
|
return 0x09
|
||
|
|
||
|
packet_name = 'block break animation'
|
||
|
definition = [
|
||
|
{'entity_id': VarInt},
|
||
|
{'location': Position},
|
||
|
{'destroy_stage': Byte},
|
||
|
]
|
||
|
|
||
|
def get_packets(old_get_packets):
|
||
|
def wrapper(func, context):
|
||
|
print('Monkey-patched.')
|
||
|
packets = func(context)
|
||
|
packets.add(AcknowledgePlayerDiggingPacket)
|
||
|
packets.add(BlockBreakAnimationPacket)
|
||
|
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},
|
||
|
]
|