mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-12-12 03:46:55 +01:00
612fa8e324
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.
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
from minecraft.networking.types import Vector, Float, Byte, Integer
|
|
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__ = ()
|
|
|
|
@property
|
|
def position(self):
|
|
return Vector(self.x, self.y, self.x)
|
|
|
|
@position.setter
|
|
def position(self, new_position):
|
|
self.x, self.y, self.z = new_position
|
|
|
|
@property
|
|
def player_motion(self):
|
|
return Vector(self.player_motion_x, self.player_motion_y,
|
|
self.player_motion_z)
|
|
|
|
@player_motion.setter
|
|
def player_motion(self, new_player_motion):
|
|
self.player_motion_x, self.player_motion_y, self.player_motion_z \
|
|
= new_player_motion
|
|
|
|
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)
|