mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
clippy
This commit is contained in:
parent
59f65cb046
commit
5c38b34dc1
8 changed files with 47 additions and 29 deletions
|
@ -104,6 +104,7 @@ fn handle_block_interact_event(
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn update_hit_result_component(
|
||||
mut commands: Commands,
|
||||
mut query: Query<(
|
||||
|
@ -125,25 +126,17 @@ fn update_hit_result_component(
|
|||
} else {
|
||||
4.5
|
||||
};
|
||||
let view_vector = view_vector(look_direction);
|
||||
let eye_position = Vec3 {
|
||||
x: position.x,
|
||||
y: position.y + **eye_height as f64,
|
||||
z: position.z,
|
||||
};
|
||||
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();
|
||||
let hit_result = azalea_physics::clip::clip(
|
||||
&instance.chunks,
|
||||
ClipContext {
|
||||
from: eye_position,
|
||||
to: end_position,
|
||||
block_shape_type: BlockShapeType::Outline,
|
||||
fluid_pick_type: FluidPickType::None,
|
||||
},
|
||||
let hit_result = pick(
|
||||
look_direction,
|
||||
&eye_position,
|
||||
world_name,
|
||||
&instance_container,
|
||||
pick_range,
|
||||
);
|
||||
if let Some(mut hit_result_ref) = hit_result_ref {
|
||||
**hit_result_ref = hit_result;
|
||||
|
@ -154,3 +147,27 @@ fn update_hit_result_component(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pick(
|
||||
look_direction: &LookDirection,
|
||||
eye_position: &Vec3,
|
||||
world_name: &WorldName,
|
||||
instance_container: &InstanceContainer,
|
||||
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 {
|
||||
from: *eye_position,
|
||||
to: end_position,
|
||||
block_shape_type: BlockShapeType::Outline,
|
||||
fluid_pick_type: FluidPickType::None,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ 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)
|
||||
.get(local_player)
|
||||
.expect("local player should always be in an instance");
|
||||
let in_loaded_chunk = instance_lock.read().chunks.get(&player_chunk_pos).is_some();
|
||||
if in_loaded_chunk {
|
||||
|
|
|
@ -325,6 +325,7 @@ fn process_packet_events(ecs: &mut World) {
|
|||
// TODO: reply with teleport confirm
|
||||
debug!("Got player position packet {:?}", p);
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
let mut system_state: SystemState<
|
||||
Query<(
|
||||
&mut LocalPlayer,
|
||||
|
@ -838,6 +839,7 @@ fn process_packet_events(ecs: &mut World) {
|
|||
|
||||
debug!("Got game event packet {:?}", p);
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
match p.event {
|
||||
EventType::ChangeGameMode => {
|
||||
let mut system_state: SystemState<Query<&mut LocalGameMode>> =
|
||||
|
|
|
@ -9,7 +9,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
let mut variants = quote! {};
|
||||
let mut player_fields = None;
|
||||
for menu in &input.menus {
|
||||
if menu.name.to_string() == "Player" {
|
||||
if menu.name == "Player" {
|
||||
player_fields = Some(generate_fields(&menu.fields, true));
|
||||
} else {
|
||||
variants.extend(generate_variant_for_menu(menu));
|
||||
|
|
|
@ -14,13 +14,13 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
len_match_variants.extend(generate_match_variant_for_len(menu));
|
||||
|
||||
// this part is only used to generate `Player::is_hotbar_slot`
|
||||
if menu.name.to_string() == "Player" {
|
||||
if menu.name == "Player" {
|
||||
let mut i = 0;
|
||||
for field in &menu.fields {
|
||||
let field_name = &field.name;
|
||||
let start = i;
|
||||
i += field.length;
|
||||
if field_name.to_string() == "inventory" {
|
||||
if field_name == "inventory" {
|
||||
hotbar_slot_start = start;
|
||||
// it only adds 8 here since it's inclusive (there's 9
|
||||
// total hotbar slots)
|
||||
|
@ -35,7 +35,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
impl Player {
|
||||
/// Returns whether the given protocol index is in the player's hotbar.
|
||||
pub fn is_hotbar_slot(i: usize) -> bool {
|
||||
i >= #hotbar_slot_start && i <= #hotbar_slot_end
|
||||
(#hotbar_slot_start..=#hotbar_slot_end).contains(&i)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
pub fn len(&self) -> usize {
|
||||
match self {
|
||||
#len_match_variants
|
||||
|
@ -126,7 +127,7 @@ fn generate_matcher(menu: &Menu, match_arms: &TokenStream, needs_fields: bool) -
|
|||
quote! { .. }
|
||||
};
|
||||
|
||||
let matcher = if menu.name.to_string() == "Player" {
|
||||
let matcher = if menu.name == "Player" {
|
||||
quote! { (Player { #menu_field_names }) }
|
||||
} else {
|
||||
quote! { { #menu_field_names } }
|
||||
|
|
|
@ -61,20 +61,18 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
|
|||
let block_state = chunk_storage.get_block_state(block_pos).unwrap_or_default();
|
||||
// TODO: add fluid stuff to this (see getFluidState in vanilla source)
|
||||
let block_shape = context.block_shape(block_state);
|
||||
let block_hit_result = clip_with_interaction_override(
|
||||
clip_with_interaction_override(
|
||||
&context.from,
|
||||
&context.to,
|
||||
block_pos,
|
||||
block_shape,
|
||||
&block_state,
|
||||
);
|
||||
// let block_distance = if let Some(block_hit_result) = block_hit_result {
|
||||
// context.from.distance_to_sqr(&block_hit_result.location)
|
||||
// } else {
|
||||
)
|
||||
// let block_distance = if let Some(block_hit_result) =
|
||||
// block_hit_result { context.from.distance_to_sqr(&
|
||||
// block_hit_result.location) } else {
|
||||
// f64::MAX
|
||||
// };
|
||||
|
||||
block_hit_result
|
||||
},
|
||||
|context| {
|
||||
let vec = context.from - context.to;
|
||||
|
|
|
@ -415,7 +415,7 @@ impl VoxelShape {
|
|||
miss: false,
|
||||
})
|
||||
} else {
|
||||
AABB::clip_iterable(&self.to_aabbs(), &from, &to, &block_pos)
|
||||
AABB::clip_iterable(&self.to_aabbs(), from, to, block_pos)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ fn remove_despawned_entities_from_indexes(
|
|||
|
||||
pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) {
|
||||
for mut look_direction in &mut query {
|
||||
look_direction.y_rot = look_direction.y_rot % 360.0;
|
||||
look_direction.y_rot %= 360.0;
|
||||
look_direction.x_rot = look_direction.x_rot.clamp(-90.0, 90.0) % 360.0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue