mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
fix panic on disconnect
This commit is contained in:
parent
084953b89f
commit
84c0908f34
3 changed files with 14 additions and 21 deletions
|
@ -6,7 +6,7 @@ use azalea_protocol::packets::game::{
|
|||
};
|
||||
use azalea_world::{
|
||||
entity::{clamp_look_direction, view_vector, EyeHeight, LookDirection, Position, WorldName},
|
||||
InstanceContainer,
|
||||
Instance, InstanceContainer,
|
||||
};
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_ecs::{
|
||||
|
@ -153,13 +153,13 @@ fn update_hit_result_component(
|
|||
y: position.y + **eye_height as f64,
|
||||
z: position.z,
|
||||
};
|
||||
let hit_result = pick(
|
||||
look_direction,
|
||||
&eye_position,
|
||||
world_name,
|
||||
&instance_container,
|
||||
pick_range,
|
||||
);
|
||||
|
||||
let Some(instance_lock) = instance_container.get(world_name) else {
|
||||
continue;
|
||||
};
|
||||
let instance = instance_lock.read();
|
||||
|
||||
let hit_result = pick(look_direction, &eye_position, &instance, pick_range);
|
||||
if let Some(mut hit_result_ref) = hit_result_ref {
|
||||
**hit_result_ref = hit_result;
|
||||
} else {
|
||||
|
@ -178,16 +178,11 @@ fn update_hit_result_component(
|
|||
pub fn pick(
|
||||
look_direction: &LookDirection,
|
||||
eye_position: &Vec3,
|
||||
world_name: &WorldName,
|
||||
instance_container: &InstanceContainer,
|
||||
instance: &Instance,
|
||||
pick_range: f64,
|
||||
) -> BlockHitResult {
|
||||
let view_vector = view_vector(look_direction);
|
||||
let end_position = eye_position + &(view_vector * pick_range);
|
||||
let instance_lock = instance_container
|
||||
.get(world_name)
|
||||
.expect("entities must always be in a valid world");
|
||||
let instance = instance_lock.read();
|
||||
azalea_physics::clip::clip(
|
||||
&instance.chunks,
|
||||
ClipContext {
|
||||
|
|
|
@ -139,9 +139,10 @@ pub fn update_in_loaded_chunk(
|
|||
) {
|
||||
for (entity, local_player, position) in &query {
|
||||
let player_chunk_pos = ChunkPos::from(position);
|
||||
let instance_lock = instance_container
|
||||
.get(local_player)
|
||||
.expect("local player should always be in an instance");
|
||||
let Some(instance_lock) = instance_container.get(local_player) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let in_loaded_chunk = instance_lock.read().chunks.get(&player_chunk_pos).is_some();
|
||||
if in_loaded_chunk {
|
||||
commands.entity(entity).insert(LocalPlayerInLoadedChunk);
|
||||
|
|
|
@ -25,10 +25,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
&to_pascal_case(&name_snake_case.to_string()),
|
||||
name_snake_case.span(),
|
||||
);
|
||||
let enum_name = Ident::new(
|
||||
&format!("{variant_name}MenuLocation"),
|
||||
variant_name.span(),
|
||||
);
|
||||
let enum_name = Ident::new(&format!("{variant_name}MenuLocation"), variant_name.span());
|
||||
menu_location_variants.extend(quote! {
|
||||
#variant_name(#enum_name),
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue