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

rename Local to LocalEntity

This commit is contained in:
mat 2023-09-14 16:48:21 -05:00
parent dea4a656a5
commit 83784d5a35
14 changed files with 60 additions and 53 deletions

View file

@ -22,8 +22,8 @@ use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerE
use azalea_chat::FormattedText; use azalea_chat::FormattedText;
use azalea_core::Vec3; use azalea_core::Vec3;
use azalea_entity::{ use azalea_entity::{
indexing::EntityIdIndex, metadata::Health, EntityPlugin, EntityUpdateSet, EyeHeight, Local, indexing::EntityIdIndex, metadata::Health, EntityPlugin, EntityUpdateSet, EyeHeight,
Position, LocalEntity, Position,
}; };
use azalea_physics::PhysicsPlugin; use azalea_physics::PhysicsPlugin;
use azalea_protocol::{ use azalea_protocol::{
@ -316,7 +316,7 @@ impl Client {
mining: mining::MineBundle::default(), mining: mining::MineBundle::default(),
attack: attack::AttackBundle::default(), attack: attack::AttackBundle::default(),
_local: Local, _local: LocalEntity,
}); });
Ok((client, rx)) Ok((client, rx))
@ -584,7 +584,7 @@ impl Client {
} }
/// A bundle for the components that are present on a local player that received /// A bundle for the components that are present on a local player that received
/// a login packet. If you want to filter for this, just use [`Local`]. /// a login packet. If you want to filter for this, just use [`LocalEntity`].
#[derive(Bundle)] #[derive(Bundle)]
pub struct JoinedClientBundle { pub struct JoinedClientBundle {
pub local_player: LocalPlayer, pub local_player: LocalPlayer,
@ -606,7 +606,7 @@ pub struct JoinedClientBundle {
pub mining: mining::MineBundle, pub mining: mining::MineBundle,
pub attack: attack::AttackBundle, pub attack: attack::AttackBundle,
pub _local: Local, pub _local: LocalEntity,
} }
pub struct AzaleaPlugin; pub struct AzaleaPlugin;

View file

@ -3,7 +3,7 @@ use std::ops::AddAssign;
use azalea_block::BlockState; use azalea_block::BlockState;
use azalea_core::{BlockHitResult, BlockPos, Direction, GameMode, Vec3}; use azalea_core::{BlockHitResult, BlockPos, Direction, GameMode, Vec3};
use azalea_entity::{ use azalea_entity::{
clamp_look_direction, view_vector, Attributes, EyeHeight, Local, LookDirection, Position, clamp_look_direction, view_vector, Attributes, EyeHeight, LocalEntity, LookDirection, Position,
}; };
use azalea_inventory::{ItemSlot, ItemSlotData}; use azalea_inventory::{ItemSlot, ItemSlotData};
use azalea_nbt::NbtList; use azalea_nbt::NbtList;
@ -318,7 +318,7 @@ pub fn handle_swing_arm_event(
fn update_modifiers_for_held_item( fn update_modifiers_for_held_item(
mut query: Query< mut query: Query<
(&mut Attributes, &InventoryComponent), (&mut Attributes, &InventoryComponent),
(With<Local>, Changed<InventoryComponent>), (With<LocalEntity>, Changed<InventoryComponent>),
>, >,
) { ) {
for (mut attributes, inventory) in &mut query { for (mut attributes, inventory) in &mut query {

View file

@ -23,10 +23,11 @@ use crate::{
/// world. If you have access to a [`Client`], you probably don't need to care /// world. If you have access to a [`Client`], you probably don't need to care
/// about this since `Client` gives you access to everything here. /// about this since `Client` gives you access to everything here.
/// ///
/// You can also use the [`Local`] marker component for queries if you're only /// You can also use the [`LocalEntity`] marker component for queries if you're
/// checking for a local player and don't need the contents of this component. /// only checking for a local player and don't need the contents of this
/// component.
/// ///
/// [`Local`]: azalea_entity::Local /// [`LocalEntity`]: azalea_entity::LocalEntity
/// [`Client`]: crate::Client /// [`Client`]: crate::Client
#[derive(Component)] #[derive(Component)]
pub struct LocalPlayer { pub struct LocalPlayer {

View file

@ -709,11 +709,10 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::TeleportEntity(p) => { ClientboundGamePacket::TeleportEntity(p) => {
let mut system_state: SystemState<( let mut system_state: SystemState<(
Commands, Commands,
Query<(&EntityIdIndex, &LocalPlayer, Option<&mut Physics>)>, Query<(&EntityIdIndex, &LocalPlayer)>,
)> = SystemState::new(ecs); )> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs); let (mut commands, mut query) = system_state.get_mut(ecs);
let (entity_id_index, local_player, physics) = let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.id)); let entity = entity_id_index.get(&MinecraftEntityId(p.id));
@ -741,11 +740,10 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::MoveEntityPos(p) => { ClientboundGamePacket::MoveEntityPos(p) => {
let mut system_state: SystemState<( let mut system_state: SystemState<(
Commands, Commands,
Query<(&EntityIdIndex, &LocalPlayer, Option<&mut Physics>)>, Query<(&EntityIdIndex, &LocalPlayer)>,
)> = SystemState::new(ecs); )> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs); let (mut commands, mut query) = system_state.get_mut(ecs);
let (entity_id_index, local_player, physics) = let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id)); let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));
@ -770,11 +768,10 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::MoveEntityPosRot(p) => { ClientboundGamePacket::MoveEntityPosRot(p) => {
let mut system_state: SystemState<( let mut system_state: SystemState<(
Commands, Commands,
Query<(&EntityIdIndex, &LocalPlayer, Option<&mut Physics>)>, Query<(&EntityIdIndex, &LocalPlayer)>,
)> = SystemState::new(ecs); )> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs); let (mut commands, mut query) = system_state.get_mut(ecs);
let (entity_id_index, local_player, physics) = let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id)); let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));

View file

@ -354,7 +354,7 @@ pub struct PlayerBundle {
/// A marker component that signifies that this entity is "local" and shouldn't /// A marker component that signifies that this entity is "local" and shouldn't
/// be updated by other clients. /// be updated by other clients.
#[derive(Component)] #[derive(Component)]
pub struct Local; pub struct LocalEntity;
#[derive(Component, Clone, Debug, PartialEq, Deref, DerefMut)] #[derive(Component, Clone, Debug, PartialEq, Deref, DerefMut)]
pub struct FluidOnEyes(azalea_registry::Fluid); pub struct FluidOnEyes(azalea_registry::Fluid);

View file

@ -13,7 +13,7 @@ use nohash_hasher::IntMap;
use std::{collections::HashMap, fmt::Debug}; use std::{collections::HashMap, fmt::Debug};
use uuid::Uuid; use uuid::Uuid;
use crate::{EntityUuid, LastSentPosition, Local, Position}; use crate::{EntityUuid, LastSentPosition, LocalEntity, Position};
use super::LoadedBy; use super::LoadedBy;
@ -87,7 +87,7 @@ pub fn deduplicate_entities(
mut commands: Commands, mut commands: Commands,
mut query: Query< mut query: Query<
(Entity, &MinecraftEntityId, &InstanceName), (Entity, &MinecraftEntityId, &InstanceName),
(Changed<MinecraftEntityId>, Without<Local>), (Changed<MinecraftEntityId>, Without<LocalEntity>),
>, >,
mut loaded_by_query: Query<&mut LoadedBy>, mut loaded_by_query: Query<&mut LoadedBy>,
mut entity_id_index_query: Query<&mut EntityIdIndex>, mut entity_id_index_query: Query<&mut EntityIdIndex>,
@ -141,7 +141,7 @@ pub fn deduplicate_local_entities(
mut commands: Commands, mut commands: Commands,
mut query: Query< mut query: Query<
(Entity, &MinecraftEntityId, &InstanceName), (Entity, &MinecraftEntityId, &InstanceName),
(Changed<MinecraftEntityId>, With<Local>), (Changed<MinecraftEntityId>, With<LocalEntity>),
>, >,
instance_container: Res<InstanceContainer>, instance_container: Res<InstanceContainer>,
) { ) {
@ -169,7 +169,7 @@ pub fn deduplicate_local_entities(
pub fn update_uuid_index( pub fn update_uuid_index(
mut entity_infos: ResMut<EntityUuidIndex>, mut entity_infos: ResMut<EntityUuidIndex>,
query: Query<(Entity, &EntityUuid, Option<&Local>), Changed<EntityUuid>>, query: Query<(Entity, &EntityUuid, Option<&LocalEntity>), Changed<EntityUuid>>,
) { ) {
for (entity, &uuid, local) in query.iter() { for (entity, &uuid, local) in query.iter() {
// only add it if it doesn't already exist in // only add it if it doesn't already exist in
@ -189,7 +189,12 @@ pub fn update_uuid_index(
/// System to keep the entity_by_id index up-to-date. /// System to keep the entity_by_id index up-to-date.
pub fn update_entity_by_id_index( pub fn update_entity_by_id_index(
mut query: Query< mut query: Query<
(Entity, &MinecraftEntityId, &InstanceName, Option<&Local>), (
Entity,
&MinecraftEntityId,
&InstanceName,
Option<&LocalEntity>,
),
Changed<MinecraftEntityId>, Changed<MinecraftEntityId>,
>, >,
instance_container: Res<InstanceContainer>, instance_container: Res<InstanceContainer>,

View file

@ -5,13 +5,13 @@ use std::collections::HashSet;
use azalea_core::{BlockPos, ChunkPos, Vec3}; use azalea_core::{BlockPos, ChunkPos, Vec3};
use azalea_world::{InstanceContainer, InstanceName, MinecraftEntityId}; use azalea_world::{InstanceContainer, InstanceName, MinecraftEntityId};
use bevy_app::{App, FixedUpdate, Plugin, PostUpdate, PreUpdate, Update}; use bevy_app::{App, Plugin, PostUpdate, PreUpdate, Update};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use log::debug; use log::debug;
use crate::{ use crate::{
metadata::Health, Dead, EyeHeight, FluidOnEyes, Local, LookDirection, Physics, Position, metadata::Health, Dead, EyeHeight, FluidOnEyes, LocalEntity, LookDirection, Physics, Position,
}; };
use indexing::EntityUuidIndex; use indexing::EntityUuidIndex;
@ -73,7 +73,7 @@ impl Plugin for EntityPlugin {
} }
} }
fn debug_new_entity(query: Query<(Entity, Option<&Local>), Added<MinecraftEntityId>>) { fn debug_new_entity(query: Query<(Entity, Option<&LocalEntity>), Added<MinecraftEntityId>>) {
for (entity, local) in query.iter() { for (entity, local) in query.iter() {
if local.is_some() { if local.is_some() {
debug!("new local entity: {:?}", entity); debug!("new local entity: {:?}", entity);

View file

@ -28,7 +28,7 @@ use derive_more::{Deref, DerefMut};
use log::warn; use log::warn;
use parking_lot::RwLock; use parking_lot::RwLock;
use crate::Local; use crate::LocalEntity;
/// An [`EntityCommand`] that applies a "relative update" to an entity, which /// An [`EntityCommand`] that applies a "relative update" to an entity, which
/// means this update won't be run multiple times by different clients in the /// means this update won't be run multiple times by different clients in the
@ -69,7 +69,7 @@ impl EntityCommand for RelativeEntityUpdate {
}; };
let entity_id = *entity_mut.get::<MinecraftEntityId>().unwrap(); let entity_id = *entity_mut.get::<MinecraftEntityId>().unwrap();
if entity_mut.contains::<Local>() { if entity_mut.contains::<LocalEntity>() {
// a client tried to update another client, which isn't allowed // a client tried to update another client, which isn't allowed
return; return;
} }
@ -99,12 +99,15 @@ impl EntityCommand for RelativeEntityUpdate {
} }
} }
/// The [`UpdatesReceived`] component should never be on [`Local`] entities. /// The [`UpdatesReceived`] component should never be on [`LocalEntity`]
/// This warns if an entity has both components. /// entities. This warns if an entity has both components.
pub fn debug_detect_updates_received_on_local_entities( pub fn debug_detect_updates_received_on_local_entities(
query: Query<Entity, (With<Local>, With<UpdatesReceived>)>, query: Query<Entity, (With<LocalEntity>, With<UpdatesReceived>)>,
) { ) {
for entity in &query { for entity in &query {
warn!("Entity {:?} has both Local and UpdatesReceived", entity); warn!(
"Entity {:?} has both LocalEntity and UpdatesReceived",
entity
);
} }
} }

View file

@ -7,8 +7,8 @@ pub mod collision;
use azalea_block::{Block, BlockState}; use azalea_block::{Block, BlockState};
use azalea_core::{math, BlockPos, Vec3}; use azalea_core::{math, BlockPos, Vec3};
use azalea_entity::{ use azalea_entity::{
metadata::Sprinting, move_relative, Attributes, InLoadedChunk, Jumping, Local, LookDirection, metadata::Sprinting, move_relative, Attributes, InLoadedChunk, Jumping, LocalEntity,
Physics, Position, LookDirection, Physics, Position,
}; };
use azalea_world::{Instance, InstanceContainer, InstanceName}; use azalea_world::{Instance, InstanceContainer, InstanceName};
use bevy_app::{App, FixedUpdate, Plugin}; use bevy_app::{App, FixedUpdate, Plugin};
@ -49,7 +49,7 @@ fn travel(
&Attributes, &Attributes,
&InstanceName, &InstanceName,
), ),
(With<Local>, With<InLoadedChunk>), (With<LocalEntity>, With<InLoadedChunk>),
>, >,
instance_container: Res<InstanceContainer>, instance_container: Res<InstanceContainer>,
) { ) {
@ -132,7 +132,7 @@ pub fn ai_step(
&Sprinting, &Sprinting,
&InstanceName, &InstanceName,
), ),
(With<Local>, With<InLoadedChunk>), (With<LocalEntity>, With<InLoadedChunk>),
>, >,
instance_container: Res<InstanceContainer>, instance_container: Res<InstanceContainer>,
) { ) {
@ -378,7 +378,7 @@ mod tests {
ResourceLocation::new("minecraft:overworld"), ResourceLocation::new("minecraft:overworld"),
), ),
MinecraftEntityId(0), MinecraftEntityId(0),
Local, LocalEntity,
)) ))
.id(); .id();
{ {
@ -437,7 +437,7 @@ mod tests {
ResourceLocation::new("minecraft:overworld"), ResourceLocation::new("minecraft:overworld"),
), ),
MinecraftEntityId(0), MinecraftEntityId(0),
Local, LocalEntity,
)) ))
.id(); .id();
let block_state = partial_world.chunks.set_block_state( let block_state = partial_world.chunks.set_block_state(
@ -497,7 +497,7 @@ mod tests {
ResourceLocation::new("minecraft:overworld"), ResourceLocation::new("minecraft:overworld"),
), ),
MinecraftEntityId(0), MinecraftEntityId(0),
Local, LocalEntity,
)) ))
.id(); .id();
let block_state = partial_world.chunks.set_block_state( let block_state = partial_world.chunks.set_block_state(
@ -551,7 +551,7 @@ mod tests {
ResourceLocation::new("minecraft:overworld"), ResourceLocation::new("minecraft:overworld"),
), ),
MinecraftEntityId(0), MinecraftEntityId(0),
Local, LocalEntity,
)) ))
.id(); .id();
let block_state = world_lock.write().chunks.set_block_state( let block_state = world_lock.write().chunks.set_block_state(
@ -604,7 +604,7 @@ mod tests {
ResourceLocation::new("minecraft:overworld"), ResourceLocation::new("minecraft:overworld"),
), ),
MinecraftEntityId(0), MinecraftEntityId(0),
Local, LocalEntity,
)) ))
.id(); .id();
let block_state = world_lock.write().chunks.set_block_state( let block_state = world_lock.write().chunks.set_block_state(
@ -662,7 +662,7 @@ mod tests {
ResourceLocation::new("minecraft:overworld"), ResourceLocation::new("minecraft:overworld"),
), ),
MinecraftEntityId(0), MinecraftEntityId(0),
Local, LocalEntity,
)) ))
.id(); .id();
let block_state = world_lock.write().chunks.set_block_state( let block_state = world_lock.write().chunks.set_block_state(

View file

@ -3,7 +3,7 @@ use azalea::ClientBuilder;
use azalea::{Bot, LookAtEvent}; use azalea::{Bot, LookAtEvent};
use azalea_client::Account; use azalea_client::Account;
use azalea_entity::metadata::{ItemItem, Player}; use azalea_entity::metadata::{ItemItem, Player};
use azalea_entity::{EyeHeight, Local, Position}; use azalea_entity::{EyeHeight, LocalEntity, Position};
use bevy_app::{FixedUpdate, Plugin}; use bevy_app::{FixedUpdate, Plugin};
use bevy_ecs::{ use bevy_ecs::{
prelude::{Entity, EventWriter}, prelude::{Entity, EventWriter},
@ -30,7 +30,7 @@ impl Plugin for LookAtStuffPlugin {
} }
fn look_at_everything( fn look_at_everything(
bots: Query<Entity, (With<Local>, With<Player>)>, bots: Query<Entity, (With<LocalEntity>, With<Player>)>,
entities: EntityFinder, entities: EntityFinder,
entity_positions: Query<(&Position, Option<&EyeHeight>)>, entity_positions: Query<(&Position, Option<&EyeHeight>)>,
mut look_at_event: EventWriter<LookAtEvent>, mut look_at_event: EventWriter<LookAtEvent>,

View file

@ -13,7 +13,8 @@ use azalea_client::mining::Mining;
use azalea_client::TickBroadcast; use azalea_client::TickBroadcast;
use azalea_core::{BlockPos, Vec3}; use azalea_core::{BlockPos, Vec3};
use azalea_entity::{ use azalea_entity::{
clamp_look_direction, metadata::Player, EyeHeight, Jumping, Local, LookDirection, Position, clamp_look_direction, metadata::Player, EyeHeight, Jumping, LocalEntity, LookDirection,
Position,
}; };
use azalea_physics::PhysicsSet; use azalea_physics::PhysicsSet;
use bevy_app::{FixedUpdate, Update}; use bevy_app::{FixedUpdate, Update};
@ -52,7 +53,7 @@ pub struct Bot {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn insert_bot( fn insert_bot(
mut commands: Commands, mut commands: Commands,
mut query: Query<Entity, (Without<Bot>, With<Local>, With<Player>)>, mut query: Query<Entity, (Without<Bot>, With<LocalEntity>, With<Player>)>,
) { ) {
for entity in &mut query { for entity in &mut query {
commands.entity(entity).insert(Bot::default()); commands.entity(entity).insert(Bot::default());

View file

@ -18,14 +18,14 @@ use bevy_ecs::{
/// use azalea::chat::SendChatEvent; /// use azalea::chat::SendChatEvent;
/// use azalea::nearest_entity::EntityFinder; /// use azalea::nearest_entity::EntityFinder;
/// use azalea_entity::metadata::{Player, AbstractMonster}; /// use azalea_entity::metadata::{Player, AbstractMonster};
/// use azalea_entity::Local; /// use azalea_entity::LocalEntity;
/// use bevy_ecs::system::Query; /// use bevy_ecs::system::Query;
/// use bevy_ecs::prelude::{Entity, EventWriter}; /// use bevy_ecs::prelude::{Entity, EventWriter};
/// use bevy_ecs::query::With; /// use bevy_ecs::query::With;
/// ///
/// /// All bots near aggressive mobs will scream in chat. /// /// All bots near aggressive mobs will scream in chat.
/// pub fn bots_near_aggressive_mobs( /// pub fn bots_near_aggressive_mobs(
/// bots: Query<Entity, (With<Local>, With<Player>)>, /// bots: Query<Entity, (With<LocalEntity>, With<Player>)>,
/// entity_finder: EntityFinder<With<AbstractMonster>>, /// entity_finder: EntityFinder<With<AbstractMonster>>,
/// mut chat_events: EventWriter<SendChatEvent>, /// mut chat_events: EventWriter<SendChatEvent>,
/// ) { /// ) {

View file

@ -20,7 +20,7 @@ use azalea_client::movement::walk_listener;
use azalea_client::{StartSprintEvent, StartWalkEvent}; use azalea_client::{StartSprintEvent, StartWalkEvent};
use azalea_core::BlockPos; use azalea_core::BlockPos;
use azalea_entity::metadata::Player; use azalea_entity::metadata::Player;
use azalea_entity::Local; use azalea_entity::LocalEntity;
use azalea_entity::{Physics, Position}; use azalea_entity::{Physics, Position};
use azalea_physics::PhysicsSet; use azalea_physics::PhysicsSet;
use azalea_world::{InstanceContainer, InstanceName}; use azalea_world::{InstanceContainer, InstanceName};
@ -73,7 +73,7 @@ pub struct Pathfinder {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn add_default_pathfinder( fn add_default_pathfinder(
mut commands: Commands, mut commands: Commands,
mut query: Query<Entity, (Without<Pathfinder>, With<Local>, With<Player>)>, mut query: Query<Entity, (Without<Pathfinder>, With<LocalEntity>, With<Player>)>,
) { ) {
for entity in &mut query { for entity in &mut query {
commands.entity(entity).insert(Pathfinder::default()); commands.entity(entity).insert(Pathfinder::default());

View file

@ -83,7 +83,7 @@ impl Simulation {
.spawn(( .spawn((
MinecraftEntityId(0), MinecraftEntityId(0),
InstanceName(instance_name), InstanceName(instance_name),
azalea_entity::Local, azalea_entity::LocalEntity,
azalea_entity::Jumping::default(), azalea_entity::Jumping::default(),
azalea_entity::LookDirection::default(), azalea_entity::LookDirection::default(),
Sprinting(true), Sprinting(true),