1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

fix warnings

This commit is contained in:
Ubuntu 2023-01-10 18:05:38 +00:00
parent a928d83ade
commit f02db24e8c
13 changed files with 83 additions and 135 deletions

View file

@ -111,6 +111,7 @@ impl Client {
last_seen_messages: LastSeenMessagesUpdate::default(),
}
.get();
self.write_packet(packet);
}
/// Send a command packet to the server. The `command` argument should not

View file

@ -32,26 +32,15 @@ use azalea_protocol::{
use azalea_world::{entity::Entity, EntityInfos, PartialWorld, World, WorldContainer};
use bevy_app::App;
use bevy_ecs::{
query::{QueryState, ROQueryItem, WorldQuery},
query::WorldQuery,
schedule::{IntoSystemDescriptor, Schedule, Stage, SystemSet},
};
use iyes_loopless::prelude::*;
use log::{debug, error, warn};
use parking_lot::{Mutex, MutexGuard, RwLock};
use std::{
fmt::Debug,
io::{self},
marker::PhantomData,
ops::{Deref, DerefMut},
sync::Arc,
time::Duration,
};
use log::{debug, error};
use parking_lot::{Mutex, RwLock};
use std::{fmt::Debug, io, ops::DerefMut, sync::Arc, time::Duration};
use thiserror::Error;
use tokio::{
sync::mpsc::{self, Receiver},
task::JoinHandle,
time::{self},
};
use tokio::{sync::mpsc, time};
pub type ClientInformation = ServerboundClientInformationPacket;
@ -107,9 +96,6 @@ pub struct Client {
pub ecs: Arc<Mutex<bevy_ecs::world::World>>,
}
/// Whether we should ignore errors when decoding packets.
const IGNORE_ERRORS: bool = !cfg!(debug_assertions);
/// An error that happened while joining the server.
#[derive(Error, Debug)]
pub enum JoinError {
@ -210,7 +196,7 @@ impl Client {
entity,
game_profile,
packet_writer_sender,
world.clone(),
world,
ecs.resource_mut::<EntityInfos>().deref_mut(),
tx,
);

View file

@ -1,20 +1,14 @@
use std::{
collections::HashMap,
io,
ops::{Deref, DerefMut},
sync::Arc,
};
use std::{collections::HashMap, io, sync::Arc};
use azalea_auth::game_profile::GameProfile;
use azalea_core::{ChunkPos, ResourceLocation};
use azalea_protocol::{connect::WriteConnection, packets::game::ServerboundGamePacket};
use azalea_protocol::packets::game::ServerboundGamePacket;
use azalea_world::{
entity::{self, Dead, Entity},
EntityInfos, PartialWorld, World, WorldContainer,
EntityInfos, PartialWorld, World,
};
use bevy_ecs::{component::Component, query::Added, system::Query};
use derive_more::{Deref, DerefMut};
use parking_lot::{Mutex, RwLock};
use parking_lot::RwLock;
use thiserror::Error;
use tokio::{sync::mpsc, task::JoinHandle};
use uuid::Uuid;
@ -136,7 +130,7 @@ pub fn update_in_loaded_chunk(
mut commands: bevy_ecs::system::Commands,
query: Query<(Entity, &LocalPlayer, &entity::Position)>,
) {
for (ecs_entity_id, local_player, position) in &query {
for (entity, local_player, position) in &query {
let player_chunk_pos = ChunkPos::from(position);
let in_loaded_chunk = local_player
.world
@ -145,13 +139,9 @@ pub fn update_in_loaded_chunk(
.get(&player_chunk_pos)
.is_some();
if in_loaded_chunk {
commands
.entity(ecs_entity_id)
.insert(LocalPlayerInLoadedChunk);
commands.entity(entity).insert(LocalPlayerInLoadedChunk);
} else {
commands
.entity(ecs_entity_id)
.remove::<LocalPlayerInLoadedChunk>();
commands.entity(entity).remove::<LocalPlayerInLoadedChunk>();
}
}
}
@ -159,7 +149,7 @@ pub fn update_in_loaded_chunk(
/// Send the "Death" event for [`LocalPlayer`]s that died with no reason.
pub fn death_event(query: Query<&LocalPlayer, Added<Dead>>) {
for local_player in &query {
local_player.tx.send(Event::Death(None));
local_player.tx.send(Event::Death(None)).unwrap();
}
}

View file

@ -7,7 +7,7 @@ use azalea_protocol::packets::game::{
serverbound_move_player_rot_packet::ServerboundMovePlayerRotPacket,
serverbound_move_player_status_only_packet::ServerboundMovePlayerStatusOnlyPacket,
};
use azalea_world::entity::{Entity, MinecraftEntityId};
use azalea_world::entity::MinecraftEntityId;
use azalea_world::{entity, MoveEntityError};
use bevy_ecs::system::Query;
use std::backtrace::Backtrace;
@ -65,7 +65,6 @@ impl Client {
pub(crate) fn send_position(
mut query: Query<
(
Entity,
&MinecraftEntityId,
&mut LocalPlayer,
&entity::Position,
@ -76,10 +75,10 @@ pub(crate) fn send_position(
&LocalPlayerInLoadedChunk,
>,
) {
for (entity, id, mut local_player, position, mut last_sent_position, mut physics, sprinting) in
for (id, mut local_player, position, mut last_sent_position, mut physics, sprinting) in
query.iter_mut()
{
local_player.send_sprinting_if_needed(entity.into(), id, sprinting);
local_player.send_sprinting_if_needed(id, sprinting);
let packet = {
// TODO: the camera being able to be controlled by other entities isn't
@ -169,7 +168,6 @@ pub(crate) fn send_position(
impl LocalPlayer {
fn send_sprinting_if_needed(
&mut self,
entity: Entity,
id: &MinecraftEntityId,
sprinting: &entity::metadata::Sprinting,
) {
@ -311,7 +309,6 @@ impl LocalPlayer {
pub fn local_player_ai_step(
mut query: Query<
(
Entity,
&mut LocalPlayer,
&mut entity::Physics,
&mut entity::Position,
@ -321,14 +318,8 @@ pub fn local_player_ai_step(
&LocalPlayerInLoadedChunk,
>,
) {
for (
ecs_entity_id,
mut local_player,
mut physics,
mut position,
mut sprinting,
mut attributes,
) in query.iter_mut()
for (mut local_player, mut physics, mut position, mut sprinting, mut attributes) in
query.iter_mut()
{
let physics_state = &mut local_player.physics_state;

View file

@ -27,7 +27,6 @@ use bevy_ecs::{
schedule::{IntoSystemDescriptor, SystemSet},
system::{Commands, Query, ResMut},
};
use iyes_loopless::prelude::*;
use log::{debug, error, trace, warn};
use parking_lot::Mutex;
use tokio::sync::mpsc;
@ -83,7 +82,7 @@ fn handle_packet(
packet: &ClientboundGamePacket,
) {
match packet {
ClientboundGamePacket::Login(p) => {
ClientboundGamePacket::Login(_p) => {
// handled by the handle_login_packet system
}
ClientboundGamePacket::SetChunkCacheRadius(p) => {
@ -110,8 +109,8 @@ fn handle_packet(
ClientboundGamePacket::Disconnect(p) => {
debug!("Got disconnect packet {:?}", p);
let (mut local_player,) = ecs
.query::<(&mut LocalPlayer,)>()
let local_player = ecs
.query::<&mut LocalPlayer>()
.get_mut(ecs, player_entity)
.unwrap();
@ -230,7 +229,7 @@ fn handle_packet(
local_player
.players
.insert(updated_info.profile.uuid, player_info.clone());
local_player.tx.send(Event::AddPlayer(player_info));
local_player.tx.send(Event::AddPlayer(player_info)).unwrap();
} else if let Some(info) = local_player.players.get_mut(&updated_info.profile.uuid)
{
// `else if` because the block for add_player above
@ -245,7 +244,7 @@ fn handle_packet(
info.display_name = updated_info.display_name.clone();
}
let info = info.clone();
local_player.tx.send(Event::UpdatePlayer(info));
local_player.tx.send(Event::UpdatePlayer(info)).unwrap();
} else {
warn!(
"Ignoring PlayerInfoUpdate for unknown player {}",
@ -262,17 +261,14 @@ fn handle_packet(
for uuid in &p.profile_ids {
if let Some(info) = local_player.players.remove(uuid) {
local_player.tx.send(Event::RemovePlayer(info));
local_player.tx.send(Event::RemovePlayer(info)).unwrap();
}
}
}
ClientboundGamePacket::SetChunkCacheCenter(p) => {
debug!("Got chunk cache center packet {:?}", p);
let mut local_player = ecs
.query::<&mut LocalPlayer>()
.get(ecs, player_entity)
.unwrap();
let local_player = ecs.query::<&LocalPlayer>().get(ecs, player_entity).unwrap();
let mut partial_world = local_player.partial_world.write();
partial_world.chunks.view_center = ChunkPos::new(p.x, p.z);
@ -281,10 +277,7 @@ fn handle_packet(
// debug!("Got chunk with light packet {} {}", p.x, p.z);
let pos = ChunkPos::new(p.x, p.z);
let mut local_player = ecs
.query::<&mut LocalPlayer>()
.get(ecs, player_entity)
.unwrap();
let local_player = ecs.query::<&LocalPlayer>().get(ecs, player_entity).unwrap();
let world = local_player.world.read();
let partial_world = local_player.partial_world.read();
@ -347,7 +340,9 @@ fn handle_packet(
if let Some(entity) = entity {
let mut entity_mut = ecs.entity_mut(entity);
apply_metadata(&mut entity_mut, (*p.packed_items).clone());
if let Err(e) = apply_metadata(&mut entity_mut, (*p.packed_items).clone()) {
warn!("{e}");
}
} else {
warn!("Server sent an entity data packet for an entity id ({}) that we don't know about", p.id);
}
@ -484,26 +479,22 @@ fn handle_packet(
ClientboundGamePacket::PlayerChat(p) => {
debug!("Got player chat packet {:?}", p);
let mut local_player = ecs
.query::<&mut LocalPlayer>()
.get(ecs, player_entity)
.unwrap();
let local_player = ecs.query::<&LocalPlayer>().get(ecs, player_entity).unwrap();
local_player
.tx
.send(Event::Chat(ChatPacket::Player(Arc::new(p.clone()))));
.send(Event::Chat(ChatPacket::Player(Arc::new(p.clone()))))
.unwrap();
}
ClientboundGamePacket::SystemChat(p) => {
debug!("Got system chat packet {:?}", p);
let mut local_player = ecs
.query::<&mut LocalPlayer>()
.get(ecs, player_entity)
.unwrap();
let local_player = ecs.query::<&LocalPlayer>().get(ecs, player_entity).unwrap();
local_player
.tx
.send(Event::Chat(ChatPacket::System(Arc::new(p.clone()))));
.send(Event::Chat(ChatPacket::System(Arc::new(p.clone()))))
.unwrap();
}
ClientboundGamePacket::Sound(_p) => {
// debug!("Got sound packet {:?}", p);
@ -514,11 +505,8 @@ fn handle_packet(
ClientboundGamePacket::BlockUpdate(p) => {
debug!("Got block update packet {:?}", p);
let mut local_player = ecs
.query::<&mut LocalPlayer>()
.get(ecs, player_entity)
.unwrap();
let mut world = local_player.world.write();
let local_player = ecs.query::<&LocalPlayer>().get(ecs, player_entity).unwrap();
let world = local_player.world.write();
world.chunks.set_block_state(&p.pos, p.block_state);
}
@ -527,11 +515,8 @@ fn handle_packet(
}
ClientboundGamePacket::SectionBlocksUpdate(p) => {
debug!("Got section blocks update packet {:?}", p);
let mut local_player = ecs
.query::<&mut LocalPlayer>()
.get(ecs, player_entity)
.unwrap();
let mut world = local_player.world.write();
let local_player = ecs.query::<&LocalPlayer>().get(ecs, player_entity).unwrap();
let world = local_player.world.write();
for state in &p.states {
world
@ -587,18 +572,17 @@ fn handle_packet(
.get(ecs, player_entity)
.unwrap();
if *entity_id == p.player_id {
if dead.is_none() {
ecs.entity_mut(player_entity).insert(Dead);
if *entity_id == p.player_id && dead.is_none() {
ecs.entity_mut(player_entity).insert(Dead);
let local_player = ecs
.query::<&mut LocalPlayer>()
.get_mut(ecs, player_entity)
.unwrap();
local_player
.tx
.send(Event::Death(Some(Arc::new(p.clone()))));
}
let local_player = ecs
.query::<&mut LocalPlayer>()
.get_mut(ecs, player_entity)
.unwrap();
local_player
.tx
.send(Event::Death(Some(Arc::new(p.clone()))))
.unwrap();
}
}
ClientboundGamePacket::PlayerLookAt(_) => {}
@ -711,15 +695,15 @@ fn handle_login_packet(
let weak_world = world_container.insert(world_name.clone(), height, min_y);
// set the partial_world to an empty world
// (when we add chunks or entities those will be in the world_container)
let mut partial_world_lock = local_player.partial_world.write();
*partial_world_lock = PartialWorld::new(
*local_player.partial_world.write() = PartialWorld::new(
local_player.client_information.view_distance.into(),
// this argument makes it so other clients don't update this player entity
// in a shared world
Some(player_entity),
&mut entity_infos,
);
local_player.world = weak_world;
let player_bundle = PlayerBundle {
entity: EntityBundle::new(
@ -755,7 +739,7 @@ fn handle_login_packet(
.get(),
);
local_player.tx.send(Event::Login);
local_player.tx.send(Event::Login).unwrap();
}
}
}

View file

@ -6,7 +6,7 @@ use azalea_world::{Chunk, World};
use parking_lot::RwLock;
use std::sync::Arc;
pub fn get_block_collisions<'a>(world: &'a World, aabb: AABB) -> BlockCollisions<'a> {
pub fn get_block_collisions(world: &World, aabb: AABB) -> BlockCollisions<'_> {
BlockCollisions::new(world, aabb)
}

View file

@ -2,7 +2,7 @@ use azalea_buf::McBuf;
use azalea_core::{ResourceLocation, Vec3};
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::EntityKind;
use azalea_world::entity::{metadata::PlayerMetadataBundle, Dead, EntityBundle, PlayerBundle};
use azalea_world::entity::{metadata::PlayerMetadataBundle, EntityBundle, PlayerBundle};
use uuid::Uuid;
/// This packet is sent by the server when a player comes into visible range,

View file

@ -32,11 +32,7 @@ impl EntityDimensions {
/// Cached position in the world must be updated.
pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed<Position>>) {
for (position, mut physics) in query.iter_mut() {
let bounding_box = physics.dimensions.make_bounding_box(&position);
let bounding_box = physics.dimensions.make_bounding_box(position);
physics.bounding_box = bounding_box;
}
}
pub fn make_bounding_box(pos: &Position, physics: &Physics) -> AABB {
physics.dimensions.make_bounding_box(&pos)
}

View file

@ -1,3 +1,5 @@
#![allow(clippy::single_match)]
// This file is generated from codegen/lib/code/entity.py.
// Don't change it manually!

View file

@ -1,3 +1,5 @@
#![allow(clippy::derive_hash_xor_eq)]
pub mod attributes;
mod data;
mod dimensions;
@ -5,17 +7,14 @@ pub mod metadata;
use crate::ChunkStorage;
use self::{
attributes::AttributeInstance,
metadata::{Health, UpdateMetadataError},
};
use self::{attributes::AttributeInstance, metadata::Health};
pub use attributes::Attributes;
use azalea_block::BlockState;
use azalea_core::{BlockPos, ChunkPos, ResourceLocation, Vec3, AABB};
use bevy_ecs::{
bundle::Bundle,
component::Component,
query::{Changed, Without},
query::Changed,
system::{Commands, Query},
};
pub use data::*;
@ -43,7 +42,6 @@ impl std::hash::Hash for MinecraftEntityId {
}
}
impl nohash_hasher::IsEnabled for MinecraftEntityId {}
pub fn set_rotation(physics: &mut Physics, y_rot: f32, x_rot: f32) {
physics.y_rot = y_rot % 360.0;
physics.x_rot = x_rot.clamp(-90.0, 90.0) % 360.0;

View file

@ -3,7 +3,7 @@ use crate::{
MaybeRemovedEntity, World, WorldContainer,
};
use azalea_core::ChunkPos;
use bevy_app::{App, CoreStage, Plugin};
use bevy_app::{App, Plugin};
use bevy_ecs::{
query::Changed,
schedule::SystemSet,
@ -120,7 +120,7 @@ impl PartialEntityInfos {
return true;
};
let this_client_updates_received = self.updates_received.get(&id).copied();
let this_client_updates_received = self.updates_received.get(id).copied();
let shared_updates_received = entity_infos.updates_received.get(&entity).copied();
@ -187,8 +187,17 @@ impl EntityInfos {
warn!("Tried to remove entity but it was not found.");
return false;
}
if world.entities_by_chunk.remove(&chunk).is_none() {
warn!("Tried to remove entity from chunk {chunk:?} but it was not found.");
if let Some(entities_in_chunk) = world.entities_by_chunk.get_mut(&chunk) {
if entities_in_chunk.remove(&entity) {
// remove the chunk if there's no entities in it anymore
if entities_in_chunk.is_empty() {
world.entities_by_chunk.remove(&chunk);
}
} else {
warn!("Tried to remove entity from chunk {chunk:?} but the entity was not there.");
}
} else {
warn!("Tried to remove entity from chunk {chunk:?} but the chunk was not found.");
}
if self.entity_by_uuid.remove(&uuid).is_none() {
warn!("Tried to remove entity from uuid {uuid:?} but it was not found.");
@ -236,7 +245,7 @@ fn update_entity_chunk_positions(
world_container: Res<WorldContainer>,
) {
for (entity, pos, last_pos, world_name) in query.iter_mut() {
let world_lock = world_container.get(&**world_name).unwrap();
let world_lock = world_container.get(world_name).unwrap();
let mut world = world_lock.write();
let old_chunk = ChunkPos::from(*last_pos);
@ -280,16 +289,6 @@ pub fn remove_despawned_entities_from_indexes(
}
}
/// Remove a chunk from the storage if the entities in it have no strong
/// references left.
pub fn remove_chunk_if_unused(world: &mut World, chunk: &ChunkPos) {
if let Some(entities) = world.entities_by_chunk.get(chunk) {
if entities.is_empty() {
world.entities_by_chunk.remove(chunk);
}
}
}
impl Debug for EntityInfos {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EntityInfos").finish()

View file

@ -1,9 +1,8 @@
use crate::{
entity::{self, Entity, MinecraftEntityId, WorldName},
Chunk, ChunkStorage, EntityInfos, MoveEntityError, PartialChunkStorage, PartialEntityInfos,
WorldContainer,
ChunkStorage, EntityInfos, PartialChunkStorage, PartialEntityInfos, WorldContainer,
};
use azalea_core::{ChunkPos, PositionDelta8};
use azalea_core::ChunkPos;
use bevy_ecs::{
component::Component,
system::{Commands, Query},
@ -116,7 +115,7 @@ pub fn clear_entities_in_chunk(
if let Some(entities) = world.entities_by_chunk.get(chunk).cloned() {
for &entity in &entities {
let id = query.get(entity).unwrap();
if partial_entity_infos.loaded_entity_ids.remove(&id) {
if partial_entity_infos.loaded_entity_ids.remove(id) {
// maybe remove it from the storage
commands.entity(entity).insert(MaybeRemovedEntity);
}

View file

@ -37,7 +37,9 @@ def generate_entity_metadata(burger_entity_data: dict, mappings: Mappings):
]
code = []
code.append('''// This file is generated from codegen/lib/code/entity.py.
code.append('''#![allow(clippy::single_match)]
// This file is generated from codegen/lib/code/entity.py.
// Don't change it manually!
use super::{EntityDataItem, EntityDataValue, OptionalUnsignedInt, Pose, Rotations, VillagerData};