fix outdated EntityDataValue

This commit is contained in:
mat 2022-09-10 19:46:01 -05:00
parent 749c243fc5
commit c31a1f9434
5 changed files with 19 additions and 4 deletions

1
Cargo.lock generated
View file

@ -294,6 +294,7 @@ dependencies = [
"azalea-chat", "azalea-chat",
"azalea-core", "azalea-core",
"azalea-nbt", "azalea-nbt",
"azalea-registry",
"log", "log",
"nohash-hasher", "nohash-hasher",
"thiserror", "thiserror",

View file

@ -365,7 +365,7 @@ fn variant_name_from(name: &syn::Ident) -> syn::Ident {
variant_name = variant_name["Serverbound".len()..].to_string(); variant_name = variant_name["Serverbound".len()..].to_string();
} }
if variant_name.ends_with("Packet") { if variant_name.ends_with("Packet") {
variant_name = variant_name[..variant_name.len()-"Packet".len()].to_string(); variant_name = variant_name[..variant_name.len() - "Packet".len()].to_string();
} }
syn::Ident::new(&variant_name, name.span()) syn::Ident::new(&variant_name, name.span())
} }

View file

@ -221,7 +221,10 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::packets::game::{clientbound_player_chat_packet::ChatType, ClientboundGamePacket}; use crate::packets::{
game::{clientbound_player_chat_packet::ChatType, ClientboundGamePacket},
handshake::ClientboundHandshakePacket,
};
use std::io::Cursor; use std::io::Cursor;
#[tokio::test] #[tokio::test]

View file

@ -13,6 +13,7 @@ azalea-buf = {path = "../azalea-buf", version = "^0.1.0"}
azalea-chat = {path = "../azalea-chat", version = "^0.1.0"} azalea-chat = {path = "../azalea-chat", version = "^0.1.0"}
azalea-core = {path = "../azalea-core", version = "^0.1.0"} azalea-core = {path = "../azalea-core", version = "^0.1.0"}
azalea-nbt = {path = "../azalea-nbt", version = "^0.1.0"} azalea-nbt = {path = "../azalea-nbt", version = "^0.1.0"}
azalea-registry = {path = "../azalea-registry", version = "^0.1.0"}
log = "0.4.17" log = "0.4.17"
nohash-hasher = "0.2.0" nohash-hasher = "0.2.0"
thiserror = "1.0.34" thiserror = "1.0.34"

View file

@ -1,7 +1,7 @@
use azalea_buf::{BufReadError, McBufVarReadable}; use azalea_buf::{BufReadError, McBufVarReadable};
use azalea_buf::{McBuf, McBufReadable, McBufWritable}; use azalea_buf::{McBuf, McBufReadable, McBufWritable};
use azalea_chat::component::Component; use azalea_chat::component::Component;
use azalea_core::{BlockPos, Direction, Particle, Slot}; use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot};
use std::io::{Read, Write}; use std::io::{Read, Write};
use uuid::Uuid; use uuid::Uuid;
@ -67,6 +67,10 @@ pub enum EntityDataValue {
// 0 for absent; 1 + actual value otherwise. Used for entity IDs. // 0 for absent; 1 + actual value otherwise. Used for entity IDs.
OptionalUnsignedInt(Option<u32>), OptionalUnsignedInt(Option<u32>),
Pose(Pose), Pose(Pose),
CatVariant(azalea_registry::CatVariant),
FrogVariant(azalea_registry::FrogVariant),
GlobalPos(GlobalPos),
PaintingVariant(azalea_registry::PaintingVariant),
} }
impl McBufReadable for EntityDataValue { impl McBufReadable for EntityDataValue {
@ -91,7 +95,7 @@ impl McBufReadable for EntityDataValue {
11 => EntityDataValue::Direction(Direction::read_from(buf)?), 11 => EntityDataValue::Direction(Direction::read_from(buf)?),
12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_from(buf)?), 12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_from(buf)?),
13 => EntityDataValue::OptionalBlockState({ 13 => EntityDataValue::OptionalBlockState({
let val = i32::read_from(buf)?; let val = i32::var_read_from(buf)?;
if val == 0 { if val == 0 {
None None
} else { } else {
@ -110,6 +114,12 @@ impl McBufReadable for EntityDataValue {
} }
}), }),
18 => EntityDataValue::Pose(Pose::read_from(buf)?), 18 => EntityDataValue::Pose(Pose::read_from(buf)?),
19 => EntityDataValue::CatVariant(azalea_registry::CatVariant::read_from(buf)?),
20 => EntityDataValue::FrogVariant(azalea_registry::FrogVariant::read_from(buf)?),
21 => EntityDataValue::GlobalPos(GlobalPos::read_from(buf)?),
22 => {
EntityDataValue::PaintingVariant(azalea_registry::PaintingVariant::read_from(buf)?)
}
_ => { _ => {
return Err(BufReadError::UnexpectedEnumVariant { return Err(BufReadError::UnexpectedEnumVariant {
id: data_type as i32, id: data_type as i32,