diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-12-07 21:09:58 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-07 21:09:58 -0600 |
| commit | 7d901e39bc10a855b545d7b6c167f45148a1fb0a (patch) | |
| tree | 88fe0a8f2f04f49f4df90e2f5462aa35a4278c68 /azalea-world/src/entity/data.rs | |
| parent | 9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (diff) | |
| download | azalea-drasl-7d901e39bc10a855b545d7b6c167f45148a1fb0a.tar.xz | |
1.19.3 (#34)
* start updating to 22w42a
* work a bit more on 22w42a
* player chat packet
* serverbound hello packet
* Update mod.rs
* add more stuff to clientbound player chat packet
* ClientboundPlayerInfoUpdatePacket
* features enabled and container closed
* serverbound chat packets
* make it compile
* 22w43a
* ServerboundChatSessionUpdatePacket
* profile_public_key isn't Option anymore
* Update bitset.rs
* joining a server works
* fix entitydatavalue
* backtraces + fix clientbound chat message
* fix some warnings and add more ecomments
* 22w44a
* generate en_us.json
* add updating guide to codegen/readme
* fix some markdown
* update list of generated things
* metadata stuff
* Replace PJS generator mod with PixLyzer (#38)
* pixlizer extractor
* start working on shape extraction
* fix generating language
* fix pixlyzer shape generation
* use empty_shape
* generate blocks and shapes
* update pixlyzer dir
* Revert "update pixlyzer dir"
This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71.
* fix
* fix
* Revert "fix"
This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d.
* fix
* detect pixlyzer fail
* fix pixlyzer
* 22w45a
* gen entities
* add async-trait dep
* update codegen/readme.md
* explain when rust_log should be used
* remove some unused code
* start fixing pixlyzer issues
* fix a thing in codegen
* almost fixed
* more progress towards 1.19.3
* 1.19.3-pre2
* fixes
* revert some hardcoded property names
* Delete clientbound_player_info_packet.rs
* handle 1.19.3 player info packets
* handle playerinforemove
* start updating to 1.19.3-rc1
* optional registries work
* fix some issues with 1.19.3
chat doesn't work yet
* aaaaaaaaaaaaaaaaa
* oh
* ignore unused shapes
* uncomment generate_blocks
* fix migrate
* 1.19.3-rc2
* fix clippy warnings
* 1.19.3-rc3
* split the azalea-buf macro into separate modules
* improve Recipe in protocol
* 1.19.3
Diffstat (limited to 'azalea-world/src/entity/data.rs')
| -rwxr-xr-x | azalea-world/src/entity/data.rs | 113 |
1 files changed, 36 insertions, 77 deletions
diff --git a/azalea-world/src/entity/data.rs b/azalea-world/src/entity/data.rs index dcff6cfe..baebd210 100755 --- a/azalea-world/src/entity/data.rs +++ b/azalea-world/src/entity/data.rs @@ -1,10 +1,9 @@ use azalea_block::BlockState; -use azalea_buf::{BufReadError, McBufVarReadable}; +use azalea_buf::{BufReadError, McBufVarReadable, McBufVarWritable}; use azalea_buf::{McBuf, McBufReadable, McBufWritable}; use azalea_chat::Component; use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot}; use enum_as_inner::EnumAsInner; -use log::warn; use nohash_hasher::IntSet; use std::io::{Cursor, Write}; use uuid::Uuid; @@ -24,12 +23,12 @@ impl McBufReadable for EntityMetadataItems { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let mut metadata = Vec::new(); loop { - let index = u8::read_from(buf)?; - if index == 0xff { + let id = u8::read_from(buf)?; + if id == 0xff { break; } let value = EntityDataValue::read_from(buf)?; - metadata.push(EntityDataItem { index, value }); + metadata.push(EntityDataItem { index: id, value }); } Ok(EntityMetadataItems(metadata)) } @@ -46,10 +45,11 @@ impl McBufWritable for EntityMetadataItems { } } -#[derive(Clone, Debug, EnumAsInner)] +#[derive(Clone, Debug, EnumAsInner, McBuf)] pub enum EntityDataValue { Byte(u8), - Int(i32), + Int(#[var] i32), + Long(i64), Float(f32), String(String), Component(Component), @@ -63,87 +63,48 @@ pub enum EntityDataValue { OptionalUuid(Option<Uuid>), // 0 for absent (implies air); otherwise, a block state ID as per the global palette // this is a varint - OptionalBlockState(Option<BlockState>), + BlockState(BlockState), CompoundTag(azalea_nbt::Tag), Particle(Particle), VillagerData(VillagerData), // 0 for absent; 1 + actual value otherwise. Used for entity IDs. - OptionalUnsignedInt(Option<u32>), + OptionalUnsignedInt(OptionalUnsignedInt), Pose(Pose), CatVariant(azalea_registry::CatVariant), FrogVariant(azalea_registry::FrogVariant), - GlobalPos(GlobalPos), + OptionalGlobalPos(Option<GlobalPos>), PaintingVariant(azalea_registry::PaintingVariant), } -#[derive(Clone, Debug, McBuf, Default)] -pub struct Rotations { - pub x: f32, - pub y: f32, - pub z: f32, -} +#[derive(Clone, Debug)] +pub struct OptionalUnsignedInt(pub Option<u32>); -impl McBufReadable for EntityDataValue { +impl McBufReadable for OptionalUnsignedInt { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let data_type = u32::var_read_from(buf)?; - Ok(match data_type { - 0 => EntityDataValue::Byte(u8::read_from(buf)?), - 1 => EntityDataValue::Int(i32::var_read_from(buf)?), - 2 => EntityDataValue::Float(f32::read_from(buf)?), - 3 => EntityDataValue::String(String::read_from(buf)?), - 4 => EntityDataValue::Component(Component::read_from(buf)?), - 5 => EntityDataValue::OptionalComponent(Option::<Component>::read_from(buf)?), - 6 => EntityDataValue::ItemStack(Slot::read_from(buf)?), - 7 => EntityDataValue::Boolean(bool::read_from(buf)?), - 8 => EntityDataValue::Rotations(Rotations::read_from(buf)?), - 9 => EntityDataValue::BlockPos(BlockPos::read_from(buf)?), - 10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_from(buf)?), - 11 => EntityDataValue::Direction(Direction::read_from(buf)?), - 12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_from(buf)?), - 13 => EntityDataValue::OptionalBlockState({ - let val = u32::var_read_from(buf)?; - if val == 0 { - None - } else { - Some(BlockState::try_from(val - 1).unwrap_or_else(|_| { - warn!("Invalid block state ID {} in entity metadata", val - 1); - BlockState::Air - })) - } - }), - 14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_from(buf)?), - 15 => EntityDataValue::Particle(Particle::read_from(buf)?), - 16 => EntityDataValue::VillagerData(VillagerData::read_from(buf)?), - 17 => EntityDataValue::OptionalUnsignedInt({ - let val = u32::var_read_from(buf)?; - if val == 0 { - None - } else { - Some(val - 1) - } - }), - 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 { - id: data_type as i32, - }) - } - }) + let val = u32::var_read_from(buf)?; + Ok(OptionalUnsignedInt(if val == 0 { + None + } else { + Some(val - 1) + })) } } - -impl McBufWritable for EntityDataValue { - fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { - todo!(); +impl McBufWritable for OptionalUnsignedInt { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + match self.0 { + Some(val) => (val + 1).var_write_into(buf), + None => 0u32.var_write_into(buf), + } } } +#[derive(Clone, Debug, McBuf, Default)] +pub struct Rotations { + pub x: f32, + pub y: f32, + pub z: f32, +} + #[derive(Clone, Debug, Copy, McBuf, Default)] pub enum Pose { #[default] @@ -157,14 +118,12 @@ pub enum Pose { Dying, } -#[derive(Debug, Clone, McBuf, Default)] +#[derive(Debug, Clone, McBuf)] pub struct VillagerData { + pub kind: azalea_registry::VillagerType, + pub profession: azalea_registry::VillagerProfession, #[var] - type_: u32, - #[var] - profession: u32, - #[var] - level: u32, + pub level: u32, } impl TryFrom<EntityMetadataItems> for Vec<EntityDataValue> { |
