|
|
|
@ -1,20 +1,12 @@ |
|
|
|
|
from minecraft.networking.packets import Packet |
|
|
|
|
from minecraft.networking.types import ( |
|
|
|
|
VarInt, Integer, UnsignedByte, Position, Vector, MutableRecord, |
|
|
|
|
attribute_alias, multi_attribute_alias, |
|
|
|
|
attribute_alias, multi_attribute_alias, Long, Boolean, VarLong, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BlockChangePacket(Packet): |
|
|
|
|
@staticmethod |
|
|
|
|
def get_id(context): |
|
|
|
|
return 0x0C if context.protocol_version >= 550 else \ |
|
|
|
|
0x0B if context.protocol_version >= 332 else \ |
|
|
|
|
0x0C if context.protocol_version >= 318 else \ |
|
|
|
|
0x0B if context.protocol_version >= 67 else \ |
|
|
|
|
0x24 if context.protocol_version >= 62 else \ |
|
|
|
|
0x23 |
|
|
|
|
|
|
|
|
|
id = 0x0B |
|
|
|
|
packet_name = 'block change' |
|
|
|
|
definition = [ |
|
|
|
|
{'location': Position}, |
|
|
|
@ -44,15 +36,7 @@ class BlockChangePacket(Packet): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MultiBlockChangePacket(Packet): |
|
|
|
|
@staticmethod |
|
|
|
|
def get_id(context): |
|
|
|
|
return 0x10 if context.protocol_version >= 550 else \ |
|
|
|
|
0x0F if context.protocol_version >= 343 else \ |
|
|
|
|
0x10 if context.protocol_version >= 332 else \ |
|
|
|
|
0x11 if context.protocol_version >= 318 else \ |
|
|
|
|
0x10 if context.protocol_version >= 67 else \ |
|
|
|
|
0x22 |
|
|
|
|
|
|
|
|
|
id = 0x3B |
|
|
|
|
packet_name = 'multi block change' |
|
|
|
|
|
|
|
|
|
fields = 'chunk_x', 'chunk_z', 'records' |
|
|
|
@ -92,29 +76,35 @@ class MultiBlockChangePacket(Packet): |
|
|
|
|
blockStateId = attribute_alias('block_state_id') |
|
|
|
|
|
|
|
|
|
def read(self, file_object, parent): |
|
|
|
|
h_position = UnsignedByte.read(file_object) |
|
|
|
|
self.x, self.z = h_position >> 4, h_position & 0xF |
|
|
|
|
self.y = UnsignedByte.read(file_object) |
|
|
|
|
self.block_state_id = VarInt.read(file_object) |
|
|
|
|
data = VarLong.read(file_object) |
|
|
|
|
self.block_state_id = int(data >> 12) |
|
|
|
|
self.x = int(data >> 8 & 0xf) |
|
|
|
|
self.z = int(data >> 4 & 0xf) |
|
|
|
|
self.y = int(data & 0xf) |
|
|
|
|
# Absolute position in world to be compatible with BlockChangePacket |
|
|
|
|
self.location = Vector(self.position.x + parent.chunk_x*16, self.position.y, self.position.z + parent.chunk_z*16) |
|
|
|
|
|
|
|
|
|
def write(self, packet_buffer): |
|
|
|
|
raise |
|
|
|
|
UnsignedByte.send(self.x << 4 | self.z & 0xF, packet_buffer) |
|
|
|
|
UnsignedByte.send(self.y, packet_buffer) |
|
|
|
|
VarInt.send(self.block_state_id, packet_buffer) |
|
|
|
|
|
|
|
|
|
def read(self, file_object): |
|
|
|
|
self.chunk_x = Integer.read(file_object) |
|
|
|
|
self.chunk_z = Integer.read(file_object) |
|
|
|
|
records_count = VarInt.read(file_object) |
|
|
|
|
coords = Long.read(file_object) |
|
|
|
|
self.chunk_x = int(coords >> 42 & 0x3fffff) |
|
|
|
|
self.chunk_z = int(coords >> 20 & 0x3fffff) |
|
|
|
|
self.chunk_y = int(coords & 0xfffff) |
|
|
|
|
self.unknown = Boolean.read(file_object) |
|
|
|
|
array_size = VarInt.read(file_object) |
|
|
|
|
self.records = [] |
|
|
|
|
for i in range(records_count): |
|
|
|
|
for i in range(array_size): |
|
|
|
|
record = self.Record() |
|
|
|
|
record.read(file_object, self) |
|
|
|
|
self.records.append(record) |
|
|
|
|
|
|
|
|
|
def write_fields(self, packet_buffer): |
|
|
|
|
raise |
|
|
|
|
Integer.send(self.chunk_x, packet_buffer) |
|
|
|
|
Integer.send(self.chunk_z, packet_buffer) |
|
|
|
|
VarInt.send(len(self.records), packet_buffer) |
|
|
|
|