aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs8
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs4
-rw-r--r--data-code-generator/main.py7
-rw-r--r--data-code-generator/packetcodegen.py42
4 files changed, 54 insertions, 7 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs
new file mode 100644
index 00000000..dad050cc
--- /dev/null
+++ b/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs
@@ -0,0 +1,8 @@
+use azalea_core::BlockPos;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, GamePacket)]
+pub struct ClientboundSetDefaultSpawnPositionPacket {
+ pub pos: BlockPos,
+ pub angle: f32,
+}
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,
}
);
diff --git a/data-code-generator/main.py b/data-code-generator/main.py
index b79571ae..e1668369 100644
--- a/data-code-generator/main.py
+++ b/data-code-generator/main.py
@@ -11,7 +11,7 @@ print(
f'\033[92mFinding Minecraft version...\033[m')
version_manifest_data = requests.get(
'https://launchermeta.mojang.com/mc/game/version_manifest.json').json()
-minecraft_version = version_manifest_data['latest']['snapshot']
+minecraft_version = version_manifest_data['latest']['release']
print(
f'\033[92mUsing \033[1m{minecraft_version}..\033[m')
package_url = next(
@@ -22,13 +22,14 @@ client_jar_url = package_data['downloads']['client']['url']
if not SKIP_BURGER:
print('\033[92mDownloading Burger...\033[m')
r = os.system('git clone https://github.com/pokechu22/Burger')
- os.system('git pull')
+ os.system('cd Burger && git pull')
print('\033[92mDownloading client jar...\033[m')
with open('client.jar', 'wb') as f:
f.write(requests.get(client_jar_url).content)
print(f'\033[92mExtracting data with Burger...\033[m')
- os.system('cd Burger && python munch.py ../client.jar --output ../burger.json')
+ os.system(
+ 'cd Burger && python munch.py ../client.jar --output ../burger.json')
client_mappings_url = package_data['downloads']['client_mappings']['url']
mappings = Mappings.parse(requests.get(client_mappings_url).text)
diff --git a/data-code-generator/packetcodegen.py b/data-code-generator/packetcodegen.py
index ccbb3845..4c59b72b 100644
--- a/data-code-generator/packetcodegen.py
+++ b/data-code-generator/packetcodegen.py
@@ -66,9 +66,7 @@ def burger_type_to_rust_type(burger_type):
def write_packet_file(state, packet_name_snake_case, code):
- path = os.path.join(
- '..', f'azalea-protocol/src/packets/{state}/{packet_name_snake_case}.rs')
- with open(path, 'w') as f:
+ with open(f'../azalea-protocol/src/packets/{state}/{packet_name_snake_case}.rs', 'w') as f:
f.write(code)
@@ -128,3 +126,41 @@ def generate(burger_packets, mappings: Mappings):
write_packet_file(state, to_snake_case(class_name),
'\n'.join(generated_packet_code))
print()
+
+ mod_rs_dir = f'../azalea-protocol/src/packets/{state}/mod.rs'
+ with open(mod_rs_dir, 'r') as f:
+ mod_rs = f.read().splitlines()
+
+ pub_mod_line = f'pub mod {to_snake_case(class_name)};'
+ if pub_mod_line not in mod_rs:
+ mod_rs.insert(0, pub_mod_line)
+ packet_mod_rs_line = f' {hex(packet["id"])}: {to_snake_case(class_name)}::{to_camel_case(class_name)},'
+
+ in_serverbound = False
+ in_clientbound = False
+ for i, line in enumerate(mod_rs):
+ if line.strip() == 'Serverbound => {':
+ in_serverbound = True
+ continue
+ elif line.strip() == 'Clientbound => {':
+ in_clientbound = True
+ continue
+ elif line.strip() in ('}', '},'):
+ if (in_serverbound and direction == 'serverbound') or (in_clientbound and direction == 'clientbound'):
+ mod_rs.insert(i, packet_mod_rs_line)
+ break
+ in_serverbound = in_clientbound = False
+ continue
+
+ if line.strip() == '' or line.strip().startswith('//') or (not in_serverbound and direction == 'serverbound') or (not in_clientbound and direction == 'clientbound'):
+ continue
+
+ line_packet_id_hex = line.strip().split(':')[0]
+ assert line_packet_id_hex.startswith('0x')
+ line_packet_id = int(line_packet_id_hex[2:], 16)
+ if line_packet_id > packet['id']:
+ mod_rs.insert(i, packet_mod_rs_line)
+ break
+
+ with open(mod_rs_dir, 'w') as f:
+ f.write('\n'.join(mod_rs))