mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-12-05 16:43:25 +01:00
7b1567c352
Improvements to the test suite: * List release version names and numbers in minecraft/__init__.py. * Make some tests, which previously ran for *all* protocol versions, run only for release protocol versions (to improve test performance). * Make some tests, which previously ran only for the latest protocol version, run for all release protocol versions (to improve coverage). * Print each protocol version being tested to the debug log, to help identify sources of errors. * Use the `nose-timer' plugin to show the run time of each test. Fix errors revealed by increased test coverage: * Fix: SoundEffectPacket.Pitch is not serialised correctly for early protocol versions. * Fix: handleExceptionTest finishes later than necessary because the test overrode an exception handler used internally by `_FakeServerTest', causing the server thread to time out after 4s. * Add support for multiple exception handlers in `Connection' (required for the above). Improvements to data descriptors: * Make syntax of property declarations more consistent/Pythonic. * Factor the definition of several aliasing properties into the utility methods `attribute_alias' and `multi_attribute_alias', which construct suitable data descriptors. * Define and use the named tuple `Direction' for (pitch, yaw) values.
59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
from minecraft.networking.types import (
|
|
Vector, Float, Byte, Integer, multi_attribute_alias,
|
|
)
|
|
from minecraft.networking.packets import Packet
|
|
|
|
|
|
class ExplosionPacket(Packet):
|
|
@staticmethod
|
|
def get_id(context):
|
|
return 0x1C if context.protocol_version >= 471 else \
|
|
0x1E if context.protocol_version >= 389 else \
|
|
0x1D if context.protocol_version >= 345 else \
|
|
0x1C if context.protocol_version >= 332 else \
|
|
0x1D if context.protocol_version >= 318 else \
|
|
0x1C if context.protocol_version >= 80 else \
|
|
0x1B if context.protocol_version >= 67 else \
|
|
0x27
|
|
|
|
packet_name = 'explosion'
|
|
|
|
class Record(Vector):
|
|
__slots__ = ()
|
|
|
|
position = multi_attribute_alias(Vector, 'x', 'y', 'z')
|
|
|
|
player_motion = multi_attribute_alias(
|
|
Vector, 'player_motion_x', 'player_motion_y', 'player_motion_z')
|
|
|
|
def read(self, file_object):
|
|
self.x = Float.read(file_object)
|
|
self.y = Float.read(file_object)
|
|
self.z = Float.read(file_object)
|
|
self.radius = Float.read(file_object)
|
|
records_count = Integer.read(file_object)
|
|
self.records = []
|
|
for i in range(records_count):
|
|
rec_x = Byte.read(file_object)
|
|
rec_y = Byte.read(file_object)
|
|
rec_z = Byte.read(file_object)
|
|
record = ExplosionPacket.Record(rec_x, rec_y, rec_z)
|
|
self.records.append(record)
|
|
self.player_motion_x = Float.read(file_object)
|
|
self.player_motion_y = Float.read(file_object)
|
|
self.player_motion_z = Float.read(file_object)
|
|
|
|
def write_fields(self, packet_buffer):
|
|
Float.send(self.x, packet_buffer)
|
|
Float.send(self.y, packet_buffer)
|
|
Float.send(self.z, packet_buffer)
|
|
Float.send(self.radius, packet_buffer)
|
|
Integer.send(len(self.records), packet_buffer)
|
|
for record in self.records:
|
|
Byte.send(record.x, packet_buffer)
|
|
Byte.send(record.y, packet_buffer)
|
|
Byte.send(record.z, packet_buffer)
|
|
Float.send(self.player_motion_x, packet_buffer)
|
|
Float.send(self.player_motion_y, packet_buffer)
|
|
Float.send(self.player_motion_z, packet_buffer)
|