mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
azalea-physics
This commit is contained in:
parent
dff54498f7
commit
99cba524d6
6 changed files with 31 additions and 8 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -14,6 +14,7 @@ members = [
|
|||
"azalea-block",
|
||||
"azalea-entity",
|
||||
"azalea-buf",
|
||||
"azalea-physics",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
|
10
azalea-physics/Cargo.toml
Normal file
10
azalea-physics/Cargo.toml
Normal file
|
@ -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"}
|
|
@ -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<Direction> {
|
||||
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;
|
|
@ -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;
|
||||
// };
|
Loading…
Add table
Reference in a new issue