diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-12 23:54:05 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-12 23:54:05 -0600 |
| commit | 6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc (patch) | |
| tree | a5e493ccd7ec24293b8d866242c3836146517122 /azalea-world/src/entity | |
| parent | fa57d03627aa20b1df44caed7cb025b6db1d9b53 (diff) | |
| download | azalea-drasl-6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc.tar.xz | |
Pathfinder (#25)
Pathfinding is very much not done, but it works enough and I want to get this merged.
TODO: fast replanning, goals that aren't a single node, falling moves (it should be able to play the dropper), parkour moves
Diffstat (limited to 'azalea-world/src/entity')
| -rw-r--r-- | azalea-world/src/entity/attributes.rs | 116 | ||||
| -rwxr-xr-x[-rw-r--r--] | azalea-world/src/entity/data.rs | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | azalea-world/src/entity/dimensions.rs | 0 | ||||
| -rw-r--r-- | azalea-world/src/entity/metadata.rs | 885 | ||||
| -rw-r--r-- | azalea-world/src/entity/mod.rs | 159 |
5 files changed, 1055 insertions, 105 deletions
diff --git a/azalea-world/src/entity/attributes.rs b/azalea-world/src/entity/attributes.rs new file mode 100644 index 00000000..1050615c --- /dev/null +++ b/azalea-world/src/entity/attributes.rs @@ -0,0 +1,116 @@ +//! https://minecraft.fandom.com/wiki/Attribute + +use std::{ + collections::HashMap, + io::{Cursor, Write}, +}; + +use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use thiserror::Error; +use uuid::{uuid, Uuid}; + +#[derive(Clone, Debug)] +pub struct AttributeModifiers { + pub speed: AttributeInstance, +} + +#[derive(Clone, Debug)] +pub struct AttributeInstance { + pub base: f64, + modifiers_by_uuid: HashMap<Uuid, AttributeModifier>, +} + +#[derive(Clone, Debug, Error)] +#[error("A modifier with this UUID is already present.")] +pub struct AlreadyPresentError; + +impl AttributeInstance { + pub fn new(base: f64) -> Self { + Self { + base, + modifiers_by_uuid: HashMap::new(), + } + } + + pub fn calculate(&self) -> f64 { + let mut total = self.base; + for modifier in self.modifiers_by_uuid.values() { + match modifier.operation { + AttributeModifierOperation::Addition => total += modifier.amount, + AttributeModifierOperation::MultiplyBase => total += self.base * modifier.amount, + _ => {} + } + match modifier.operation { + AttributeModifierOperation::MultiplyTotal => total *= 1.0 + modifier.amount, + _ => {} + } + } + total + } + + /// Add a new modifier to this attribute. + pub fn insert(&mut self, modifier: AttributeModifier) -> Result<(), AlreadyPresentError> { + if self + .modifiers_by_uuid + .insert(modifier.uuid, modifier) + .is_some() + { + Err(AlreadyPresentError) + } else { + Ok(()) + } + } + + /// Remove the modifier with the given UUID from this attribute, returning + /// the previous modifier is present. + pub fn remove(&mut self, uuid: &Uuid) -> Option<AttributeModifier> { + self.modifiers_by_uuid.remove(uuid) + } +} + +#[derive(Clone, Debug)] +pub struct AttributeModifier { + pub uuid: Uuid, + pub name: String, + pub amount: f64, + pub operation: AttributeModifierOperation, +} + +#[derive(Clone, Debug, Copy, McBuf)] +pub enum AttributeModifierOperation { + Addition, + MultiplyBase, + MultiplyTotal, +} + +pub fn sprinting_modifier() -> AttributeModifier { + AttributeModifier { + uuid: uuid!("662A6B8D-DA3E-4C1C-8813-96EA6097278D"), + name: "Sprinting speed boost".to_string(), + amount: 0.30000001192092896, + operation: AttributeModifierOperation::MultiplyTotal, + } +} + +impl McBufReadable for AttributeModifier { + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let uuid = Uuid::read_from(buf)?; + let amount = f64::read_from(buf)?; + let operation = AttributeModifierOperation::read_from(buf)?; + Ok(Self { + uuid, + name: "Unknown synced attribute modifier".to_string(), + amount, + operation, + }) + } +} + +impl McBufWritable for AttributeModifier { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + self.uuid.write_into(buf)?; + self.amount.write_into(buf)?; + self.operation.write_into(buf)?; + Ok(()) + } +} diff --git a/azalea-world/src/entity/data.rs b/azalea-world/src/entity/data.rs index dcff6cfe..dcff6cfe 100644..100755 --- a/azalea-world/src/entity/data.rs +++ b/azalea-world/src/entity/data.rs diff --git a/azalea-world/src/entity/dimensions.rs b/azalea-world/src/entity/dimensions.rs index 1d013d10..1d013d10 100644..100755 --- a/azalea-world/src/entity/dimensions.rs +++ b/azalea-world/src/entity/dimensions.rs diff --git a/azalea-world/src/entity/metadata.rs b/azalea-world/src/entity/metadata.rs index 59a8cb88..a031ade2 100644 --- a/azalea-world/src/entity/metadata.rs +++ b/azalea-world/src/entity/metadata.rs @@ -6,7 +6,10 @@ use super::{EntityDataValue, Pose, Rotations, VillagerData}; use azalea_block::BlockState; use azalea_chat::Component; use azalea_core::{BlockPos, Direction, Particle, Slot}; -use std::{collections::VecDeque, ops::Deref}; +use std::{ + collections::VecDeque, + ops::{Deref, DerefMut}, +}; use uuid::Uuid; #[derive(Debug, Clone)] @@ -64,6 +67,11 @@ impl Deref for Allay { &self.abstract_creature } } +impl DerefMut for Allay { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct AreaEffectCloud { @@ -132,6 +140,11 @@ impl Deref for AreaEffectCloud { &self.abstract_entity } } +impl DerefMut for AreaEffectCloud { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct ArmorStand { @@ -250,6 +263,11 @@ impl Deref for ArmorStand { &self.abstract_living } } +impl DerefMut for ArmorStand { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_living + } +} #[derive(Debug, Clone)] pub struct Arrow { @@ -336,6 +354,11 @@ impl Deref for Arrow { &self.abstract_entity } } +impl DerefMut for Arrow { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Axolotl { @@ -398,6 +421,11 @@ impl Deref for Axolotl { &self.abstract_animal } } +impl DerefMut for Axolotl { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Bat { @@ -456,6 +484,11 @@ impl Deref for Bat { &self.abstract_insentient } } +impl DerefMut for Bat { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_insentient + } +} #[derive(Debug, Clone)] pub struct Bee { @@ -536,6 +569,11 @@ impl Deref for Bee { &self.abstract_animal } } +impl DerefMut for Bee { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Blaze { @@ -594,6 +632,11 @@ impl Deref for Blaze { &self.abstract_monster } } +impl DerefMut for Blaze { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Boat { @@ -680,6 +723,11 @@ impl Deref for Boat { &self.abstract_entity } } +impl DerefMut for Boat { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Cat { @@ -748,6 +796,11 @@ impl Deref for Cat { &self.abstract_tameable } } +impl DerefMut for Cat { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_tameable + } +} #[derive(Debug, Clone)] pub struct CaveSpider { @@ -786,6 +839,11 @@ impl Deref for CaveSpider { &self.spider } } +impl DerefMut for CaveSpider { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.spider + } +} #[derive(Debug, Clone)] pub struct ChestBoat { @@ -824,6 +882,11 @@ impl Deref for ChestBoat { &self.boat } } +impl DerefMut for ChestBoat { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.boat + } +} #[derive(Debug, Clone)] pub struct ChestMinecart { @@ -862,6 +925,11 @@ impl Deref for ChestMinecart { &self.abstract_minecart } } +impl DerefMut for ChestMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct Chicken { @@ -900,6 +968,11 @@ impl Deref for Chicken { &self.abstract_animal } } +impl DerefMut for Chicken { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Cod { @@ -950,6 +1023,11 @@ impl Deref for Cod { &self.abstract_creature } } +impl DerefMut for Cod { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct CommandBlockMinecart { @@ -1006,6 +1084,11 @@ impl Deref for CommandBlockMinecart { &self.abstract_minecart } } +impl DerefMut for CommandBlockMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct Cow { @@ -1044,6 +1127,11 @@ impl Deref for Cow { &self.abstract_animal } } +impl DerefMut for Cow { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Creeper { @@ -1106,6 +1194,11 @@ impl Deref for Creeper { &self.abstract_monster } } +impl DerefMut for Creeper { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Dolphin { @@ -1168,6 +1261,11 @@ impl Deref for Dolphin { &self.abstract_creature } } +impl DerefMut for Dolphin { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Donkey { @@ -1270,6 +1368,11 @@ impl Deref for Donkey { &self.abstract_animal } } +impl DerefMut for Donkey { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct DragonFireball { @@ -1308,6 +1411,11 @@ impl Deref for DragonFireball { &self.abstract_entity } } +impl DerefMut for DragonFireball { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Drowned { @@ -1346,6 +1454,11 @@ impl Deref for Drowned { &self.zombie } } +impl DerefMut for Drowned { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.zombie + } +} #[derive(Debug, Clone)] pub struct Egg { @@ -1396,6 +1509,11 @@ impl Deref for Egg { &self.abstract_entity } } +impl DerefMut for Egg { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct ElderGuardian { @@ -1434,6 +1552,11 @@ impl Deref for ElderGuardian { &self.guardian } } +impl DerefMut for ElderGuardian { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.guardian + } +} #[derive(Debug, Clone)] pub struct EndCrystal { @@ -1490,6 +1613,11 @@ impl Deref for EndCrystal { &self.abstract_entity } } +impl DerefMut for EndCrystal { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct EnderDragon { @@ -1540,6 +1668,11 @@ impl Deref for EnderDragon { &self.abstract_insentient } } +impl DerefMut for EnderDragon { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_insentient + } +} #[derive(Debug, Clone)] pub struct EnderPearl { @@ -1590,6 +1723,11 @@ impl Deref for EnderPearl { &self.abstract_entity } } +impl DerefMut for EnderPearl { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Enderman { @@ -1654,6 +1792,11 @@ impl Deref for Enderman { &self.abstract_monster } } +impl DerefMut for Enderman { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Endermite { @@ -1692,6 +1835,11 @@ impl Deref for Endermite { &self.abstract_monster } } +impl DerefMut for Endermite { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Evoker { @@ -1748,6 +1896,11 @@ impl Deref for Evoker { &self.abstract_monster } } +impl DerefMut for Evoker { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct EvokerFangs { @@ -1786,6 +1939,11 @@ impl Deref for EvokerFangs { &self.abstract_entity } } +impl DerefMut for EvokerFangs { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct ExperienceBottle { @@ -1836,6 +1994,11 @@ impl Deref for ExperienceBottle { &self.abstract_entity } } +impl DerefMut for ExperienceBottle { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct ExperienceOrb { @@ -1874,6 +2037,11 @@ impl Deref for ExperienceOrb { &self.abstract_entity } } +impl DerefMut for ExperienceOrb { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct EyeOfEnder { @@ -1924,6 +2092,11 @@ impl Deref for EyeOfEnder { &self.abstract_entity } } +impl DerefMut for EyeOfEnder { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct FallingBlock { @@ -1974,6 +2147,11 @@ impl Deref for FallingBlock { &self.abstract_entity } } +impl DerefMut for FallingBlock { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Fireball { @@ -2024,6 +2202,11 @@ impl Deref for Fireball { &self.abstract_entity } } +impl DerefMut for Fireball { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct FireworkRocket { @@ -2088,6 +2271,11 @@ impl Deref for FireworkRocket { &self.abstract_entity } } +impl DerefMut for FireworkRocket { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct FishingBobber { @@ -2144,6 +2332,11 @@ impl Deref for FishingBobber { &self.abstract_entity } } +impl DerefMut for FishingBobber { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Fox { @@ -2260,6 +2453,11 @@ impl Deref for Fox { &self.abstract_animal } } +impl DerefMut for Fox { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Frog { @@ -2318,6 +2516,11 @@ impl Deref for Frog { &self.abstract_animal } } +impl DerefMut for Frog { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct FurnaceMinecart { @@ -2368,6 +2571,11 @@ impl Deref for FurnaceMinecart { &self.abstract_minecart } } +impl DerefMut for FurnaceMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct Ghast { @@ -2418,6 +2626,11 @@ impl Deref for Ghast { &self.abstract_insentient } } +impl DerefMut for Ghast { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_insentient + } +} #[derive(Debug, Clone)] pub struct Giant { @@ -2456,6 +2669,11 @@ impl Deref for Giant { &self.abstract_monster } } +impl DerefMut for Giant { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct GlowItemFrame { @@ -2494,6 +2712,11 @@ impl Deref for GlowItemFrame { &self.item_frame } } +impl DerefMut for GlowItemFrame { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.item_frame + } +} #[derive(Debug, Clone)] pub struct GlowSquid { @@ -2544,6 +2767,11 @@ impl Deref for GlowSquid { &self.squid } } +impl DerefMut for GlowSquid { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.squid + } +} #[derive(Debug, Clone)] pub struct Goat { @@ -2606,6 +2834,11 @@ impl Deref for Goat { &self.abstract_animal } } +impl DerefMut for Goat { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Guardian { @@ -2662,6 +2895,11 @@ impl Deref for Guardian { &self.abstract_monster } } +impl DerefMut for Guardian { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Hoglin { @@ -2714,6 +2952,11 @@ impl Deref for Hoglin { &self.abstract_animal } } +impl DerefMut for Hoglin { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct HopperMinecart { @@ -2752,6 +2995,11 @@ impl Deref for HopperMinecart { &self.abstract_minecart } } +impl DerefMut for HopperMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct Horse { @@ -2854,6 +3102,11 @@ impl Deref for Horse { &self.abstract_animal } } +impl DerefMut for Horse { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Husk { @@ -2892,6 +3145,11 @@ impl Deref for Husk { &self.zombie } } +impl DerefMut for Husk { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.zombie + } +} #[derive(Debug, Clone)] pub struct Illusioner { @@ -2948,6 +3206,11 @@ impl Deref for Illusioner { &self.abstract_monster } } +impl DerefMut for Illusioner { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct IronGolem { @@ -3006,6 +3269,11 @@ impl Deref for IronGolem { &self.abstract_creature } } +impl DerefMut for IronGolem { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Item { @@ -3056,6 +3324,11 @@ impl Deref for Item { &self.abstract_entity } } +impl DerefMut for Item { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct ItemFrame { @@ -3112,6 +3385,11 @@ impl Deref for ItemFrame { &self.abstract_entity } } +impl DerefMut for ItemFrame { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct LeashKnot { @@ -3150,6 +3428,11 @@ impl Deref for LeashKnot { &self.abstract_entity } } +impl DerefMut for LeashKnot { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct LightningBolt { @@ -3188,6 +3471,11 @@ impl Deref for LightningBolt { &self.abstract_entity } } +impl DerefMut for LightningBolt { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Llama { @@ -3308,6 +3596,11 @@ impl Deref for Llama { &self.abstract_animal } } +impl DerefMut for Llama { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct LlamaSpit { @@ -3346,6 +3639,11 @@ impl Deref for LlamaSpit { &self.abstract_entity } } +impl DerefMut for LlamaSpit { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct MagmaCube { @@ -3384,6 +3682,11 @@ impl Deref for MagmaCube { &self.slime } } +impl DerefMut for MagmaCube { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.slime + } +} #[derive(Debug, Clone)] pub struct Marker { @@ -3422,6 +3725,11 @@ impl Deref for Marker { &self.abstract_entity } } +impl DerefMut for Marker { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Minecart { @@ -3460,6 +3768,11 @@ impl Deref for Minecart { &self.abstract_minecart } } +impl DerefMut for Minecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct Mooshroom { @@ -3507,6 +3820,11 @@ impl Deref for Mooshroom { &self.cow } } +impl DerefMut for Mooshroom { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.cow + } +} #[derive(Debug, Clone)] pub struct Mule { @@ -3609,6 +3927,11 @@ impl Deref for Mule { &self.abstract_animal } } +impl DerefMut for Mule { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Ocelot { @@ -3659,6 +3982,11 @@ impl Deref for Ocelot { &self.abstract_animal } } +impl DerefMut for Ocelot { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Painting { @@ -3711,6 +4039,11 @@ impl Deref for Painting { &self.abstract_entity } } +impl DerefMut for Painting { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Panda { @@ -3823,6 +4156,11 @@ impl Deref for Panda { &self.abstract_animal } } +impl DerefMut for Panda { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Parrot { @@ -3873,6 +4211,11 @@ impl Deref for Parrot { &self.abstract_tameable } } +impl DerefMut for Parrot { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_tameable + } +} #[derive(Debug, Clone)] pub struct Phantom { @@ -3923,6 +4266,11 @@ impl Deref for Phantom { &self.abstract_insentient } } +impl DerefMut for Phantom { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_insentient + } +} #[derive(Debug, Clone)] pub struct Pig { @@ -3979,6 +4327,11 @@ impl Deref for Pig { &self.abstract_animal } } +impl DerefMut for Pig { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Piglin { @@ -4049,6 +4402,11 @@ impl Deref for Piglin { &self.abstract_monster } } +impl DerefMut for Piglin { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct PiglinBrute { @@ -4101,6 +4459,11 @@ impl Deref for PiglinBrute { &self.abstract_monster } } +impl DerefMut for PiglinBrute { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Pillager { @@ -4157,6 +4520,11 @@ impl Deref for Pillager { &self.abstract_monster } } +impl DerefMut for Pillager { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Player { @@ -4239,6 +4607,11 @@ impl Deref for Player { &self.abstract_living } } +impl DerefMut for Player { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_living + } +} #[derive(Debug, Clone)] pub struct PolarBear { @@ -4289,6 +4662,11 @@ impl Deref for PolarBear { &self.abstract_animal } } +impl DerefMut for PolarBear { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Potion { @@ -4339,6 +4717,11 @@ impl Deref for Potion { &self.abstract_entity } } +impl DerefMut for Potion { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Pufferfish { @@ -4395,6 +4778,11 @@ impl Deref for Pufferfish { &self.abstract_creature } } +impl DerefMut for Pufferfish { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Rabbit { @@ -4445,6 +4833,11 @@ impl Deref for Rabbit { &self.abstract_animal } } +impl DerefMut for Rabbit { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Ravager { @@ -4495,6 +4888,11 @@ impl Deref for Ravager { &self.abstract_monster } } +impl DerefMut for Ravager { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Salmon { @@ -4545,6 +4943,11 @@ impl Deref for Salmon { &self.abstract_creature } } +impl DerefMut for Salmon { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Sheep { @@ -4603,6 +5006,11 @@ impl Deref for Sheep { &self.abstract_animal } } +impl DerefMut for Sheep { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Shulker { @@ -4665,6 +5073,11 @@ impl Deref for Shulker { &self.abstract_creature } } +impl DerefMut for Shulker { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct ShulkerBullet { @@ -4703,6 +5116,11 @@ impl Deref for ShulkerBullet { &self.abstract_entity } } +impl DerefMut for ShulkerBullet { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Silverfish { @@ -4741,6 +5159,11 @@ impl Deref for Silverfish { &self.abstract_monster } } +impl DerefMut for Silverfish { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Skeleton { @@ -4791,6 +5214,11 @@ impl Deref for Skeleton { &self.abstract_monster } } +impl DerefMut for Skeleton { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct SkeletonHorse { @@ -4887,6 +5315,11 @@ impl Deref for SkeletonHorse { &self.abstract_animal } } +impl DerefMut for SkeletonHorse { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Slime { @@ -4937,6 +5370,11 @@ impl Deref for Slime { &self.abstract_insentient } } +impl DerefMut for Slime { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_insentient + } +} #[derive(Debug, Clone)] pub struct SmallFireball { @@ -4987,6 +5425,11 @@ impl Deref for SmallFireball { &self.abstract_entity } } +impl DerefMut for SmallFireball { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct SnowGolem { @@ -5045,6 +5488,11 @@ impl Deref for SnowGolem { &self.abstract_creature } } +impl DerefMut for SnowGolem { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Snowball { @@ -5095,6 +5543,11 @@ impl Deref for Snowball { &self.abstract_entity } } +impl DerefMut for Snowball { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct SpawnerMinecart { @@ -5133,6 +5586,11 @@ impl Deref for SpawnerMinecart { &self.abstract_minecart } } +impl DerefMut for SpawnerMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct SpectralArrow { @@ -5213,6 +5671,11 @@ impl Deref for SpectralArrow { &self.abstract_entity } } +impl DerefMut for SpectralArrow { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Spider { @@ -5271,6 +5734,11 @@ impl Deref for Spider { &self.abstract_monster } } +impl DerefMut for Spider { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Squid { @@ -5309,6 +5777,11 @@ impl Deref for Squid { &self.abstract_creature } } +impl DerefMut for Squid { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Stray { @@ -5347,6 +5820,11 @@ impl Deref for Stray { &self.abstract_monster } } +impl DerefMut for Stray { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Strider { @@ -5409,6 +5887,11 @@ impl Deref for Strider { &self.abstract_animal } } +impl DerefMut for Strider { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Tadpole { @@ -5459,6 +5942,11 @@ impl Deref for Tadpole { &self.abstract_creature } } +impl DerefMut for Tadpole { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Tnt { @@ -5509,6 +5997,11 @@ impl Deref for Tnt { &self.abstract_entity } } +impl DerefMut for Tnt { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct TntMinecart { @@ -5547,6 +6040,11 @@ impl Deref for TntMinecart { &self.abstract_minecart } } +impl DerefMut for TntMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_minecart + } +} #[derive(Debug, Clone)] pub struct TraderLlama { @@ -5585,6 +6083,11 @@ impl Deref for TraderLlama { &self.llama } } +impl DerefMut for TraderLlama { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.llama + } +} #[derive(Debug, Clone)] pub struct Trident { @@ -5677,6 +6180,11 @@ impl Deref for Trident { &self.abstract_entity } } +impl DerefMut for Trident { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct TropicalFish { @@ -5733,6 +6241,11 @@ impl Deref for TropicalFish { &self.abstract_creature } } +impl DerefMut for TropicalFish { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct Turtle { @@ -5813,6 +6326,11 @@ impl Deref for Turtle { &self.abstract_animal } } +impl DerefMut for Turtle { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct Vex { @@ -5863,6 +6381,11 @@ impl Deref for Vex { &self.abstract_monster } } +impl DerefMut for Vex { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Villager { @@ -5919,6 +6442,11 @@ impl Deref for Villager { &self.abstract_ageable } } +impl DerefMut for Villager { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_ageable + } +} #[derive(Debug, Clone)] pub struct Vindicator { @@ -5969,6 +6497,11 @@ impl Deref for Vindicator { &self.abstract_monster } } +impl DerefMut for Vindicator { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct WanderingTrader { @@ -6019,6 +6552,11 @@ impl Deref for WanderingTrader { &self.abstract_ageable } } +impl DerefMut for WanderingTrader { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_ageable + } +} #[derive(Debug, Clone)] pub struct Warden { @@ -6069,6 +6607,11 @@ impl Deref for Warden { &self.abstract_monster } } +impl DerefMut for Warden { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Witch { @@ -6125,6 +6668,11 @@ impl Deref for Witch { &self.abstract_monster } } +impl DerefMut for Witch { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Wither { @@ -6193,6 +6741,11 @@ impl Deref for Wither { &self.abstract_monster } } +impl DerefMut for Wither { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct WitherSkeleton { @@ -6231,6 +6784,11 @@ impl Deref for WitherSkeleton { &self.abstract_monster } } +impl DerefMut for WitherSkeleton { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct WitherSkull { @@ -6281,6 +6839,11 @@ impl Deref for WitherSkull { &self.abstract_entity } } +impl DerefMut for WitherSkull { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct Wolf { @@ -6343,6 +6906,11 @@ impl Deref for Wolf { &self.abstract_tameable } } +impl DerefMut for Wolf { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_tameable + } +} #[derive(Debug, Clone)] pub struct Zoglin { @@ -6393,6 +6961,11 @@ impl Deref for Zoglin { &self.abstract_monster } } +impl DerefMut for Zoglin { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct Zombie { @@ -6455,6 +7028,11 @@ impl Deref for Zombie { &self.abstract_monster } } +impl DerefMut for Zombie { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_monster + } +} #[derive(Debug, Clone)] pub struct ZombieHorse { @@ -6551,6 +7129,11 @@ impl Deref for ZombieHorse { &self.abstract_animal } } +impl DerefMut for ZombieHorse { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub struct ZombieVillager { @@ -6607,6 +7190,11 @@ impl Deref for ZombieVillager { &self.zombie } } +impl DerefMut for ZombieVillager { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.zombie + } +} #[derive(Debug, Clone)] pub struct ZombifiedPiglin { @@ -6645,6 +7233,11 @@ impl Deref for ZombifiedPiglin { &self.zombie } } +impl DerefMut for ZombifiedPiglin { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.zombie + } +} #[derive(Debug, Clone)] pub struct AbstractAgeable { @@ -6695,6 +7288,11 @@ impl Deref for AbstractAgeable { &self.abstract_creature } } +impl DerefMut for AbstractAgeable { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct AbstractAnimal { @@ -6733,6 +7331,11 @@ impl Deref for AbstractAnimal { &self.abstract_ageable } } +impl DerefMut for AbstractAnimal { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_ageable + } +} #[derive(Debug, Clone)] pub struct AbstractCreature { @@ -6773,6 +7376,11 @@ impl Deref for AbstractCreature { &self.abstract_insentient } } +impl DerefMut for AbstractCreature { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_insentient + } +} #[derive(Debug, Clone)] pub struct AbstractEntity { @@ -6982,6 +7590,11 @@ impl Deref for AbstractInsentient { &self.abstract_living } } +impl DerefMut for AbstractInsentient { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_living + } +} #[derive(Debug, Clone)] pub struct AbstractLiving { @@ -7084,6 +7697,11 @@ impl Deref for AbstractLiving { &self.abstract_entity } } +impl DerefMut for AbstractLiving { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct AbstractMinecart { @@ -7164,6 +7782,11 @@ impl Deref for AbstractMinecart { &self.abstract_entity } } +impl DerefMut for AbstractMinecart { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_entity + } +} #[derive(Debug, Clone)] pub struct AbstractMonster { @@ -7202,6 +7825,11 @@ impl Deref for AbstractMonster { &self.abstract_creature } } +impl DerefMut for AbstractMonster { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_creature + } +} #[derive(Debug, Clone)] pub struct AbstractTameable { @@ -7274,6 +7902,11 @@ impl Deref for AbstractTameable { &self.abstract_animal } } +impl DerefMut for AbstractTameable { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.abstract_animal + } +} #[derive(Debug, Clone)] pub enum EntityMetadata { @@ -7748,3 +8381,253 @@ impl EntityMetadata { } } } + +impl Deref for EntityMetadata { + type Target = AbstractEntity; + fn deref(&self) -> &Self::Target { + match self { + EntityMetadata::Allay(entity) => entity, + EntityMetadata::AreaEffectCloud(entity) => entity, + EntityMetadata::ArmorStand(entity) => entity, + EntityMetadata::Arrow(entity) => entity, + EntityMetadata::Axolotl(entity) => entity, + EntityMetadata::Bat(entity) => entity, + EntityMetadata::Bee(entity) => entity, + EntityMetadata::Blaze(entity) => entity, + EntityMetadata::Boat(entity) => entity, + EntityMetadata::Cat(entity) => entity, + EntityMetadata::CaveSpider(entity) => entity, + EntityMetadata::ChestBoat(entity) => entity, + EntityMetadata::ChestMinecart(entity) => entity, + EntityMetadata::Chicken(entity) => entity, + EntityMetadata::Cod(entity) => entity, + EntityMetadata::CommandBlockMinecart(entity) => entity, + EntityMetadata::Cow(entity) => entity, + EntityMetadata::Creeper(entity) => entity, + EntityMetadata::Dolphin(entity) => entity, + EntityMetadata::Donkey(entity) => entity, + EntityMetadata::DragonFireball(entity) => entity, + EntityMetadata::Drowned(entity) => entity, + EntityMetadata::Egg(entity) => entity, + EntityMetadata::ElderGuardian(entity) => entity, + EntityMetadata::EndCrystal(entity) => entity, + EntityMetadata::EnderDragon(entity) => entity, + EntityMetadata::EnderPearl(entity) => entity, + EntityMetadata::Enderman(entity) => entity, + EntityMetadata::Endermite(entity) => entity, + EntityMetadata::Evoker(entity) => entity, + EntityMetadata::EvokerFangs(entity) => entity, + EntityMetadata::ExperienceBottle(entity) => entity, + EntityMetadata::ExperienceOrb(entity) => entity, + EntityMetadata::EyeOfEnder(entity) => entity, + EntityMetadata::FallingBlock(entity) => entity, + EntityMetadata::Fireball(entity) => entity, + EntityMetadata::FireworkRocket(entity) => entity, + EntityMetadata::FishingBobber(entity) => entity, + EntityMetadata::Fox(entity) => entity, + EntityMetadata::Frog(entity) => entity, + EntityMetadata::FurnaceMinecart(entity) => entity, + EntityMetadata::Ghast(entity) => entity, + EntityMetadata::Giant(entity) => entity, + EntityMetadata::GlowItemFrame(entity) => entity, + EntityMetadata::GlowSquid(entity) => entity, + EntityMetadata::Goat(entity) => entity, + EntityMetadata::Guardian(entity) => entity, + EntityMetadata::Hoglin(entity) => entity, + EntityMetadata::HopperMinecart(entity) => entity, + EntityMetadata::Horse(entity) => entity, + EntityMetadata::Husk(entity) => entity, + EntityMetadata::Illusioner(entity) => entity, + EntityMetadata::IronGolem(entity) => entity, + EntityMetadata::Item(entity) => entity, + EntityMetadata::ItemFrame(entity) => entity, + EntityMetadata::LeashKnot(entity) => entity, + EntityMetadata::LightningBolt(entity) => entity, + EntityMetadata::Llama(entity) => entity, + EntityMetadata::LlamaSpit(entity) => entity, + EntityMetadata::MagmaCube(entity) => entity, + EntityMetadata::Marker(entity) => entity, + EntityMetadata::Minecart(entity) => entity, + EntityMetadata::Mooshroom(entity) => entity, + EntityMetadata::Mule(entity) => entity, + EntityMetadata::Ocelot(entity) => entity, + EntityMetadata::Painting(entity) => entity, + EntityMetadata::Panda(entity) => entity, + EntityMetadata::Parrot(entity) => entity, + EntityMetadata::Phantom(entity) => entity, + EntityMetadata::Pig(entity) => entity, + EntityMetadata::Piglin(entity) => entity, + EntityMetadata::PiglinBrute(entity) => entity, + EntityMetadata::Pillager(entity) => entity, + EntityMetadata::Player(entity) => entity, + EntityMetadata::PolarBear(entity) => entity, + EntityMetadata::Potion(entity) => entity, + EntityMetadata::Pufferfish(entity) => entity, + EntityMetadata::Rabbit(entity) => entity, + EntityMetadata::Ravager(entity) => entity, + EntityMetadata::Salmon(entity) => entity, + EntityMetadata::Sheep(entity) => entity, + EntityMetadata::Shulker(entity) => entity, + EntityMetadata::ShulkerBullet(entity) => entity, + EntityMetadata::Silverfish(entity) => entity, + EntityMetadata::Skeleton(entity) => entity, + EntityMetadata::SkeletonHorse(entity) => entity, + EntityMetadata::Slime(entity) => entity, + EntityMetadata::SmallFireball(entity) => entity, + EntityMetadata::SnowGolem(entity) => entity, + EntityMetadata::Snowball(entity) => entity, + EntityMetadata::SpawnerMinecart(entity) => entity, + EntityMetadata::SpectralArrow(entity) => entity, + EntityMetadata::Spider(entity) => entity, + EntityMetadata::Squid(entity) => entity, + EntityMetadata::Stray(entity) => entity, + EntityMetadata::Strider(entity) => entity, + EntityMetadata::Tadpole(entity) => entity, + EntityMetadata::Tnt(entity) => entity, + EntityMetadata::TntMinecart(entity) => entity, + EntityMetadata::TraderLlama(entity) => entity, + EntityMetadata::Trident(entity) => entity, + EntityMetadata::TropicalFish(entity) => entity, + EntityMetadata::Turtle(entity) => entity, + EntityMetadata::Vex(entity) => entity, + EntityMetadata::Villager(entity) => entity, + EntityMetadata::Vindicator(entity) => entity, + EntityMetadata::WanderingTrader(entity) => entity, + EntityMetadata::Warden(entity) => entity, + EntityMetadata::Witch(entity) => entity, + EntityMetadata::Wither(entity) => entity, + EntityMetadata::WitherSkeleton(entity) => entity, + EntityMetadata::WitherSkull(entity) => entity, + EntityMetadata::Wolf(entity) => entity, + EntityMetadata::Zoglin(entity) => entity, + EntityMetadata::Zombie(entity) => entity, + EntityMetadata::ZombieHorse(entity) => entity, + EntityMetadata::ZombieVillager(entity) => entity, + EntityMetadata::ZombifiedPiglin(entity) => entity, + } + } +} +impl DerefMut for EntityMetadata { + fn deref_mut(&mut self) -> &mut Self::Target { + match self { + EntityMetadata::Allay(entity) => entity, + EntityMetadata::AreaEffectCloud(entity) => entity, + EntityMetadata::ArmorStand(entity) => entity, + EntityMetadata::Arrow(entity) => entity, + EntityMetadata::Axolotl(entity) => entity, + EntityMetadata::Bat(entity) => entity, + EntityMetadata::Bee(entity) => entity, + EntityMetadata::Blaze(entity) => entity, + EntityMetadata::Boat(entity) => entity, + EntityMetadata::Cat(entity) => entity, + EntityMetadata::CaveSpider(entity) => entity, + EntityMetadata::ChestBoat(entity) => entity, + EntityMetadata::ChestMinecart(entity) => entity, + EntityMetadata::Chicken(entity) => entity, + EntityMetadata::Cod(entity) => entity, + EntityMetadata::CommandBlockMinecart(entity) => entity, + EntityMetadata::Cow(entity) => entity, + EntityMetadata::Creeper(entity) => entity, + EntityMetadata::Dolphin(entity) => entity, + EntityMetadata::Donkey(entity) => entity, + EntityMetadata::DragonFireball(entity) => entity, + EntityMetadata::Drowned(entity) => entity, + EntityMetadata::Egg(entity) => entity, + EntityMetadata::ElderGuardian(entity) => entity, + EntityMetadata::EndCrystal(entity) => entity, + EntityMetadata::EnderDragon(entity) => entity, + EntityMetadata::EnderPearl(entity) => entity, + EntityMetadata::Enderman(entity) => entity, + EntityMetadata::Endermite(entity) => entity, + EntityMetadata::Evoker(entity) => entity, + EntityMetadata::EvokerFangs(entity) => entity, + EntityMetadata::ExperienceBottle(entity) => entity, + EntityMetadata::ExperienceOrb(entity) => entity, + EntityMetadata::EyeOfEnder(entity) => entity, + EntityMetadata::FallingBlock(entity) => entity, + EntityMetadata::Fireball(entity) => entity, + EntityMetadata::FireworkRocket(entity) => entity, + EntityMetadata::FishingBobber(entity) => entity, + EntityMetadata::Fox(entity) => entity, + EntityMetadata::Frog(entity) => entity, + EntityMetadata::FurnaceMinecart(entity) => entity, + EntityMetadata::Ghast(entity) => entity, + EntityMetadata::Giant(entity) => entity, + EntityMetadata::GlowItemFrame(entity) => entity, + EntityMetadata::GlowSquid(entity) => entity, + EntityMetadata::Goat(entity) => entity, + EntityMetadata::Guardian(entity) => entity, + EntityMetadata::Hoglin(entity) => entity, + EntityMetadata::HopperMinecart(entity) => entity, + EntityMetadata::Horse(entity) => entity, + EntityMetadata::Husk(entity) => entity, + EntityMetadata::Illusioner(entity) => entity, + EntityMetadata::IronGolem(entity) => entity, + EntityMetadata::Item(entity) => entity, + EntityMetadata::ItemFrame(entity) => entity, + EntityMetadata::LeashKnot(entity) => entity, + EntityMetadata::LightningBolt(entity) => entity, + EntityMetadata::Llama(entity) => entity, + EntityMetadata::LlamaSpit(entity) => entity, + EntityMetadata::MagmaCube(entity) => entity, + EntityMetadata::Marker(entity) => entity, + EntityMetadata::Minecart(entity) => entity, + EntityMetadata::Mooshroom(entity) => entity, + EntityMetadata::Mule(entity) => entity, + EntityMetadata::Ocelot(entity) => entity, + EntityMetadata::Painting(entity) => entity, + EntityMetadata::Panda(entity) => entity, + EntityMetadata::Parrot(entity) => entity, + EntityMetadata::Phantom(entity) => entity, + EntityMetadata::Pig(entity) => entity, + EntityMetadata::Piglin(entity) => entity, + EntityMetadata::PiglinBrute(entity) => entity, + EntityMetadata::Pillager(entity) => entity, + EntityMetadata::Player(entity) => entity, + EntityMetadata::PolarBear(entity) => entity, + EntityMetadata::Potion(entity) => entity, + EntityMetadata::Pufferfish(entity) => entity, + EntityMetadata::Rabbit(entity) => entity, + EntityMetadata::Ravager(entity) => entity, + EntityMetadata::Salmon(entity) => entity, + EntityMetadata::Sheep(entity) => entity, + EntityMetadata::Shulker(entity) => entity, + EntityMetadata::ShulkerBullet(entity) => entity, + EntityMetadata::Silverfish(entity) => entity, + EntityMetadata::Skeleton(entity) => entity, + EntityMetadata::SkeletonHorse(entity) => entity, + EntityMetadata::Slime(entity) => entity, + EntityMetadata::SmallFireball(entity) => entity, + EntityMetadata::SnowGolem(entity) => entity, + EntityMetadata::Snowball(entity) => entity, + EntityMetadata::SpawnerMinecart(entity) => entity, + EntityMetadata::SpectralArrow(entity) => entity, + EntityMetadata::Spider(entity) => entity, + EntityMetadata::Squid(entity) => entity, + EntityMetadata::Stray(entity) => entity, + EntityMetadata::Strider(entity) => entity, + EntityMetadata::Tadpole(entity) => entity, + EntityMetadata::Tnt(entity) => entity, + EntityMetadata::TntMinecart(entity) => entity, + EntityMetadata::TraderLlama(entity) => entity, + EntityMetadata::Trident(entity) => entity, + EntityMetadata::TropicalFish(entity) => entity, + EntityMetadata::Turtle(entity) => entity, + EntityMetadata::Vex(entity) => entity, + EntityMetadata::Villager(entity) => entity, + EntityMetadata::Vindicator(entity) => entity, + EntityMetadata::WanderingTrader(entity) => entity, + EntityMetadata::Warden(entity) => entity, + EntityMetadata::Witch(entity) => entity, + EntityMetadata::Wither(entity) => entity, + EntityMetadata::WitherSkeleton(entity) => entity, + EntityMetadata::WitherSkull(entity) => entity, + EntityMetadata::Wolf(entity) => entity, + EntityMetadata::Zoglin(entity) => entity, + EntityMetadata::Zombie(entity) => entity, + EntityMetadata::ZombieHorse(entity) => entity, + EntityMetadata::ZombieVillager(entity) => entity, + EntityMetadata::ZombifiedPiglin(entity) => entity, + } + } +} diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index e537e7e0..63147ced 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -1,108 +1,44 @@ +pub mod attributes; mod data; mod dimensions; pub mod metadata; +use self::attributes::{AttributeInstance, AttributeModifiers}; pub use self::metadata::EntityMetadata; use crate::Dimension; use azalea_block::BlockState; use azalea_core::{BlockPos, Vec3, AABB}; pub use data::*; pub use dimensions::*; +use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::ptr::NonNull; use uuid::Uuid; +/// A reference to an entity in a dimension. #[derive(Debug)] -pub struct EntityRef<'d> { +pub struct Entity<'d, D = &'d mut Dimension> { /// The dimension this entity is in. - pub dimension: &'d Dimension, + pub dimension: D, /// The incrementing numerical id of the entity. pub id: u32, - pub data: &'d EntityData, + pub data: NonNull<EntityData>, + _marker: PhantomData<&'d ()>, } -impl<'d> EntityRef<'d> { - pub fn new(dimension: &'d Dimension, id: u32, data: &'d EntityData) -> Self { +impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { + pub fn new(dimension: D, id: u32, data: NonNull<EntityData>) -> Self { // TODO: have this be based on the entity type Self { dimension, id, data, + _marker: PhantomData, } } } -impl<'d> EntityRef<'d> { - #[inline] - pub fn pos(&self) -> &Vec3 { - &self.pos - } - - pub fn make_bounding_box(&self) -> AABB { - self.dimensions.make_bounding_box(self.pos()) - } - - /// Get the position of the block below the entity, but a little lower. - pub fn on_pos_legacy(&self) -> BlockPos { - self.on_pos(0.2) - } - - // int x = Mth.floor(this.position.x); - // int y = Mth.floor(this.position.y - (double)var1); - // int z = Mth.floor(this.position.z); - // BlockPos var5 = new BlockPos(x, y, z); - // if (this.level.getBlockState(var5).isAir()) { - // BlockPos var6 = var5.below(); - // BlockState var7 = this.level.getBlockState(var6); - // if (var7.is(BlockTags.FENCES) || var7.is(BlockTags.WALLS) || var7.getBlock() instanceof FenceGateBlock) { - // return var6; - // } - // } - // return var5; - pub fn on_pos(&self, offset: f32) -> BlockPos { - let x = self.pos().x.floor() as i32; - let y = (self.pos().y - offset as f64).floor() as i32; - let z = self.pos().z.floor() as i32; - let pos = BlockPos { x, y, z }; - - // TODO: check if block below is a fence, wall, or fence gate - let block_pos = pos.below(); - let block_state = self.dimension.get_block_state(&block_pos); - if block_state == Some(BlockState::Air) { - let block_pos_below = block_pos.below(); - let block_state_below = self.dimension.get_block_state(&block_pos_below); - if let Some(_block_state_below) = block_state_below { - // if block_state_below.is_fence() - // || block_state_below.is_wall() - // || block_state_below.is_fence_gate() - // { - // return block_pos_below; - // } - } - } - - pos - } -} - -#[derive(Debug)] -pub struct EntityMut<'d> { - /// The dimension this entity is in. - pub dimension: &'d mut Dimension, - /// The incrementing numerical id of the entity. - pub id: u32, - pub data: NonNull<EntityData>, -} - -impl<'d> EntityMut<'d> { - pub fn new(dimension: &'d mut Dimension, id: u32, data: NonNull<EntityData>) -> Self { - Self { - dimension, - id, - data, - } - } - +impl<'d, D: DerefMut<Target = Dimension>> Entity<'d, D> { /// Sets the position of the entity. This doesn't update the cache in /// azalea-world, and should only be used within azalea-world! /// @@ -158,7 +94,7 @@ impl<'d> EntityMut<'d> { } } -impl<'d> EntityMut<'d> { +impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { #[inline] pub fn pos(&self) -> &Vec3 { &self.pos @@ -192,10 +128,10 @@ impl<'d> EntityMut<'d> { let pos = BlockPos { x, y, z }; // TODO: check if block below is a fence, wall, or fence gate - let block_pos = pos.below(); + let block_pos = pos.down(1); let block_state = self.dimension.get_block_state(&block_pos); if block_state == Some(BlockState::Air) { - let block_pos_below = block_pos.below(); + let block_pos_below = block_pos.down(1); let block_state_below = self.dimension.get_block_state(&block_pos_below); if let Some(_block_state_below) = block_state_below { // if block_state_below.is_fence() @@ -211,36 +147,33 @@ impl<'d> EntityMut<'d> { } } -impl<'d> From<EntityMut<'d>> for EntityRef<'d> { - fn from(entity: EntityMut<'d>) -> EntityRef<'d> { - let data = unsafe { entity.data.as_ref() }; - EntityRef { - dimension: entity.dimension, - id: entity.id, - data, - } - } -} - -impl Deref for EntityMut<'_> { - type Target = EntityData; - - fn deref(&self) -> &Self::Target { - unsafe { self.data.as_ref() } - } -} - -impl DerefMut for EntityMut<'_> { +// impl< +// 'd, +// D: DerefMut<Target = Dimension> + Deref<Target = Dimension>, +// D2: Deref<Target = Dimension>, +// > From<Entity<'d, D>> for Entity<'d, D2> +// { +// fn from(entity: Entity<'d, D>) -> Entity<'d, D> { +// Entity { +// dimension: entity.dimension, +// id: entity.id, +// data: entity.data, +// _marker: PhantomData, +// } +// } +// } + +impl<D: DerefMut<Target = Dimension>> DerefMut for Entity<'_, D> { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { self.data.as_mut() } } } -impl Deref for EntityRef<'_> { +impl<D: Deref<Target = Dimension>> Deref for Entity<'_, D> { type Target = EntityData; fn deref(&self) -> &Self::Target { - self.data + unsafe { self.data.as_ref() } } } @@ -279,8 +212,13 @@ pub struct EntityData { /// (equivalent to the space key being held down in vanilla). pub jumping: bool, + pub has_impulse: bool, + /// Stores some extra data about the entity, including the entity type. pub metadata: EntityMetadata, + + /// The attributes and modifiers that the entity has (for example, speed). + pub attributes: AttributeModifiers, } impl EntityData { @@ -313,20 +251,33 @@ impl EntityData { bounding_box: dimensions.make_bounding_box(&pos), dimensions, + has_impulse: false, + jumping: false, metadata, + + attributes: AttributeModifiers { + // TODO: do the correct defaults for everything, some entities have different defaults + speed: AttributeInstance::new(0.1), + }, } } + /// Get the position of the entity in the dimension. #[inline] pub fn pos(&self) -> &Vec3 { &self.pos } - pub(crate) unsafe fn as_ptr(&mut self) -> NonNull<EntityData> { + pub unsafe fn as_ptr(&mut self) -> NonNull<EntityData> { NonNull::new_unchecked(self as *mut EntityData) } + + pub unsafe fn as_const_ptr(&self) -> NonNull<EntityData> { + // this is cursed + NonNull::new_unchecked(self as *const EntityData as *mut EntityData) + } } #[cfg(test)] @@ -345,8 +296,8 @@ mod tests { EntityMetadata::Player(metadata::Player::default()), ), ); - let entity: EntityMut = dim.entity_mut(0).unwrap(); - let entity_ref: EntityRef = entity.into(); + let entity: Entity = dim.entity_mut(0).unwrap(); + let entity_ref = Entity::from(entity); assert_eq!(entity_ref.uuid, uuid); } } |
