aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-01-01 19:44:51 -0600
committermat <github@matdoes.dev>2022-01-01 19:44:51 -0600
commite81b85dd5bdd6d42ee84f24ed4a142f6141f170e (patch)
tree16d950954429b403e2adcc582feb64da73da42df /azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
parent1a961d968b80b720ef2d3900c0b95e1c16a0089e (diff)
downloadazalea-drasl-e81b85dd5bdd6d42ee84f24ed4a142f6141f170e.tar.xz
add a couple more packets
Diffstat (limited to 'azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs')
-rw-r--r--azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
new file mode 100644
index 00000000..63047801
--- /dev/null
+++ b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
@@ -0,0 +1,30 @@
+use super::GamePacket;
+use crate::mc_buf::{Readable, Writable};
+use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
+
+#[derive(Clone, Debug)]
+pub struct ClientboundCustomPayloadPacket {
+ pub identifier: ResourceLocation,
+ pub data: Vec<u8>,
+}
+
+impl ClientboundCustomPayloadPacket {
+ pub fn get(self) -> GamePacket {
+ GamePacket::ClientboundCustomPayloadPacket(self)
+ }
+
+ pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_resource_location(&self.identifier)?;
+ buf.write_bytes(&self.data)?;
+ Ok(())
+ }
+
+ pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
+ buf: &mut T,
+ ) -> Result<GamePacket, String> {
+ let identifier = buf.read_resource_location().await?;
+ let data = buf.read_bytes().await?;
+
+ Ok(ClientboundCustomPayloadPacket { identifier, data }.get())
+ }
+}