diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2024-04-23 10:34:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 10:34:50 -0500 |
| commit | 1d80f531b74bc3b31023753acb81b35efcdadd73 (patch) | |
| tree | 675635c7c41fbb456e3e0dd7b9f09c7211d356f0 /azalea-core/src | |
| parent | 0ddad8bd9c7c0e8846aec8bc90c95416418c9a63 (diff) | |
| download | azalea-drasl-1d80f531b74bc3b31023753acb81b35efcdadd73.tar.xz | |
1.20.5 (#127)
* 23w51b
* make recalculate_near_end_of_path public
so other plugins can do .after(recalculate_near_end_of_path)
* update to 24w03a i think
* start implementing 24w13a
* registries work (but a lot of packets are still broken)
* fix recipes and commands packets
* i love codecs :D i am not going insane :D mojang's java is very readable :D
* item components are "implemented" meowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeowmeow
* update to 1.20.5-pre3
* fix all the broken packets and clippy (mojang please don't do an update like this again or i will murder someone)
* 1.20.5-rc1
* fix failing tests
* 1.20.5
Diffstat (limited to 'azalea-core/src')
| -rwxr-xr-x | azalea-core/src/lib.rs | 2 | ||||
| -rwxr-xr-x | azalea-core/src/particle.rs | 294 | ||||
| -rwxr-xr-x | azalea-core/src/position.rs | 4 | ||||
| -rw-r--r-- | azalea-core/src/registry_holder.rs | 89 | ||||
| -rwxr-xr-x | azalea-core/src/resource_location.rs | 9 |
5 files changed, 47 insertions, 351 deletions
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs index 5471120b..83dd6245 100755 --- a/azalea-core/src/lib.rs +++ b/azalea-core/src/lib.rs @@ -1,5 +1,6 @@ #![doc = include_str!("../README.md")] #![feature(lazy_cell)] +#![feature(trait_upcasting)] #![allow(incomplete_features)] #![feature(generic_const_exprs)] @@ -13,7 +14,6 @@ pub mod direction; pub mod game_type; pub mod math; pub mod objectives; -pub mod particle; pub mod position; pub mod registry_holder; pub mod resource_location; diff --git a/azalea-core/src/particle.rs b/azalea-core/src/particle.rs deleted file mode 100755 index 4137d867..00000000 --- a/azalea-core/src/particle.rs +++ /dev/null @@ -1,294 +0,0 @@ -use crate::position::BlockPos; -use azalea_buf::McBuf; -use azalea_inventory::ItemSlot; -use azalea_registry::ParticleKind; - -#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] -#[derive(Debug, Clone, McBuf, Default)] -pub struct Particle { - #[var] - pub id: i32, - pub data: ParticleData, -} - -#[derive(Clone, Debug, McBuf, Default)] -pub enum ParticleData { - AmbientEntityEffect, - AngryVillager, - Block(BlockParticle), - BlockMarker(BlockParticle), - Bubble, - Cloud, - Crit, - DamageIndicator, - DragonBreath, - DrippingLava, - FallingLava, - LandingLava, - DrippingWater, - FallingWater, - Dust(DustParticle), - DustColorTransition(DustColorTransitionParticle), - Effect, - ElderGuardian, - EnchantedHit, - Enchant, - EndRod, - #[default] - EntityEffect, - ExplosionEmitter, - Explosion, - Gust, - GustEmitter, - SonicBoom, - FallingDust(BlockParticle), - Firework, - Fishing, - Flame, - CherryLeaves, - SculkSoul, - SculkCharge(SculkChargeParticle), - SculkChargePop, - SoulFireFlame, - Soul, - Flash, - HappyVillager, - Composter, - Heart, - InstantEffect, - Item(ItemParticle), - Vibration(VibrationParticle), - ItemSlime, - ItemSnowball, - LargeSmoke, - Lava, - Mycelium, - Note, - Poof, - Portal, - Rain, - Smoke, - WhiteSmoke, - Sneeze, - Spit, - SquidInk, - SweepAttack, - TotemOfUndying, - Underwater, - Splash, - Witch, - BubblePop, - CurrentDown, - BubbleColumnUp, - Nautilus, - Dolphin, - CampfireCozySmoke, - CampfireSignalSmoke, - DrippingHoney, - FallingHoney, - LandingHoney, - FallingNectar, - FallingSporeBlossom, - Ash, - CrimsonSpore, - WarpedSpore, - SporeBlossomAir, - DrippingObsidianTear, - FallingObsidianTear, - LandingObsidianTear, - ReversePortal, - WhiteAsh, - SmallFlame, - Snowflake, - DrippingDripstoneLava, - FallingDripstoneLava, - DrippingDripstoneWater, - FallingDripstoneWater, - GlowSquidInk, - Glow, - WaxOn, - WaxOff, - ElectricSpark, - Scrape, - Shriek(ShriekParticle), - EggCrack, - DustPlume, - GustDust, - TrialSpawnerDetection, -} - -impl From<ParticleKind> for ParticleData { - /// Convert a particle kind into particle data. If the particle has data - /// attached (like block particles), then it's set to the default. - fn from(kind: ParticleKind) -> Self { - // this is mostly just here so it fails to compile when a new particle is added - // to ParticleKind, since ParticleData has to be updated manually - match kind { - ParticleKind::AmbientEntityEffect => Self::AmbientEntityEffect, - ParticleKind::AngryVillager => Self::AngryVillager, - ParticleKind::Block => Self::Block(BlockParticle::default()), - ParticleKind::BlockMarker => Self::BlockMarker(BlockParticle::default()), - ParticleKind::Bubble => Self::Bubble, - ParticleKind::Cloud => Self::Cloud, - ParticleKind::Crit => Self::Crit, - ParticleKind::DamageIndicator => Self::DamageIndicator, - ParticleKind::DragonBreath => Self::DragonBreath, - ParticleKind::DrippingLava => Self::DrippingLava, - ParticleKind::FallingLava => Self::FallingLava, - ParticleKind::LandingLava => Self::LandingLava, - ParticleKind::DrippingWater => Self::DrippingWater, - ParticleKind::FallingWater => Self::FallingWater, - ParticleKind::Dust => Self::Dust(DustParticle::default()), - ParticleKind::DustColorTransition => { - Self::DustColorTransition(DustColorTransitionParticle::default()) - } - ParticleKind::Effect => Self::Effect, - ParticleKind::ElderGuardian => Self::ElderGuardian, - ParticleKind::EnchantedHit => Self::EnchantedHit, - ParticleKind::Enchant => Self::Enchant, - ParticleKind::EndRod => Self::EndRod, - ParticleKind::EntityEffect => Self::EntityEffect, - ParticleKind::ExplosionEmitter => Self::ExplosionEmitter, - ParticleKind::Explosion => Self::Explosion, - ParticleKind::Gust => Self::Gust, - ParticleKind::GustEmitter => Self::GustEmitter, - ParticleKind::SonicBoom => Self::SonicBoom, - ParticleKind::FallingDust => Self::FallingDust(BlockParticle::default()), - ParticleKind::Firework => Self::Firework, - ParticleKind::Fishing => Self::Fishing, - ParticleKind::Flame => Self::Flame, - ParticleKind::CherryLeaves => Self::CherryLeaves, - ParticleKind::SculkSoul => Self::SculkSoul, - ParticleKind::SculkCharge => Self::SculkCharge(SculkChargeParticle::default()), - ParticleKind::SculkChargePop => Self::SculkChargePop, - ParticleKind::SoulFireFlame => Self::SoulFireFlame, - ParticleKind::Soul => Self::Soul, - ParticleKind::Flash => Self::Flash, - ParticleKind::HappyVillager => Self::HappyVillager, - ParticleKind::Composter => Self::Composter, - ParticleKind::Heart => Self::Heart, - ParticleKind::InstantEffect => Self::InstantEffect, - ParticleKind::Item => Self::Item(ItemParticle::default()), - ParticleKind::Vibration => Self::Vibration(VibrationParticle::default()), - ParticleKind::ItemSlime => Self::ItemSlime, - ParticleKind::ItemSnowball => Self::ItemSnowball, - ParticleKind::LargeSmoke => Self::LargeSmoke, - ParticleKind::Lava => Self::Lava, - ParticleKind::Mycelium => Self::Mycelium, - ParticleKind::Note => Self::Note, - ParticleKind::Poof => Self::Poof, - ParticleKind::Portal => Self::Portal, - ParticleKind::Rain => Self::Rain, - ParticleKind::Smoke => Self::Smoke, - ParticleKind::WhiteSmoke => Self::WhiteSmoke, - ParticleKind::Sneeze => Self::Sneeze, - ParticleKind::Spit => Self::Spit, - ParticleKind::SquidInk => Self::SquidInk, - ParticleKind::SweepAttack => Self::SweepAttack, - ParticleKind::TotemOfUndying => Self::TotemOfUndying, - ParticleKind::Underwater => Self::Underwater, - ParticleKind::Splash => Self::Splash, - ParticleKind::Witch => Self::Witch, - ParticleKind::BubblePop => Self::BubblePop, - ParticleKind::CurrentDown => Self::CurrentDown, - ParticleKind::BubbleColumnUp => Self::BubbleColumnUp, - ParticleKind::Nautilus => Self::Nautilus, - ParticleKind::Dolphin => Self::Dolphin, - ParticleKind::CampfireCosySmoke => Self::CampfireCozySmoke, - ParticleKind::CampfireSignalSmoke => Self::CampfireSignalSmoke, - ParticleKind::DrippingHoney => Self::DrippingHoney, - ParticleKind::FallingHoney => Self::FallingHoney, - ParticleKind::LandingHoney => Self::LandingHoney, - ParticleKind::FallingNectar => Self::FallingNectar, - ParticleKind::FallingSporeBlossom => Self::FallingSporeBlossom, - ParticleKind::Ash => Self::Ash, - ParticleKind::CrimsonSpore => Self::CrimsonSpore, - ParticleKind::WarpedSpore => Self::WarpedSpore, - ParticleKind::SporeBlossomAir => Self::SporeBlossomAir, - ParticleKind::DrippingObsidianTear => Self::DrippingObsidianTear, - ParticleKind::FallingObsidianTear => Self::FallingObsidianTear, - ParticleKind::LandingObsidianTear => Self::LandingObsidianTear, - ParticleKind::ReversePortal => Self::ReversePortal, - ParticleKind::WhiteAsh => Self::WhiteAsh, - ParticleKind::SmallFlame => Self::SmallFlame, - ParticleKind::Snowflake => Self::Snowflake, - ParticleKind::DrippingDripstoneLava => Self::DrippingDripstoneLava, - ParticleKind::FallingDripstoneLava => Self::FallingDripstoneLava, - ParticleKind::DrippingDripstoneWater => Self::DrippingDripstoneWater, - ParticleKind::FallingDripstoneWater => Self::FallingDripstoneWater, - ParticleKind::GlowSquidInk => Self::GlowSquidInk, - ParticleKind::Glow => Self::Glow, - ParticleKind::WaxOn => Self::WaxOn, - ParticleKind::WaxOff => Self::WaxOff, - ParticleKind::ElectricSpark => Self::ElectricSpark, - ParticleKind::Scrape => Self::Scrape, - ParticleKind::Shriek => Self::Shriek(ShriekParticle::default()), - ParticleKind::EggCrack => Self::EggCrack, - ParticleKind::DustPlume => Self::DustPlume, - ParticleKind::GustDust => Self::GustDust, - ParticleKind::TrialSpawnerDetection => Self::TrialSpawnerDetection, - } - } -} - -#[derive(Debug, Clone, McBuf, Default)] -pub struct BlockParticle { - #[var] - pub block_state: i32, -} -#[derive(Debug, Clone, McBuf, Default)] -pub struct DustParticle { - /// Red value, 0-1 - pub red: f32, - /// Green value, 0-1 - pub green: f32, - /// Blue value, 0-1 - pub blue: f32, - /// The scale, will be clamped between 0.01 and 4. - pub scale: f32, -} - -#[derive(Debug, Clone, McBuf, Default)] -pub struct DustColorTransitionParticle { - /// Red value, 0-1 - pub from_red: f32, - /// Green value, 0-1 - pub from_green: f32, - /// Blue value, 0-1 - pub from_blue: f32, - /// The scale, will be clamped between 0.01 and 4. - pub scale: f32, - /// Red value, 0-1 - pub to_red: f32, - /// Green value, 0-1 - pub to_green: f32, - /// Blue value, 0-1 - pub to_blue: f32, -} - -#[derive(Debug, Clone, McBuf, Default)] -pub struct ItemParticle { - pub item: ItemSlot, -} - -#[derive(Debug, Clone, McBuf, Default)] -pub struct VibrationParticle { - pub origin: BlockPos, - pub position_type: String, - pub block_position: BlockPos, - #[var] - pub entity_id: u32, - #[var] - pub ticks: u32, -} - -#[derive(Debug, Clone, McBuf, Default)] -pub struct SculkChargeParticle { - pub roll: f32, -} - -#[derive(Debug, Clone, McBuf, Default)] -pub struct ShriekParticle { - #[var] - pub delay: i32, // The time in ticks before the particle is displayed -} diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index e2a9c4cc..31b2d008 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -424,11 +424,11 @@ impl From<ChunkSectionBlockPos> for u16 { impl nohash_hasher::IsEnabled for ChunkSectionBlockPos {} /// A block pos with an attached world -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct GlobalPos { - pub pos: BlockPos, // this is actually a ResourceKey in Minecraft, but i don't think it matters? pub world: ResourceLocation, + pub pos: BlockPos, } impl From<&BlockPos> for ChunkPos { diff --git a/azalea-core/src/registry_holder.rs b/azalea-core/src/registry_holder.rs index 1c21c890..c75e3919 100644 --- a/azalea-core/src/registry_holder.rs +++ b/azalea-core/src/registry_holder.rs @@ -5,7 +5,6 @@ //! the game, including the types of chat messages, dimensions, and //! biomes. -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; use simdnbt::{ owned::{NbtCompound, NbtTag}, Deserialize, FromNbtTag, Serialize, ToNbtTag, @@ -20,23 +19,51 @@ use crate::resource_location::ResourceLocation; /// This is the registry that is sent to the client upon login. #[derive(Default, Debug, Clone)] pub struct RegistryHolder { - pub map: HashMap<ResourceLocation, NbtCompound>, + pub map: HashMap<ResourceLocation, HashMap<ResourceLocation, NbtCompound>>, } impl RegistryHolder { + pub fn append( + &mut self, + id: ResourceLocation, + entries: HashMap<ResourceLocation, Option<NbtCompound>>, + ) { + let map = self.map.entry(id).or_default(); + for (key, value) in entries { + if let Some(value) = value { + map.insert(key, value); + } else { + map.remove(&key); + } + } + } + fn get<T: Deserialize>( &self, name: &ResourceLocation, - ) -> Option<Result<T, simdnbt::DeserializeError>> { + ) -> Option<Result<RegistryType<T>, simdnbt::DeserializeError>> { // this is suboptimal, ideally simdnbt should just have a way to get the // owned::NbtCompound as a borrow::NbtCompound - let nbt_owned_compound = self.map.get(name)?; - let mut nbt_bytes = Vec::new(); - nbt_owned_compound.write(&mut nbt_bytes); - let nbt_borrow_compound = - simdnbt::borrow::NbtCompound::read(&mut Cursor::new(&nbt_bytes)).ok()?; - Some(T::from_compound(&nbt_borrow_compound)) + let mut map = HashMap::new(); + + for (key, value) in self.map.get(name)? { + // convert the value to T + let mut nbt_bytes = Vec::new(); + value.write(&mut nbt_bytes); + let nbt_borrow_compound = + simdnbt::borrow::NbtCompound::read(&mut Cursor::new(&nbt_bytes)).ok()?; + let value = match T::from_compound(&nbt_borrow_compound) { + Ok(value) => value, + Err(err) => { + return Some(Err(err)); + } + }; + + map.insert(key.clone(), value); + } + + Some(Ok(RegistryType { map })) } /// Get the dimension type registry, or `None` if it doesn't exist. You @@ -57,48 +84,10 @@ impl RegistryHolder { } } -impl McBufReadable for RegistryHolder { - fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let nbt_tag = simdnbt::borrow::NbtTag::read(buf)?; - let nbt_compound = nbt_tag - .compound() - .ok_or_else(|| BufReadError::Custom("RegistryHolder must be a compound".to_string()))?; - Ok(RegistryHolder { - map: simdnbt::Deserialize::from_compound(nbt_compound)?, - }) - } -} - -impl McBufWritable for RegistryHolder { - fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { - let mut written = Vec::new(); - self.map.clone().to_compound().write_into(&mut written)?; - buf.write_all(&written) - } -} - /// A collection of values for a certain type of registry data. -#[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "strict_registry", simdnbt(deny_unknown_fields))] -pub struct RegistryType<T> -where - T: Serialize + Deserialize, -{ - #[simdnbt(rename = "type")] - pub kind: ResourceLocation, - pub value: Vec<TypeValue<T>>, -} - -/// A value for a certain type of registry data. -#[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "strict_registry", simdnbt(deny_unknown_fields))] -pub struct TypeValue<T> -where - T: Serialize + Deserialize, -{ - pub id: u32, - pub name: ResourceLocation, - pub element: T, +#[derive(Debug, Clone)] +pub struct RegistryType<T> { + pub map: HashMap<ResourceLocation, T>, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs index f9f95004..a6dcc0be 100755 --- a/azalea-core/src/resource_location.rs +++ b/azalea-core/src/resource_location.rs @@ -3,6 +3,7 @@ use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; use simdnbt::{owned::NbtTag, FromNbtTag, ToNbtTag}; use std::{ + fmt, io::{Cursor, Write}, str::FromStr, }; @@ -41,13 +42,13 @@ impl ResourceLocation { } } -impl std::fmt::Display for ResourceLocation { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for ResourceLocation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", self.namespace, self.path) } } -impl std::fmt::Debug for ResourceLocation { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for ResourceLocation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", self.namespace, self.path) } } |
