diff options
| author | mat <git@matdoes.dev> | 2025-11-13 12:34:47 +0930 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-11-13 07:04:52 +0400 |
| commit | fbaae39cdf9c5a7a34005a51a37b85f7cdd5ea00 (patch) | |
| tree | 3126fb34a4e0ac979a1103a8227a2b9a136c1553 /azalea-core/src | |
| parent | a4312599f7c04709a92b7be238dcf577bafbb14f (diff) | |
| download | azalea-drasl-fbaae39cdf9c5a7a34005a51a37b85f7cdd5ea00.tar.xz | |
rename ResourceLocation to Identifier ahead of mojmap changes
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/checksum.rs | 4 | ||||
| -rw-r--r-- | azalea-core/src/data_registry.rs | 14 | ||||
| -rw-r--r-- | azalea-core/src/identifier.rs (renamed from azalea-core/src/resource_location.rs) | 58 | ||||
| -rw-r--r-- | azalea-core/src/lib.rs | 7 | ||||
| -rw-r--r-- | azalea-core/src/position.rs | 10 | ||||
| -rw-r--r-- | azalea-core/src/registry_holder.rs | 28 | ||||
| -rw-r--r-- | azalea-core/src/sound.rs | 4 |
7 files changed, 64 insertions, 61 deletions
diff --git a/azalea-core/src/checksum.rs b/azalea-core/src/checksum.rs index 4661d171..df94d58e 100644 --- a/azalea-core/src/checksum.rs +++ b/azalea-core/src/checksum.rs @@ -6,7 +6,7 @@ use serde::{Serialize, ser}; use thiserror::Error; use tracing::error; -use crate::{registry_holder::RegistryHolder, resource_location::ResourceLocation}; +use crate::{identifier::Identifier, registry_holder::RegistryHolder}; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, AzBuf)] pub struct Checksum(pub u32); @@ -200,7 +200,7 @@ impl<'a, 'r> ser::Serializer for ChecksumSerializer<'a, 'r> { let value = self .registries .map - .get(&ResourceLocation::from(name)) + .get(&Identifier::from(name)) .and_then(|r| r.get_index(variant_index as usize)) .map(|r| r.0.to_string()) .unwrap_or_default(); diff --git a/azalea-core/src/data_registry.rs b/azalea-core/src/data_registry.rs index 6e2c29ff..d3fae125 100644 --- a/azalea-core/src/data_registry.rs +++ b/azalea-core/src/data_registry.rs @@ -3,23 +3,23 @@ use std::{io::Cursor, str::FromStr}; use azalea_registry::DataRegistry; use simdnbt::owned::NbtCompound; -use crate::{registry_holder::RegistryHolder, resource_location::ResourceLocation}; +use crate::{identifier::Identifier, registry_holder::RegistryHolder}; pub trait ResolvableDataRegistry: DataRegistry { - fn resolve_name(&self, registries: &RegistryHolder) -> Option<ResourceLocation> { + fn resolve_name(&self, registries: &RegistryHolder) -> Option<Identifier> { self.resolve(registries).map(|(name, _)| name.clone()) } fn resolve<'a>( &self, registries: &'a RegistryHolder, - ) -> Option<(&'a ResourceLocation, &'a NbtCompound)> { - let name_resourcelocation = ResourceLocation::from_str(Self::NAME).unwrap_or_else(|_| { + ) -> Option<(&'a Identifier, &'a NbtCompound)> { + let name_ident = Identifier::from_str(Self::NAME).unwrap_or_else(|_| { panic!( - "Name for registry should be a valid ResourceLocation: {}", + "Name for registry should be a valid Identifier: {}", Self::NAME ) }); - let registry_values = registries.map.get(&name_resourcelocation)?; + let registry_values = registries.map.get(&name_ident)?; let resolved = registry_values.get_index(self.protocol_id() as usize)?; Some(resolved) } @@ -27,7 +27,7 @@ pub trait ResolvableDataRegistry: DataRegistry { fn resolve_and_deserialize<T: simdnbt::Deserialize>( &self, registries: &RegistryHolder, - ) -> Option<Result<(ResourceLocation, T), simdnbt::DeserializeError>> { + ) -> Option<Result<(Identifier, T), simdnbt::DeserializeError>> { let (name, value) = self.resolve(registries)?; let mut nbt_bytes = Vec::new(); diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/identifier.rs index 1591f678..d1e46aef 100644 --- a/azalea-core/src/resource_location.rs +++ b/azalea-core/src/identifier.rs @@ -1,4 +1,4 @@ -//! A resource, like minecraft:stone +//! An arbitrary string identifier. use std::{ fmt, @@ -10,8 +10,12 @@ use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; use simdnbt::{FromNbtTag, ToNbtTag, owned::NbtTag}; +/// An identifier, like `minecraft:stone` or `brigadier:number`. +/// +/// This was formerly called a `ResourceLocation`. +#[doc(alias = "ResourceLocation")] #[derive(Hash, Clone, PartialEq, Eq, Default)] -pub struct ResourceLocation { +pub struct Identifier { pub namespace: String, pub path: String, } @@ -19,8 +23,8 @@ pub struct ResourceLocation { static DEFAULT_NAMESPACE: &str = "minecraft"; // static REALMS_NAMESPACE: &str = "realms"; -impl ResourceLocation { - pub fn new(resource_string: &str) -> ResourceLocation { +impl Identifier { + pub fn new(resource_string: &str) -> Identifier { let sep_byte_position_option = resource_string.chars().position(|c| c == ':'); let (namespace, path) = if let Some(sep_byte_position) = sep_byte_position_option { if sep_byte_position == 0 { @@ -34,49 +38,49 @@ impl ResourceLocation { } else { (DEFAULT_NAMESPACE, resource_string) }; - ResourceLocation { + Identifier { namespace: namespace.to_string(), path: path.to_string(), } } } -impl fmt::Display for ResourceLocation { +impl fmt::Display for Identifier { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", self.namespace, self.path) } } -impl fmt::Debug for ResourceLocation { +impl fmt::Debug for Identifier { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", self.namespace, self.path) } } -impl FromStr for ResourceLocation { +impl FromStr for Identifier { type Err = &'static str; fn from_str(s: &str) -> Result<Self, Self::Err> { - Ok(ResourceLocation::new(s)) + Ok(Identifier::new(s)) } } -impl From<&str> for ResourceLocation { +impl From<&str> for Identifier { fn from(s: &str) -> Self { - ResourceLocation::new(s) + Identifier::new(s) } } -impl AzaleaRead for ResourceLocation { +impl AzaleaRead for Identifier { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let location_string = String::azalea_read(buf)?; - Ok(ResourceLocation::new(&location_string)) + Ok(Identifier::new(&location_string)) } } -impl AzaleaWrite for ResourceLocation { +impl AzaleaWrite for Identifier { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { self.to_string().azalea_write(buf) } } -impl Serialize for ResourceLocation { +impl Serialize for Identifier { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer, @@ -85,30 +89,30 @@ impl Serialize for ResourceLocation { } } -impl<'de> Deserialize<'de> for ResourceLocation { +impl<'de> Deserialize<'de> for Identifier { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de>, { let s = String::deserialize(deserializer)?; if s.contains(':') { - Ok(ResourceLocation::new(&s)) + Ok(Identifier::new(&s)) } else { Err(de::Error::invalid_value( de::Unexpected::Str(&s), - &"a valid ResourceLocation", + &"a valid Identifier", )) } } } -impl FromNbtTag for ResourceLocation { +impl FromNbtTag for Identifier { fn from_nbt_tag(tag: simdnbt::borrow::NbtTag) -> Option<Self> { tag.string().and_then(|s| s.to_str().parse().ok()) } } -impl ToNbtTag for ResourceLocation { +impl ToNbtTag for Identifier { fn to_nbt_tag(self) -> NbtTag { NbtTag::String(self.to_string().into()) } @@ -120,25 +124,25 @@ mod tests { #[test] fn basic_resource_location() { - let r = ResourceLocation::new("abcdef:ghijkl"); + let r = Identifier::new("abcdef:ghijkl"); assert_eq!(r.namespace, "abcdef"); assert_eq!(r.path, "ghijkl"); } #[test] fn no_namespace() { - let r = ResourceLocation::new("azalea"); + let r = Identifier::new("azalea"); assert_eq!(r.namespace, "minecraft"); assert_eq!(r.path, "azalea"); } #[test] fn colon_start() { - let r = ResourceLocation::new(":azalea"); + let r = Identifier::new(":azalea"); assert_eq!(r.namespace, "minecraft"); assert_eq!(r.path, "azalea"); } #[test] fn colon_end() { - let r = ResourceLocation::new("azalea:"); + let r = Identifier::new("azalea:"); assert_eq!(r.namespace, "azalea"); assert_eq!(r.path, ""); } @@ -146,15 +150,15 @@ mod tests { #[test] fn azbuf_resource_location() { let mut buf = Vec::new(); - ResourceLocation::new("minecraft:dirt") + Identifier::new("minecraft:dirt") .azalea_write(&mut buf) .unwrap(); let mut buf = Cursor::new(&buf[..]); assert_eq!( - ResourceLocation::azalea_read(&mut buf).unwrap(), - ResourceLocation::new("minecraft:dirt") + Identifier::azalea_read(&mut buf).unwrap(), + Identifier::new("minecraft:dirt") ); } } diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs index 9fdf4b6c..b87e6143 100644 --- a/azalea-core/src/lib.rs +++ b/azalea-core/src/lib.rs @@ -15,11 +15,16 @@ pub mod direction; pub mod filterable; pub mod game_type; pub mod hit_result; +pub mod identifier; pub mod math; pub mod objectives; pub mod position; pub mod registry_holder; -pub mod resource_location; +pub mod resource_location { + #![deprecated(note = "renamed to `identifier`.")] + #[deprecated(note = "renamed to `identifier::Identifier`.")] + pub type ResourceLocation = crate::identifier::Identifier; +} pub mod sound; #[cfg(feature = "bevy_ecs")] pub mod tick; diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 1686a7ad..03ea49ec 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -16,9 +16,7 @@ use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; use serde::{Serialize, Serializer}; use simdnbt::Deserialize; -use crate::{ - codec_utils::IntArray, direction::Direction, math, resource_location::ResourceLocation, -}; +use crate::{codec_utils::IntArray, direction::Direction, identifier::Identifier, math}; macro_rules! vec3_impl { ($name:ident, $type:ty) => { @@ -723,7 +721,7 @@ impl nohash_hasher::IsEnabled for ChunkSectionBlockPos {} #[derive(Debug, Clone, PartialEq, Serialize)] pub struct GlobalPos { // this is actually a ResourceKey in Minecraft, but i don't think it matters? - pub dimension: ResourceLocation, + pub dimension: Identifier, pub pos: BlockPos, } @@ -958,7 +956,7 @@ impl AzaleaRead for BlockPos { impl AzaleaRead for GlobalPos { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { Ok(GlobalPos { - dimension: ResourceLocation::azalea_read(buf)?, + dimension: Identifier::azalea_read(buf)?, pos: BlockPos::azalea_read(buf)?, }) } @@ -987,7 +985,7 @@ impl AzaleaWrite for BlockPos { impl AzaleaWrite for GlobalPos { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { - ResourceLocation::azalea_write(&self.dimension, buf)?; + Identifier::azalea_write(&self.dimension, buf)?; BlockPos::azalea_write(&self.pos, buf)?; Ok(()) diff --git a/azalea-core/src/registry_holder.rs b/azalea-core/src/registry_holder.rs index 7c5bfede..6730cd20 100644 --- a/azalea-core/src/registry_holder.rs +++ b/azalea-core/src/registry_holder.rs @@ -14,7 +14,7 @@ use simdnbt::{ }; use tracing::error; -use crate::resource_location::ResourceLocation; +use crate::identifier::Identifier; /// The base of the registry. /// @@ -26,15 +26,11 @@ use crate::resource_location::ResourceLocation; /// world. #[derive(Default, Debug, Clone)] pub struct RegistryHolder { - pub map: HashMap<ResourceLocation, IndexMap<ResourceLocation, NbtCompound>>, + pub map: HashMap<Identifier, IndexMap<Identifier, NbtCompound>>, } impl RegistryHolder { - pub fn append( - &mut self, - id: ResourceLocation, - entries: Vec<(ResourceLocation, Option<NbtCompound>)>, - ) { + pub fn append(&mut self, id: Identifier, entries: Vec<(Identifier, Option<NbtCompound>)>) { let map = self.map.entry(id).or_default(); for (key, value) in entries { if let Some(value) = value { @@ -49,7 +45,7 @@ impl RegistryHolder { /// /// You should do some type of error handling if this returns `None`. pub fn dimension_type(&self) -> Option<RegistryType<DimensionTypeElement>> { - let name = ResourceLocation::new("minecraft:dimension_type"); + let name = Identifier::new("minecraft:dimension_type"); match self.get(&name) { Some(Ok(registry)) => Some(registry), Some(Err(err)) => { @@ -65,7 +61,7 @@ impl RegistryHolder { fn get<T: Deserialize>( &self, - name: &ResourceLocation, + name: &Identifier, ) -> 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 @@ -95,14 +91,14 @@ impl RegistryHolder { /// A collection of values for a certain type of registry data. #[derive(Debug, Clone)] pub struct RegistryType<T> { - pub map: HashMap<ResourceLocation, T>, + pub map: HashMap<Identifier, T>, } #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "strict_registry", simdnbt(deny_unknown_fields))] pub struct TrimMaterialElement { pub asset_name: String, - pub ingredient: ResourceLocation, + pub ingredient: Identifier, pub item_model_index: f32, pub override_armor_materials: HashMap<String, String>, pub description: Option<String>, @@ -145,13 +141,13 @@ pub struct DimensionTypeElement { pub ambient_light: f32, pub bed_works: bool, pub coordinate_scale: f32, - pub effects: ResourceLocation, + pub effects: Identifier, pub fixed_time: Option<u32>, pub has_ceiling: bool, pub has_raids: bool, pub has_skylight: bool, pub height: u32, - pub infiniburn: ResourceLocation, + pub infiniburn: Identifier, pub logical_height: u32, pub min_y: i32, pub monster_spawn_block_light_limit: u32, @@ -185,7 +181,7 @@ pub enum MonsterSpawnLightLevel { /// A complex value with a type, minimum, and maximum. /// Vanilla minecraft only uses one type, "minecraft:uniform". Complex { - kind: ResourceLocation, + kind: Identifier, value: MonsterSpawnLightLevelValues, }, } @@ -195,7 +191,7 @@ impl FromNbtTag for MonsterSpawnLightLevel { if let Some(value) = tag.int() { Some(Self::Simple(value as u32)) } else if let Some(value) = tag.compound() { - let kind = ResourceLocation::from_nbt_tag(value.get("type")?)?; + let kind = Identifier::from_nbt_tag(value.get("type")?)?; let value = MonsterSpawnLightLevelValues::from_nbt_tag(value.get("value")?)?; Some(Self::Complex { kind, value }) } else { @@ -285,7 +281,7 @@ pub struct BiomeEffects { pub music: Option<BiomeMusic>, pub mood_sound: BiomeMoodSound, pub additions_sound: Option<AdditionsSound>, - pub ambient_sound: Option<ResourceLocation>, + pub ambient_sound: Option<Identifier>, pub particle: Option<BiomeParticle>, } diff --git a/azalea-core/src/sound.rs b/azalea-core/src/sound.rs index 3f7b86c3..ebc18928 100644 --- a/azalea-core/src/sound.rs +++ b/azalea-core/src/sound.rs @@ -1,10 +1,10 @@ use azalea_buf::AzBuf; use serde::Serialize; -use crate::resource_location::ResourceLocation; +use crate::identifier::Identifier; #[derive(Clone, Debug, PartialEq, AzBuf, Serialize)] pub struct CustomSound { - pub location: ResourceLocation, + pub location: Identifier, pub fixed_range: Option<f32>, } |
