aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src/entity
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-12-07 21:09:58 -0600
committerGitHub <noreply@github.com>2022-12-07 21:09:58 -0600
commit7d901e39bc10a855b545d7b6c167f45148a1fb0a (patch)
tree88fe0a8f2f04f49f4df90e2f5462aa35a4278c68 /azalea-world/src/entity
parent9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (diff)
downloadazalea-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')
-rwxr-xr-xazalea-world/src/entity/data.rs113
-rw-r--r--azalea-world/src/entity/metadata.rs154
2 files changed, 175 insertions, 92 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> {
diff --git a/azalea-world/src/entity/metadata.rs b/azalea-world/src/entity/metadata.rs
index a74635b3..44ec6dae 100644
--- a/azalea-world/src/entity/metadata.rs
+++ b/azalea-world/src/entity/metadata.rs
@@ -2,7 +2,7 @@
// Don't change it manually!
#![allow(clippy::clone_on_copy, clippy::derivable_impls)]
-use super::{EntityDataValue, Pose, Rotations, VillagerData};
+use super::{EntityDataValue, OptionalUnsignedInt, Pose, Rotations, VillagerData};
use azalea_block::BlockState;
use azalea_chat::Component;
use azalea_core::{BlockPos, Direction, Particle, Slot};
@@ -114,7 +114,7 @@ impl Default for AreaEffectCloud {
fn default() -> Self {
Self {
abstract_entity: Default::default(),
- radius: 0.5,
+ radius: 3.0,
color: 0,
waiting: false,
particle: Default::default(),
@@ -731,6 +731,119 @@ impl DerefMut for Boat {
}
#[derive(Debug, Clone)]
+pub struct Camel {
+ pub abstract_animal: AbstractAnimal,
+ pub tamed: bool,
+ pub eating: bool,
+ pub standing: bool,
+ pub bred: bool,
+ pub saddled: bool,
+ pub owner_uuid: Option<Uuid>,
+ pub dash: bool,
+ pub last_pose_change_tick: i64,
+}
+
+impl Camel {
+ pub fn read(metadata: &mut VecDeque<EntityDataValue>) -> Option<Self> {
+ let abstract_animal = AbstractAnimal::read(metadata)?;
+ let bitfield = metadata.pop_front()?.into_byte().ok()?;
+ let tamed = bitfield & 0x2 != 0;
+ let eating = bitfield & 0x10 != 0;
+ let standing = bitfield & 0x20 != 0;
+ let bred = bitfield & 0x8 != 0;
+ let saddled = bitfield & 0x4 != 0;
+ let owner_uuid = metadata.pop_front()?.into_optional_uuid().ok()?;
+ let dash = metadata.pop_front()?.into_boolean().ok()?;
+ let last_pose_change_tick = metadata.pop_front()?.into_long().ok()?;
+ Some(Self {
+ abstract_animal,
+ tamed,
+ eating,
+ standing,
+ bred,
+ saddled,
+ owner_uuid,
+ dash,
+ last_pose_change_tick,
+ })
+ }
+
+ pub fn write(&self) -> Vec<EntityDataValue> {
+ let mut metadata = Vec::new();
+ metadata.extend(self.abstract_animal.write());
+ let mut bitfield = 0u8;
+ if self.tamed {
+ bitfield &= 0x2;
+ }
+ if self.eating {
+ bitfield &= 0x10;
+ }
+ if self.standing {
+ bitfield &= 0x20;
+ }
+ if self.bred {
+ bitfield &= 0x8;
+ }
+ if self.saddled {
+ bitfield &= 0x4;
+ }
+ metadata.push(EntityDataValue::Byte(bitfield));
+ metadata.push(EntityDataValue::OptionalUuid(self.owner_uuid.clone()));
+ metadata.push(EntityDataValue::Boolean(self.dash.clone()));
+ metadata.push(EntityDataValue::Long(self.last_pose_change_tick.clone()));
+ metadata
+ }
+}
+
+impl Default for Camel {
+ fn default() -> Self {
+ Self {
+ abstract_animal: Default::default(),
+ tamed: false,
+ eating: false,
+ standing: false,
+ bred: false,
+ saddled: false,
+ owner_uuid: None,
+ dash: false,
+ last_pose_change_tick: -52,
+ }
+ }
+}
+
+impl Camel {
+ pub fn set_index(&mut self, index: u8, value: EntityDataValue) -> Option<()> {
+ match index {
+ 0..=16 => self.abstract_animal.set_index(index, value)?,
+ 17 => {
+ let bitfield = value.into_byte().ok()?;
+ self.tamed = bitfield & 0x2 != 0;
+ self.eating = bitfield & 0x10 != 0;
+ self.standing = bitfield & 0x20 != 0;
+ self.bred = bitfield & 0x8 != 0;
+ self.saddled = bitfield & 0x4 != 0;
+ }
+ 18 => self.owner_uuid = value.into_optional_uuid().ok()?,
+ 19 => self.dash = value.into_boolean().ok()?,
+ 20 => self.last_pose_change_tick = value.into_long().ok()?,
+ _ => {}
+ }
+ Some(())
+ }
+}
+impl Deref for Camel {
+ type Target = AbstractAnimal;
+ fn deref(&self) -> &Self::Target {
+ &self.abstract_animal
+ }
+}
+impl DerefMut for Camel {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.abstract_animal
+ }
+}
+
+#[derive(Debug, Clone)]
pub struct Cat {
pub abstract_tameable: AbstractTameable,
pub variant: azalea_registry::CatVariant,
@@ -1733,7 +1846,7 @@ impl DerefMut for EnderPearl {
#[derive(Debug, Clone)]
pub struct Enderman {
pub abstract_monster: AbstractMonster,
- pub carry_state: Option<BlockState>,
+ pub carry_state: BlockState,
pub creepy: bool,
pub stared_at: bool,
}
@@ -1741,7 +1854,7 @@ pub struct Enderman {
impl Enderman {
pub fn read(metadata: &mut VecDeque<EntityDataValue>) -> Option<Self> {
let abstract_monster = AbstractMonster::read(metadata)?;
- let carry_state = metadata.pop_front()?.into_optional_block_state().ok()?;
+ let carry_state = metadata.pop_front()?.into_block_state().ok()?;
let creepy = metadata.pop_front()?.into_boolean().ok()?;
let stared_at = metadata.pop_front()?.into_boolean().ok()?;
Some(Self {
@@ -1755,9 +1868,7 @@ impl Enderman {
pub fn write(&self) -> Vec<EntityDataValue> {
let mut metadata = Vec::new();
metadata.extend(self.abstract_monster.write());
- metadata.push(EntityDataValue::OptionalBlockState(
- self.carry_state.clone(),
- ));
+ metadata.push(EntityDataValue::BlockState(self.carry_state.clone()));
metadata.push(EntityDataValue::Boolean(self.creepy.clone()));
metadata.push(EntityDataValue::Boolean(self.stared_at.clone()));
metadata
@@ -1768,7 +1879,7 @@ impl Default for Enderman {
fn default() -> Self {
Self {
abstract_monster: Default::default(),
- carry_state: None,
+ carry_state: BlockState::Air,
creepy: false,
stared_at: false,
}
@@ -1779,7 +1890,7 @@ impl Enderman {
pub fn set_index(&mut self, index: u8, value: EntityDataValue) -> Option<()> {
match index {
0..=15 => self.abstract_monster.set_index(index, value)?,
- 16 => self.carry_state = value.into_optional_block_state().ok()?,
+ 16 => self.carry_state = value.into_block_state().ok()?,
17 => self.creepy = value.into_boolean().ok()?,
18 => self.stared_at = value.into_boolean().ok()?,
_ => {}
@@ -2213,7 +2324,7 @@ impl DerefMut for Fireball {
pub struct FireworkRocket {
pub abstract_entity: AbstractEntity,
pub fireworks_item: Slot,
- pub attached_to_target: Option<u32>,
+ pub attached_to_target: OptionalUnsignedInt,
pub shot_at_angle: bool,
}
@@ -2248,7 +2359,7 @@ impl Default for FireworkRocket {
Self {
abstract_entity: Default::default(),
fireworks_item: Slot::Empty,
- attached_to_target: None,
+ attached_to_target: OptionalUnsignedInt(None),
shot_at_angle: false,
}
}
@@ -2464,7 +2575,7 @@ impl DerefMut for Fox {
pub struct Frog {
pub abstract_animal: AbstractAnimal,
pub variant: azalea_registry::FrogVariant,
- pub tongue_target: Option<u32>,
+ pub tongue_target: OptionalUnsignedInt,
}
impl Frog {
@@ -2495,7 +2606,7 @@ impl Default for Frog {
Self {
abstract_animal: Default::default(),
variant: azalea_registry::FrogVariant::Temperate,
- tongue_target: None,
+ tongue_target: OptionalUnsignedInt(None),
}
}
}
@@ -6421,7 +6532,11 @@ impl Default for Villager {
Self {
abstract_ageable: Default::default(),
unhappy_counter: 0,
- villager_data: Default::default(),
+ villager_data: VillagerData {
+ kind: azalea_registry::VillagerType::Plains,
+ profession: azalea_registry::VillagerProfession::None,
+ level: 0,
+ },
}
}
}
@@ -7169,7 +7284,11 @@ impl Default for ZombieVillager {
Self {
zombie: Default::default(),
converting: false,
- villager_data: Default::default(),
+ villager_data: VillagerData {
+ kind: azalea_registry::VillagerType::Plains,
+ profession: azalea_registry::VillagerProfession::None,
+ level: 0,
+ },
}
}
}
@@ -7920,6 +8039,7 @@ pub enum EntityMetadata {
Bee(Bee),
Blaze(Blaze),
Boat(Boat),
+ Camel(Camel),
Cat(Cat),
CaveSpider(CaveSpider),
ChestBoat(ChestBoat),
@@ -8047,6 +8167,7 @@ impl From<azalea_registry::EntityType> for EntityMetadata {
azalea_registry::EntityType::Bee => EntityMetadata::Bee(Bee::default()),
azalea_registry::EntityType::Blaze => EntityMetadata::Blaze(Blaze::default()),
azalea_registry::EntityType::Boat => EntityMetadata::Boat(Boat::default()),
+ azalea_registry::EntityType::Camel => EntityMetadata::Camel(Camel::default()),
azalea_registry::EntityType::Cat => EntityMetadata::Cat(Cat::default()),
azalea_registry::EntityType::CaveSpider => {
EntityMetadata::CaveSpider(CaveSpider::default())
@@ -8270,6 +8391,7 @@ impl EntityMetadata {
EntityMetadata::Bee(entity) => entity.set_index(index, value),
EntityMetadata::Blaze(entity) => entity.set_index(index, value),
EntityMetadata::Boat(entity) => entity.set_index(index, value),
+ EntityMetadata::Camel(entity) => entity.set_index(index, value),
EntityMetadata::Cat(entity) => entity.set_index(index, value),
EntityMetadata::CaveSpider(entity) => entity.set_index(index, value),
EntityMetadata::ChestBoat(entity) => entity.set_index(index, value),
@@ -8396,6 +8518,7 @@ impl Deref for EntityMetadata {
EntityMetadata::Bee(entity) => entity,
EntityMetadata::Blaze(entity) => entity,
EntityMetadata::Boat(entity) => entity,
+ EntityMetadata::Camel(entity) => entity,
EntityMetadata::Cat(entity) => entity,
EntityMetadata::CaveSpider(entity) => entity,
EntityMetadata::ChestBoat(entity) => entity,
@@ -8520,6 +8643,7 @@ impl DerefMut for EntityMetadata {
EntityMetadata::Bee(entity) => entity,
EntityMetadata::Blaze(entity) => entity,
EntityMetadata::Boat(entity) => entity,
+ EntityMetadata::Camel(entity) => entity,
EntityMetadata::Cat(entity) => entity,
EntityMetadata::CaveSpider(entity) => entity,
EntityMetadata::ChestBoat(entity) => entity,