Position type fix. Add new PlayerBlockPlacementPacket

This commit is contained in:
gurland authored and joo committed 2018-05-18 08:50:59 +01:00
1 parent ae0a3b3989
commit c584f29154
2 files changed
+30 -4

No files matched your search

@@ -2,7 +2,7 @@ from minecraft.networking.packets import (
Packet, PacketBuffer
)
from minecraft.networking.types import (
VarInt, Integer, UnsignedByte, Position
VarInt, Integer, UnsignedByte, Position, Float
)
@@ -29,8 +29,7 @@ class BlockChangePacket(Packet):
def write(self, socket, compression_threshold=None):
packet_buffer = PacketBuffer()
(x, y, z) = self.location
Position.send(x, y, z, packet_buffer)
Position.send(self.location, packet_buffer)
blockData = ((self.blockId << 4) | (self.blockMeta & 0xF))
VarInt.send(blockData)
self._write_buffer(socket, packet_buffer, compression_threshold)
@@ -107,3 +106,28 @@ class MultiBlockChangePacket(Packet):
def write(self, socket, compression_threshold=None):
raise NotImplementedError
class PlayerBlockPlacementPacket(Packet):
"""Realizaton of http://wiki.vg/Protocol#Player_Block_Placement packet
Usage:
packet = PlayerBlockPlacementPacket()
packet.location = Position(x=1200, y=65, z=-420)
packet.face = 2 # 0: Bottom, 1: Top, 2: North, 3: South, 4: West, 5: East
packet.hand = 0 # 0: Main, 2: Off
Next values are called in-block coordinates.
They are calculated using raytracing. From 0 to 1:
packet.x = 0.725
packet.y = 0.125
packet.z = 0.555"""
id = 0x1F
packet_name = 'player block placement'
definition = [
{'location': Position},
{'face': VarInt},
{'hand': VarInt},
{'x': Float},
{'y': Float},
{'z': Float},
]