From 634cb8d72c6608512aedba19e5cd669104bc35ea Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Wed, 3 May 2023 20:57:27 -0500 Subject: 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 --- azalea-physics/src/lib.rs | 49 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'azalea-physics/src/lib.rs') diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index 049091f7..57c2100e 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -1,14 +1,15 @@ #![doc = include_str!("../README.md")] #![feature(trait_alias)] +pub mod clip; pub mod collision; use azalea_block::{Block, BlockState}; use azalea_core::{BlockPos, Vec3}; use azalea_world::{ entity::{ - metadata::Sprinting, move_relative, Attributes, Jumping, Local, Physics, Position, - WorldName, + clamp_look_direction, metadata::Sprinting, move_relative, Attributes, Jumping, Local, + LookDirection, Physics, Position, WorldName, }, Instance, InstanceContainer, }; @@ -30,7 +31,11 @@ pub struct PhysicsPlugin; impl Plugin for PhysicsPlugin { fn build(&self, app: &mut App) { app.add_event::() - .add_system(force_jump_listener.before(azalea_world::entity::update_bounding_box)) + .add_system( + force_jump_listener + .before(azalea_world::entity::update_bounding_box) + .after(clamp_look_direction), + ) .add_systems( (ai_step, travel) .chain() @@ -43,11 +48,20 @@ impl Plugin for PhysicsPlugin { /// Move the entity with the given acceleration while handling friction, /// gravity, collisions, and some other stuff. fn travel( - mut query: Query<(&mut Physics, &mut Position, &Attributes, &WorldName), With>, - world_container: Res, + mut query: Query< + ( + &mut Physics, + &mut LookDirection, + &mut Position, + &Attributes, + &WorldName, + ), + With, + >, + instance_container: Res, ) { - for (mut physics, mut position, attributes, world_name) in &mut query { - let world_lock = world_container + for (mut physics, direction, mut position, attributes, world_name) in &mut query { + let world_lock = instance_container .get(world_name) .expect("All entities should be in a valid world"); let world = world_lock.read(); @@ -85,6 +99,7 @@ fn travel( block_friction, &world, &mut physics, + &direction, &mut position, attributes, ); @@ -158,13 +173,21 @@ pub fn ai_step( pub struct ForceJumpEvent(pub Entity); pub fn force_jump_listener( - mut query: Query<(&mut Physics, &Position, &Sprinting, &WorldName)>, - world_container: Res, + mut query: Query<( + &mut Physics, + &Position, + &LookDirection, + &Sprinting, + &WorldName, + )>, + instance_container: Res, mut events: EventReader, ) { for event in events.iter() { - if let Ok((mut physics, position, sprinting, world_name)) = query.get_mut(event.0) { - let world_lock = world_container + if let Ok((mut physics, position, direction, sprinting, world_name)) = + query.get_mut(event.0) + { + let world_lock = instance_container .get(world_name) .expect("All entities should be in a valid world"); let world = world_lock.read(); @@ -178,7 +201,7 @@ pub fn force_jump_listener( }; if **sprinting { // sprint jumping gives some extra velocity - let y_rot = physics.y_rot * 0.017453292; + let y_rot = direction.y_rot * 0.017453292; physics.delta += Vec3 { x: (-f32::sin(y_rot) * 0.2) as f64, y: 0., @@ -204,11 +227,13 @@ fn handle_relative_friction_and_calculate_movement( block_friction: f32, world: &Instance, physics: &mut Physics, + direction: &LookDirection, position: &mut Position, attributes: &Attributes, ) -> Vec3 { move_relative( physics, + direction, get_friction_influenced_speed(physics, attributes, block_friction), &Vec3 { x: physics.xxa as f64, -- cgit v1.2.3