diff options
| author | mat <git@matdoes.dev> | 2025-01-12 05:07:53 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-01-12 05:07:53 +0000 |
| commit | 608ccb8e54454460a1b41a456f99b16d70fb5913 (patch) | |
| tree | 763c879fd83e64d946a6a7d210eed995b8aaf5de /azalea-physics | |
| parent | a5cb21f039ab2aa08b8f78a86d3924479c1bbe33 (diff) | |
| download | azalea-drasl-608ccb8e54454460a1b41a456f99b16d70fb5913.tar.xz | |
fix panic on bot disconnect
Diffstat (limited to 'azalea-physics')
| -rw-r--r-- | azalea-physics/src/fluids.rs | 2 | ||||
| -rw-r--r-- | azalea-physics/src/lib.rs | 6 | ||||
| -rw-r--r-- | azalea-physics/tests/physics.rs | 46 |
3 files changed, 49 insertions, 5 deletions
diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs index eca4266e..6e89cdea 100644 --- a/azalea-physics/src/fluids.rs +++ b/azalea-physics/src/fluids.rs @@ -23,7 +23,7 @@ pub fn update_in_water_state_and_do_fluid_pushing( for (mut physics, position, instance_name) in &mut query { let world_lock = instance_container .get(instance_name) - .expect("All entities should be in a valid world"); + .expect("All entities with InLoadedChunk should be in a valid world"); let world = world_lock.read(); physics.water_fluid_height = 0.; diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index 6ea4e946..c626dcdf 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -109,10 +109,8 @@ pub fn ai_step( if !physics.is_in_lava() || physics.on_ground() && fluid_height <= fluid_jump_threshold { - if physics.on_ground() - || in_water - && fluid_height <= fluid_jump_threshold - && physics.no_jump_delay == 0 + if (physics.on_ground() || in_water && fluid_height <= fluid_jump_threshold) + && physics.no_jump_delay == 0 { jump_from_ground( &mut physics, diff --git a/azalea-physics/tests/physics.rs b/azalea-physics/tests/physics.rs index c7e85006..d2986ff0 100644 --- a/azalea-physics/tests/physics.rs +++ b/azalea-physics/tests/physics.rs @@ -363,3 +363,49 @@ fn test_negative_coordinates_weird_wall_collision() { let entity_pos = app.world_mut().get::<Position>(entity).unwrap(); assert_eq!(entity_pos.y, 70.5); } + +#[test] +fn spawn_and_unload_world() { + let mut app = make_test_app(); + let world_lock = app.world_mut().resource_mut::<InstanceContainer>().insert( + ResourceLocation::new("minecraft:overworld"), + 384, + -64, + ); + let mut partial_world = PartialInstance::default(); + + partial_world.chunks.set( + &ChunkPos { x: -1, z: -1 }, + Some(Chunk::default()), + &mut world_lock.write().chunks, + ); + let _entity = app + .world_mut() + .spawn(( + EntityBundle::new( + Uuid::nil(), + Vec3 { + x: -7.5, + y: 73., + z: -7.5, + }, + azalea_registry::EntityKind::Player, + ResourceLocation::new("minecraft:overworld"), + ), + MinecraftEntityId(0), + LocalEntity, + )) + .id(); + + // do a tick + app.world_mut().run_schedule(GameTick); + app.update(); + + // now unload the partial_world and world_lock + drop(partial_world); + drop(world_lock); + + // do another tick + app.world_mut().run_schedule(GameTick); + app.update(); +} |
