From fbaae39cdf9c5a7a34005a51a37b85f7cdd5ea00 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 13 Nov 2025 12:34:47 +0930 Subject: rename ResourceLocation to Identifier ahead of mojmap changes --- CHANGELOG.md | 1 + azalea-client/src/client.rs | 7 +- azalea-client/src/plugins/packet/game/events.rs | 4 +- azalea-client/src/test_utils/simulation.rs | 12 +- .../tests/change_dimension_to_nether_and_back.rs | 28 ++-- .../despawn_entities_when_changing_dimension.rs | 12 +- azalea-client/tests/fast_login.rs | 6 +- .../tests/login_to_dimension_with_same_name.rs | 22 +-- azalea-client/tests/reply_to_ping_with_pong.rs | 6 +- azalea-client/tests/set_health_before_login.rs | 6 +- azalea-core/src/checksum.rs | 4 +- azalea-core/src/data_registry.rs | 14 +- azalea-core/src/identifier.rs | 164 +++++++++++++++++++++ azalea-core/src/lib.rs | 7 +- azalea-core/src/position.rs | 10 +- azalea-core/src/registry_holder.rs | 28 ++-- azalea-core/src/resource_location.rs | 160 -------------------- azalea-core/src/sound.rs | 4 +- azalea-entity/src/attributes.rs | 16 +- azalea-entity/src/lib.rs | 4 +- azalea-inventory/src/components/mod.rs | 44 +++--- azalea-inventory/src/components/profile.rs | 4 +- azalea-inventory/src/item/consume_effect.rs | 4 +- azalea-physics/src/fluids.rs | 4 +- azalea-physics/tests/physics.rs | 26 ++-- azalea-protocol/src/common/recipe.rs | 6 +- azalea-protocol/src/common/tags.rs | 12 +- azalea-protocol/src/packets/common.rs | 6 +- .../src/packets/config/c_cookie_request.rs | 4 +- .../src/packets/config/c_custom_payload.rs | 4 +- .../src/packets/config/c_registry_data.rs | 6 +- .../src/packets/config/c_store_cookie.rs | 4 +- .../packets/config/c_update_enabled_features.rs | 4 +- .../src/packets/config/s_cookie_response.rs | 4 +- .../src/packets/config/s_custom_click_action.rs | 4 +- .../src/packets/config/s_custom_payload.rs | 4 +- azalea-protocol/src/packets/game/c_add_entity.rs | 4 +- azalea-protocol/src/packets/game/c_commands.rs | 20 +-- .../src/packets/game/c_cookie_request.rs | 4 +- .../src/packets/game/c_custom_payload.rs | 7 +- azalea-protocol/src/packets/game/c_login.rs | 4 +- .../src/packets/game/c_select_advancements_tab.rs | 4 +- azalea-protocol/src/packets/game/c_stop_sound.rs | 6 +- azalea-protocol/src/packets/game/c_store_cookie.rs | 4 +- .../src/packets/game/c_update_advancements.rs | 24 +-- .../src/packets/game/c_update_recipes.rs | 4 +- azalea-protocol/src/packets/game/c_waypoint.rs | 6 +- .../src/packets/game/s_cookie_response.rs | 4 +- .../src/packets/game/s_custom_click_action.rs | 4 +- .../src/packets/game/s_custom_payload.rs | 7 +- azalea-protocol/src/packets/game/s_place_recipe.rs | 4 +- .../src/packets/game/s_recipe_book_seen_recipe.rs | 4 +- .../src/packets/game/s_seen_advancements.rs | 6 +- .../src/packets/game/s_set_jigsaw_block.rs | 8 +- .../src/packets/login/c_cookie_request.rs | 4 +- .../src/packets/login/c_custom_query.rs | 4 +- .../src/packets/login/s_cookie_response.rs | 4 +- azalea-registry/src/lib.rs | 36 ++--- azalea-world/src/container.rs | 8 +- azalea/src/lib.rs | 5 +- azalea/src/pathfinder/simulation.rs | 8 +- codegen/lib/code/data_components.py | 12 +- codegen/lib/code/utils.py | 4 +- codegen/lib/extract.py | 10 +- 64 files changed, 434 insertions(+), 440 deletions(-) create mode 100644 azalea-core/src/identifier.rs delete mode 100644 azalea-core/src/resource_location.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index b49fda01..03459fc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ is breaking anyways, semantic versioning is not followed. - Rename `SendPacketEvent` to `SendGamePacketEvent` and `PingEvent` to `GamePingEvent`. - Swap the order of the type parameters in entity filtering functions so query is first, then filter. - Add optional `timeout_ticks` field to `Client::open_container_at`. +- Rename `ResourceLocation` to `Identifier` to match Minecraft's new internal naming. ### Fixed diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 6957619e..e0902779 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -10,8 +10,7 @@ use std::{ use azalea_auth::game_profile::GameProfile; use azalea_core::{ - data_registry::ResolvableDataRegistry, position::Vec3, resource_location::ResourceLocation, - tick::GameTick, + data_registry::ResolvableDataRegistry, identifier::Identifier, position::Vec3, tick::GameTick, }; use azalea_entity::{ EntityUpdateSystems, PlayerAbilities, Position, @@ -487,7 +486,7 @@ impl Client { pub fn resolve_registry_name( &self, registry: &impl ResolvableDataRegistry, - ) -> Option { + ) -> Option { self.with_registry_holder(|registries| registry.resolve_name(registries)) } /// Resolve the given registry to its name and data and call the given @@ -502,7 +501,7 @@ impl Client { pub fn with_resolved_registry( &self, registry: impl ResolvableDataRegistry, - f: impl FnOnce(&ResourceLocation, &NbtCompound) -> R, + f: impl FnOnce(&Identifier, &NbtCompound) -> R, ) -> Option { self.with_registry_holder(|registries| { registry diff --git a/azalea-client/src/plugins/packet/game/events.rs b/azalea-client/src/plugins/packet/game/events.rs index 7c773b44..53d93855 100644 --- a/azalea-client/src/plugins/packet/game/events.rs +++ b/azalea-client/src/plugins/packet/game/events.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Weak}; use azalea_chat::FormattedText; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol::packets::{ Packet, game::{ClientboundGamePacket, ClientboundPlayerCombatKill, ServerboundGamePacket}, @@ -145,7 +145,7 @@ pub struct ResourcePackEvent { #[derive(Message, Debug, Clone)] pub struct InstanceLoadedEvent { pub entity: Entity, - pub name: ResourceLocation, + pub name: Identifier, pub instance: Weak>, } diff --git a/azalea-client/src/test_utils/simulation.rs b/azalea-client/src/test_utils/simulation.rs index 8d52177a..13470600 100644 --- a/azalea-client/src/test_utils/simulation.rs +++ b/azalea-client/src/test_utils/simulation.rs @@ -6,8 +6,8 @@ use azalea_buf::AzaleaWrite; use azalea_core::{ delta::LpVec3, game_type::{GameMode, OptionalGameType}, + identifier::Identifier, position::{BlockPos, ChunkPos, Vec3}, - resource_location::ResourceLocation, tick::GameTick, }; use azalea_entity::metadata::PlayerMetadataBundle; @@ -76,9 +76,9 @@ impl Simulation { ConnectionProtocol::Configuration => {} ConnectionProtocol::Game => { simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), @@ -302,13 +302,13 @@ fn tick_app(app: &mut App) { pub fn default_login_packet() -> ClientboundLogin { make_basic_login_packet( DimensionType::new_raw(0), // overworld - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ) } pub fn make_basic_login_packet( dimension_type: DimensionType, - dimension: ResourceLocation, + dimension: Identifier, ) -> ClientboundLogin { ClientboundLogin { player_id: MinecraftEntityId(0), @@ -338,7 +338,7 @@ pub fn make_basic_login_packet( pub fn make_basic_respawn_packet( dimension_type: DimensionType, - dimension: ResourceLocation, + dimension: Identifier, ) -> ClientboundRespawn { ClientboundRespawn { common: CommonPlayerSpawnInfo { diff --git a/azalea-client/tests/change_dimension_to_nether_and_back.rs b/azalea-client/tests/change_dimension_to_nether_and_back.rs index e3b5d96e..9594da04 100644 --- a/azalea-client/tests/change_dimension_to_nether_and_back.rs +++ b/azalea-client/tests/change_dimension_to_nether_and_back.rs @@ -1,5 +1,5 @@ use azalea_client::{InConfigState, InGameState, test_utils::prelude::*}; -use azalea_core::{position::ChunkPos, resource_location::ResourceLocation}; +use azalea_core::{identifier::Identifier, position::ChunkPos}; use azalea_entity::LocalEntity; use azalea_protocol::packets::{ ConnectionProtocol, Packet, @@ -19,11 +19,11 @@ fn test_change_dimension_to_nether_and_back() { fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { let make_basic_login_or_respawn_packet = if using_respawn { - |dimension: DimensionType, instance_name: ResourceLocation| { + |dimension: DimensionType, instance_name: Identifier| { make_basic_respawn_packet(dimension, instance_name).into_variant() } } else { - |dimension: DimensionType, instance_name: ResourceLocation| { + |dimension: DimensionType, instance_name: Identifier| { make_basic_login_packet(dimension, instance_name).into_variant() } }; @@ -33,26 +33,26 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { assert!(!simulation.has_component::()); simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![ ( // this dimension should never be created. it just exists to make sure we're not // hard-coding the dimension type id anywhere. - ResourceLocation::new("azalea:fakedimension"), + Identifier::new("azalea:fakedimension"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(16)), ("min_y".into(), NbtTag::Int(0)), ])), ), ( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), ])), ), ( - ResourceLocation::new("minecraft:nether"), + Identifier::new("minecraft:nether"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(256)), ("min_y".into(), NbtTag::Int(0)), @@ -76,13 +76,13 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { simulation.receive_packet(make_basic_login_packet( DimensionType::new_raw(1), // overworld - ResourceLocation::new("azalea:a"), + Identifier::new("azalea:a"), )); simulation.tick(); assert_eq!( *simulation.component::(), - ResourceLocation::new("azalea:a"), + Identifier::new("azalea:a"), "InstanceName should be azalea:a after setting dimension to that" ); @@ -99,7 +99,7 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { simulation.receive_packet(make_basic_login_or_respawn_packet( DimensionType::new_raw(2), // nether - ResourceLocation::new("azalea:b"), + Identifier::new("azalea:b"), )); simulation.tick(); @@ -109,7 +109,7 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { ); assert_eq!( *simulation.component::(), - ResourceLocation::new("azalea:b"), + Identifier::new("azalea:b"), "InstanceName should be azalea:b after changing dimensions to that" ); @@ -121,7 +121,7 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { .expect("chunk should exist"); simulation.receive_packet(make_basic_login_or_respawn_packet( DimensionType::new_raw(2), // nether - ResourceLocation::new("minecraft:nether"), + Identifier::new("minecraft:nether"), )); simulation.tick(); @@ -131,13 +131,13 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { simulation.receive_packet(make_basic_login_packet( DimensionType::new_raw(1), // overworld - ResourceLocation::new("azalea:a"), + Identifier::new("azalea:a"), )); simulation.tick(); assert_eq!( *simulation.component::(), - ResourceLocation::new("azalea:a"), + Identifier::new("azalea:a"), "InstanceName should be azalea:a after setting dimension back to that" ); assert!( diff --git a/azalea-client/tests/despawn_entities_when_changing_dimension.rs b/azalea-client/tests/despawn_entities_when_changing_dimension.rs index 9143b3eb..38388c04 100644 --- a/azalea-client/tests/despawn_entities_when_changing_dimension.rs +++ b/azalea-client/tests/despawn_entities_when_changing_dimension.rs @@ -1,5 +1,5 @@ use azalea_client::test_utils::prelude::*; -use azalea_core::{position::ChunkPos, resource_location::ResourceLocation}; +use azalea_core::{identifier::Identifier, position::ChunkPos}; use azalea_entity::metadata::Cow; use azalea_protocol::packets::{ ConnectionProtocol, @@ -15,17 +15,17 @@ fn test_despawn_entities_when_changing_dimension() { let mut simulation = Simulation::new(ConnectionProtocol::Configuration); simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![ ( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), ])), ), ( - ResourceLocation::new("minecraft:nether"), + Identifier::new("minecraft:nether"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(256)), ("min_y".into(), NbtTag::Int(0)), @@ -45,7 +45,7 @@ fn test_despawn_entities_when_changing_dimension() { simulation.receive_packet(make_basic_login_packet( DimensionType::new_raw(0), // overworld - ResourceLocation::new("azalea:a"), + Identifier::new("azalea:a"), )); simulation.tick(); @@ -65,7 +65,7 @@ fn test_despawn_entities_when_changing_dimension() { simulation.receive_packet(make_basic_respawn_packet( DimensionType::new_raw(1), // nether - ResourceLocation::new("azalea:b"), + Identifier::new("azalea:b"), )); simulation.tick(); diff --git a/azalea-client/tests/fast_login.rs b/azalea-client/tests/fast_login.rs index f11ada9c..7962d79e 100644 --- a/azalea-client/tests/fast_login.rs +++ b/azalea-client/tests/fast_login.rs @@ -1,5 +1,5 @@ use azalea_client::{InConfigState, test_utils::prelude::*}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_entity::metadata::Health; use azalea_protocol::packets::{ ConnectionProtocol, @@ -16,9 +16,9 @@ fn test_fast_login() { assert!(simulation.has_component::()); simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), diff --git a/azalea-client/tests/login_to_dimension_with_same_name.rs b/azalea-client/tests/login_to_dimension_with_same_name.rs index eb1db2a8..0a28cfd3 100644 --- a/azalea-client/tests/login_to_dimension_with_same_name.rs +++ b/azalea-client/tests/login_to_dimension_with_same_name.rs @@ -1,7 +1,7 @@ use azalea_client::{ InConfigState, InGameState, local_player::InstanceHolder, test_utils::prelude::*, }; -use azalea_core::{position::ChunkPos, resource_location::ResourceLocation}; +use azalea_core::{identifier::Identifier, position::ChunkPos}; use azalea_entity::LocalEntity; use azalea_protocol::packets::{ ConnectionProtocol, Packet, @@ -22,11 +22,11 @@ fn test_login_to_dimension_with_same_name() { fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) { let make_basic_login_or_respawn_packet = if using_respawn { - |dimension: DimensionType, instance_name: ResourceLocation| { + |dimension: DimensionType, instance_name: Identifier| { make_basic_respawn_packet(dimension, instance_name).into_variant() } } else { - |dimension: DimensionType, instance_name: ResourceLocation| { + |dimension: DimensionType, instance_name: Identifier| { make_basic_login_packet(dimension, instance_name).into_variant() } }; @@ -36,9 +36,9 @@ fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) { assert!(!simulation.has_component::()); simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), @@ -61,13 +61,13 @@ fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) { simulation.receive_packet(make_basic_login_packet( DimensionType::new_raw(0), // overworld - ResourceLocation::new("azalea:overworld"), + Identifier::new("azalea:overworld"), )); simulation.tick(); assert_eq!( *simulation.component::(), - ResourceLocation::new("azalea:overworld"), + Identifier::new("azalea:overworld"), "InstanceName should be azalea:overworld after setting dimension to that" ); @@ -84,9 +84,9 @@ fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) { simulation.receive_packet(ClientboundStartConfiguration); simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(256)), ("min_y".into(), NbtTag::Int(0)), @@ -98,7 +98,7 @@ fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) { simulation.receive_packet(ClientboundFinishConfiguration); simulation.receive_packet(make_basic_login_or_respawn_packet( DimensionType::new_raw(0), - ResourceLocation::new("azalea:overworld"), + Identifier::new("azalea:overworld"), )); simulation.tick(); @@ -108,7 +108,7 @@ fn generic_test_login_to_dimension_with_same_name(using_respawn: bool) { ); assert_eq!( *simulation.component::(), - ResourceLocation::new("azalea:overworld"), + Identifier::new("azalea:overworld"), "InstanceName should still be azalea:overworld after changing dimensions to that" ); assert_eq!( diff --git a/azalea-client/tests/reply_to_ping_with_pong.rs b/azalea-client/tests/reply_to_ping_with_pong.rs index 444ec41c..ff369a1d 100644 --- a/azalea-client/tests/reply_to_ping_with_pong.rs +++ b/azalea-client/tests/reply_to_ping_with_pong.rs @@ -4,7 +4,7 @@ use azalea_client::{ packet::{config::SendConfigPacketEvent, game::SendGamePacketEvent}, test_utils::prelude::*, }; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol::packets::{ ConnectionProtocol, config::{ @@ -42,9 +42,9 @@ fn reply_to_ping_with_pong() { // move into game state and test ClientboundPing there simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), diff --git a/azalea-client/tests/set_health_before_login.rs b/azalea-client/tests/set_health_before_login.rs index 367bd10c..5b2dfc8e 100644 --- a/azalea-client/tests/set_health_before_login.rs +++ b/azalea-client/tests/set_health_before_login.rs @@ -1,5 +1,5 @@ use azalea_client::{InConfigState, test_utils::prelude::*}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_entity::{LocalEntity, metadata::Health}; use azalea_protocol::packets::{ ConnectionProtocol, @@ -16,9 +16,9 @@ fn test_set_health_before_login() { assert!(simulation.has_component::()); simulation.receive_packet(ClientboundRegistryData { - registry_id: ResourceLocation::new("minecraft:dimension_type"), + registry_id: Identifier::new("minecraft:dimension_type"), entries: vec![( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), Some(NbtCompound::from_values(vec![ ("height".into(), NbtTag::Int(384)), ("min_y".into(), NbtTag::Int(-64)), 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 { + fn resolve_name(&self, registries: &RegistryHolder) -> Option { 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( &self, registries: &RegistryHolder, - ) -> Option> { + ) -> Option> { let (name, value) = self.resolve(registries)?; let mut nbt_bytes = Vec::new(); diff --git a/azalea-core/src/identifier.rs b/azalea-core/src/identifier.rs new file mode 100644 index 00000000..d1e46aef --- /dev/null +++ b/azalea-core/src/identifier.rs @@ -0,0 +1,164 @@ +//! An arbitrary string identifier. + +use std::{ + fmt, + io::{self, Cursor, Write}, + str::FromStr, +}; + +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 Identifier { + pub namespace: String, + pub path: String, +} + +static DEFAULT_NAMESPACE: &str = "minecraft"; +// static REALMS_NAMESPACE: &str = "realms"; + +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 { + (DEFAULT_NAMESPACE, &resource_string[1..]) + } else { + ( + &resource_string[..sep_byte_position], + &resource_string[sep_byte_position + 1..], + ) + } + } else { + (DEFAULT_NAMESPACE, resource_string) + }; + Identifier { + namespace: namespace.to_string(), + path: path.to_string(), + } + } +} + +impl fmt::Display for Identifier { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}:{}", self.namespace, self.path) + } +} +impl fmt::Debug for Identifier { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}:{}", self.namespace, self.path) + } +} +impl FromStr for Identifier { + type Err = &'static str; + + fn from_str(s: &str) -> Result { + Ok(Identifier::new(s)) + } +} +impl From<&str> for Identifier { + fn from(s: &str) -> Self { + Identifier::new(s) + } +} + +impl AzaleaRead for Identifier { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { + let location_string = String::azalea_read(buf)?; + Ok(Identifier::new(&location_string)) + } +} +impl AzaleaWrite for Identifier { + fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { + self.to_string().azalea_write(buf) + } +} + +impl Serialize for Identifier { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&self.to_string()) + } +} + +impl<'de> Deserialize<'de> for Identifier { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + if s.contains(':') { + Ok(Identifier::new(&s)) + } else { + Err(de::Error::invalid_value( + de::Unexpected::Str(&s), + &"a valid Identifier", + )) + } + } +} + +impl FromNbtTag for Identifier { + fn from_nbt_tag(tag: simdnbt::borrow::NbtTag) -> Option { + tag.string().and_then(|s| s.to_str().parse().ok()) + } +} + +impl ToNbtTag for Identifier { + fn to_nbt_tag(self) -> NbtTag { + NbtTag::String(self.to_string().into()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn basic_resource_location() { + let r = Identifier::new("abcdef:ghijkl"); + assert_eq!(r.namespace, "abcdef"); + assert_eq!(r.path, "ghijkl"); + } + #[test] + fn no_namespace() { + let r = Identifier::new("azalea"); + assert_eq!(r.namespace, "minecraft"); + assert_eq!(r.path, "azalea"); + } + #[test] + fn colon_start() { + let r = Identifier::new(":azalea"); + assert_eq!(r.namespace, "minecraft"); + assert_eq!(r.path, "azalea"); + } + #[test] + fn colon_end() { + let r = Identifier::new("azalea:"); + assert_eq!(r.namespace, "azalea"); + assert_eq!(r.path, ""); + } + + #[test] + fn azbuf_resource_location() { + let mut buf = Vec::new(); + Identifier::new("minecraft:dirt") + .azalea_write(&mut buf) + .unwrap(); + + let mut buf = Cursor::new(&buf[..]); + + assert_eq!( + 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 { 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>, + pub map: HashMap>, } impl RegistryHolder { - pub fn append( - &mut self, - id: ResourceLocation, - entries: Vec<(ResourceLocation, Option)>, - ) { + pub fn append(&mut self, id: Identifier, entries: Vec<(Identifier, Option)>) { 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> { - 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( &self, - name: &ResourceLocation, + name: &Identifier, ) -> Option, 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 { - pub map: HashMap, + pub map: HashMap, } #[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, pub description: Option, @@ -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, 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, pub mood_sound: BiomeMoodSound, pub additions_sound: Option, - pub ambient_sound: Option, + pub ambient_sound: Option, pub particle: Option, } diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs deleted file mode 100644 index 1591f678..00000000 --- a/azalea-core/src/resource_location.rs +++ /dev/null @@ -1,160 +0,0 @@ -//! A resource, like minecraft:stone - -use std::{ - fmt, - io::{self, Cursor, Write}, - str::FromStr, -}; - -use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; -use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; -use simdnbt::{FromNbtTag, ToNbtTag, owned::NbtTag}; - -#[derive(Hash, Clone, PartialEq, Eq, Default)] -pub struct ResourceLocation { - pub namespace: String, - pub path: String, -} - -static DEFAULT_NAMESPACE: &str = "minecraft"; -// static REALMS_NAMESPACE: &str = "realms"; - -impl ResourceLocation { - pub fn new(resource_string: &str) -> ResourceLocation { - 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 { - (DEFAULT_NAMESPACE, &resource_string[1..]) - } else { - ( - &resource_string[..sep_byte_position], - &resource_string[sep_byte_position + 1..], - ) - } - } else { - (DEFAULT_NAMESPACE, resource_string) - }; - ResourceLocation { - namespace: namespace.to_string(), - path: path.to_string(), - } - } -} - -impl fmt::Display for ResourceLocation { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}:{}", self.namespace, self.path) - } -} -impl fmt::Debug for ResourceLocation { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}:{}", self.namespace, self.path) - } -} -impl FromStr for ResourceLocation { - type Err = &'static str; - - fn from_str(s: &str) -> Result { - Ok(ResourceLocation::new(s)) - } -} -impl From<&str> for ResourceLocation { - fn from(s: &str) -> Self { - ResourceLocation::new(s) - } -} - -impl AzaleaRead for ResourceLocation { - fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { - let location_string = String::azalea_read(buf)?; - Ok(ResourceLocation::new(&location_string)) - } -} -impl AzaleaWrite for ResourceLocation { - fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { - self.to_string().azalea_write(buf) - } -} - -impl Serialize for ResourceLocation { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(&self.to_string()) - } -} - -impl<'de> Deserialize<'de> for ResourceLocation { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let s = String::deserialize(deserializer)?; - if s.contains(':') { - Ok(ResourceLocation::new(&s)) - } else { - Err(de::Error::invalid_value( - de::Unexpected::Str(&s), - &"a valid ResourceLocation", - )) - } - } -} - -impl FromNbtTag for ResourceLocation { - fn from_nbt_tag(tag: simdnbt::borrow::NbtTag) -> Option { - tag.string().and_then(|s| s.to_str().parse().ok()) - } -} - -impl ToNbtTag for ResourceLocation { - fn to_nbt_tag(self) -> NbtTag { - NbtTag::String(self.to_string().into()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn basic_resource_location() { - let r = ResourceLocation::new("abcdef:ghijkl"); - assert_eq!(r.namespace, "abcdef"); - assert_eq!(r.path, "ghijkl"); - } - #[test] - fn no_namespace() { - let r = ResourceLocation::new("azalea"); - assert_eq!(r.namespace, "minecraft"); - assert_eq!(r.path, "azalea"); - } - #[test] - fn colon_start() { - let r = ResourceLocation::new(":azalea"); - assert_eq!(r.namespace, "minecraft"); - assert_eq!(r.path, "azalea"); - } - #[test] - fn colon_end() { - let r = ResourceLocation::new("azalea:"); - assert_eq!(r.namespace, "azalea"); - assert_eq!(r.path, ""); - } - - #[test] - fn azbuf_resource_location() { - let mut buf = Vec::new(); - ResourceLocation::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") - ); - } -} 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, } diff --git a/azalea-entity/src/attributes.rs b/azalea-entity/src/attributes.rs index 75423746..ca02e639 100644 --- a/azalea-entity/src/attributes.rs +++ b/azalea-entity/src/attributes.rs @@ -3,7 +3,7 @@ use std::collections::{HashMap, hash_map}; use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use bevy_ecs::component::Component; use thiserror::Error; @@ -23,7 +23,7 @@ pub struct Attributes { #[derive(Clone, Debug)] pub struct AttributeInstance { pub base: f64, - modifiers_by_id: HashMap, + modifiers_by_id: HashMap, // TODO: add cache } @@ -73,14 +73,14 @@ impl AttributeInstance { /// Remove the modifier with the given ID from this attribute, returning /// the previous modifier is present. - pub fn remove(&mut self, id: &ResourceLocation) -> Option { + pub fn remove(&mut self, id: &Identifier) -> Option { self.modifiers_by_id.remove(id) } } #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct AttributeModifier { - pub id: ResourceLocation, + pub id: Identifier, pub amount: f64, pub operation: AttributeModifierOperation, } @@ -94,21 +94,21 @@ pub enum AttributeModifierOperation { pub fn sprinting_modifier() -> AttributeModifier { AttributeModifier { - id: ResourceLocation::new("sprinting"), + id: Identifier::new("sprinting"), amount: 0.3f32 as f64, operation: AttributeModifierOperation::AddMultipliedTotal, } } pub fn base_attack_speed_modifier(amount: f64) -> AttributeModifier { AttributeModifier { - id: ResourceLocation::new("base_attack_speed"), + id: Identifier::new("base_attack_speed"), amount, operation: AttributeModifierOperation::AddValue, } } pub fn creative_block_interaction_range_modifier() -> AttributeModifier { AttributeModifier { - id: ResourceLocation::new("creative_mode_block_range"), + id: Identifier::new("creative_mode_block_range"), amount: 0.5, operation: AttributeModifierOperation::AddValue, } @@ -116,7 +116,7 @@ pub fn creative_block_interaction_range_modifier() -> AttributeModifier { pub fn creative_entity_interaction_range_modifier() -> AttributeModifier { AttributeModifier { - id: ResourceLocation::new("creative_mode_entity_range"), + id: Identifier::new("creative_mode_entity_range"), amount: 2.0, operation: AttributeModifierOperation::AddValue, } diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs index 1f9e426e..927b4637 100644 --- a/azalea-entity/src/lib.rs +++ b/azalea-entity/src/lib.rs @@ -22,9 +22,9 @@ use azalea_block::{BlockState, fluid_state::FluidKind}; use azalea_buf::AzBuf; use azalea_core::{ aabb::Aabb, + identifier::Identifier, math, position::{BlockPos, ChunkPos, Vec3}, - resource_location::ResourceLocation, }; use azalea_registry::EntityKind; use azalea_world::{ChunkStorage, InstanceName}; @@ -496,7 +496,7 @@ impl EntityBundle { uuid: Uuid, pos: Vec3, kind: azalea_registry::EntityKind, - world_name: ResourceLocation, + world_name: Identifier, ) -> Self { let dimensions = EntityDimensions::from(kind); diff --git a/azalea-inventory/src/components/mod.rs b/azalea-inventory/src/components/mod.rs index 7f3fa831..34d0a9b4 100644 --- a/azalea-inventory/src/components/mod.rs +++ b/azalea-inventory/src/components/mod.rs @@ -14,9 +14,9 @@ use azalea_core::{ checksum::{Checksum, get_checksum}, codec_utils::*, filterable::Filterable, + identifier::Identifier, position::GlobalPos, registry_holder::RegistryHolder, - resource_location::ResourceLocation, sound::CustomSound, }; use azalea_registry::{ @@ -372,7 +372,7 @@ pub struct BlockStatePropertyMatcher { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] pub struct BlockPredicate { #[serde(skip_serializing_if = "is_default")] - pub blocks: Option>, + pub blocks: Option>, #[serde(skip_serializing_if = "is_default")] pub properties: Option>, #[serde(skip_serializing_if = "is_default")] @@ -426,7 +426,7 @@ pub enum AttributeModifierOperation { // circular dependency) #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] pub struct AttributeModifier { - pub id: ResourceLocation, + pub id: Identifier, pub amount: f64, pub operation: AttributeModifierOperation, } @@ -558,7 +558,7 @@ impl Food { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] pub struct ToolRule { - pub blocks: HolderSet, + pub blocks: HolderSet, #[serde(skip_serializing_if = "is_default")] pub speed: Option, #[serde(skip_serializing_if = "is_default")] @@ -779,7 +779,7 @@ pub struct OminousBottleAmplifier { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(transparent)] pub struct Recipes { - pub recipes: Vec, + pub recipes: Vec, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] @@ -839,7 +839,7 @@ impl Default for Fireworks { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(transparent)] pub struct NoteBlockSound { - pub sound: ResourceLocation, + pub sound: Identifier, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] @@ -930,7 +930,7 @@ pub struct ContainerLoot { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(untagged)] pub enum JukeboxPlayable { - Referenced(ResourceLocation), + Referenced(Identifier), Direct(Holder), } @@ -1006,7 +1006,7 @@ pub struct UseRemainder { pub struct UseCooldown { pub seconds: f32, #[serde(skip_serializing_if = "is_default")] - pub cooldown_group: Option, + pub cooldown_group: Option, } impl UseCooldown { @@ -1031,19 +1031,19 @@ pub struct Enchantable { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] pub struct Repairable { - pub items: HolderSet, + pub items: HolderSet, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(transparent)] pub struct ItemModel { - pub resource_location: ResourceLocation, + pub resource_location: Identifier, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] pub struct DamageResistant { /// In vanilla this only allows tag keys, i.e. it must start with '#' - pub types: ResourceLocation, + pub types: Identifier, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] @@ -1052,11 +1052,11 @@ pub struct Equippable { #[serde(skip_serializing_if = "is_default_equip_sound")] pub equip_sound: SoundEvent, #[serde(skip_serializing_if = "is_default")] - pub asset_id: Option, + pub asset_id: Option, #[serde(skip_serializing_if = "is_default")] - pub camera_overlay: Option, + pub camera_overlay: Option, #[serde(skip_serializing_if = "is_default")] - pub allowed_entities: Option>, + pub allowed_entities: Option>, #[serde(skip_serializing_if = "is_true")] pub dispensable: bool, #[serde(skip_serializing_if = "is_true")] @@ -1119,7 +1119,7 @@ pub struct Glider; #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(transparent)] pub struct TooltipStyle { - pub resource_location: ResourceLocation, + pub resource_location: Identifier, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] @@ -1268,7 +1268,7 @@ pub struct PaintingVariantData { pub width: i32, #[var] pub height: i32, - pub asset_id: ResourceLocation, + pub asset_id: Identifier, #[serde(skip_serializing_if = "is_default")] pub title: Option, #[serde(skip_serializing_if = "is_default")] @@ -1344,7 +1344,7 @@ pub struct BlocksAttacks { #[serde(skip_serializing_if = "is_default")] pub item_damage: ItemDamageFunction, #[serde(skip_serializing_if = "is_default")] - pub bypassed_by: Option, + pub bypassed_by: Option, #[serde(skip_serializing_if = "is_default")] pub block_sound: Option>, #[serde(skip_serializing_if = "is_default")] @@ -1383,7 +1383,7 @@ pub struct DamageReduction { #[serde(skip_serializing_if = "is_default_horizontal_blocking_angle")] pub horizontal_blocking_angle: f32, #[serde(skip_serializing_if = "is_default")] - pub kind: Option>, + pub kind: Option>, pub base: f32, pub factor: f32, } @@ -1409,7 +1409,7 @@ impl Default for ItemDamageFunction { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(untagged)] pub enum ProvidesTrimMaterial { - Referenced(ResourceLocation), + Referenced(Identifier), Direct(Holder), } @@ -1422,7 +1422,7 @@ pub struct DirectTrimMaterial { pub struct MaterialAssetGroup { pub base: AssetInfo, #[serde(skip_serializing_if = "is_default")] - pub overrides: Vec<(ResourceLocation, AssetInfo)>, + pub overrides: Vec<(Identifier, AssetInfo)>, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] @@ -1433,7 +1433,7 @@ pub struct AssetInfo { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(transparent)] pub struct ProvidesBannerPatterns { - pub key: ResourceLocation, + pub key: Identifier, } #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] @@ -1457,7 +1457,7 @@ pub struct CowVariant { #[derive(Clone, PartialEq, AzBuf, Debug, Serialize)] #[serde(untagged)] pub enum ChickenVariant { - Referenced(ResourceLocation), + Referenced(Identifier), Direct(ChickenVariantData), } diff --git a/azalea-inventory/src/components/profile.rs b/azalea-inventory/src/components/profile.rs index 499d42bb..153b43d3 100644 --- a/azalea-inventory/src/components/profile.rs +++ b/azalea-inventory/src/components/profile.rs @@ -2,7 +2,7 @@ use azalea_auth::game_profile::{ GameProfile, GameProfileProperties, SerializableProfileProperties, }; use azalea_buf::AzBuf; -use azalea_core::{codec_utils::*, resource_location::ResourceLocation}; +use azalea_core::{codec_utils::*, identifier::Identifier}; use serde::{Serialize, Serializer}; use uuid::Uuid; @@ -70,5 +70,5 @@ pub enum PlayerModelType { #[derive(Clone, Debug, AzBuf, PartialEq, Serialize)] #[serde(transparent)] pub struct ResourceTexture { - pub id: ResourceLocation, + pub id: Identifier, } diff --git a/azalea-inventory/src/item/consume_effect.rs b/azalea-inventory/src/item/consume_effect.rs index 8aab42b8..7054e6c8 100644 --- a/azalea-inventory/src/item/consume_effect.rs +++ b/azalea-inventory/src/item/consume_effect.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::{codec_utils::is_default, resource_location::ResourceLocation}; +use azalea_core::{codec_utils::is_default, identifier::Identifier}; use azalea_registry::{HolderSet, MobEffect, SoundEvent}; use serde::Serialize; @@ -16,7 +16,7 @@ pub enum ConsumeEffect { }, RemoveEffects { #[serde(skip_serializing_if = "is_default")] - effects: HolderSet, + effects: HolderSet, }, ClearAllEffects, TeleportRandomly { diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs index c37a9917..01ffe75f 100644 --- a/azalea-physics/src/fluids.rs +++ b/azalea-physics/src/fluids.rs @@ -4,8 +4,8 @@ use azalea_block::{ }; use azalea_core::{ direction::Direction, + identifier::Identifier, position::{BlockPos, Vec3}, - resource_location::ResourceLocation, }; use azalea_entity::{HasClientLoaded, LocalEntity, Physics, Position}; use azalea_world::{Instance, InstanceContainer, InstanceName}; @@ -40,7 +40,7 @@ pub fn update_in_water_state_and_do_fluid_pushing( let is_ultrawarm = world .registries .map - .get(&ResourceLocation::new("minecraft:dimension_type")) + .get(&Identifier::new("minecraft:dimension_type")) .and_then(|d| { d.get(&**instance_name) .map(|d| d.byte("ultrawarm") != Some(0)) diff --git a/azalea-physics/tests/physics.rs b/azalea-physics/tests/physics.rs index b312b31e..09cb5379 100644 --- a/azalea-physics/tests/physics.rs +++ b/azalea-physics/tests/physics.rs @@ -5,9 +5,9 @@ use azalea_block::{ properties::WaterLevel, }; use azalea_core::{ + identifier::Identifier, position::{BlockPos, ChunkPos, Vec3}, registry_holder::RegistryHolder, - resource_location::ResourceLocation, tick::GameTick, }; use azalea_entity::{EntityBundle, EntityPlugin, HasClientLoaded, LocalEntity, Physics, Position}; @@ -29,7 +29,7 @@ pub fn insert_overworld(app: &mut App) -> Arc> { app.world_mut() .resource_mut::() .get_or_insert( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), 384, -64, &RegistryHolder::default(), @@ -59,7 +59,7 @@ fn test_gravity() { z: 0., }, azalea_registry::EntityKind::Zombie, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -115,7 +115,7 @@ fn test_collision() { z: 0.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -172,7 +172,7 @@ fn test_slab_collision() { z: 0.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -223,7 +223,7 @@ fn test_top_slab_collision() { z: 0.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -258,7 +258,7 @@ fn test_weird_wall_collision() { .world_mut() .resource_mut::() .get_or_insert( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), 384, -64, &RegistryHolder::default(), @@ -281,7 +281,7 @@ fn test_weird_wall_collision() { z: 0.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -321,7 +321,7 @@ fn test_negative_coordinates_weird_wall_collision() { .world_mut() .resource_mut::() .get_or_insert( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), 384, -64, &RegistryHolder::default(), @@ -344,7 +344,7 @@ fn test_negative_coordinates_weird_wall_collision() { z: -7.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -388,7 +388,7 @@ fn spawn_and_unload_world() { .world_mut() .resource_mut::() .get_or_insert( - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), 384, -64, &RegistryHolder::default(), @@ -411,7 +411,7 @@ fn spawn_and_unload_world() { z: -7.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, @@ -527,7 +527,7 @@ fn test_afk_pool() { z: 1.5, }, azalea_registry::EntityKind::Player, - ResourceLocation::new("minecraft:overworld"), + Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), LocalEntity, diff --git a/azalea-protocol/src/common/recipe.rs b/azalea-protocol/src/common/recipe.rs index 8ab2d5ba..709679f1 100644 --- a/azalea-protocol/src/common/recipe.rs +++ b/azalea-protocol/src/common/recipe.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_inventory::ItemStack; use azalea_registry::HolderSet; @@ -56,7 +56,7 @@ pub struct SmithingRecipeDisplay { #[derive(Clone, Debug, PartialEq, AzBuf)] pub struct Ingredient { - pub allowed: HolderSet, + pub allowed: HolderSet, } /// [`azalea_registry::SlotDisplay`] @@ -66,7 +66,7 @@ pub enum SlotDisplayData { AnyFuel, Item(ItemStackDisplay), ItemStack(ItemStackSlotDisplay), - Tag(ResourceLocation), + Tag(Identifier), SmithingTrim(Box), WithRemainder(Box), Composite(CompositeSlotDisplay), diff --git a/azalea-protocol/src/common/tags.rs b/azalea-protocol/src/common/tags.rs index 0b798519..f8ddfc81 100644 --- a/azalea-protocol/src/common/tags.rs +++ b/azalea-protocol/src/common/tags.rs @@ -4,15 +4,15 @@ use std::{ }; use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use indexmap::IndexMap; #[derive(Clone, Debug, PartialEq)] -pub struct TagMap(pub IndexMap>); +pub struct TagMap(pub IndexMap>); #[derive(Clone, Debug, PartialEq)] pub struct Tags { - pub name: ResourceLocation, + pub name: Identifier, pub elements: Vec, } @@ -21,7 +21,7 @@ impl AzaleaRead for TagMap { let length = u32::azalea_read_var(buf)? as usize; let mut data = IndexMap::with_capacity(length); for _ in 0..length { - let tag_type = ResourceLocation::azalea_read(buf)?; + let tag_type = Identifier::azalea_read(buf)?; let tags_count = i32::azalea_read_var(buf)? as usize; let mut tags_vec = Vec::with_capacity(tags_count); for _ in 0..tags_count { @@ -46,7 +46,7 @@ impl AzaleaWrite for TagMap { } impl AzaleaRead for Tags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { - let name = ResourceLocation::azalea_read(buf)?; + let name = Identifier::azalea_read(buf)?; let elements = Vec::::azalea_read_var(buf)?; Ok(Tags { name, elements }) } @@ -61,7 +61,7 @@ impl AzaleaWrite for Tags { } impl Deref for TagMap { - type Target = IndexMap>; + type Target = IndexMap>; fn deref(&self) -> &Self::Target { &self.0 diff --git a/azalea-protocol/src/packets/common.rs b/azalea-protocol/src/packets/common.rs index ad87fa8d..fcbf0b05 100644 --- a/azalea-protocol/src/packets/common.rs +++ b/azalea-protocol/src/packets/common.rs @@ -2,16 +2,16 @@ use azalea_buf::AzBuf; use azalea_core::{ data_registry::ResolvableDataRegistry, game_type::{GameMode, OptionalGameType}, + identifier::Identifier, position::GlobalPos, registry_holder::{DimensionTypeElement, RegistryHolder}, - resource_location::ResourceLocation, }; use tracing::error; #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct CommonPlayerSpawnInfo { pub dimension_type: azalea_registry::DimensionType, - pub dimension: ResourceLocation, + pub dimension: Identifier, pub seed: i64, pub game_type: GameMode, pub previous_game_type: OptionalGameType, @@ -27,7 +27,7 @@ impl CommonPlayerSpawnInfo { pub fn dimension_type( &self, registry_holder: &RegistryHolder, - ) -> Option<(ResourceLocation, DimensionTypeElement)> { + ) -> Option<(Identifier, DimensionTypeElement)> { let dimension_res = self .dimension_type .resolve_and_deserialize::(registry_holder); diff --git a/azalea-protocol/src/packets/config/c_cookie_request.rs b/azalea-protocol/src/packets/config/c_cookie_request.rs index c1a42cac..ff368b63 100644 --- a/azalea-protocol/src/packets/config/c_cookie_request.rs +++ b/azalea-protocol/src/packets/config/c_cookie_request.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] pub struct ClientboundCookieRequest { - pub key: ResourceLocation, + pub key: Identifier, } diff --git a/azalea-protocol/src/packets/config/c_custom_payload.rs b/azalea-protocol/src/packets/config/c_custom_payload.rs index 19335264..03776bf9 100644 --- a/azalea-protocol/src/packets/config/c_custom_payload.rs +++ b/azalea-protocol/src/packets/config/c_custom_payload.rs @@ -1,9 +1,9 @@ use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] pub struct ClientboundCustomPayload { - pub identifier: ResourceLocation, + pub identifier: Identifier, pub data: UnsizedByteArray, } diff --git a/azalea-protocol/src/packets/config/c_registry_data.rs b/azalea-protocol/src/packets/config/c_registry_data.rs index 18d2e73b..16a86a9f 100644 --- a/azalea-protocol/src/packets/config/c_registry_data.rs +++ b/azalea-protocol/src/packets/config/c_registry_data.rs @@ -1,10 +1,10 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; use simdnbt::owned::NbtCompound; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] pub struct ClientboundRegistryData { - pub registry_id: ResourceLocation, - pub entries: Vec<(ResourceLocation, Option)>, + pub registry_id: Identifier, + pub entries: Vec<(Identifier, Option)>, } diff --git a/azalea-protocol/src/packets/config/c_store_cookie.rs b/azalea-protocol/src/packets/config/c_store_cookie.rs index 5fa03729..3d797d18 100644 --- a/azalea-protocol/src/packets/config/c_store_cookie.rs +++ b/azalea-protocol/src/packets/config/c_store_cookie.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] pub struct ClientboundStoreCookie { - pub key: ResourceLocation, + pub key: Identifier, pub payload: Vec, } diff --git a/azalea-protocol/src/packets/config/c_update_enabled_features.rs b/azalea-protocol/src/packets/config/c_update_enabled_features.rs index 7d86ceb4..b4e0e9c1 100644 --- a/azalea-protocol/src/packets/config/c_update_enabled_features.rs +++ b/azalea-protocol/src/packets/config/c_update_enabled_features.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundConfigPacket)] pub struct ClientboundUpdateEnabledFeatures { - pub features: Vec, + pub features: Vec, } diff --git a/azalea-protocol/src/packets/config/s_cookie_response.rs b/azalea-protocol/src/packets/config/s_cookie_response.rs index 590a651e..ae44953e 100644 --- a/azalea-protocol/src/packets/config/s_cookie_response.rs +++ b/azalea-protocol/src/packets/config/s_cookie_response.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundConfigPacket)] pub struct ServerboundCookieResponse { - pub key: ResourceLocation, + pub key: Identifier, pub payload: Option>, } diff --git a/azalea-protocol/src/packets/config/s_custom_click_action.rs b/azalea-protocol/src/packets/config/s_custom_click_action.rs index 0c33d635..21b5cfbb 100644 --- a/azalea-protocol/src/packets/config/s_custom_click_action.rs +++ b/azalea-protocol/src/packets/config/s_custom_click_action.rs @@ -1,10 +1,10 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundConfigPacket; use simdnbt::owned::Nbt; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundConfigPacket)] pub struct ServerboundCustomClickAction { - pub id: ResourceLocation, + pub id: Identifier, pub payload: Nbt, } diff --git a/azalea-protocol/src/packets/config/s_custom_payload.rs b/azalea-protocol/src/packets/config/s_custom_payload.rs index fec04fb5..1bdc85af 100644 --- a/azalea-protocol/src/packets/config/s_custom_payload.rs +++ b/azalea-protocol/src/packets/config/s_custom_payload.rs @@ -1,9 +1,9 @@ use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundConfigPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundConfigPacket)] pub struct ServerboundCustomPayload { - pub identifier: ResourceLocation, + pub identifier: Identifier, pub data: UnsizedByteArray, } diff --git a/azalea-protocol/src/packets/game/c_add_entity.rs b/azalea-protocol/src/packets/game/c_add_entity.rs index fe473289..fbd2cb8a 100644 --- a/azalea-protocol/src/packets/game/c_add_entity.rs +++ b/azalea-protocol/src/packets/game/c_add_entity.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::{delta::LpVec3, position::Vec3, resource_location::ResourceLocation}; +use azalea_core::{delta::LpVec3, identifier::Identifier, position::Vec3}; use azalea_entity::{EntityBundle, metadata::apply_default_metadata}; use azalea_protocol_macros::ClientboundGamePacket; use azalea_world::MinecraftEntityId; @@ -34,7 +34,7 @@ impl ClientboundAddEntity { /// /// You must apply the metadata after inserting the bundle with /// [`Self::apply_metadata`]. - pub fn as_entity_bundle(&self, world_name: ResourceLocation) -> EntityBundle { + pub fn as_entity_bundle(&self, world_name: Identifier) -> EntityBundle { EntityBundle::new(self.uuid, self.position, self.entity_type, world_name) } diff --git a/azalea-protocol/src/packets/game/c_commands.rs b/azalea-protocol/src/packets/game/c_commands.rs index 303f8481..46be5613 100644 --- a/azalea-protocol/src/packets/game/c_commands.rs +++ b/azalea-protocol/src/packets/game/c_commands.rs @@ -1,7 +1,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; -use azalea_core::{bitset::FixedBitSet, resource_location::ResourceLocation}; +use azalea_core::{bitset::FixedBitSet, identifier::Identifier}; use azalea_protocol_macros::ClientboundGamePacket; use tracing::warn; @@ -131,7 +131,7 @@ pub enum BrigadierParser { Team, ItemSlot, ItemSlots, - ResourceLocation, + Identifier, Function, EntityAnchor, IntRange, @@ -139,11 +139,11 @@ pub enum BrigadierParser { Dimension, GameMode, Time { min: i32 }, - ResourceOrTag { registry_key: ResourceLocation }, - ResourceOrTagKey { registry_key: ResourceLocation }, - Resource { registry_key: ResourceLocation }, - ResourceKey { registry_key: ResourceLocation }, - ResourceSelector { registry_key: ResourceLocation }, + ResourceOrTag { registry_key: Identifier }, + ResourceOrTagKey { registry_key: Identifier }, + Resource { registry_key: Identifier }, + ResourceKey { registry_key: Identifier }, + ResourceSelector { registry_key: Identifier }, TemplateMirror, TemplateRotation, Heightmap, @@ -210,7 +210,7 @@ impl AzaleaRead for BrigadierNodeStub { let name = String::azalea_read(buf)?; let parser = BrigadierParser::azalea_read(buf)?; let suggestions_type = if has_suggestions_type { - Some(ResourceLocation::azalea_read(buf)?) + Some(Identifier::azalea_read(buf)?) } else { None }; @@ -318,7 +318,7 @@ pub enum NodeType { Argument { name: String, parser: BrigadierParser, - suggestions_type: Option, + suggestions_type: Option, }, } @@ -379,7 +379,7 @@ mod tests { node_type: NodeType::Argument { name: "position".to_string(), parser: BrigadierParser::Vec3, - suggestions_type: Some(ResourceLocation::new("minecraft:test_suggestion")), + suggestions_type: Some(Identifier::new("minecraft:test_suggestion")), }, is_restricted: false, }; diff --git a/azalea-protocol/src/packets/game/c_cookie_request.rs b/azalea-protocol/src/packets/game/c_cookie_request.rs index 06828aec..7b1e8e30 100644 --- a/azalea-protocol/src/packets/game/c_cookie_request.rs +++ b/azalea-protocol/src/packets/game/c_cookie_request.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundCookieRequest { - pub key: ResourceLocation, + pub key: Identifier, } diff --git a/azalea-protocol/src/packets/game/c_custom_payload.rs b/azalea-protocol/src/packets/game/c_custom_payload.rs index 33c446c2..e76967a6 100644 --- a/azalea-protocol/src/packets/game/c_custom_payload.rs +++ b/azalea-protocol/src/packets/game/c_custom_payload.rs @@ -1,10 +1,9 @@ -use azalea_buf::AzBuf; -use azalea_buf::UnsizedByteArray; -use azalea_core::resource_location::ResourceLocation; +use azalea_buf::{AzBuf, UnsizedByteArray}; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundCustomPayload { - pub identifier: ResourceLocation, + pub identifier: Identifier, pub data: UnsizedByteArray, } diff --git a/azalea-protocol/src/packets/game/c_login.rs b/azalea-protocol/src/packets/game/c_login.rs index 61f553e3..1c89dbac 100644 --- a/azalea-protocol/src/packets/game/c_login.rs +++ b/azalea-protocol/src/packets/game/c_login.rs @@ -1,5 +1,5 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; use azalea_world::MinecraftEntityId; @@ -13,7 +13,7 @@ use crate::packets::common::CommonPlayerSpawnInfo; pub struct ClientboundLogin { pub player_id: MinecraftEntityId, pub hardcore: bool, - pub levels: Vec, + pub levels: Vec, #[var] pub max_players: i32, #[var] diff --git a/azalea-protocol/src/packets/game/c_select_advancements_tab.rs b/azalea-protocol/src/packets/game/c_select_advancements_tab.rs index ec390ce5..0eee09de 100644 --- a/azalea-protocol/src/packets/game/c_select_advancements_tab.rs +++ b/azalea-protocol/src/packets/game/c_select_advancements_tab.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundSelectAdvancementsTab { - pub tab: Option, + pub tab: Option, } diff --git a/azalea-protocol/src/packets/game/c_stop_sound.rs b/azalea-protocol/src/packets/game/c_stop_sound.rs index 70f3c424..f6b42325 100644 --- a/azalea-protocol/src/packets/game/c_stop_sound.rs +++ b/azalea-protocol/src/packets/game/c_stop_sound.rs @@ -1,7 +1,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; -use azalea_core::{bitset::FixedBitSet, resource_location::ResourceLocation}; +use azalea_core::{bitset::FixedBitSet, identifier::Identifier}; use azalea_protocol_macros::ClientboundGamePacket; use super::c_sound::SoundSource; @@ -9,7 +9,7 @@ use super::c_sound::SoundSource; #[derive(Clone, Debug, PartialEq, ClientboundGamePacket)] pub struct ClientboundStopSound { pub source: Option, - pub name: Option, + pub name: Option, } impl AzaleaRead for ClientboundStopSound { @@ -21,7 +21,7 @@ impl AzaleaRead for ClientboundStopSound { None }; let name = if set.index(1) { - Some(ResourceLocation::azalea_read(buf)?) + Some(Identifier::azalea_read(buf)?) } else { None }; diff --git a/azalea-protocol/src/packets/game/c_store_cookie.rs b/azalea-protocol/src/packets/game/c_store_cookie.rs index 0b48ed0e..9646c3b9 100644 --- a/azalea-protocol/src/packets/game/c_store_cookie.rs +++ b/azalea-protocol/src/packets/game/c_store_cookie.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundStoreCookie { - pub key: ResourceLocation, + pub key: Identifier, pub payload: Vec, } diff --git a/azalea-protocol/src/packets/game/c_update_advancements.rs b/azalea-protocol/src/packets/game/c_update_advancements.rs index d1b1fa80..7296d916 100644 --- a/azalea-protocol/src/packets/game/c_update_advancements.rs +++ b/azalea-protocol/src/packets/game/c_update_advancements.rs @@ -5,7 +5,7 @@ use std::{ use azalea_buf::AzBuf; use azalea_chat::FormattedText; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_inventory::ItemStack; use azalea_protocol_macros::ClientboundGamePacket; use indexmap::IndexMap; @@ -14,14 +14,14 @@ use indexmap::IndexMap; pub struct ClientboundUpdateAdvancements { pub reset: bool, pub added: Vec, - pub removed: Vec, - pub progress: IndexMap, + pub removed: Vec, + pub progress: IndexMap, pub show_advancements: bool, } #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct Advancement { - pub parent_id: Option, + pub parent_id: Option, pub display: Option, pub requirements: Vec>, pub sends_telemetry_event: bool, @@ -35,7 +35,7 @@ pub struct DisplayInfo { pub frame: FrameType, pub show_toast: bool, pub hidden: bool, - pub background: Option, + pub background: Option, pub x: f32, pub y: f32, } @@ -80,7 +80,7 @@ impl azalea_buf::AzaleaRead for DisplayInfo { let hidden = (data & 0b100) != 0; let background = if has_background { - Some(ResourceLocation::azalea_read(buf)?) + Some(Identifier::azalea_read(buf)?) } else { None }; @@ -116,7 +116,7 @@ pub struct CriterionProgress { #[derive(Clone, Debug, AzBuf, PartialEq)] pub struct AdvancementHolder { - pub id: ResourceLocation, + pub id: Identifier, pub value: Advancement, } @@ -131,7 +131,7 @@ mod tests { let packet = ClientboundUpdateAdvancements { reset: true, added: [AdvancementHolder { - id: ResourceLocation::new("minecraft:test"), + id: Identifier::new("minecraft:test"), value: Advancement { parent_id: None, display: Some(DisplayInfo { @@ -151,9 +151,9 @@ mod tests { }] .into_iter() .collect(), - removed: vec![ResourceLocation::new("minecraft:test2")], + removed: vec![Identifier::new("minecraft:test2")], progress: [( - ResourceLocation::new("minecraft:test3"), + Identifier::new("minecraft:test3"), [( "minecraft:test4".to_string(), CriterionProgress { @@ -180,7 +180,7 @@ mod tests { .added .into_iter() .find_map(|a| { - if a.id == ResourceLocation::new("minecraft:test") { + if a.id == Identifier::new("minecraft:test") { Some(a.value) } else { None @@ -192,7 +192,7 @@ mod tests { .added .into_iter() .find_map(|a| { - if a.id == ResourceLocation::new("minecraft:test") { + if a.id == Identifier::new("minecraft:test") { Some(a.value) } else { None diff --git a/azalea-protocol/src/packets/game/c_update_recipes.rs b/azalea-protocol/src/packets/game/c_update_recipes.rs index c425622e..e05708a3 100644 --- a/azalea-protocol/src/packets/game/c_update_recipes.rs +++ b/azalea-protocol/src/packets/game/c_update_recipes.rs @@ -1,14 +1,14 @@ use std::collections::HashMap; use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; use crate::common::recipe::{Ingredient, SlotDisplayData}; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundGamePacket)] pub struct ClientboundUpdateRecipes { - pub item_sets: HashMap, + pub item_sets: HashMap, pub stonecutter_recipes: Vec, } diff --git a/azalea-protocol/src/packets/game/c_waypoint.rs b/azalea-protocol/src/packets/game/c_waypoint.rs index d7c6ad91..0debb0d0 100644 --- a/azalea-protocol/src/packets/game/c_waypoint.rs +++ b/azalea-protocol/src/packets/game/c_waypoint.rs @@ -1,7 +1,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; -use azalea_core::{color::RgbColor, position::Vec3i, resource_location::ResourceLocation}; +use azalea_core::{color::RgbColor, identifier::Identifier, position::Vec3i}; use azalea_protocol_macros::ClientboundGamePacket; use uuid::Uuid; @@ -33,7 +33,7 @@ pub enum WaypointIdentifier { #[derive(Clone, Debug, PartialEq)] pub struct WaypointIcon { - pub style: ResourceLocation, + pub style: Identifier, pub color: Option, } impl AzaleaWrite for WaypointIcon { @@ -50,7 +50,7 @@ impl AzaleaWrite for WaypointIcon { } impl AzaleaRead for WaypointIcon { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { - let style = ResourceLocation::azalea_read(buf)?; + let style = Identifier::azalea_read(buf)?; let color = Option::::azalea_read(buf)?; let color = color.map(|c| RgbColor::new(c.r, c.g, c.b)); diff --git a/azalea-protocol/src/packets/game/s_cookie_response.rs b/azalea-protocol/src/packets/game/s_cookie_response.rs index fd6b8a51..a6a99cf7 100644 --- a/azalea-protocol/src/packets/game/s_cookie_response.rs +++ b/azalea-protocol/src/packets/game/s_cookie_response.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundCookieResponse { - pub key: ResourceLocation, + pub key: Identifier, pub payload: Option>, } diff --git a/azalea-protocol/src/packets/game/s_custom_click_action.rs b/azalea-protocol/src/packets/game/s_custom_click_action.rs index 338137c4..193405df 100644 --- a/azalea-protocol/src/packets/game/s_custom_click_action.rs +++ b/azalea-protocol/src/packets/game/s_custom_click_action.rs @@ -1,10 +1,10 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; use simdnbt::owned::Nbt; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundCustomClickAction { - pub id: ResourceLocation, + pub id: Identifier, pub payload: Nbt, } diff --git a/azalea-protocol/src/packets/game/s_custom_payload.rs b/azalea-protocol/src/packets/game/s_custom_payload.rs index 1f2897e2..8753c7f7 100644 --- a/azalea-protocol/src/packets/game/s_custom_payload.rs +++ b/azalea-protocol/src/packets/game/s_custom_payload.rs @@ -1,10 +1,9 @@ -use azalea_buf::AzBuf; -use azalea_buf::UnsizedByteArray; -use azalea_core::resource_location::ResourceLocation; +use azalea_buf::{AzBuf, UnsizedByteArray}; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundCustomPayload { - pub identifier: ResourceLocation, + pub identifier: Identifier, pub data: UnsizedByteArray, } diff --git a/azalea-protocol/src/packets/game/s_place_recipe.rs b/azalea-protocol/src/packets/game/s_place_recipe.rs index fe56cd96..a1f007a0 100644 --- a/azalea-protocol/src/packets/game/s_place_recipe.rs +++ b/azalea-protocol/src/packets/game/s_place_recipe.rs @@ -1,11 +1,11 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundPlaceRecipe { #[var] pub container_id: i32, - pub recipe: ResourceLocation, + pub recipe: Identifier, pub shift_down: bool, } diff --git a/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs b/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs index 7fa1da45..350c7290 100644 --- a/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs +++ b/azalea-protocol/src/packets/game/s_recipe_book_seen_recipe.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundRecipeBookSeenRecipe { - pub recipe: ResourceLocation, + pub recipe: Identifier, } diff --git a/azalea-protocol/src/packets/game/s_seen_advancements.rs b/azalea-protocol/src/packets/game/s_seen_advancements.rs index 1c502568..7d9e552b 100644 --- a/azalea-protocol/src/packets/game/s_seen_advancements.rs +++ b/azalea-protocol/src/packets/game/s_seen_advancements.rs @@ -1,7 +1,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundGamePacket; use crate::packets::BufReadError; @@ -9,7 +9,7 @@ use crate::packets::BufReadError; #[derive(Clone, Debug, PartialEq, ServerboundGamePacket)] pub struct ServerboundSeenAdvancements { pub action: Action, - pub tab: Option, + pub tab: Option, } #[derive(AzBuf, Clone, Copy, Debug, Eq, PartialEq)] @@ -22,7 +22,7 @@ impl AzaleaRead for ServerboundSeenAdvancements { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let action = Action::azalea_read(buf)?; let tab = if action == Action::OpenedTab { - Some(ResourceLocation::azalea_read(buf)?) + Some(Identifier::azalea_read(buf)?) } else { None }; diff --git a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs index 8999faf4..ac942d88 100644 --- a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs +++ b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs @@ -4,7 +4,7 @@ use std::{ }; use azalea_buf::{AzBuf, AzaleaRead}; -use azalea_core::{position::BlockPos, resource_location::ResourceLocation}; +use azalea_core::{identifier::Identifier, position::BlockPos}; use azalea_protocol_macros::ServerboundGamePacket; use crate::packets::{AzaleaWrite, BufReadError}; @@ -12,9 +12,9 @@ use crate::packets::{AzaleaWrite, BufReadError}; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundGamePacket)] pub struct ServerboundSetJigsawBlock { pub pos: BlockPos, - pub name: ResourceLocation, - pub target: ResourceLocation, - pub pool: ResourceLocation, + pub name: Identifier, + pub target: Identifier, + pub pool: Identifier, pub final_state: String, pub joint: String, #[var] diff --git a/azalea-protocol/src/packets/login/c_cookie_request.rs b/azalea-protocol/src/packets/login/c_cookie_request.rs index 2574d718..fbe72c6a 100644 --- a/azalea-protocol/src/packets/login/c_cookie_request.rs +++ b/azalea-protocol/src/packets/login/c_cookie_request.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundLoginPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ClientboundLoginPacket)] pub struct ClientboundCookieRequest { - pub key: ResourceLocation, + pub key: Identifier, } diff --git a/azalea-protocol/src/packets/login/c_custom_query.rs b/azalea-protocol/src/packets/login/c_custom_query.rs index c74d6e21..9c7ee50a 100644 --- a/azalea-protocol/src/packets/login/c_custom_query.rs +++ b/azalea-protocol/src/packets/login/c_custom_query.rs @@ -1,13 +1,13 @@ use std::hash::Hash; use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ClientboundLoginPacket; #[derive(Hash, Clone, Debug, AzBuf, PartialEq, ClientboundLoginPacket)] pub struct ClientboundCustomQuery { #[var] pub transaction_id: u32, - pub identifier: ResourceLocation, + pub identifier: Identifier, pub data: UnsizedByteArray, } diff --git a/azalea-protocol/src/packets/login/s_cookie_response.rs b/azalea-protocol/src/packets/login/s_cookie_response.rs index 8a7af784..c9e7ced9 100644 --- a/azalea-protocol/src/packets/login/s_cookie_response.rs +++ b/azalea-protocol/src/packets/login/s_cookie_response.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; -use azalea_core::resource_location::ResourceLocation; +use azalea_core::identifier::Identifier; use azalea_protocol_macros::ServerboundLoginPacket; #[derive(Clone, Debug, AzBuf, PartialEq, ServerboundLoginPacket)] pub struct ServerboundCookieResponse { - pub key: ResourceLocation, + pub key: Identifier, pub payload: Option>, } diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs index 88b154a2..a3145b15 100644 --- a/azalea-registry/src/lib.rs +++ b/azalea-registry/src/lib.rs @@ -88,22 +88,20 @@ impl AzaleaWrite for CustomRegistry { +pub enum HolderSet { Direct { contents: Vec, }, Named { - key: ResourceLocation, - contents: Vec, + key: Identifier, + contents: Vec, }, } -impl AzaleaRead - for HolderSet -{ +impl AzaleaRead for HolderSet { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let size = i32::azalea_read_var(buf)? - 1; if size == -1 { - let key = ResourceLocation::azalea_read(buf)?; + let key = Identifier::azalea_read(buf)?; Ok(Self::Named { key, contents: Vec::new(), @@ -117,9 +115,7 @@ impl AzaleaRead } } } -impl AzaleaWrite - for HolderSet -{ +impl AzaleaWrite for HolderSet { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self { Self::Direct { contents } => { @@ -136,8 +132,8 @@ impl AzaleaWrite Ok(()) } } -impl Debug - for HolderSet +impl Debug + for HolderSet { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -150,16 +146,14 @@ impl De } } } -impl From> - for HolderSet -{ +impl From> for HolderSet { fn from(contents: Vec) -> Self { Self::Direct { contents } } } #[cfg(feature = "serde")] -impl Serialize - for HolderSet +impl Serialize + for HolderSet { fn serialize(&self, serializer: S) -> Result where @@ -177,9 +171,7 @@ impl Default - for HolderSet -{ +impl Default for HolderSet { fn default() -> Self { Self::Direct { contents: Vec::new(), @@ -188,7 +180,7 @@ impl Default } /// A reference to either a registry or a custom value (usually something with a -/// ResourceLocation). +/// Identifier). pub enum Holder { Reference(R), Direct(Direct), @@ -1646,7 +1638,7 @@ enum CommandArgumentKind { Team => "minecraft:team", ItemSlot => "minecraft:item_slot", ItemSlots => "minecraft:item_slots", - ResourceLocation => "minecraft:resource_location", + Identifier => "minecraft:resource_location", Function => "minecraft:function", EntityAnchor => "minecraft:entity_anchor", IntRange => "minecraft:int_range", diff --git a/azalea-world/src/container.rs b/azalea-world/src/container.rs index 279f3061..ff79ec81 100644 --- a/azalea-world/src/container.rs +++ b/azalea-world/src/container.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Weak}, }; -use azalea_core::{registry_holder::RegistryHolder, resource_location::ResourceLocation}; +use azalea_core::{identifier::Identifier, registry_holder::RegistryHolder}; use bevy_ecs::{component::Component, resource::Resource}; use derive_more::{Deref, DerefMut}; use nohash_hasher::IntMap; @@ -31,7 +31,7 @@ pub struct InstanceContainer { // telling them apart. We hope most servers are nice and don't do that though. It's only an // issue when there's multiple clients with the same WorldContainer in different worlds // anyways. - pub instances: FxHashMap>>, + pub instances: FxHashMap>>, } impl InstanceContainer { @@ -50,7 +50,7 @@ impl InstanceContainer { #[must_use = "the world will be immediately forgotten if unused"] pub fn get_or_insert( &mut self, - name: ResourceLocation, + name: Identifier, height: u32, min_y: i32, default_registries: &RegistryHolder, @@ -93,4 +93,4 @@ impl InstanceContainer { /// same instance. #[derive(Component, Clone, Debug, PartialEq, Deref, DerefMut)] #[doc(alias("worldname", "world name"))] -pub struct InstanceName(pub ResourceLocation); +pub struct InstanceName(pub Identifier); diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index 069837b3..f4f0844d 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -21,10 +21,13 @@ pub use azalea_buf as buf; pub use azalea_chat::FormattedText; pub use azalea_client::*; pub use azalea_core as core; +#[deprecated(note = "renamed to `Identifier`.")] +#[expect(deprecated)] +pub use azalea_core::resource_location::ResourceLocation; // these are re-exported on this level because they're very common pub use azalea_core::{ + identifier::Identifier, position::{BlockPos, Vec3}, - resource_location::ResourceLocation, }; pub use azalea_entity as entity; pub use azalea_physics as physics; diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 94836d3b..3b8a46cc 100644 --- a/azalea/src/pathfinder/simulation.rs +++ b/azalea/src/pathfinder/simulation.rs @@ -6,9 +6,7 @@ use azalea_client::{ PhysicsState, interact::BlockStatePredictionHandler, inventory::Inventory, local_player::LocalGameMode, mining::MineBundle, }; -use azalea_core::{ - game_type::GameMode, position::Vec3, resource_location::ResourceLocation, tick::GameTick, -}; +use azalea_core::{game_type::GameMode, identifier::Identifier, position::Vec3, tick::GameTick}; use azalea_entity::{ Attributes, LookDirection, Physics, Position, default_attributes, dimensions::EntityDimensions, }; @@ -44,8 +42,8 @@ impl SimulatedPlayerBundle { } } -fn simulation_instance_name() -> ResourceLocation { - ResourceLocation::new("azalea:simulation") +fn simulation_instance_name() -> Identifier { + Identifier::new("azalea:simulation") } fn create_simulation_instance(chunks: ChunkStorage) -> (App, Arc>) { diff --git a/codegen/lib/code/data_components.py b/codegen/lib/code/data_components.py index 89796a91..57e30172 100644 --- a/codegen/lib/code/data_components.py +++ b/codegen/lib/code/data_components.py @@ -220,7 +220,7 @@ use crate::{ "probability": "f32", } enum_and_struct_fields["ConsumeEffect::RemoveEffects"] = { - "effects": "HolderSet", + "effects": "HolderSet", } enum_and_struct_fields["ConsumeEffect::ClearAllEffects"] = {} enum_and_struct_fields["ConsumeEffect::TeleportRandomly"] = { @@ -342,7 +342,7 @@ use crate::{ return t if isinstance(python_value, dict): - if target_rust_type == "ResourceLocation" and len(python_value) == 1: + if target_rust_type == "Identifier" and len(python_value) == 1: return python_to_rust_value( list(python_value.values())[0], target_rust_type ) @@ -401,8 +401,8 @@ use crate::{ return str(python_value).lower() if isinstance(python_value, str): fields_for_rust_type = enum_and_struct_fields.get(target_rust_type, []) - if "Referenced(ResourceLocation)" in fields_for_rust_type: - return f"{target_rust_type}::Referenced({python_to_rust_value(python_value, 'ResourceLocation')})" + if "Referenced(Identifier)" in fields_for_rust_type: + return f"{target_rust_type}::Referenced({python_to_rust_value(python_value, 'Identifier')})" elif "Registry(registry::Instrument)" in fields_for_rust_type: return f"{target_rust_type}::Registry({python_to_rust_value(python_value, 'azalea_registry::Instrument')})" elif target_rust_type.startswith("HolderSet<"): @@ -415,8 +415,8 @@ use crate::{ holder_type = target_rust_type.split("<", 1)[1].split(",", 1)[0] inner_type = python_to_rust_value(python_value, holder_type) return f"azalea_registry::Holder::Reference({inner_type})" - elif target_rust_type == "ResourceLocation": - # convert minecraft:air into ResourceLocation::from_static("minecraft:air") + elif target_rust_type == "Identifier": + # convert minecraft:air into Identifier::from_static("minecraft:air") return f'"{python_value}".into()' else: # enum variant diff --git a/codegen/lib/code/utils.py b/codegen/lib/code/utils.py index b8970628..bbb8f647 100644 --- a/codegen/lib/code/utils.py +++ b/codegen/lib/code/utils.py @@ -57,8 +57,8 @@ def burger_type_to_rust_type( field_type_rs = "FormattedText" uses.add("azalea_chat::FormattedText") elif burger_type == "identifier": - field_type_rs = "ResourceLocation" - uses.add("azalea_core::resource_location::ResourceLocation") + field_type_rs = "Identifier" + uses.add("azalea_core::resource_location::Identifier") elif burger_type == "uuid": field_type_rs = "Uuid" uses.add("uuid::Uuid") diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py index 357059f6..b575b697 100644 --- a/codegen/lib/extract.py +++ b/codegen/lib/extract.py @@ -254,16 +254,16 @@ def get_packet_list(version_id: str): packet_list = [] for state, state_value in packets_report.items(): for direction, direction_value in state_value.items(): - for packet_resourcelocation, packet_value in direction_value.items(): - assert packet_resourcelocation.startswith("minecraft:") - packet_resourcelocation = upper_first_letter( - to_camel_case(packet_resourcelocation[len("minecraft:") :]) + for packet_identifier, packet_value in direction_value.items(): + assert packet_identifier.startswith("minecraft:") + packet_identifier = upper_first_letter( + to_camel_case(packet_identifier[len("minecraft:") :]) ) packet_list.append( { "state": state, "direction": direction, - "name": packet_resourcelocation, + "name": packet_identifier, "id": packet_value["protocol_id"], } ) -- cgit v1.2.3