Dynamic chunk loading
This commit is contained in:
1 parent
2085307a44
commit
5c0dffbf9d
33 files changed
+367
-181
No files matched your search
@@ -4,5 +4,7 @@ version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
pumpkin-core = { path = "../pumpkin-core"}
|
||||
|
||||
num-traits = "0.2"
|
||||
num-derive = "0.4"
|
||||
+31
-12
@@ -1,5 +1,8 @@
|
||||
use entity_type::EntityType;
|
||||
use pose::EntityPose;
|
||||
use pumpkin_core::math::{
|
||||
get_section_cord, position::WorldPosition, vector2::Vector2, vector3::Vector3,
|
||||
};
|
||||
|
||||
pub mod entity_type;
|
||||
pub mod pose;
|
||||
@@ -9,12 +12,10 @@ pub type EntityId = i32;
|
||||
pub struct Entity {
|
||||
pub entity_id: EntityId,
|
||||
pub entity_type: EntityType,
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub z: f64,
|
||||
pub lastx: f64,
|
||||
pub lasty: f64,
|
||||
pub lastz: f64,
|
||||
pub pos: Vector3<f64>,
|
||||
pub block_pos: WorldPosition,
|
||||
pub chunk_pos: Vector2<i32>,
|
||||
|
||||
pub yaw: f32,
|
||||
pub head_yaw: f32,
|
||||
pub pitch: f32,
|
||||
@@ -28,12 +29,9 @@ impl Entity {
|
||||
Self {
|
||||
entity_id,
|
||||
entity_type,
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
lastx: 0.0,
|
||||
lasty: 0.0,
|
||||
lastz: 0.0,
|
||||
pos: Vector3::new(0.0, 0.0, 0.0),
|
||||
block_pos: WorldPosition(Vector3::new(0, 0, 0)),
|
||||
chunk_pos: Vector2::new(0, 0),
|
||||
yaw: 0.0,
|
||||
head_yaw: 0.0,
|
||||
pitch: 0.0,
|
||||
@@ -41,4 +39,25 @@ impl Entity {
|
||||
pose: EntityPose::Standing,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_pos(&mut self, x: f64, y: f64, z: f64) {
|
||||
if self.pos.x != x || self.pos.y != y || self.pos.z != z {
|
||||
self.pos = Vector3::new(x, y, z);
|
||||
let i = x.floor() as i32;
|
||||
let j = y.floor() as i32;
|
||||
let k = z.floor() as i32;
|
||||
|
||||
let block_pos = self.block_pos.0;
|
||||
if i != block_pos.x || j != block_pos.y || k != block_pos.z {
|
||||
self.block_pos = WorldPosition(Vector3::new(i, j, k));
|
||||
|
||||
if get_section_cord(i) != self.chunk_pos.x
|
||||
|| get_section_cord(k) != self.chunk_pos.z
|
||||
{
|
||||
self.chunk_pos =
|
||||
Vector2::new(get_section_cord(block_pos.x), get_section_cord(block_pos.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user