Port over custom packets and update to 1.16.2
This commit is contained in:
		@@ -1,18 +1,14 @@
 | 
			
		||||
from math import floor
 | 
			
		||||
 | 
			
		||||
from minecraft.networking.packets import Packet, PacketBuffer
 | 
			
		||||
from minecraft.networking.types import (
 | 
			
		||||
    VarInt, Integer, Boolean, UnsignedByte, Long, Short,
 | 
			
		||||
    multi_attribute_alias, Vector, UnsignedLong
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from protocol.types import Nbt
 | 
			
		||||
from minecraft.networking.packets import Packet
 | 
			
		||||
from minecraft.networking.types import (
 | 
			
		||||
    VarInt, Integer, UnsignedByte, Position, Vector, MutableRecord,
 | 
			
		||||
    attribute_alias, multi_attribute_alias, Long, Boolean, VarLong,
 | 
			
		||||
    Short, UnsignedLong, Byte, BlockFace,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from protocol.types import Nbt, Slot
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BlockChangePacket(Packet):
 | 
			
		||||
    id = 0x0B
 | 
			
		||||
@@ -176,9 +172,7 @@ class ChunkDataPacket(Packet):
 | 
			
		||||
            y = e['y']
 | 
			
		||||
            self.chunks[floor(y/16)].entities.append(e)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Chunk:
 | 
			
		||||
 | 
			
		||||
    position = multi_attribute_alias(Vector, 'x', 'y', 'z')
 | 
			
		||||
 | 
			
		||||
    def __init__(self, x, y, z, empty=True):
 | 
			
		||||
@@ -246,3 +240,87 @@ class Chunk:
 | 
			
		||||
    def origin(self):
 | 
			
		||||
        return self.position*16
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AcknowledgePlayerDiggingPacket(Packet):
 | 
			
		||||
    id = 0x07
 | 
			
		||||
    packet_name = 'acknowledge player digging'
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'location': Position},
 | 
			
		||||
        {'block': VarInt},
 | 
			
		||||
        {'status': VarInt},
 | 
			
		||||
        {'successful': Boolean},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BlockBreakAnimationPacket(Packet):
 | 
			
		||||
    id = 0x08
 | 
			
		||||
    packet_name = 'block break animation'
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'entity_id': VarInt},
 | 
			
		||||
        {'location': Position},
 | 
			
		||||
        {'destroy_stage': Byte},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SetSlotPacket(Packet):
 | 
			
		||||
    id = 0x15
 | 
			
		||||
    packet_name = 'set slot'
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'window_id': Byte},
 | 
			
		||||
        {'slot': Short},
 | 
			
		||||
        {'slot_data': Slot},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TimeUpdatePacket(Packet):
 | 
			
		||||
    id = 0x4E
 | 
			
		||||
    packet_name = 'time update'
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'world_age': Long},
 | 
			
		||||
        {'time_of_day': Long},
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PlayerDiggingPacket(Packet):
 | 
			
		||||
    # used when player mines / breaks blocks
 | 
			
		||||
    # https://wiki.vg/Protocol#Player_Digging
 | 
			
		||||
 | 
			
		||||
    id = 0x1B
 | 
			
		||||
    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 = 0x18
 | 
			
		||||
    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 = 0x25
 | 
			
		||||
    packet_name = 'held item change'
 | 
			
		||||
 | 
			
		||||
    definition = [
 | 
			
		||||
        {'slot': Short},
 | 
			
		||||
    ]
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,12 @@
 | 
			
		||||
from __future__ import division
 | 
			
		||||
 | 
			
		||||
from minecraft.networking.types.basic import Type, Byte, Short, Integer, Long, Float, Double, ShortPrefixedByteArray
 | 
			
		||||
 | 
			
		||||
import struct
 | 
			
		||||
 | 
			
		||||
from minecraft.networking.types.basic import (
 | 
			
		||||
    Type, Byte, Short, Integer, Long, Float, Double,
 | 
			
		||||
    ShortPrefixedByteArray, Boolean, VarInt, TrailingByteArray
 | 
			
		||||
)
 | 
			
		||||
from minecraft.networking.types.utility import Vector
 | 
			
		||||
from minecraft.networking.types.basic import Type, Byte, Short, Integer, Long, Float, Double, ShortPrefixedByteArray
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IntegerPrefixedByteArray(Type):
 | 
			
		||||
@@ -19,6 +20,7 @@ class IntegerPrefixedByteArray(Type):
 | 
			
		||||
        Integer.send(len(value), socket)
 | 
			
		||||
        socket.send(value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TAG_End = 0
 | 
			
		||||
TAG_Byte = 1
 | 
			
		||||
TAG_Short = 2
 | 
			
		||||
@@ -96,3 +98,36 @@ class Nbt(Type):
 | 
			
		||||
    def send(value, socket):
 | 
			
		||||
        # TODO
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user