Fix: MapPacket.write_fields() is incorrect.
This commit is contained in:
1 parent
8578326c2f
commit
db714f9490
3 files changed
+33
-15
No files matched your search
@@ -114,11 +114,20 @@ class MapPacket(Packet):
|
|||||||
|
|
||||||
VarInt.send(len(self.icons), packet_buffer)
|
VarInt.send(len(self.icons), packet_buffer)
|
||||||
for icon in self.icons:
|
for icon in self.icons:
|
||||||
type_and_direction = (icon.direction << 4) & 0xF0
|
if self.context.protocol_version >= 373:
|
||||||
type_and_direction |= (icon.type & 0xF)
|
VarInt.send(icon.type, packet_buffer)
|
||||||
|
else:
|
||||||
|
type_and_direction = (icon.type << 4) & 0xF0
|
||||||
|
type_and_direction |= (icon.direction & 0xF)
|
||||||
UnsignedByte.send(type_and_direction, packet_buffer)
|
UnsignedByte.send(type_and_direction, packet_buffer)
|
||||||
Byte.send(icon.location[0], packet_buffer)
|
Byte.send(icon.location[0], packet_buffer)
|
||||||
Byte.send(icon.location[1], packet_buffer)
|
Byte.send(icon.location[1], packet_buffer)
|
||||||
|
if self.context.protocol_version >= 373:
|
||||||
|
UnsignedByte.send(icon.direction, packet_buffer)
|
||||||
|
if self.context.protocol_version >= 364:
|
||||||
|
Boolean.send(icon.display_name is not None, packet_buffer)
|
||||||
|
if icon.display_name is not None:
|
||||||
|
String.send(icon.display_name, packet_buffer)
|
||||||
|
|
||||||
UnsignedByte.send(self.width, packet_buffer)
|
UnsignedByte.send(self.width, packet_buffer)
|
||||||
if self.width:
|
if self.width:
|
||||||
|
|||||||
@@ -45,26 +45,28 @@ class MapPacketTest(unittest.TestCase):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def make_map_packet(
|
def make_map_packet(
|
||||||
context, width=2, height=2, offset=(2, 2), pixels=b"this"):
|
context, width=2, height=2, offset=(2, 2), pixels=b"this"):
|
||||||
|
|
||||||
packet = MapPacket(context)
|
packet = MapPacket(context)
|
||||||
|
|
||||||
packet.map_id = 1
|
packet.map_id = 1
|
||||||
packet.scale = 42
|
packet.scale = 42
|
||||||
packet.is_tracking_position = True
|
packet.is_tracking_position = True
|
||||||
packet.icons = []
|
packet.icons = []
|
||||||
packet.icons.append(
|
d_name = u'Marshmallow' if context.protocol_version >= 364 else None
|
||||||
MapPacket.MapIcon(type=2, direction=2, location=(1, 1))
|
packet.icons.append(MapPacket.MapIcon(
|
||||||
)
|
type=2, direction=2, location=(1, 1), display_name=d_name
|
||||||
packet.icons.append(
|
))
|
||||||
MapPacket.MapIcon(type=3, direction=3, location=(3, 3))
|
packet.icons.append(MapPacket.MapIcon(
|
||||||
)
|
type=3, direction=3, location=(3, 3)
|
||||||
|
))
|
||||||
packet.width = width
|
packet.width = width
|
||||||
packet.height = height
|
packet.height = height if width else 0
|
||||||
packet.offset = offset
|
packet.offset = offset if width else None
|
||||||
packet.pixels = pixels
|
packet.pixels = pixels if width else None
|
||||||
return packet
|
return packet
|
||||||
|
|
||||||
def packet_roundtrip(self, context):
|
def packet_roundtrip(self, context, **kwds):
|
||||||
packet = self.make_map_packet(context)
|
packet = self.make_map_packet(context, **kwds)
|
||||||
|
|
||||||
packet_buffer = PacketBuffer()
|
packet_buffer = PacketBuffer()
|
||||||
packet.write(packet_buffer)
|
packet.write(packet_buffer)
|
||||||
@@ -93,6 +95,9 @@ class MapPacketTest(unittest.TestCase):
|
|||||||
def test_packet_roundtrip(self):
|
def test_packet_roundtrip(self):
|
||||||
self.packet_roundtrip(ConnectionContext(protocol_version=106))
|
self.packet_roundtrip(ConnectionContext(protocol_version=106))
|
||||||
self.packet_roundtrip(ConnectionContext(protocol_version=107))
|
self.packet_roundtrip(ConnectionContext(protocol_version=107))
|
||||||
|
self.packet_roundtrip(ConnectionContext(protocol_version=379))
|
||||||
|
self.packet_roundtrip(ConnectionContext(protocol_version=379),
|
||||||
|
width=0)
|
||||||
|
|
||||||
def test_map_set(self):
|
def test_map_set(self):
|
||||||
map_set = MapPacket.MapSet()
|
map_set = MapPacket.MapSet()
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import unittest
|
|||||||
from minecraft.networking.types import (
|
from minecraft.networking.types import (
|
||||||
Type, Boolean, UnsignedByte, Byte, Short, UnsignedShort,
|
Type, Boolean, UnsignedByte, Byte, Short, UnsignedShort,
|
||||||
Integer, VarInt, Long, Float, Double, ShortPrefixedByteArray,
|
Integer, VarInt, Long, Float, Double, ShortPrefixedByteArray,
|
||||||
VarIntPrefixedByteArray, UUID, String as StringType
|
VarIntPrefixedByteArray, UUID, String as StringType, Position,
|
||||||
|
TrailingByteArray, UnsignedLong,
|
||||||
)
|
)
|
||||||
from minecraft.networking.packets import PacketBuffer
|
from minecraft.networking.packets import PacketBuffer
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ TEST_DATA = {
|
|||||||
Byte: [-22, 22],
|
Byte: [-22, 22],
|
||||||
Short: [-340, 22, 350],
|
Short: [-340, 22, 350],
|
||||||
UnsignedShort: [0, 400],
|
UnsignedShort: [0, 400],
|
||||||
|
UnsignedLong: [0, 400],
|
||||||
Integer: [-1000, 1000],
|
Integer: [-1000, 1000],
|
||||||
VarInt: [1, 250, 50000, 10000000],
|
VarInt: [1, 250, 50000, 10000000],
|
||||||
Long: [50000000],
|
Long: [50000000],
|
||||||
@@ -22,8 +24,10 @@ TEST_DATA = {
|
|||||||
Double: [36.004002],
|
Double: [36.004002],
|
||||||
ShortPrefixedByteArray: [bytes(245)],
|
ShortPrefixedByteArray: [bytes(245)],
|
||||||
VarIntPrefixedByteArray: [bytes(1234)],
|
VarIntPrefixedByteArray: [bytes(1234)],
|
||||||
|
TrailingByteArray: [b'Q^jO<5*|+o LGc('],
|
||||||
UUID: ["12345678-1234-5678-1234-567812345678"],
|
UUID: ["12345678-1234-5678-1234-567812345678"],
|
||||||
StringType: ["hello world"]
|
StringType: ["hello world"],
|
||||||
|
Position: [(758, 0, 691)],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user