Decode 26.3 block entity data packets
This commit is contained in:
1 parent
46b27f4b94
commit
a48b366b09
2 files changed
+46
-2
No files matched your search
@@ -293,6 +293,29 @@ class ChunkDataPacket(Packet):
|
||||
data_size = VarInt.read(file_object)
|
||||
self.data = file_object.read(data_size)
|
||||
self.sections = decode_chunk_sections(self.data)
|
||||
self.block_entities = []
|
||||
for _ in range(VarInt.read(file_object)):
|
||||
packed_xz = UnsignedByte.read(file_object)
|
||||
y = Short.read(file_object)
|
||||
block_entity_type = VarInt.read(file_object)
|
||||
data = nbt_plain(read_anonymous_nbt(file_object))
|
||||
self.block_entities.append({
|
||||
'x': self.x * 16 + (packed_xz >> 4),
|
||||
'y': y,
|
||||
'z': self.z * 16 + (packed_xz & 0x0F),
|
||||
'type': block_entity_type,
|
||||
'data': data,
|
||||
})
|
||||
|
||||
|
||||
class BlockEntityDataPacket(Packet):
|
||||
id = 0x06
|
||||
packet_name = "block entity data"
|
||||
|
||||
def read(self, file_object):
|
||||
self.location = Position.read_with_context(file_object, self.context)
|
||||
self.block_entity_type = VarInt.read(file_object)
|
||||
self.data = nbt_plain(read_anonymous_nbt(file_object))
|
||||
|
||||
|
||||
class BlockUpdatePacket(Packet):
|
||||
@@ -1203,7 +1226,8 @@ class ModernPlayingReactor(PacketReactor):
|
||||
ClientboundChunkBatchFinished, ClientboundPlayerChatPacket,
|
||||
EntityAnimationPacket, EntitySwingAnimationPacket,
|
||||
BlockChangedAckPacket, AddEntityPacket, SetEntityDataPacket,
|
||||
RemoveEntitiesPacket, MoveEntityPositionPacket,
|
||||
BlockEntityDataPacket, RemoveEntitiesPacket,
|
||||
MoveEntityPositionPacket,
|
||||
MoveEntityPositionRotationPacket, MoveEntityRotationPacket,
|
||||
EntityPositionSyncPacket, PlayerInfoUpdatePacket,
|
||||
PlayerInfoRemovePacket, ContainerOpenPacket,
|
||||
|
||||
@@ -2,7 +2,7 @@ import io
|
||||
import unittest
|
||||
|
||||
from minecraft.networking.modern import (
|
||||
ModernPlayingReactor, SetEntityDataPacket,
|
||||
BlockEntityDataPacket, ModernPlayingReactor, SetEntityDataPacket,
|
||||
)
|
||||
|
||||
|
||||
@@ -16,6 +16,26 @@ def encode_varint(value):
|
||||
|
||||
|
||||
class EntityMetadataPacketTests(unittest.TestCase):
|
||||
def test_block_entity_data_packet_decodes_sign_location_and_is_registered(self):
|
||||
x, y, z = 5, 64, -3
|
||||
packed_position = ((x & 0x3FFFFFF) << 38 |
|
||||
(z & 0x3FFFFFF) << 12 | (y & 0xFFF))
|
||||
payload = (packed_position.to_bytes(8, 'big') +
|
||||
encode_varint(7) + bytes((0,)))
|
||||
class Context:
|
||||
@staticmethod
|
||||
def protocol_later_eq(_version):
|
||||
return True
|
||||
|
||||
packet = BlockEntityDataPacket(context=Context())
|
||||
packet.read(io.BytesIO(payload))
|
||||
|
||||
self.assertEqual((packet.location.x, packet.location.y,
|
||||
packet.location.z), (x, y, z))
|
||||
self.assertEqual(packet.block_entity_type, 7)
|
||||
self.assertIn(BlockEntityDataPacket,
|
||||
ModernPlayingReactor.get_clientbound_packets(None))
|
||||
|
||||
def test_item_stack_metadata_decodes_and_is_registered(self):
|
||||
entity_id = 42
|
||||
item_id = 86
|
||||
|
||||
Reference in new issue
Block a user