aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-07 18:26:19 -0500
committermat <github@matdoes.dev>2022-05-07 18:26:19 -0500
commitc10b732510868819a652b76e31278906914d699d (patch)
tree3c1039ec3d200bc16ead375bc0f418194ca68d19
parentaa3ba64aa45abcafb6aa9c1981730d3270a3b0a5 (diff)
downloadazalea-drasl-c10b732510868819a652b76e31278906914d699d.tar.xz
improve data generator and add packet
-rwxr-xr-x.gitignore1
-rwxr-xr-xCargo.toml1
-rwxr-xr-xazalea-client/src/connect.rs6
-rw-r--r--azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs11
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs2
-rw-r--r--data-code-generator/main.py8
-rw-r--r--data-code-generator/packetcodegen.py10
7 files changed, 33 insertions, 6 deletions
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<Slot>,
+ 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)} {{')