aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-12 00:56:02 -0600
committerGitHub <noreply@github.com>2025-12-12 00:56:02 -0600
commitf9c25665c203d6377ace62f1e95381d037d8fd9e (patch)
tree8b4131d20fe661d3cc1175ec27f801fe61df41ea /azalea/src
parent82ad975242292d5875780b4398b62637674bf50a (diff)
downloadazalea-drasl-f9c25665c203d6377ace62f1e95381d037d8fd9e.tar.xz
Refactor azalea-registry (#294)
* move registries in azalea-registry into separate modules * rename Item and Block to ItemKind and BlockKind * remove 'extra' registries from azalea-registry * hide deprecated items from docs * use DamageKindKey instead of Identifier when parsing registries * store tag entries as a Vec instead of a HashSet * sort tag values by protocol id * update changelog
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/auto_tool.rs9
-rw-r--r--azalea/src/container.rs4
-rw-r--r--azalea/src/lib.rs25
-rw-r--r--azalea/src/pathfinder/extras/utils.rs2
-rw-r--r--azalea/src/pathfinder/mining.rs49
-rw-r--r--azalea/src/pathfinder/simulation.rs6
-rw-r--r--azalea/src/pathfinder/tests.rs15
-rw-r--r--azalea/src/pathfinder/world.rs46
8 files changed, 82 insertions, 74 deletions
diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs
index b71fb0b0..06103976 100644
--- a/azalea/src/auto_tool.rs
+++ b/azalea/src/auto_tool.rs
@@ -3,7 +3,7 @@ use azalea_client::Client;
use azalea_core::position::BlockPos;
use azalea_entity::{ActiveEffects, Attributes, FluidOnEyes, Physics, inventory::Inventory};
use azalea_inventory::{ItemStack, Menu, components};
-use azalea_registry::EntityKind;
+use azalea_registry::builtin::{BlockKind, EntityKind, ItemKind};
use crate::bot::BotClientExt;
@@ -89,10 +89,7 @@ pub fn accurate_best_tool_in_hotbar_for_block(
let block = Box::<dyn BlockTrait>::from(block);
let registry_block = block.as_registry_block();
- if matches!(
- registry_block,
- azalea_registry::Block::Water | azalea_registry::Block::Lava
- ) {
+ if matches!(registry_block, BlockKind::Water | BlockKind::Lava) {
// can't mine fluids
return BestToolResult {
index: 0,
@@ -107,7 +104,7 @@ pub fn accurate_best_tool_in_hotbar_for_block(
ItemStack::Empty => {
this_item_speed = Some(azalea_entity::mining::get_mine_progress(
block.as_ref(),
- azalea_registry::Item::Air,
+ ItemKind::Air,
fluid_on_eyes,
physics,
attributes,
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index e82eeac8..c01b16be 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -37,12 +37,12 @@ pub trait ContainerClientExt {
/// configure this.
///
/// ```
- /// # use azalea::{prelude::*, registry::Block};
+ /// # use azalea::{prelude::*, registry::builtin::BlockKind};
/// # async fn example(mut bot: azalea::Client) {
/// let target_pos = bot
/// .world()
/// .read()
- /// .find_block(bot.position(), &Block::Chest.into());
+ /// .find_block(bot.position(), &BlockKind::Chest.into());
/// let Some(target_pos) = target_pos else {
/// bot.chat("no chest found");
/// return;
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index bf188791..8440e31f 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -15,24 +15,33 @@ use std::{net::SocketAddr, time::Duration};
use app::Plugins;
pub use azalea_auth as auth;
-pub use azalea_block as blocks;
+pub use azalea_block as block;
+#[doc(hidden)]
+#[deprecated = "moved to `azalea::block`"]
+pub mod blocks {
+ pub type BlockStates = azalea_block::BlockStates;
+ pub type BlockState = azalea_block::BlockState;
+ pub trait BlockTrait: azalea_block::BlockTrait {}
+ // azalea_block has more items but rust doesn't mark them deprecated if we
+ // `use azalea_block::*`, so hopefully the three types above are enough for
+ // most users :(
+}
+
pub use azalea_brigadier as brigadier;
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},
-};
+pub use azalea_core::position::{BlockPos, Vec3};
pub use azalea_entity as entity;
pub use azalea_physics as physics;
pub use azalea_protocol as protocol;
pub use azalea_registry as registry;
+#[doc(hidden)]
+#[deprecated(note = "renamed to `Identifier`.")]
+pub use azalea_registry::identifier::Identifier as ResourceLocation;
+pub use azalea_registry::identifier::Identifier;
pub use azalea_world as world;
pub use bevy_app as app;
use bevy_app::AppExit;
diff --git a/azalea/src/pathfinder/extras/utils.rs b/azalea/src/pathfinder/extras/utils.rs
index 30b1ae52..3ae0b457 100644
--- a/azalea/src/pathfinder/extras/utils.rs
+++ b/azalea/src/pathfinder/extras/utils.rs
@@ -130,7 +130,7 @@ mod tests {
let set_solid_block_at = |x, y, z| {
partial_world.chunks.set_block_state(
&BlockPos::new(x, y, z),
- azalea_registry::Block::Stone.into(),
+ BlockKind::Stone.into(),
&world,
);
};
diff --git a/azalea/src/pathfinder/mining.rs b/azalea/src/pathfinder/mining.rs
index a985ca71..c592831d 100644
--- a/azalea/src/pathfinder/mining.rs
+++ b/azalea/src/pathfinder/mining.rs
@@ -4,6 +4,7 @@ use azalea_block::{
BlockState, BlockStates, block_state::BlockStateIntegerRepr, properties::Waterlogged,
};
use azalea_inventory::Menu;
+use azalea_registry::builtin::BlockKind;
use nohash_hasher::IntMap;
use super::costs::BLOCK_BREAK_ADDITIONAL_PENALTY;
@@ -21,8 +22,8 @@ pub struct MiningCache {
impl MiningCache {
pub fn new(inventory_menu: Option<Menu>) -> Self {
- let water_block_states = BlockStates::from(azalea_registry::Block::Water);
- let lava_block_states = BlockStates::from(azalea_registry::Block::Lava);
+ let water_block_states = BlockStates::from(BlockKind::Water);
+ let lava_block_states = BlockStates::from(BlockKind::Lava);
let mut water_block_state_range_min = BlockStateIntegerRepr::MAX;
let mut water_block_state_range_max = BlockStateIntegerRepr::MIN;
@@ -41,29 +42,29 @@ impl MiningCache {
let lava_block_state_range = lava_block_state_range_min..=lava_block_state_range_max;
let mut falling_blocks: Vec<BlockState> = vec![
- azalea_registry::Block::Sand.into(),
- azalea_registry::Block::RedSand.into(),
- azalea_registry::Block::Gravel.into(),
- azalea_registry::Block::Anvil.into(),
- azalea_registry::Block::ChippedAnvil.into(),
- azalea_registry::Block::DamagedAnvil.into(),
+ BlockKind::Sand.into(),
+ BlockKind::RedSand.into(),
+ BlockKind::Gravel.into(),
+ BlockKind::Anvil.into(),
+ BlockKind::ChippedAnvil.into(),
+ BlockKind::DamagedAnvil.into(),
// concrete powders
- azalea_registry::Block::WhiteConcretePowder.into(),
- azalea_registry::Block::OrangeConcretePowder.into(),
- azalea_registry::Block::MagentaConcretePowder.into(),
- azalea_registry::Block::LightBlueConcretePowder.into(),
- azalea_registry::Block::YellowConcretePowder.into(),
- azalea_registry::Block::LimeConcretePowder.into(),
- azalea_registry::Block::PinkConcretePowder.into(),
- azalea_registry::Block::GrayConcretePowder.into(),
- azalea_registry::Block::LightGrayConcretePowder.into(),
- azalea_registry::Block::CyanConcretePowder.into(),
- azalea_registry::Block::PurpleConcretePowder.into(),
- azalea_registry::Block::BlueConcretePowder.into(),
- azalea_registry::Block::BrownConcretePowder.into(),
- azalea_registry::Block::GreenConcretePowder.into(),
- azalea_registry::Block::RedConcretePowder.into(),
- azalea_registry::Block::BlackConcretePowder.into(),
+ BlockKind::WhiteConcretePowder.into(),
+ BlockKind::OrangeConcretePowder.into(),
+ BlockKind::MagentaConcretePowder.into(),
+ BlockKind::LightBlueConcretePowder.into(),
+ BlockKind::YellowConcretePowder.into(),
+ BlockKind::LimeConcretePowder.into(),
+ BlockKind::PinkConcretePowder.into(),
+ BlockKind::GrayConcretePowder.into(),
+ BlockKind::LightGrayConcretePowder.into(),
+ BlockKind::CyanConcretePowder.into(),
+ BlockKind::PurpleConcretePowder.into(),
+ BlockKind::BlueConcretePowder.into(),
+ BlockKind::BrownConcretePowder.into(),
+ BlockKind::GreenConcretePowder.into(),
+ BlockKind::RedConcretePowder.into(),
+ BlockKind::BlackConcretePowder.into(),
];
falling_blocks.sort_unstable_by_key(|block| block.id());
diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs
index df049b3e..957cef37 100644
--- a/azalea/src/pathfinder/simulation.rs
+++ b/azalea/src/pathfinder/simulation.rs
@@ -6,12 +6,12 @@ use azalea_client::{
PhysicsState, interact::BlockStatePredictionHandler, local_player::LocalGameMode,
mining::MineBundle,
};
-use azalea_core::{game_type::GameMode, identifier::Identifier, position::Vec3, tick::GameTick};
+use azalea_core::{game_type::GameMode, position::Vec3, tick::GameTick};
use azalea_entity::{
Attributes, LookDirection, Physics, Position, dimensions::EntityDimensions,
inventory::Inventory,
};
-use azalea_registry::EntityKind;
+use azalea_registry::{builtin::EntityKind, identifier::Identifier};
use azalea_world::{ChunkStorage, Instance, InstanceContainer, MinecraftEntityId, PartialInstance};
use bevy_app::App;
use bevy_ecs::prelude::*;
@@ -97,7 +97,7 @@ fn create_simulation_player_complete_bundle(
azalea_entity::EntityBundle::new(
Uuid::nil(),
*player.position,
- azalea_registry::EntityKind::Player,
+ EntityKind::Player,
instance_name,
),
azalea_client::local_player::InstanceHolder {
diff --git a/azalea/src/pathfinder/tests.rs b/azalea/src/pathfinder/tests.rs
index 7b33ca18..8c573405 100644
--- a/azalea/src/pathfinder/tests.rs
+++ b/azalea/src/pathfinder/tests.rs
@@ -7,6 +7,7 @@ use std::{
use azalea_block::BlockState;
use azalea_core::position::{BlockPos, ChunkPos, Vec3};
+use azalea_registry::builtin::BlockKind;
use azalea_world::{Chunk, ChunkStorage, PartialChunkStorage};
use super::{
@@ -66,7 +67,7 @@ fn setup_simulation_world(
partial_chunks.set(&chunk_pos, Some(Chunk::default()), &mut chunks);
}
for block_pos in solid_blocks {
- chunks.set_block_state(*block_pos, azalea_registry::Block::Stone.into());
+ chunks.set_block_state(*block_pos, BlockKind::Stone.into());
}
for (block_pos, block_state) in extra_blocks {
chunks.set_block_state(*block_pos, *block_state);
@@ -285,17 +286,11 @@ fn test_mine_through_non_colliding_block() {
BlockPos::new(0, 72, 1),
&[BlockPos::new(0, 71, 1)],
&[
- (
- BlockPos::new(0, 71, 0),
- azalea_registry::Block::SculkVein.into(),
- ),
- (
- BlockPos::new(0, 70, 0),
- azalea_registry::Block::GrassBlock.into(),
- ),
+ (BlockPos::new(0, 71, 0), BlockKind::SculkVein.into()),
+ (BlockPos::new(0, 70, 0), BlockKind::GrassBlock.into()),
// this is an extra check to make sure that we don't accidentally break the block
// below (since tnt will break instantly)
- (BlockPos::new(0, 69, 0), azalea_registry::Block::Tnt.into()),
+ (BlockPos::new(0, 69, 0), BlockKind::Tnt.into()),
],
);
diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs
index 0f1a8305..980cda9a 100644
--- a/azalea/src/pathfinder/world.rs
+++ b/azalea/src/pathfinder/world.rs
@@ -9,7 +9,7 @@ use azalea_core::{
position::{BlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos},
};
use azalea_physics::collision::BlockWithShape;
-use azalea_registry::{Block, tags};
+use azalea_registry::{builtin::BlockKind, tags};
use azalea_world::{Instance, palette::PalettedContainer};
use parking_lot::RwLock;
@@ -531,8 +531,8 @@ pub fn is_block_state_passable(block_state: BlockState) -> bool {
if !block_state.is_collision_shape_empty() {
return false;
}
- let registry_block = Block::from(block_state);
- if registry_block == Block::Water {
+ let registry_block = BlockKind::from(block_state);
+ if registry_block == BlockKind::Water {
return false;
}
if block_state
@@ -541,26 +541,26 @@ pub fn is_block_state_passable(block_state: BlockState) -> bool {
{
return false;
}
- if registry_block == Block::Lava {
+ if registry_block == BlockKind::Lava {
return false;
}
// block.waterlogged currently doesn't account for seagrass and some other water
// blocks
- if block_state == Block::Seagrass.into() {
+ if block_state == BlockKind::Seagrass.into() {
return false;
}
// don't walk into fire
- if registry_block == Block::Fire || registry_block == Block::SoulFire {
+ if registry_block == BlockKind::Fire || registry_block == BlockKind::SoulFire {
return false;
}
- if registry_block == Block::PowderSnow {
+ if registry_block == BlockKind::PowderSnow {
// we can't jump out of powder snow
return false;
}
- if registry_block == Block::SweetBerryBush {
+ if registry_block == BlockKind::SweetBerryBush {
// these hurt us
return false;
}
@@ -588,9 +588,9 @@ pub fn is_block_state_solid(block_state: BlockState) -> bool {
return true;
}
- let block = Block::from(block_state);
+ let block = BlockKind::from(block_state);
// solid enough
- if matches!(block, Block::DirtPath | Block::Farmland) {
+ if matches!(block, BlockKind::DirtPath | BlockKind::Farmland) {
return true;
}
@@ -604,7 +604,7 @@ pub fn is_block_state_standable(block_state: BlockState) -> bool {
return true;
}
- let block = Block::from(block_state);
+ let block = BlockKind::from(block_state);
if tags::blocks::SLABS.contains(&block) || tags::blocks::STAIRS.contains(&block) {
return true;
}
@@ -626,9 +626,11 @@ mod tests {
partial_world
.chunks
.set(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()), &mut world);
- partial_world
- .chunks
- .set_block_state(BlockPos::new(0, 0, 0), Block::Stone.into(), &world);
+ partial_world.chunks.set_block_state(
+ BlockPos::new(0, 0, 0),
+ BlockKind::Stone.into(),
+ &world,
+ );
partial_world
.chunks
.set_block_state(BlockPos::new(0, 1, 0), BlockState::AIR, &world);
@@ -645,9 +647,11 @@ mod tests {
partial_world
.chunks
.set(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()), &mut world);
- partial_world
- .chunks
- .set_block_state(BlockPos::new(0, 0, 0), Block::Stone.into(), &world);
+ partial_world.chunks.set_block_state(
+ BlockPos::new(0, 0, 0),
+ BlockKind::Stone.into(),
+ &world,
+ );
partial_world
.chunks
.set_block_state(BlockPos::new(0, 1, 0), BlockState::AIR, &world);
@@ -664,9 +668,11 @@ mod tests {
partial_world
.chunks
.set(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default()), &mut world);
- partial_world
- .chunks
- .set_block_state(BlockPos::new(0, 0, 0), Block::Stone.into(), &world);
+ partial_world.chunks.set_block_state(
+ BlockPos::new(0, 0, 0),
+ BlockKind::Stone.into(),
+ &world,
+ );
partial_world
.chunks
.set_block_state(BlockPos::new(0, 1, 0), BlockState::AIR, &world);