diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-05-03 20:57:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-03 20:57:27 -0500 |
| commit | 634cb8d72c6608512aedba19e5cd669104bc35ea (patch) | |
| tree | f8e76ce9eb43403d29cc0cbcf9a4f51522419dc2 /azalea-physics/src/lib.rs | |
| parent | 1fb4418f2c9cbd004c64c2f23d2d0352ee12c0e5 (diff) | |
| download | azalea-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-physics/src/lib.rs')
| -rw-r--r-- | azalea-physics/src/lib.rs | 49 |
1 files changed, 37 insertions, 12 deletions
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::<ForceJumpEvent>() - .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<Local>>, - world_container: Res<InstanceContainer>, + mut query: Query< + ( + &mut Physics, + &mut LookDirection, + &mut Position, + &Attributes, + &WorldName, + ), + With<Local>, + >, + instance_container: Res<InstanceContainer>, ) { - 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<InstanceContainer>, + mut query: Query<( + &mut Physics, + &Position, + &LookDirection, + &Sprinting, + &WorldName, + )>, + instance_container: Res<InstanceContainer>, mut events: EventReader<ForceJumpEvent>, ) { 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, |
