mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 14:42:32 +00:00
improve data generator and add packet
This commit is contained in:
parent
aa3ba64aa4
commit
c10b732510
7 changed files with 33 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ data-code-generator/Burger
|
|||
data-code-generator/client.jar
|
||||
data-code-generator/burger.json
|
||||
__pycache__
|
||||
*.tmp
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
[workspace]
|
||||
|
||||
members = [
|
||||
"bot",
|
||||
"azalea-client",
|
||||
|
|
|
@ -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!();
|
||||
|
|
|
@ -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<Slot>,
|
||||
pub carried_item: Slot,
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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!')
|
||||
|
|
|
@ -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)} {{')
|
||||
|
|
Loading…
Reference in a new issue