aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/movement.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-05-03 20:57:27 -0500
committerGitHub <noreply@github.com>2023-05-03 20:57:27 -0500
commit634cb8d72c6608512aedba19e5cd669104bc35ea (patch)
treef8e76ce9eb43403d29cc0cbcf9a4f51522419dc2 /azalea-client/src/movement.rs
parent1fb4418f2c9cbd004c64c2f23d2d0352ee12c0e5 (diff)
downloadazalea-drasl-634cb8d72c6608512aedba19e5cd669104bc35ea.tar.xz
Inventory (#48)
* start adding azalea-inventory * design more of how inventories are defined * start working on az-inv-macros * inventory macro works * start adding inventory codegen * update some deps * add inventory codegen * manually write inventory menus * put the inventories in Client * start on containersetcontent * inventory menu should hopefully work * checks in containersetcontent * format a comment * move some variant matches * inventory.rs * inventory stuff * more inventory stuff * inventory/container tracking works * start adding interact function * sequence number * start adding HitResultComponent * implement traverse_blocks * start adding clip * add clip function * update_hit_result_component * start trying to fix * fix * make some stuff simpler * clippy * lever * chest * container handle * fix ambiguity * fix some doc tests * move some container stuff from az-client to azalea * clicking container * start implementing simulate_click * keep working on simulate click * implement more of simulate_click this is really boring * inventory fixes * start implementing shift clicking * fix panic in azalea-chat i hope * shift clicking implemented * more inventory stuff * fix items not showing in containers sometimes * fix test * fix all warnings * remove a println --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea-client/src/movement.rs')
-rw-r--r--azalea-client/src/movement.rs49
1 files changed, 31 insertions, 18 deletions
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index f6123c70..d68be8b8 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -16,6 +16,7 @@ use azalea_world::{
};
use bevy_app::{App, CoreSchedule, IntoSystemAppConfigs, Plugin};
use bevy_ecs::{
+ component::Component,
entity::Entity,
event::EventReader,
query::With,
@@ -84,18 +85,26 @@ impl Client {
**jumping_ref
}
- /// Sets your rotation. `y_rot` is yaw (looking to the side), `x_rot` is
- /// pitch (looking up and down). You can get these numbers from the vanilla
- /// f3 screen.
+ /// Sets the direction the client is looking. `y_rot` is yaw (looking to the
+ /// side), `x_rot` is pitch (looking up and down). You can get these
+ /// numbers from the vanilla f3 screen.
/// `y_rot` goes from -180 to 180, and `x_rot` goes from -90 to 90.
- pub fn set_rotation(&mut self, y_rot: f32, x_rot: f32) {
+ pub fn set_direction(&mut self, y_rot: f32, x_rot: f32) {
let mut ecs = self.ecs.lock();
- let mut physics = self.query::<&mut entity::Physics>(&mut ecs);
+ let mut look_direction = self.query::<&mut entity::LookDirection>(&mut ecs);
- entity::set_rotation(&mut physics, y_rot, x_rot);
+ (look_direction.y_rot, look_direction.x_rot) = (y_rot, x_rot);
}
}
+/// A component that contains the look direction that was last sent over the
+/// network.
+#[derive(Debug, Component, Clone, Default)]
+pub struct LastSentLookDirection {
+ pub x_rot: f32,
+ pub y_rot: f32,
+}
+
#[allow(clippy::type_complexity)]
pub(crate) fn send_position(
mut query: Query<
@@ -106,6 +115,8 @@ pub(crate) fn send_position(
&entity::Position,
&mut entity::LastSentPosition,
&mut entity::Physics,
+ &entity::LookDirection,
+ &mut LastSentLookDirection,
&entity::metadata::Sprinting,
),
&LocalPlayerInLoadedChunk,
@@ -118,6 +129,8 @@ pub(crate) fn send_position(
position,
mut last_sent_position,
mut physics,
+ direction,
+ mut last_direction,
sprinting,
) in query.iter_mut()
{
@@ -130,8 +143,8 @@ pub(crate) fn send_position(
let x_delta = position.x - last_sent_position.x;
let y_delta = position.y - last_sent_position.y;
let z_delta = position.z - last_sent_position.z;
- let y_rot_delta = (physics.y_rot - physics.y_rot_last) as f64;
- let x_rot_delta = (physics.x_rot - physics.x_rot_last) as f64;
+ let y_rot_delta = (direction.y_rot - last_direction.y_rot) as f64;
+ let x_rot_delta = (direction.x_rot - last_direction.x_rot) as f64;
physics_state.position_remainder += 1;
@@ -140,19 +153,19 @@ pub(crate) fn send_position(
let sending_position = ((x_delta.powi(2) + y_delta.powi(2) + z_delta.powi(2))
> 2.0e-4f64.powi(2))
|| physics_state.position_remainder >= 20;
- let sending_rotation = y_rot_delta != 0.0 || x_rot_delta != 0.0;
+ let sending_direction = y_rot_delta != 0.0 || x_rot_delta != 0.0;
// if self.is_passenger() {
// TODO: posrot packet for being a passenger
// }
- let packet = if sending_position && sending_rotation {
+ let packet = if sending_position && sending_direction {
Some(
ServerboundMovePlayerPosRotPacket {
x: position.x,
y: position.y,
z: position.z,
- x_rot: physics.x_rot,
- y_rot: physics.y_rot,
+ x_rot: direction.x_rot,
+ y_rot: direction.y_rot,
on_ground: physics.on_ground,
}
.get(),
@@ -167,11 +180,11 @@ pub(crate) fn send_position(
}
.get(),
)
- } else if sending_rotation {
+ } else if sending_direction {
Some(
ServerboundMovePlayerRotPacket {
- x_rot: physics.x_rot,
- y_rot: physics.y_rot,
+ x_rot: direction.x_rot,
+ y_rot: direction.y_rot,
on_ground: physics.on_ground,
}
.get(),
@@ -191,9 +204,9 @@ pub(crate) fn send_position(
**last_sent_position = **position;
physics_state.position_remainder = 0;
}
- if sending_rotation {
- physics.y_rot_last = physics.y_rot;
- physics.x_rot_last = physics.x_rot;
+ if sending_direction {
+ last_direction.y_rot = direction.y_rot;
+ last_direction.x_rot = direction.x_rot;
}
physics.last_on_ground = physics.on_ground;