From 489cdb01aa94870301ea0f56e47a01a839b91b56 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 24 Oct 2022 21:25:36 -0500 Subject: [PATCH] fix repeated ids in game/mod.rs --- azalea-protocol/src/packets/game/mod.rs | 2 -- codegen/lib/code/packet.py | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index ae66c0be..039f8e2c 100644 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -290,14 +290,12 @@ declare_state_packets!( 0x49: clientbound_set_camera_packet::ClientboundSetCameraPacket, 0x4a: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket, 0x4b: clientbound_set_chunk_cache_center_packet::ClientboundSetChunkCacheCenterPacket, - 0x4c: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket, 0x4c: clientbound_set_chunk_cache_radius_packet::ClientboundSetChunkCacheRadiusPacket, 0x4d: clientbound_set_default_spawn_position_packet::ClientboundSetDefaultSpawnPositionPacket, 0x4e: clientbound_set_display_chat_preview_packet::ClientboundSetDisplayChatPreviewPacket, 0x4f: clientbound_set_display_objective_packet::ClientboundSetDisplayObjectivePacket, 0x50: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket, 0x51: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket, - 0x52: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket, 0x52: clientbound_set_entity_motion_packet::ClientboundSetEntityMotionPacket, 0x53: clientbound_set_equipment_packet::ClientboundSetEquipmentPacket, 0x54: clientbound_set_experience_packet::ClientboundSetExperiencePacket, diff --git a/codegen/lib/code/packet.py b/codegen/lib/code/packet.py index 1d95ef71..a7751c23 100644 --- a/codegen/lib/code/packet.py +++ b/codegen/lib/code/packet.py @@ -121,6 +121,9 @@ def generate_packet(burger_packets, mappings: Mappings, target_packet_id, target def set_packets(packet_ids: list[int], packet_class_names: list[str], direction: str, state: str): assert len(packet_ids) == len(packet_class_names) + # ids are repeated + assert len(packet_ids) == len(set(packet_ids)) + # sort the packets by id packet_ids, packet_class_names = [list(x) for x in zip( *sorted(zip(packet_ids, packet_class_names), key=lambda pair: pair[0]))] # type: ignore @@ -376,6 +379,8 @@ def change_packet_ids(id_map: dict[int, int], direction: str, state: str): for packet_id in existing_packet_ids: new_packet_id = id_map.get(packet_id, packet_id) + if new_packet_id in new_packet_ids: + raise Exception('Two packets have the same id') new_packet_ids.append(new_packet_id) set_packets(new_packet_ids, existing_packet_class_names, direction, state)