aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-07 12:22:57 -0500
committermat <github@matdoes.dev>2022-05-07 12:22:57 -0500
commitf0a277788c30392b630d4a8e8b09e9cd3e54c14f (patch)
tree7689dc322b5919be8cb1aa3e898ea2049ce67f4a
parentb9c31efc0161457771861e6858a4a4da0b6a2727 (diff)
downloadazalea-drasl-f0a277788c30392b630d4a8e8b09e9cd3e54c14f.tar.xz
add set time packet and update readme
-rwxr-xr-xazalea-client/src/connect.rs3
-rwxr-xr-xazalea-protocol/README.md15
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_time_packet.rs7
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs2
4 files changed, 27 insertions, 0 deletions
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index 6edb3d13..15d6df4c 100755
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -261,6 +261,9 @@ impl Client {
GamePacket::ClientboundInitializeBorderPacket(p) => {
println!("Got initialize border packet {:?}", p);
}
+ GamePacket::ClientboundSetTimePacket(p) => {
+ println!("Got set time packet {:?}", p);
+ }
_ => panic!("Unexpected packet {:?}", packet),
}
println!();
diff --git a/azalea-protocol/README.md b/azalea-protocol/README.md
index 99b8b8d2..52aaebd2 100755
--- a/azalea-protocol/README.md
+++ b/azalea-protocol/README.md
@@ -7,3 +7,18 @@ The goal is to **only** support the latest Minecraft version in order to ease de
This is not yet complete, search for `TODO` in the code for things that need to be done.
Unfortunately, compiling the crate requires Rust nightly because specialization is not stable yet.
+
+## Adding a new packet
+
+Adding new packets is usually pretty easy, but you'll want to have Minecraft's decompiled source code which you can obtain with tools such as [DecompilerMC](https://github.com/hube12/DecompilerMC).
+
+1. Find the packet in Minecraft's source code. Minecraft's packets are in the `net/minecraft/network/protocol/<state>` directory. The state for your packet is usually `game`.
+2. Add a new file in the [`packets/<state>`](./src/packets/game) directory with the snake_cased version of the name Minecraft uses.
+3. Copy the code from a similar packet and change the struct name.
+4. Add the fields from Minecraft's source code from either the read or write methods.
+If it's a `varint`, use `#[var] pub <name>: i32` (or u32 if it makes more sense).
+If it's a `varlong`, use `#[var] pub <name>: i64` (or u64).
+If it's a byte, use i8 or u8.
+Etc.. You can look at [wiki.vg](https://wiki.vg/Protocol) if you're not sure about how a packet is structured, but be aware that wiki.vg uses different names for most things.
+5. Add the packet to the `mod.rs` file in the same directory. You will have to look at [wiki.vg](https://wiki.vg/Protocol) to determine the packet id here.
+6. That's it! Format your code, submit a pull request, and wait for it to be reviewed.
diff --git a/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs
new file mode 100644
index 00000000..02bf88d7
--- /dev/null
+++ b/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs
@@ -0,0 +1,7 @@
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, GamePacket)]
+pub struct ClientboundSetTimePacket {
+ pub game_time: u64,
+ pub day_time: u64,
+}
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index 852a9525..0b717add 100755
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -19,6 +19,7 @@ pub mod clientbound_set_carried_item_packet;
pub mod clientbound_set_chunk_cache_center;
pub mod clientbound_set_entity_data_packet;
pub mod clientbound_set_entity_link_packet;
+pub mod clientbound_set_time_packet;
pub mod clientbound_update_attributes_packet;
pub mod clientbound_update_recipes_packet;
pub mod clientbound_update_tags_packet;
@@ -55,6 +56,7 @@ declare_state_packets!(
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