aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/dimensions.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-07-14 22:20:40 -0500
committerGitHub <noreply@github.com>2023-07-14 22:20:40 -0500
commit7405427199e5a994d4a6a706f84434a69cb7a7d9 (patch)
treeca537e5d761bc053187d952fced0915c850b92aa /azalea-entity/src/dimensions.rs
parentd1afd02aa84e7b4450c1607277f078eb2a0f1bf3 (diff)
downloadazalea-drasl-7405427199e5a994d4a6a706f84434a69cb7a7d9.tar.xz
Mining (#95)
* more mining stuff * initialize azalea-tags crate * more mining stuff 2 * mining in ecs * well technically mining works but no codegen for how long it takes to mine each block yet * rename downloads to __cache__ it was bothering me since it's not *just* downloads * codegen block behavior * fix not sending packet to finish breaking block * mining animation 🎉 * clippy * cleanup, move Client::mine into a client extension * add azalea/src/mining.rs --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea-entity/src/dimensions.rs')
-rwxr-xr-xazalea-entity/src/dimensions.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/azalea-entity/src/dimensions.rs b/azalea-entity/src/dimensions.rs
new file mode 100755
index 00000000..5e716307
--- /dev/null
+++ b/azalea-entity/src/dimensions.rs
@@ -0,0 +1,38 @@
+use azalea_core::{Vec3, AABB};
+use bevy_ecs::{query::Changed, system::Query};
+
+use super::{Physics, Position};
+
+#[derive(Debug, Default)]
+pub struct EntityDimensions {
+ pub width: f32,
+ pub height: f32,
+}
+
+impl EntityDimensions {
+ pub fn make_bounding_box(&self, pos: &Vec3) -> AABB {
+ let radius = (self.width / 2.0) as f64;
+ let height = self.height as f64;
+ AABB {
+ min_x: pos.x - radius,
+ min_y: pos.y,
+ min_z: pos.z - radius,
+
+ max_x: pos.x + radius,
+ max_y: pos.y + height,
+ max_z: pos.z + radius,
+ }
+ }
+}
+
+/// Sets the position of the entity. This doesn't update the cache in
+/// azalea-world, and should only be used within azalea-world!
+///
+/// # Safety
+/// Cached position in the world must be updated.
+pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed<Position>>) {
+ for (position, mut physics) in query.iter_mut() {
+ let bounding_box = physics.dimensions.make_bounding_box(position);
+ physics.bounding_box = bounding_box;
+ }
+}