mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
add more stuff to PositionXYZ
This commit is contained in:
parent
bf4fd29e7f
commit
dff54498f7
2 changed files with 88 additions and 18 deletions
|
@ -2,19 +2,54 @@ use crate::ResourceLocation;
|
||||||
use azalea_buf::{McBufReadable, McBufWritable};
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
use std::{
|
use std::{
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
ops::Rem,
|
ops::{Add, Mul, Rem},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait PositionXYZ<T> {
|
pub trait PositionXYZ<T>
|
||||||
fn add_x(&self, n: T) -> Self;
|
where
|
||||||
fn add_y(&self, n: T) -> Self;
|
T: Add<T, Output = T> + Mul<T, Output = T>,
|
||||||
fn add_z(&self, n: T) -> Self;
|
{
|
||||||
|
fn x(&self) -> T;
|
||||||
|
fn y(&self) -> T;
|
||||||
|
fn z(&self) -> T;
|
||||||
|
|
||||||
|
fn set_x(&self, n: T) -> Self;
|
||||||
|
fn set_y(&self, n: T) -> Self;
|
||||||
|
fn set_z(&self, n: T) -> Self;
|
||||||
|
|
||||||
|
// hopefully these get optimized
|
||||||
|
fn add_x(&self, n: T) -> Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.set_x(self.x() + n)
|
||||||
|
}
|
||||||
|
fn add_y(&self, n: T) -> Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.set_y(self.y() + n)
|
||||||
|
}
|
||||||
|
fn add_z(&self, n: T) -> Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.set_z(self.z() + n)
|
||||||
|
}
|
||||||
|
|
||||||
fn add(&self, x: T, y: T, z: T) -> Self
|
fn add(&self, x: T, y: T, z: T) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
self.add_x(x).add_y(y).add_z(z)
|
self.add_x(x).add_y(y).add_z(z)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn length_sqr(&self) -> T
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.x() * self.x() + self.y() * self.y() + self.z() * self.z()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
|
@ -43,25 +78,34 @@ impl Rem<i32> for BlockPos {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PositionXYZ<i32> for BlockPos {
|
impl PositionXYZ<i32> for BlockPos {
|
||||||
fn add_x(&self, n: i32) -> Self {
|
fn x(&self) -> i32 {
|
||||||
|
self.x
|
||||||
|
}
|
||||||
|
fn y(&self) -> i32 {
|
||||||
|
self.y
|
||||||
|
}
|
||||||
|
fn z(&self) -> i32 {
|
||||||
|
self.z
|
||||||
|
}
|
||||||
|
fn set_x(&self, n: i32) -> Self {
|
||||||
BlockPos {
|
BlockPos {
|
||||||
x: self.x + n,
|
x: n,
|
||||||
y: self.y,
|
y: self.y,
|
||||||
z: self.z,
|
z: self.z,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn add_y(&self, n: i32) -> Self {
|
fn set_y(&self, n: i32) -> Self {
|
||||||
BlockPos {
|
BlockPos {
|
||||||
x: self.x,
|
x: self.x,
|
||||||
y: self.y + n,
|
y: n,
|
||||||
z: self.z,
|
z: self.z,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn add_z(&self, n: i32) -> Self {
|
fn set_z(&self, n: i32) -> Self {
|
||||||
BlockPos {
|
BlockPos {
|
||||||
x: self.x,
|
x: self.x,
|
||||||
y: self.y,
|
y: self.y,
|
||||||
z: self.z + n,
|
z: n,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,25 +182,34 @@ pub struct Vec3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PositionXYZ<f64> for Vec3 {
|
impl PositionXYZ<f64> for Vec3 {
|
||||||
fn add_x(&self, n: f64) -> Self {
|
fn x(&self) -> f64 {
|
||||||
|
self.x
|
||||||
|
}
|
||||||
|
fn y(&self) -> f64 {
|
||||||
|
self.y
|
||||||
|
}
|
||||||
|
fn z(&self) -> f64 {
|
||||||
|
self.z
|
||||||
|
}
|
||||||
|
fn set_x(&self, n: f64) -> Self {
|
||||||
Vec3 {
|
Vec3 {
|
||||||
x: self.x + n,
|
x: n,
|
||||||
y: self.y,
|
y: self.y,
|
||||||
z: self.z,
|
z: self.z,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn add_y(&self, n: f64) -> Self {
|
fn set_y(&self, n: f64) -> Self {
|
||||||
Vec3 {
|
Vec3 {
|
||||||
x: self.x,
|
x: self.x,
|
||||||
y: self.y + n,
|
y: n,
|
||||||
z: self.z,
|
z: self.z,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn add_z(&self, n: f64) -> Self {
|
fn set_z(&self, n: f64) -> Self {
|
||||||
Vec3 {
|
Vec3 {
|
||||||
x: self.x,
|
x: self.x,
|
||||||
y: self.y,
|
y: self.y,
|
||||||
z: self.z + n,
|
z: n,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod block_hit_result;
|
||||||
|
|
||||||
use crate::Entity;
|
use crate::Entity;
|
||||||
pub use aabb::AABB;
|
pub use aabb::AABB;
|
||||||
use azalea_core::PositionDelta;
|
use azalea_core::{PositionDelta, PositionXYZ, Vec3};
|
||||||
pub use block_hit_result::BlockHitResult;
|
pub use block_hit_result::BlockHitResult;
|
||||||
|
|
||||||
pub enum MoverType {
|
pub enum MoverType {
|
||||||
|
@ -15,6 +15,7 @@ pub enum MoverType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity {
|
impl Entity {
|
||||||
|
/// Move an entity by a given delta, checking for collisions.
|
||||||
pub fn move_entity(&mut self, mover_type: &MoverType, movement: &PositionDelta) {
|
pub fn move_entity(&mut self, mover_type: &MoverType, movement: &PositionDelta) {
|
||||||
// if self.no_physics {
|
// if self.no_physics {
|
||||||
// return;
|
// return;
|
||||||
|
@ -35,4 +36,20 @@ impl Entity {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fn collide(movement: &Vec3, dimension: &Dimension) -> Vec3 {
|
||||||
|
// if movement.length_sqr() == 0.0 {
|
||||||
|
// *movement
|
||||||
|
// } else {
|
||||||
|
// // Self::collide_bounding_box(
|
||||||
|
// // Some(self),
|
||||||
|
// // movement,
|
||||||
|
// // entityBoundingBox,
|
||||||
|
// // this.level,
|
||||||
|
// // entityCollisions,
|
||||||
|
// // )
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn collide_bounding_box(self: )
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue