aboutsummaryrefslogtreecommitdiff
path: root/azalea-physics/src/collision/mod.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-01-10 16:45:27 -0600
committerGitHub <noreply@github.com>2025-01-10 16:45:27 -0600
commit0d16f01571ec8315f3979eae46981e559ade1cf9 (patch)
treeea43c32a57b0e6a67579d75a134dfbc009d09781 /azalea-physics/src/collision/mod.rs
parent615d8f9d2ac56b3244d328587243301da253eafd (diff)
downloadazalea-drasl-0d16f01571ec8315f3979eae46981e559ade1cf9.tar.xz
Fluid physics (#199)
* start implementing fluid physics * Initial implementation of fluid pushing * different travel function in water * bubble columns * jumping in water * cleanup * change ultrawarm to be required * fix for clippy
Diffstat (limited to 'azalea-physics/src/collision/mod.rs')
-rw-r--r--azalea-physics/src/collision/mod.rs44
1 files changed, 36 insertions, 8 deletions
diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs
index 39fc43f8..530aa47f 100644
--- a/azalea-physics/src/collision/mod.rs
+++ b/azalea-physics/src/collision/mod.rs
@@ -6,7 +6,7 @@ mod world_collisions;
use std::{ops::Add, sync::LazyLock};
-use azalea_block::FluidState;
+use azalea_block::{fluid_state::FluidState, BlockState};
use azalea_core::{
aabb::AABB,
direction::Axis,
@@ -22,6 +22,7 @@ use tracing::warn;
use self::world_collisions::get_block_collisions;
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MoverType {
Own,
Player,
@@ -111,7 +112,7 @@ fn collide(movement: &Vec3, world: &Instance, physics: &azalea_entity::Physics)
y: 0.,
z: movement.z,
},
- &entity_bounding_box.move_relative(&directly_up_delta),
+ &entity_bounding_box.move_relative(directly_up_delta),
world,
entity_collisions.clone(),
)
@@ -132,7 +133,7 @@ fn collide(movement: &Vec3, world: &Instance, physics: &azalea_entity::Physics)
y: -step_to_delta.y + movement.y,
z: 0.,
},
- &entity_bounding_box.move_relative(&step_to_delta),
+ &entity_bounding_box.move_relative(step_to_delta),
world,
entity_collisions.clone(),
));
@@ -143,8 +144,10 @@ fn collide(movement: &Vec3, world: &Instance, physics: &azalea_entity::Physics)
}
/// Move an entity by a given delta, checking for collisions.
+///
+/// In Mojmap, this is `Entity.move`.
pub fn move_colliding(
- _mover_type: &MoverType,
+ _mover_type: MoverType,
movement: &Vec3,
world: &Instance,
position: &mut Mut<azalea_entity::Position>,
@@ -296,7 +299,7 @@ fn collide_with_shapes(
if y_movement != 0. {
y_movement = Shapes::collide(&Axis::Y, &entity_box, collision_boxes, y_movement);
if y_movement != 0. {
- entity_box = entity_box.move_relative(&Vec3 {
+ entity_box = entity_box.move_relative(Vec3 {
x: 0.,
y: y_movement,
z: 0.,
@@ -311,7 +314,7 @@ fn collide_with_shapes(
if more_z_movement && z_movement != 0. {
z_movement = Shapes::collide(&Axis::Z, &entity_box, collision_boxes, z_movement);
if z_movement != 0. {
- entity_box = entity_box.move_relative(&Vec3 {
+ entity_box = entity_box.move_relative(Vec3 {
x: 0.,
y: 0.,
z: z_movement,
@@ -322,7 +325,7 @@ fn collide_with_shapes(
if x_movement != 0. {
x_movement = Shapes::collide(&Axis::X, &entity_box, collision_boxes, x_movement);
if x_movement != 0. {
- entity_box = entity_box.move_relative(&Vec3 {
+ entity_box = entity_box.move_relative(Vec3 {
x: x_movement,
y: 0.,
z: 0.,
@@ -352,7 +355,7 @@ pub fn fluid_shape(
) -> &'static VoxelShape {
if fluid.amount == 9 {
let fluid_state_above = world.get_fluid_state(&pos.up(1)).unwrap_or_default();
- if fluid_state_above.fluid == fluid.fluid {
+ if fluid_state_above.kind == fluid.kind {
return &BLOCK_SHAPE;
}
}
@@ -384,3 +387,28 @@ pub fn fluid_shape(
fn calculate_shape_for_fluid(amount: u8) -> VoxelShape {
box_shape(0.0, 0.0, 0.0, 1.0, (f32::from(amount) / 9.0) as f64, 1.0)
}
+
+/// Whether the block is treated as "motion blocking".
+///
+/// This is marked as deprecated in Minecraft.
+pub fn legacy_blocks_motion(block: BlockState) -> bool {
+ let registry_block = azalea_registry::Block::from(block);
+ legacy_calculate_solid(block)
+ && registry_block != azalea_registry::Block::Cobweb
+ && registry_block != azalea_registry::Block::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::Block>::from(block);
+ if let Some(solid) = block_trait.behavior().force_solid {
+ return solid;
+ }
+
+ let shape = block.collision_shape();
+ if shape.is_empty() {
+ return false;
+ }
+ let bounds = shape.bounds();
+ bounds.size() >= 0.7291666666666666 || bounds.get_size(Axis::Y) >= 1.0
+}