aboutsummaryrefslogtreecommitdiff
path: root/azalea
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
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')
-rw-r--r--azalea/benches/checks.rs8
-rw-r--r--azalea/benches/pathfinder.rs7
-rw-r--r--azalea/benches/physics.rs3
-rw-r--r--azalea/examples/steal.rs5
-rw-r--r--azalea/examples/testbot/commands/debug.rs2
-rw-r--r--azalea/examples/todo/craft_dig_straight_down.rs4
-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
14 files changed, 98 insertions, 87 deletions
diff --git a/azalea/benches/checks.rs b/azalea/benches/checks.rs
index ee737359..bd1b9085 100644
--- a/azalea/benches/checks.rs
+++ b/azalea/benches/checks.rs
@@ -1,23 +1,23 @@
use std::hint::black_box;
use azalea::pathfinder::mining::MiningCache;
-pub use azalea_registry as registry;
+use azalea_registry::builtin::BlockKind;
use criterion::{Criterion, criterion_group, criterion_main};
fn benchmark(c: &mut Criterion) {
let mining_cache = MiningCache::new(None);
- let stone = registry::Block::Stone.into();
+ let stone = BlockKind::Stone.into();
c.bench_function("is_liquid stone", |b| {
b.iter(|| mining_cache.is_liquid(black_box(stone)));
});
- let water = registry::Block::Water.into();
+ let water = BlockKind::Water.into();
c.bench_function("is_liquid water", |b| {
b.iter(|| mining_cache.is_liquid(black_box(water)));
});
- let lava = registry::Block::Lava.into();
+ let lava = BlockKind::Lava.into();
c.bench_function("is_liquid lava", |b| {
b.iter(|| mining_cache.is_liquid(black_box(lava)));
});
diff --git a/azalea/benches/pathfinder.rs b/azalea/benches/pathfinder.rs
index aff6c00c..5ad73d7d 100644
--- a/azalea/benches/pathfinder.rs
+++ b/azalea/benches/pathfinder.rs
@@ -13,6 +13,7 @@ use azalea::{
};
use azalea_core::position::{ChunkBlockPos, ChunkPos};
use azalea_inventory::Menu;
+use azalea_registry::builtin::BlockKind;
use azalea_world::{Chunk, ChunkStorage, PartialChunkStorage};
use criterion::{Bencher, Criterion, criterion_group, criterion_main};
use parking_lot::RwLock;
@@ -44,13 +45,13 @@ fn generate_bedrock_world(
for z in 0..16_u8 {
chunk.set_block_state(
&ChunkBlockPos::new(x, 1, z),
- azalea_registry::Block::Bedrock.into(),
+ BlockKind::Bedrock.into(),
chunks.min_y,
);
if rng.random_bool(0.5) {
chunk.set_block_state(
&ChunkBlockPos::new(x, 2, z),
- azalea_registry::Block::Bedrock.into(),
+ BlockKind::Bedrock.into(),
chunks.min_y,
);
}
@@ -102,7 +103,7 @@ fn generate_mining_world(
for z in 0..16_u8 {
chunk.set_block_state(
&ChunkBlockPos::new(x, y, z),
- azalea_registry::Block::Stone.into(),
+ BlockKind::Stone.into(),
chunks.min_y,
);
}
diff --git a/azalea/benches/physics.rs b/azalea/benches/physics.rs
index 2f122014..a0811566 100644
--- a/azalea/benches/physics.rs
+++ b/azalea/benches/physics.rs
@@ -3,6 +3,7 @@ use azalea::{
pathfinder::simulation::{SimulatedPlayerBundle, SimulationSet},
};
use azalea_core::position::{ChunkBlockPos, ChunkPos};
+use azalea_registry::builtin::BlockKind;
use azalea_world::{Chunk, ChunkStorage, PartialChunkStorage};
use criterion::{Bencher, Criterion, criterion_group, criterion_main};
@@ -27,7 +28,7 @@ fn generate_world(partial_chunks: &mut PartialChunkStorage, size: u32) -> ChunkS
for z in 0..16_u8 {
chunk.set_block_state(
&ChunkBlockPos::new(x, 1, z),
- azalea_registry::Block::OakFence.into(),
+ BlockKind::OakFence.into(),
chunks.min_y,
);
}
diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs
index 899c2568..c928545f 100644
--- a/azalea/examples/steal.rs
+++ b/azalea/examples/steal.rs
@@ -4,6 +4,7 @@ use std::sync::Arc;
use azalea::{BlockPos, pathfinder::goals::RadiusGoal, prelude::*};
use azalea_inventory::{ItemStack, operations::QuickMoveClick};
+use azalea_registry::builtin::{BlockKind, ItemKind};
use parking_lot::Mutex;
#[tokio::main]
@@ -55,7 +56,7 @@ async fn steal(bot: Client, state: State) -> anyhow::Result<()> {
let chest_block = bot
.world()
.read()
- .find_blocks(bot.position(), &azalea::registry::Block::Chest.into())
+ .find_blocks(bot.position(), &BlockKind::Chest.into())
.find(
// find the closest chest that hasn't been checked
|block_pos| !state.checked_chests.lock().contains(block_pos),
@@ -79,7 +80,7 @@ async fn steal(bot: Client, state: State) -> anyhow::Result<()> {
let ItemStack::Present(item) = slot else {
continue;
};
- if item.kind == azalea::registry::Item::Diamond {
+ if item.kind == ItemKind::Diamond {
println!("clicking slot ^");
chest.click(QuickMoveClick::Left { slot: index as u16 });
}
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs
index dfd055ea..c5b93c7d 100644
--- a/azalea/examples/testbot/commands/debug.rs
+++ b/azalea/examples/testbot/commands/debug.rs
@@ -142,7 +142,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
println!("getblock xyz {x} {y} {z}");
let block_pos = BlockPos::new(x, y, z);
let block = source.bot.world().read().get_block_state(block_pos);
- source.reply(format!("Block at {block_pos} is {block:?}"));
+ source.reply(format!("BlockKind at {block_pos} is {block:?}"));
1
})),
)));
diff --git a/azalea/examples/todo/craft_dig_straight_down.rs b/azalea/examples/todo/craft_dig_straight_down.rs
index 951c3de2..0d9961d4 100644
--- a/azalea/examples/todo/craft_dig_straight_down.rs
+++ b/azalea/examples/todo/craft_dig_straight_down.rs
@@ -38,7 +38,7 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
bot.goto(pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0)))
.await;
let chest = bot
- .open_container_at(&bot.world().find_block(azalea::Block::Chest))
+ .open_container_at(&bot.world().find_block(BlockKind::Chest))
.await
.unwrap();
bot.take_amount_from_container(&chest, 5, |i| i.id == "#minecraft:planks")
@@ -46,7 +46,7 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
chest.close().await;
let crafting_table = bot
- .open_crafting_table(&bot.world.find_block(azalea::Block::CraftingTable))
+ .open_crafting_table(&bot.world.find_block(BlockKind::CraftingTable))
.await
.unwrap();
bot.craft(&crafting_table, &bot.recipe_for("minecraft:sticks"))
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);