diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-12 00:56:02 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-12 00:56:02 -0600 |
| commit | f9c25665c203d6377ace62f1e95381d037d8fd9e (patch) | |
| tree | 8b4131d20fe661d3cc1175ec27f801fe61df41ea /azalea-physics | |
| parent | 82ad975242292d5875780b4398b62637674bf50a (diff) | |
| download | azalea-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-physics')
| -rw-r--r-- | azalea-physics/src/clip.rs | 5 | ||||
| -rw-r--r-- | azalea-physics/src/collision/mod.rs | 11 | ||||
| -rw-r--r-- | azalea-physics/src/fluids.rs | 5 | ||||
| -rw-r--r-- | azalea-physics/src/lib.rs | 14 | ||||
| -rw-r--r-- | azalea-physics/tests/physics.rs | 33 |
5 files changed, 36 insertions, 32 deletions
diff --git a/azalea-physics/src/clip.rs b/azalea-physics/src/clip.rs index dbab0da6..625a709e 100644 --- a/azalea-physics/src/clip.rs +++ b/azalea-physics/src/clip.rs @@ -11,6 +11,7 @@ use azalea_core::{ math::{self, EPSILON, lerp}, position::{BlockPos, Vec3}, }; +use azalea_registry::{builtin::BlockKind, tags}; use azalea_world::ChunkStorage; use crate::collision::{BlockWithShape, EMPTY_SHAPE, VoxelShape}; @@ -34,9 +35,7 @@ impl ClipContext { BlockShapeType::Outline => block_state.outline_shape(), BlockShapeType::Visual => block_state.collision_shape(), BlockShapeType::FallDamageResetting => { - if azalea_registry::tags::blocks::FALL_DAMAGE_RESETTING - .contains(&azalea_registry::Block::from(block_state)) - { + if tags::blocks::FALL_DAMAGE_RESETTING.contains(&BlockKind::from(block_state)) { block_state.collision_shape() } else { &EMPTY_SHAPE diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs index e6423fc4..6c622d40 100644 --- a/azalea-physics/src/collision/mod.rs +++ b/azalea-physics/src/collision/mod.rs @@ -7,7 +7,7 @@ pub mod world_collisions; use std::{ops::Add, sync::LazyLock}; -use azalea_block::{BlockState, fluid_state::FluidState}; +use azalea_block::{BlockState, BlockTrait, fluid_state::FluidState}; use azalea_core::{ aabb::Aabb, direction::Axis, @@ -18,6 +18,7 @@ use azalea_entity::{ Attributes, Jumping, LookDirection, OnClimbable, Physics, PlayerAbilities, Pose, Position, metadata::Sprinting, }; +use azalea_registry::builtin::BlockKind; use azalea_world::{ChunkStorage, Instance}; use bevy_ecs::{entity::Entity, world::Mut}; pub use blocks::BlockWithShape; @@ -483,15 +484,15 @@ pub fn legacy_blocks_motion(block: BlockState) -> bool { return false; } - let registry_block = azalea_registry::Block::from(block); + let registry_block = BlockKind::from(block); legacy_calculate_solid(block) - && registry_block != azalea_registry::Block::Cobweb - && registry_block != azalea_registry::Block::BambooSapling + && registry_block != BlockKind::Cobweb + && registry_block != BlockKind::BambooSapling } pub fn legacy_calculate_solid(block: BlockState) -> bool { // force_solid has to be checked before anything else - let block_trait = Box::<dyn azalea_block::BlockTrait>::from(block); + let block_trait = Box::<dyn BlockTrait>::from(block); if let Some(solid) = block_trait.behavior().force_solid { return solid; } diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs index 3675ca3e..fa6a1586 100644 --- a/azalea-physics/src/fluids.rs +++ b/azalea-physics/src/fluids.rs @@ -7,6 +7,7 @@ use azalea_core::{ position::{BlockPos, Vec3}, }; use azalea_entity::{HasClientLoaded, LocalEntity, Physics, Position}; +use azalea_registry::builtin::BlockKind; use azalea_world::{Instance, InstanceContainer, InstanceName}; use bevy_ecs::prelude::*; @@ -255,11 +256,11 @@ fn is_solid_face( if direction == Direction::Up { return true; } - let registry_block = azalea_registry::Block::from(block_state); + let registry_block = BlockKind::from(block_state); if matches!( registry_block, // frosted ice is from frost walker - azalea_registry::Block::Ice | azalea_registry::Block::FrostedIce + BlockKind::Ice | BlockKind::FrostedIce ) { return false; } diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index b993a7b5..663c60db 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -20,7 +20,7 @@ use azalea_entity::{ LookDirection, OnClimbable, Physics, Pose, Position, dimensions::EntityDimensions, metadata::Sprinting, move_relative, }; -use azalea_registry::{Block, EntityKind, MobEffect}; +use azalea_registry::builtin::{BlockKind, EntityKind, MobEffect}; use azalea_world::{Instance, InstanceContainer, InstanceName}; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; @@ -296,10 +296,10 @@ fn handle_entity_inside_block( block_pos: BlockPos, physics: &mut Physics, ) { - let registry_block = azalea_registry::Block::from(block); + let registry_block = BlockKind::from(block); #[allow(clippy::single_match)] match registry_block { - azalea_registry::Block::BubbleColumn => { + BlockKind::BubbleColumn => { let block_above = world.get_block_state(block_pos.up(1)).unwrap_or_default(); let is_block_above_empty = block_above.is_collision_shape_empty() && FluidState::from(block_above).is_empty(); @@ -417,14 +417,14 @@ fn handle_relative_friction_and_calculate_movement(ctx: &mut MoveCtx, block_fric // Vec3(var3.x, 0.2D, var3.z); } if ctx.physics.horizontal_collision || *ctx.jumping { - let block_at_feet: Block = ctx + let block_at_feet: BlockKind = ctx .world .chunks .get_block_state(BlockPos::from(*ctx.position)) .unwrap_or_default() .into(); - if *ctx.on_climbable || block_at_feet == Block::PowderSnow { + if *ctx.on_climbable || block_at_feet == BlockKind::PowderSnow { ctx.physics.velocity.y = 0.2; } } @@ -454,12 +454,12 @@ fn handle_on_climbable( // sneaking on ladders/vines if y < 0.0 && pose == Some(Pose::Crouching) - && azalea_registry::Block::from( + && BlockKind::from( world .chunks .get_block_state(position.into()) .unwrap_or_default(), - ) != azalea_registry::Block::Scaffolding + ) != BlockKind::Scaffolding { y = 0.; } diff --git a/azalea-physics/tests/physics.rs b/azalea-physics/tests/physics.rs index 09cb5379..57747692 100644 --- a/azalea-physics/tests/physics.rs +++ b/azalea-physics/tests/physics.rs @@ -5,13 +5,16 @@ use azalea_block::{ properties::WaterLevel, }; use azalea_core::{ - identifier::Identifier, position::{BlockPos, ChunkPos, Vec3}, registry_holder::RegistryHolder, tick::GameTick, }; use azalea_entity::{EntityBundle, EntityPlugin, HasClientLoaded, LocalEntity, Physics, Position}; use azalea_physics::PhysicsPlugin; +use azalea_registry::{ + builtin::{BlockKind, EntityKind}, + identifier::Identifier, +}; use azalea_world::{Chunk, Instance, InstanceContainer, MinecraftEntityId, PartialInstance}; use bevy_app::App; use parking_lot::RwLock; @@ -58,7 +61,7 @@ fn test_gravity() { y: 70., z: 0., }, - azalea_registry::EntityKind::Zombie, + EntityKind::Zombie, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -114,7 +117,7 @@ fn test_collision() { y: 70., z: 0.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -124,12 +127,12 @@ fn test_collision() { .id(); let block_state = partial_world.chunks.set_block_state( BlockPos { x: 0, y: 69, z: 0 }, - azalea_registry::Block::Stone.into(), + BlockKind::Stone.into(), &world_lock.write().chunks, ); assert!( block_state.is_some(), - "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" + "BlockKind state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); app.update(); app.world_mut().run_schedule(GameTick); @@ -171,7 +174,7 @@ fn test_slab_collision() { y: 71., z: 0.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -190,7 +193,7 @@ fn test_slab_collision() { ); assert!( block_state.is_some(), - "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" + "BlockKind state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); // do a few steps so we fall on the slab for _ in 0..20 { @@ -222,7 +225,7 @@ fn test_top_slab_collision() { y: 71., z: 0.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -240,7 +243,7 @@ fn test_top_slab_collision() { ); assert!( block_state.is_some(), - "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" + "BlockKind state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); // do a few steps so we fall on the slab for _ in 0..20 { @@ -280,7 +283,7 @@ fn test_weird_wall_collision() { y: 73., z: 0.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -302,7 +305,7 @@ fn test_weird_wall_collision() { ); assert!( block_state.is_some(), - "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" + "BlockKind state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); // do a few steps so we fall on the wall for _ in 0..20 { @@ -343,7 +346,7 @@ fn test_negative_coordinates_weird_wall_collision() { y: 73., z: -7.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -369,7 +372,7 @@ fn test_negative_coordinates_weird_wall_collision() { ); assert!( block_state.is_some(), - "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" + "BlockKind state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); // do a few steps so we fall on the wall for _ in 0..20 { @@ -410,7 +413,7 @@ fn spawn_and_unload_world() { y: 73., z: -7.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), @@ -526,7 +529,7 @@ fn test_afk_pool() { y: 70., z: 1.5, }, - azalea_registry::EntityKind::Player, + EntityKind::Player, Identifier::new("minecraft:overworld"), ), MinecraftEntityId(0), |
