mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 14:42:32 +00:00
actually generate a packet!
This commit is contained in:
parent
7b61d41f86
commit
aa3ba64aa4
4 changed files with 54 additions and 7 deletions
|
@ -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,
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ pub mod clientbound_player_position_packet;
|
||||||
pub mod clientbound_recipe_packet;
|
pub mod clientbound_recipe_packet;
|
||||||
pub mod clientbound_set_carried_item_packet;
|
pub mod clientbound_set_carried_item_packet;
|
||||||
pub mod clientbound_set_chunk_cache_center;
|
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_data_packet;
|
||||||
pub mod clientbound_set_entity_link_packet;
|
pub mod clientbound_set_entity_link_packet;
|
||||||
pub mod clientbound_set_time_packet;
|
pub mod clientbound_set_time_packet;
|
||||||
|
@ -53,12 +54,13 @@ declare_state_packets!(
|
||||||
0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
|
0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
|
||||||
0x49: clientbound_set_chunk_cache_center::ClientboundSetChunkCacheCenterPacket,
|
0x49: clientbound_set_chunk_cache_center::ClientboundSetChunkCacheCenterPacket,
|
||||||
0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
|
0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
|
||||||
|
0x4b: clientbound_set_default_spawn_position_packet::ClientboundSetDefaultSpawnPositionPacket,
|
||||||
0x4d: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket,
|
0x4d: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket,
|
||||||
0x45: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket,
|
0x45: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket,
|
||||||
0x4f: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket,
|
0x4f: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket,
|
||||||
0x59: clientbound_set_time_packet::ClientboundSetTimePacket,
|
0x59: clientbound_set_time_packet::ClientboundSetTimePacket,
|
||||||
0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket,
|
0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket,
|
||||||
0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,
|
0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,
|
||||||
0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket
|
0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,7 +11,7 @@ print(
|
||||||
f'\033[92mFinding Minecraft version...\033[m')
|
f'\033[92mFinding Minecraft version...\033[m')
|
||||||
version_manifest_data = requests.get(
|
version_manifest_data = requests.get(
|
||||||
'https://launchermeta.mojang.com/mc/game/version_manifest.json').json()
|
'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(
|
print(
|
||||||
f'\033[92mUsing \033[1m{minecraft_version}..\033[m')
|
f'\033[92mUsing \033[1m{minecraft_version}..\033[m')
|
||||||
package_url = next(
|
package_url = next(
|
||||||
|
@ -22,13 +22,14 @@ client_jar_url = package_data['downloads']['client']['url']
|
||||||
if not SKIP_BURGER:
|
if not SKIP_BURGER:
|
||||||
print('\033[92mDownloading Burger...\033[m')
|
print('\033[92mDownloading Burger...\033[m')
|
||||||
r = os.system('git clone https://github.com/pokechu22/Burger')
|
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')
|
print('\033[92mDownloading client jar...\033[m')
|
||||||
with open('client.jar', 'wb') as f:
|
with open('client.jar', 'wb') as f:
|
||||||
f.write(requests.get(client_jar_url).content)
|
f.write(requests.get(client_jar_url).content)
|
||||||
|
|
||||||
print(f'\033[92mExtracting data with Burger...\033[m')
|
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']
|
client_mappings_url = package_data['downloads']['client_mappings']['url']
|
||||||
mappings = Mappings.parse(requests.get(client_mappings_url).text)
|
mappings = Mappings.parse(requests.get(client_mappings_url).text)
|
||||||
|
|
|
@ -66,9 +66,7 @@ def burger_type_to_rust_type(burger_type):
|
||||||
|
|
||||||
|
|
||||||
def write_packet_file(state, packet_name_snake_case, code):
|
def write_packet_file(state, packet_name_snake_case, code):
|
||||||
path = os.path.join(
|
with open(f'../azalea-protocol/src/packets/{state}/{packet_name_snake_case}.rs', 'w') as f:
|
||||||
'..', f'azalea-protocol/src/packets/{state}/{packet_name_snake_case}.rs')
|
|
||||||
with open(path, 'w') as f:
|
|
||||||
f.write(code)
|
f.write(code)
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,3 +126,41 @@ def generate(burger_packets, mappings: Mappings):
|
||||||
write_packet_file(state, to_snake_case(class_name),
|
write_packet_file(state, to_snake_case(class_name),
|
||||||
'\n'.join(generated_packet_code))
|
'\n'.join(generated_packet_code))
|
||||||
print()
|
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))
|
||||||
|
|
Loading…
Reference in a new issue