diff --git a/Cargo.lock b/Cargo.lock index 5221945c..c77a753d 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,14 @@ dependencies = [ "num-traits", ] +[[package]] +name = "azalea-physics" +version = "0.1.0" +dependencies = [ + "azalea-core", + "azalea-entity", +] + [[package]] name = "azalea-protocol" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index c40178b3..03c048c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ members = [ "azalea-block", "azalea-entity", "azalea-buf", + "azalea-physics", ] [profile.release] diff --git a/azalea-physics/Cargo.toml b/azalea-physics/Cargo.toml new file mode 100644 index 00000000..fc007e18 --- /dev/null +++ b/azalea-physics/Cargo.toml @@ -0,0 +1,10 @@ +[package] +edition = "2021" +name = "azalea-physics" +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +azalea-core = {path = "../azalea-core"} +azalea-entity = {path = "../azalea-entity"} diff --git a/azalea-entity/src/physics/aabb.rs b/azalea-physics/src/aabb.rs similarity index 97% rename from azalea-entity/src/physics/aabb.rs rename to azalea-physics/src/aabb.rs index f9edbb0f..46e93317 100644 --- a/azalea-entity/src/physics/aabb.rs +++ b/azalea-physics/src/aabb.rs @@ -1,4 +1,4 @@ -use crate::physics::BlockHitResult; +use crate::BlockHitResult; use azalea_core::{BlockPos, Direction, PositionXYZ, Vec3}; pub const EPSILON: f64 = 1.0E-7; @@ -393,14 +393,14 @@ impl AABB { start_y: f64, start_z: f64, ) -> Option { - let mut t_x = (begin - start_x) / delta_x; - let mut t_y = (begin - start_y) / delta_y; - let mut t_z = (begin - start_z) / delta_z; + let t_x = (begin - start_x) / delta_x; + let t_y = (start_y + t_x) / delta_y; + let t_z = (start_z + t_x) / delta_z; if 0.0 < t_x && t_x < t[0] && min_x - EPSILON < t_y && t_y < max_x + EPSILON - && max_x - EPSILON < t_z + && min_z - EPSILON < t_z && t_z < max_z + EPSILON { t[0] = t_x; diff --git a/azalea-entity/src/physics/block_hit_result.rs b/azalea-physics/src/block_hit_result.rs similarity index 100% rename from azalea-entity/src/physics/block_hit_result.rs rename to azalea-physics/src/block_hit_result.rs diff --git a/azalea-entity/src/physics/mod.rs b/azalea-physics/src/lib.rs similarity index 84% rename from azalea-entity/src/physics/mod.rs rename to azalea-physics/src/lib.rs index 7d62ee64..45ac0186 100644 --- a/azalea-entity/src/physics/mod.rs +++ b/azalea-physics/src/lib.rs @@ -1,9 +1,9 @@ mod aabb; mod block_hit_result; -use crate::Entity; pub use aabb::AABB; use azalea_core::{PositionDelta, PositionXYZ, Vec3}; +use azalea_entity::Entity; pub use block_hit_result::BlockHitResult; pub enum MoverType { @@ -14,9 +14,13 @@ pub enum MoverType { Shulker, } -impl Entity { +trait HasPhysics { + fn move_entity(&mut self, mover_type: &MoverType, movement: &PositionDelta); +} + +impl HasPhysics for Entity { /// Move an entity by a given delta, checking for collisions. - pub fn move_entity(&mut self, mover_type: &MoverType, movement: &PositionDelta) { + fn move_entity(&mut self, mover_type: &MoverType, movement: &PositionDelta) { // if self.no_physics { // return; // };