Add support for Minecraft 18w43a to 1.14 (protocols 441 to 477)

This commit introduces two backward-incompatible changes which may break
existing code:

(1) `networking.packets.clientbound.play.SpawnObjectPacket.EntityType'
is no longer accessible as an attribute of the the `SpawnObjectPacket'
class: the values now depend on a `ConnectionContext`, and must be
accessed through an instance, or using `SpawnObjectPacket.field_enum'.
See the text of the `AttributeError` raised from the descriptor for
`SpawnObjectPacket.EntityType` for the full details.

(2) For some subclasses of `networking.types.Type', it is necessary to
call the methods `read_with_context' and `send_with_context' instead of
`read' and `send', supplying a `ConnectionContext' for those data types
- currently only `Position` - whose layout depends on it.
This commit is contained in:
joodicator committed 2019-05-11 08:43:51 +02:00
1 parent 9b43d6f004
commit 612fa8e324
20 files changed
+463 -219

No files matched your search

+1 -1
View File
@@ -103,7 +103,7 @@ class FakeClientHandler(object):
# Called upon entering the play state.
self.write_packet(clientbound.play.JoinGamePacket(
entity_id=0, game_mode=0, dimension=0, difficulty=2, max_players=1,
level_type='default', reduced_debug_info=False))
level_type='default', reduced_debug_info=False, render_distance=9))
def handle_play_packet(self, packet):
# Called upon each packet received after handle_play_start() returns.
+1 -1
View File
@@ -409,7 +409,7 @@ class VersionNegotiationEdgeCases(fake_server._FakeServerTest):
status_response = '{"description": {"text": "FakeServer"}}'
class ClientHandler(fake_server.FakeClientHandler):
def _run_status(self):
def handle_status(self, request_packet):
packet = clientbound.status.ResponsePacket()
packet.json_response = status_response
self.write_packet(packet)
+6 -4
View File
@@ -187,7 +187,8 @@ class TestReadWritePackets(unittest.TestCase):
self._test_read_write_packet(packet)
def test_spawn_object_packet(self):
EntityType = clientbound.play.SpawnObjectPacket.EntityType
EntityType = clientbound.play.SpawnObjectPacket.field_enum(
'type_id', self.context)
object_uuid = 'd9568851-85bc-4a10-8d6a-261d130626fa'
pos_look = PositionAndLook(x=68.0, y=38.0, z=76.0, yaw=16, pitch=23)
@@ -195,6 +196,7 @@ class TestReadWritePackets(unittest.TestCase):
entity_id, type_name, type_id = 49846, 'EGG', EntityType.EGG
packet = clientbound.play.SpawnObjectPacket(
context=self.context,
x=pos_look.x, y=pos_look.y, z=pos_look.z,
yaw=pos_look.yaw, pitch=pos_look.pitch,
velocity_x=velocity.x, velocity_y=velocity.y,
@@ -207,9 +209,9 @@ class TestReadWritePackets(unittest.TestCase):
self.assertEqual(packet.type, type_name)
packet2 = clientbound.play.SpawnObjectPacket(
position_and_look=pos_look, velocity=velocity,
type=type_name, object_uuid=object_uuid,
entity_id=entity_id, data=1)
context=self.context, position_and_look=pos_look,
velocity=velocity, type=type_name,
object_uuid=object_uuid, entity_id=entity_id, data=1)
self.assertEqual(packet.__dict__, packet2.__dict__)
packet2.position = pos_look.position
+1
View File
@@ -51,6 +51,7 @@ class MapPacketTest(unittest.TestCase):
packet.map_id = 1
packet.scale = 42
packet.is_tracking_position = True
packet.is_locked = False
packet.icons = []
d_name = u'Marshmallow' if context.protocol_version >= 364 else None
packet.icons.append(MapPacket.MapIcon(
+34 -16
View File
@@ -8,6 +8,8 @@ from minecraft.networking.types import (
String as StringType, Position, TrailingByteArray, UnsignedLong,
)
from minecraft.networking.packets import PacketBuffer
from minecraft.networking.connection import ConnectionContext
from minecraft import SUPPORTED_PROTOCOL_VERSIONS
TEST_DATA = {
@@ -33,34 +35,50 @@ TEST_DATA = {
class SerializationTest(unittest.TestCase):
def test_serialization(self):
for data_type in Type.__subclasses__():
if data_type in TEST_DATA:
test_cases = TEST_DATA[data_type]
for protocol_version in SUPPORTED_PROTOCOL_VERSIONS:
context = ConnectionContext(protocol_version=protocol_version)
for test_data in test_cases:
packet_buffer = PacketBuffer()
data_type.send(test_data, packet_buffer)
packet_buffer.reset_cursor()
for data_type in Type.__subclasses__():
if data_type in TEST_DATA:
test_cases = TEST_DATA[data_type]
deserialized = data_type.read(packet_buffer)
if data_type is FixedPointInteger:
self.assertAlmostEqual(
test_data, deserialized, delta=1.0/32.0)
elif data_type is Float or data_type is Double:
self.assertAlmostEquals(test_data, deserialized, 3)
else:
self.assertEqual(test_data, deserialized)
for test_data in test_cases:
packet_buffer = PacketBuffer()
data_type.send_with_context(
test_data, packet_buffer, context)
packet_buffer.reset_cursor()
deserialized = data_type.read_with_context(
packet_buffer, context)
if data_type is FixedPointInteger:
self.assertAlmostEqual(
test_data, deserialized, delta=1.0/32.0)
elif data_type is Float or data_type is Double:
self.assertAlmostEquals(test_data, deserialized, 3)
else:
self.assertEqual(test_data, deserialized)
def test_exceptions(self):
base_type = Type()
with self.assertRaises(NotImplementedError):
base_type.read(None)
with self.assertRaises(NotImplementedError):
base_type.read_with_context(None, None)
with self.assertRaises(NotImplementedError):
base_type.send(None, None)
with self.assertRaises(NotImplementedError):
base_type.send_with_context(None, None, None)
with self.assertRaises(TypeError):
Position.read(None)
with self.assertRaises(TypeError):
Position.send(None, None)
empty_socket = PacketBuffer()
with self.assertRaises(Exception):
VarInt.read(empty_socket)