diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-15 14:52:26 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-15 14:52:26 -0600 |
| commit | 0d004b72ac22641978c6ef93ca8641eb621e2f48 (patch) | |
| tree | 61eca3b0bd0339b36b947afd76724b2b6447572c /azalea-physics/src/lib.rs | |
| parent | b9da6f74756abb8daf7253765fdc5f5521381090 (diff) | |
| download | azalea-drasl-0d004b72ac22641978c6ef93ca8641eb621e2f48.tar.xz | |
Rename "dimension" to "world" (#39)
* rename "dimension" to "world"
* Update mod.rs
Diffstat (limited to 'azalea-physics/src/lib.rs')
| -rwxr-xr-x | azalea-physics/src/lib.rs | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index 852874b8..2295e6f2 100755 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -8,7 +8,7 @@ use azalea_block::{Block, BlockState}; use azalea_core::{BlockPos, Vec3}; use azalea_world::{ entity::{Entity, EntityData}, - Dimension, + World, }; use collision::{MovableEntity, MoverType}; @@ -19,7 +19,7 @@ pub trait HasPhysics { fn jump_from_ground(&mut self); } -impl<D: DerefMut<Target = Dimension>> HasPhysics for Entity<'_, D> { +impl<D: DerefMut<Target = World>> 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) { @@ -40,7 +40,7 @@ impl<D: DerefMut<Target = Dimension>> HasPhysics for Entity<'_, D> { let block_pos_below = get_block_pos_below_that_affects_movement(self); let block_state_below = self - .dimension + .world .get_block_state(&block_pos_below) .unwrap_or(BlockState::Air); let block_below: Box<dyn Block> = block_state_below.into(); @@ -142,7 +142,7 @@ fn get_block_pos_below_that_affects_movement(entity: &EntityData) -> BlockPos { ) } -fn handle_relative_friction_and_calculate_movement<D: DerefMut<Target = Dimension>>( +fn handle_relative_friction_and_calculate_movement<D: DerefMut<Target = World>>( entity: &mut Entity<D>, acceleration: &Vec3, block_friction: f32, @@ -181,10 +181,10 @@ 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 = Dimension>>(entity: &Entity<D>) -> f32 { - let block_at_pos = entity.dimension.get_block_state(&entity.pos().into()); +fn block_jump_factor<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { + let block_at_pos = entity.world.get_block_state(&entity.pos().into()); let block_below = entity - .dimension + .world .get_block_state(&get_block_pos_below_that_affects_movement(entity)); let block_at_pos_jump_factor = if let Some(block) = block_at_pos { @@ -209,11 +209,11 @@ fn block_jump_factor<D: DerefMut<Target = Dimension>>(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 = Dimension>>(entity: &Entity<D>) -> f32 { +fn jump_power<D: DerefMut<Target = World>>(entity: &Entity<D>) -> f32 { 0.42 * block_jump_factor(entity) } -fn jump_boost_power<D: DerefMut<Target = Dimension>>(_entity: &Entity<D>) -> f64 { +fn jump_boost_power<D: DerefMut<Target = World>>(_entity: &Entity<D>) -> f64 { // TODO: potion effects // if let Some(effects) = entity.effects() { // if let Some(jump_effect) = effects.get(&Effect::Jump) { @@ -231,14 +231,14 @@ fn jump_boost_power<D: DerefMut<Target = Dimension>>(_entity: &Entity<D>) -> f64 mod tests { use super::*; use azalea_core::ChunkPos; - use azalea_world::{Chunk, Dimension}; + use azalea_world::{Chunk, World}; use uuid::Uuid; #[test] fn test_gravity() { - let mut dim = Dimension::default(); + let mut world = World::default(); - dim.add_entity( + world.add_entity( 0, EntityData::new( Uuid::from_u128(0), @@ -249,7 +249,7 @@ mod tests { }, ), ); - let mut entity = dim.entity_mut(0).unwrap(); + let mut entity = world.entity_mut(0).unwrap(); // y should start at 70 assert_eq!(entity.pos().y, 70.); entity.ai_step(); @@ -266,10 +266,11 @@ mod tests { } #[test] fn test_collision() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); - dim.add_entity( + world.add_entity( 0, EntityData::new( Uuid::from_u128(0), @@ -280,12 +281,12 @@ mod tests { }, ), ); - let block_state = dim.set_block_state(&BlockPos { x: 0, y: 69, z: 0 }, BlockState::Stone); + let block_state = world.set_block_state(&BlockPos { x: 0, y: 69, z: 0 }, BlockState::Stone); assert!( block_state.is_some(), "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); - let mut entity = dim.entity_mut(0).unwrap(); + let mut entity = world.entity_mut(0).unwrap(); entity.ai_step(); // delta will change, but it won't move until next tick assert_eq!(entity.pos().y, 70.); @@ -297,10 +298,11 @@ mod tests { #[test] fn test_slab_collision() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); - dim.add_entity( + world.add_entity( 0, EntityData::new( Uuid::from_u128(0), @@ -311,7 +313,7 @@ mod tests { }, ), ); - let block_state = dim.set_block_state( + let block_state = world.set_block_state( &BlockPos { x: 0, y: 69, z: 0 }, BlockState::StoneSlab_BottomFalse, ); @@ -319,7 +321,7 @@ mod tests { block_state.is_some(), "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); - let mut entity = dim.entity_mut(0).unwrap(); + let mut entity = world.entity_mut(0).unwrap(); // do a few steps so we fall on the slab for _ in 0..20 { entity.ai_step(); @@ -329,10 +331,11 @@ mod tests { #[test] fn test_top_slab_collision() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); - dim.add_entity( + world.add_entity( 0, EntityData::new( Uuid::from_u128(0), @@ -343,7 +346,7 @@ mod tests { }, ), ); - let block_state = dim.set_block_state( + let block_state = world.set_block_state( &BlockPos { x: 0, y: 69, z: 0 }, BlockState::StoneSlab_TopFalse, ); @@ -351,7 +354,7 @@ mod tests { block_state.is_some(), "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); - let mut entity = dim.entity_mut(0).unwrap(); + let mut entity = world.entity_mut(0).unwrap(); // do a few steps so we fall on the slab for _ in 0..20 { entity.ai_step(); @@ -361,10 +364,11 @@ mod tests { #[test] fn test_weird_wall_collision() { - let mut dim = Dimension::default(); - dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + let mut world = World::default(); + world + .set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) .unwrap(); - dim.add_entity( + world.add_entity( 0, EntityData::new( Uuid::from_u128(0), @@ -375,7 +379,7 @@ mod tests { }, ), ); - let block_state = dim.set_block_state( + let block_state = world.set_block_state( &BlockPos { x: 0, y: 69, z: 0 }, BlockState::CobblestoneWall_LowLowLowFalseFalseLow, ); @@ -383,7 +387,7 @@ mod tests { block_state.is_some(), "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" ); - let mut entity = dim.entity_mut(0).unwrap(); + let mut entity = world.entity_mut(0).unwrap(); // do a few steps so we fall on the slab for _ in 0..20 { entity.ai_step(); |
