diff options
| author | mat <github@matdoes.dev> | 2022-12-11 00:15:37 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-12-11 00:15:37 -0600 |
| commit | 37b9f10b3bcc74b48df2c6843a5286a7d41e2414 (patch) | |
| tree | 6a995f7ad3f3309e57c276e10dc7e655dae9c5bb /azalea-physics/src/lib.rs | |
| parent | 2d6737b247b74e964fd734d5ab4828a3193c296f (diff) | |
| download | azalea-drasl-37b9f10b3bcc74b48df2c6843a5286a7d41e2414.tar.xz | |
make entities have a reference to WeakWorlds instead
... and other exciting bug fixes
Diffstat (limited to 'azalea-physics/src/lib.rs')
| -rw-r--r-- | azalea-physics/src/lib.rs | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index d419535e..76ae3990 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -2,15 +2,14 @@ pub mod collision; -use std::ops::DerefMut; - use azalea_block::{Block, BlockState}; use azalea_core::{BlockPos, Vec3}; use azalea_world::{ entity::{Entity, EntityData}, - World, + WeakWorld, }; use collision::{MovableEntity, MoverType}; +use std::ops::Deref; pub trait HasPhysics { fn travel(&mut self, acceleration: &Vec3); @@ -19,7 +18,7 @@ pub trait HasPhysics { fn jump_from_ground(&mut self); } -impl<D: DerefMut<Target = World>> HasPhysics for Entity<'_, D> { +impl<D: Deref<Target = WeakWorld>> HasPhysics for Entity<'_, D> { /// Move the entity with the given acceleration while handling friction, /// gravity, collisions, and some other stuff. fn travel(&mut self, acceleration: &Vec3) { @@ -143,7 +142,7 @@ fn get_block_pos_below_that_affects_movement(entity: &EntityData) -> BlockPos { ) } -fn handle_relative_friction_and_calculate_movement<D: DerefMut<Target = World>>( +fn handle_relative_friction_and_calculate_movement<D: Deref<Target = WeakWorld>>( entity: &mut Entity<D>, acceleration: &Vec3, block_friction: f32, @@ -183,7 +182,7 @@ fn get_friction_influenced_speed(entity: &EntityData, friction: f32) -> f32 { /// Returns the what the entity's jump should be multiplied by based on the /// block they're standing on. -fn block_jump_factor<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { +fn block_jump_factor<D: Deref<Target = WeakWorld>>(entity: &Entity<D>) -> f32 { let block_at_pos = entity.world.get_block_state(&entity.pos().into()); let block_below = entity .world @@ -211,11 +210,11 @@ fn block_jump_factor<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { // public double getJumpBoostPower() { // return this.hasEffect(MobEffects.JUMP) ? (double)(0.1F * // (float)(this.getEffect(MobEffects.JUMP).getAmplifier() + 1)) : 0.0D; } -fn jump_power<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { +fn jump_power<D: Deref<Target = WeakWorld>>(entity: &Entity<D>) -> f32 { 0.42 * block_jump_factor(entity) } -fn jump_boost_power<D: DerefMut<Target = World>>(_entity: &Entity<D>) -> f64 { +fn jump_boost_power<D: Deref<Target = WeakWorld>>(_entity: &Entity<D>) -> f64 { // TODO: potion effects // if let Some(effects) = entity.effects() { // if let Some(jump_effect) = effects.get(&Effect::Jump) { @@ -235,13 +234,13 @@ mod tests { use azalea_core::ChunkPos; use azalea_world::{ entity::{metadata, EntityMetadata}, - Chunk, World, + Chunk, PartialWorld, }; use uuid::Uuid; #[test] fn test_gravity() { - let mut world = World::default(); + let mut world = PartialWorld::default(); world.add_entity( 0, @@ -272,7 +271,7 @@ mod tests { } #[test] fn test_collision() { - let mut world = World::default(); + let mut world = PartialWorld::default(); world .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); @@ -305,7 +304,7 @@ mod tests { #[test] fn test_slab_collision() { - let mut world = World::default(); + let mut world = PartialWorld::default(); world .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); @@ -339,7 +338,7 @@ mod tests { #[test] fn test_top_slab_collision() { - let mut world = World::default(); + let mut world = PartialWorld::default(); world .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); @@ -373,7 +372,7 @@ mod tests { #[test] fn test_weird_wall_collision() { - let mut world = World::default(); + let mut world = PartialWorld::default(); world .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); |
