From 6ae94b96e6d51e3bf251d4a01f17fa7d41c9500f Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 20 Dec 2021 15:22:02 -0600 Subject: start adding nbt to the protocol --- .../src/packets/game/clientbound_login_packet.rs | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'azalea-protocol/src/packets') diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs index 0e23460e..54205c48 100644 --- a/azalea-protocol/src/packets/game/clientbound_login_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs @@ -1,9 +1,8 @@ use super::GamePacket; use crate::mc_buf::{Readable, Writable}; use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; -use std::hash::Hash; -#[derive(Hash, Clone, Debug)] +#[derive(Clone, Debug)] pub struct ClientboundLoginPacket { // private final int playerId; // private final boolean hardcore; @@ -27,7 +26,17 @@ pub struct ClientboundLoginPacket { pub game_type: GameType, pub previous_game_type: Option, pub levels: Vec, - // pub registry_holder: azalea_core::registry::RegistryAccess, + pub registry_holder: azalea_nbt::Tag, + pub dimension_type: azalea_nbt::Tag, + pub dimension: ResourceLocation, + pub seed: i64, + pub max_players: i32, + pub chunk_radius: i32, + pub simulation_distance: i32, + pub reduced_debug_info: bool, + pub show_death_screen: bool, + pub is_debug: bool, + pub is_flat: bool, } impl ClientboundLoginPacket { @@ -35,10 +44,19 @@ impl ClientboundLoginPacket { GamePacket::ClientboundLoginPacket(self) } - pub fn write(&self, buf: &mut Vec) { - buf.write_int(self.player_id); - // buf.write_bool(self.hardcore); - // buf.write_byte(self.game_type. + pub fn write(&self, buf: &mut Vec) -> Result<(), std::io::Error> { + buf.write_int(self.player_id)?; + buf.write_boolean(self.hardcore)?; + buf.write_byte(self.game_type.to_id())?; + buf.write_byte(GameType::to_optional_id(&self.previous_game_type) as u8)?; + buf.write_list(&self.levels, |buf, resource_location| { + buf.write_utf(&resource_location.to_string()) + })?; + self.registry_holder + .write(buf) + .map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "write registry holder"))?; + + Ok(()) } pub async fn read( -- cgit v1.2.3