From aa3ba64aa45abcafb6aa9c1981730d3270a3b0a5 Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 7 May 2022 17:59:03 -0500 Subject: actually generate a packet! --- azalea-protocol/src/packets/game/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'azalea-protocol/src/packets/game/mod.rs') diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index 0b717add..99cafe56 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -17,6 +17,7 @@ pub mod clientbound_player_position_packet; pub mod clientbound_recipe_packet; pub mod clientbound_set_carried_item_packet; pub mod clientbound_set_chunk_cache_center; +pub mod clientbound_set_default_spawn_position_packet; pub mod clientbound_set_entity_data_packet; pub mod clientbound_set_entity_link_packet; pub mod clientbound_set_time_packet; @@ -53,12 +54,13 @@ declare_state_packets!( 0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket, 0x49: clientbound_set_chunk_cache_center::ClientboundSetChunkCacheCenterPacket, 0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket, + 0x4b: clientbound_set_default_spawn_position_packet::ClientboundSetDefaultSpawnPositionPacket, 0x4d: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket, 0x45: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket, 0x4f: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket, 0x59: clientbound_set_time_packet::ClientboundSetTimePacket, 0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket, 0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket, - 0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket + 0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket, } ); -- cgit v1.2.3 From c10b732510868819a652b76e31278906914d699d Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 7 May 2022 18:26:19 -0500 Subject: improve data generator and add packet --- .gitignore | 1 + Cargo.toml | 1 - azalea-client/src/connect.rs | 6 ++++++ .../packets/game/clientbound_container_set_content_packet.rs | 11 +++++++++++ azalea-protocol/src/packets/game/mod.rs | 2 ++ data-code-generator/main.py | 8 ++++++-- data-code-generator/packetcodegen.py | 10 +++++++--- 7 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs (limited to 'azalea-protocol/src/packets/game/mod.rs') diff --git a/.gitignore b/.gitignore index 67d18b48..db837531 100755 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ data-code-generator/Burger data-code-generator/client.jar data-code-generator/burger.json __pycache__ +*.tmp diff --git a/Cargo.toml b/Cargo.toml index 1c9c754b..d17c7515 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,4 @@ [workspace] - members = [ "bot", "azalea-client", diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index 15d6df4c..e35024e0 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -264,6 +264,12 @@ impl Client { GamePacket::ClientboundSetTimePacket(p) => { println!("Got set time packet {:?}", p); } + GamePacket::ClientboundSetDefaultSpawnPositionPacket(p) => { + println!("Got set default spawn position packet {:?}", p); + } + GamePacket::ClientboundContainerSetContentPacket(p) => { + println!("Got container set content packet {:?}", p); + } _ => panic!("Unexpected packet {:?}", packet), } println!(); diff --git a/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs b/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs new file mode 100644 index 00000000..e46f5af1 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs @@ -0,0 +1,11 @@ +use azalea_core::Slot; +use packet_macros::GamePacket; + +#[derive(Clone, Debug, GamePacket)] +pub struct ClientboundContainerSetContentPacket { + pub container_id: u8, + #[var] + pub state_id: i32, + pub items: Vec, + pub carried_item: Slot, +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index 99cafe56..d112f576 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -2,6 +2,7 @@ pub mod clientbound_add_entity_packet; pub mod clientbound_add_mob_packet; pub mod clientbound_add_player_packet; pub mod clientbound_change_difficulty_packet; +pub mod clientbound_container_set_content_packet; pub mod clientbound_custom_payload_packet; pub mod clientbound_declare_commands_packet; pub mod clientbound_disconnect_packet; @@ -40,6 +41,7 @@ declare_state_packets!( 0x04: clientbound_add_player_packet::ClientboundAddPlayerPacket, 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket, 0x12: clientbound_declare_commands_packet::ClientboundDeclareCommandsPacket, + 0x14: clientbound_container_set_content_packet::ClientboundContainerSetContentPacket, 0x1a: clientbound_disconnect_packet::ClientboundDisconnectPacket, 0x1b: clientbound_entity_event_packet::ClientboundEntityEventPacket, 0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket, diff --git a/data-code-generator/main.py b/data-code-generator/main.py index e1668369..07a591e4 100644 --- a/data-code-generator/main.py +++ b/data-code-generator/main.py @@ -2,6 +2,7 @@ from mappings import Mappings import packetcodegen import requests import json +import sys import os # enable this if you already have the burger.json and don't want to wait @@ -34,11 +35,14 @@ if not SKIP_BURGER: client_mappings_url = package_data['downloads']['client_mappings']['url'] mappings = Mappings.parse(requests.get(client_mappings_url).text) - with open('burger.json', 'r') as f: burger_data = json.load(f) burger_packets_data = burger_data[0]['packets']['packet'] -packetcodegen.generate(burger_packets_data, mappings) +packet_ids = list(map(int, sys.argv[1:])) +print(packet_ids) +packetcodegen.generate(burger_packets_data, mappings, packet_ids) os.system('cd .. && cargo fmt') + +print('Done!') diff --git a/data-code-generator/packetcodegen.py b/data-code-generator/packetcodegen.py index 4c59b72b..12855d08 100644 --- a/data-code-generator/packetcodegen.py +++ b/data-code-generator/packetcodegen.py @@ -70,8 +70,7 @@ def write_packet_file(state, packet_name_snake_case, code): f.write(code) -def generate(burger_packets, mappings: Mappings): - packet_ids = [75] +def generate(burger_packets, mappings: Mappings, packet_ids): for packet in burger_packets.values(): if packet['id'] not in packet_ids: continue @@ -79,6 +78,10 @@ def generate(burger_packets, mappings: Mappings): direction = packet['direction'].lower() # serverbound or clientbound state = {'PLAY': 'game'}.get(packet['state'], packet['state'].lower()) + # TODO: have something better to control this + if state != 'game' or direction != 'clientbound': + continue + generated_packet_code = [] uses = set() generated_packet_code.append( @@ -86,7 +89,8 @@ def generate(burger_packets, mappings: Mappings): uses.add(f'packet_macros::{to_camel_case(state)}Packet') obfuscated_class_name = packet['class'].split('.')[0] - class_name = mappings.get_class(obfuscated_class_name).split('.')[-1] + class_name = mappings.get_class( + obfuscated_class_name).split('.')[-1].split('$')[0] generated_packet_code.append( f'pub struct {to_camel_case(class_name)} {{') -- cgit v1.2.3