aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/client_impl
diff options
context:
space:
mode:
Diffstat (limited to 'azalea/src/client_impl')
-rw-r--r--azalea/src/client_impl/entity_query.rs54
-rw-r--r--azalea/src/client_impl/mod.rs47
2 files changed, 45 insertions, 56 deletions
diff --git a/azalea/src/client_impl/entity_query.rs b/azalea/src/client_impl/entity_query.rs
index 44fbe9e8..27c3aa9a 100644
--- a/azalea/src/client_impl/entity_query.rs
+++ b/azalea/src/client_impl/entity_query.rs
@@ -2,7 +2,7 @@ use std::{any, sync::Arc};
use azalea_core::position::Vec3;
use azalea_entity::Position;
-use azalea_world::InstanceName;
+use azalea_world::WorldName;
use bevy_ecs::{
component::Component,
entity::Entity,
@@ -44,9 +44,9 @@ impl Client {
/// # Examples
///
/// ```
- /// # use azalea_world::InstanceName;
+ /// # use azalea_world::WorldName;
/// # fn example(client: &azalea::Client) {
- /// let world_name = client.component::<InstanceName>();
+ /// let world_name = client.component::<WorldName>();
/// # }
pub fn component<T: Component>(&self) -> MappedRwLockReadGuard<'_, T> {
self.get_component::<T>().unwrap_or_else(|| {
@@ -150,9 +150,9 @@ impl Client {
/// Quickly returns an [`EntityRef`] for an arbitrary entity that
/// matches the given predicate function that is in the same
- /// [`Instance`] as the client.
+ /// [`World`] as the client.
///
- /// [`Instance`]: azalea_world::Instance
+ /// [`World`]: azalea_world::World
pub fn any_entity_by<Q: QueryData, F: QueryFilter>(
&self,
predicate: impl EntityPredicate<Q, F>,
@@ -162,7 +162,7 @@ impl Client {
}
/// Quickly returns a lightweight [`Entity`] for an arbitrary entity that
/// matches the given predicate function that is in the same
- /// [`Instance`] as the client.
+ /// [`World`] as the client.
///
/// To get an [`EntityRef`], consider using [`Self::any_entity_by`]
/// instead.
@@ -184,13 +184,13 @@ impl Client {
/// # }
/// ```
///
- /// [`Instance`]: azalea_world::Instance
+ /// [`World`]: azalea_world::World
pub fn any_entity_id_by<Q: QueryData, F: QueryFilter>(
&self,
predicate: impl EntityPredicate<Q, F>,
) -> Option<Entity> {
- let instance_name = self.get_component::<InstanceName>()?.clone();
- predicate.find_any(self.ecs.clone(), &instance_name)
+ let world_name = self.get_component::<WorldName>()?.clone();
+ predicate.find_any(self.ecs.clone(), &world_name)
}
/// Return an [`EntityRef`] for the nearest entity that matches the
@@ -225,7 +225,7 @@ impl Client {
self.nearest_entity_ids_by(predicate).first().copied()
}
- /// Returns an array of all [`EntityRef`]s in the instance that match the
+ /// Returns an array of all [`EntityRef`]s in the world that match the
/// predicate, sorted by nearest first.
///
/// To only get the nearest entity, consider using
@@ -240,7 +240,7 @@ impl Client {
.map(|e| self.entity_ref_for(e))
.collect()
}
- /// Returns an array of all [`Entity`]s in the instance that match the
+ /// Returns an array of all [`Entity`]s in the world that match the
/// predicate, sorted by nearest first.
///
/// To only get the nearest entity, consider using
@@ -259,18 +259,18 @@ impl Client {
&self,
predicate: impl EntityPredicate<Q, F>,
) -> Box<[Entity]> {
- let (instance_name, position) = {
- let Some(instance_name) = self.get_component::<InstanceName>() else {
+ let (world_name, position) = {
+ let Some(world_name) = self.get_component::<WorldName>() else {
return Box::new([]);
};
let Some(position) = self.get_component::<Position>() else {
return Box::new([]);
};
- (instance_name.clone(), **position)
+ (world_name.clone(), **position)
};
- predicate.find_all_sorted(self.ecs.clone(), &instance_name, position)
+ predicate.find_all_sorted(self.ecs.clone(), &world_name, position)
}
/// Get a component from an entity.
@@ -316,15 +316,11 @@ impl Client {
}
pub trait EntityPredicate<Q: QueryData, Filter: QueryFilter> {
- fn find_any(
- &self,
- ecs_lock: Arc<RwLock<World>>,
- instance_name: &InstanceName,
- ) -> Option<Entity>;
+ fn find_any(&self, ecs_lock: Arc<RwLock<World>>, world_name: &WorldName) -> Option<Entity>;
fn find_all_sorted(
&self,
ecs_lock: Arc<RwLock<World>>,
- instance_name: &InstanceName,
+ world_name: &WorldName,
nearest_to: Vec3,
) -> Box<[Entity]>;
}
@@ -333,30 +329,26 @@ where
F: Fn(ROQueryItem<Q>) -> bool,
for<'w, 's> <<Q as QueryData>::ReadOnly as QueryData>::Item<'w, 's>: Copy,
{
- fn find_any(
- &self,
- ecs_lock: Arc<RwLock<World>>,
- instance_name: &InstanceName,
- ) -> Option<Entity> {
+ fn find_any(&self, ecs_lock: Arc<RwLock<World>>, world_name: &WorldName) -> Option<Entity> {
let mut ecs = ecs_lock.write();
- let mut query = ecs.query_filtered::<(Entity, &InstanceName, Q), Filter>();
+ let mut query = ecs.query_filtered::<(Entity, &WorldName, Q), Filter>();
query
.iter(&ecs)
- .find(|(_, e_instance_name, q)| *e_instance_name == instance_name && (self)(*q))
+ .find(|(_, e_world_name, q)| *e_world_name == world_name && (self)(*q))
.map(|(e, _, _)| e)
}
fn find_all_sorted(
&self,
ecs_lock: Arc<RwLock<World>>,
- instance_name: &InstanceName,
+ world_name: &WorldName,
nearest_to: Vec3,
) -> Box<[Entity]> {
let mut ecs = ecs_lock.write();
- let mut query = ecs.query_filtered::<(Entity, &InstanceName, &Position, Q), Filter>();
+ let mut query = ecs.query_filtered::<(Entity, &WorldName, &Position, Q), Filter>();
let mut entities = query
.iter(&ecs)
- .filter(|(_, e_instance_name, _, q)| *e_instance_name == instance_name && (self)(*q))
+ .filter(|(_, e_world_name, _, q)| *e_world_name == world_name && (self)(*q))
.map(|(e, _, position, _)| (e, Vec3::from(position)))
.collect::<Vec<(Entity, Vec3)>>();
diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs
index f884898f..d55e5a38 100644
--- a/azalea/src/client_impl/mod.rs
+++ b/azalea/src/client_impl/mod.rs
@@ -7,7 +7,7 @@ use azalea_client::{
connection::RawConnection,
disconnect::DisconnectEvent,
join::{ConnectOpts, StartJoinServerEvent},
- local_player::{Hunger, InstanceHolder, TabList},
+ local_player::{Hunger, TabList, WorldHolder},
packet::game::SendGamePacketEvent,
player::{GameProfileComponent, PlayerInfo},
start_ecs_runner,
@@ -25,13 +25,9 @@ use azalea_protocol::{
resolve::ResolveError,
};
use azalea_registry::{DataRegistryKeyRef, identifier::Identifier};
-use azalea_world::{Instance, InstanceName, PartialInstance};
+use azalea_world::{PartialWorld, World, WorldName};
use bevy_app::App;
-use bevy_ecs::{
- entity::Entity,
- resource::Resource,
- world::{Mut, World},
-};
+use bevy_ecs::{entity::Entity, resource::Resource, world::Mut};
use parking_lot::RwLock;
use tokio::sync::mpsc;
use uuid::Uuid;
@@ -67,17 +63,17 @@ pub struct Client {
/// A mutually exclusive reference to the entity component system (ECS).
///
/// You probably don't need to access this directly. Note that if you're
- /// using a shared world (i.e. a swarm), the ECS will contain all entities
- /// in all instances/dimensions.
+ /// using a shared world (i.e. a swarm), the ECS will also contain all
+ /// entities in all worlds.
///
/// You can nearly always use [`Self::component`], [`Self::query_self`],
/// [`Self::query_entity`], or another one of those related functions to
/// access the ECS instead.
- pub ecs: Arc<RwLock<World>>,
+ pub ecs: Arc<RwLock<bevy_ecs::world::World>>,
}
pub struct StartClientOpts {
- pub ecs_lock: Arc<RwLock<World>>,
+ pub ecs_lock: Arc<RwLock<bevy_ecs::world::World>>,
pub account: Account,
pub connect_opts: ConnectOpts,
pub event_sender: Option<mpsc::UnboundedSender<Event>>,
@@ -144,7 +140,7 @@ impl Client {
/// World, and schedule runner function.
/// You should only use this if you want to change these fields from the
/// defaults, otherwise use [`Client::join`].
- pub fn new(entity: Entity, ecs: Arc<RwLock<World>>) -> Self {
+ pub fn new(entity: Entity, ecs: Arc<RwLock<bevy_ecs::world::World>>) -> Self {
Self {
// default our id to 0, it'll be set later
entity,
@@ -278,15 +274,16 @@ impl Client {
f(value)
}
- /// Get an `RwLock` with a reference to our (potentially shared) world.
+ /// Get an `RwLock` with a reference to our (potentially shared) Minecraft
+ /// world.
///
- /// This gets the [`Instance`] from the client's [`InstanceHolder`]
+ /// This gets the [`World`] from the client's [`WorldHolder`]
/// component. If it's a normal client, then it'll be the same as the
/// world the client has loaded. If the client is using a shared world,
/// then the shared world will be a superset of the client's world.
- pub fn world(&self) -> Arc<RwLock<Instance>> {
- let instance_holder = self.component::<InstanceHolder>();
- instance_holder.instance.clone()
+ pub fn world(&self) -> Arc<RwLock<World>> {
+ let world_holder = self.component::<WorldHolder>();
+ world_holder.shared.clone()
}
/// Get an `RwLock` with a reference to the world that this client has
@@ -298,15 +295,15 @@ impl Client {
/// let world = client.partial_world();
/// let is_0_0_loaded = world.read().chunks.limited_get(&ChunkPos::new(0, 0)).is_some();
/// # }
- pub fn partial_world(&self) -> Arc<RwLock<PartialInstance>> {
- let instance_holder = self.component::<InstanceHolder>();
- instance_holder.partial_instance.clone()
+ pub fn partial_world(&self) -> Arc<RwLock<PartialWorld>> {
+ let world_holder = self.component::<WorldHolder>();
+ world_holder.partial.clone()
}
/// Returns whether we have a received the login packet yet.
pub fn logged_in(&self) -> bool {
// the login packet tells us the world name
- self.query_self::<Option<&InstanceName>, _>(|ins| ins.is_some())
+ self.query_self::<Option<&WorldName>, _>(|ins| ins.is_some())
}
/// Returns the client as an [`EntityRef`], allowing you to treat it as any
@@ -409,8 +406,8 @@ impl Client {
/// Call the given function with the client's [`RegistryHolder`].
///
- /// The player's instance (aka world) will be locked during this time, which
- /// may result in a deadlock if you try to access the instance again while
+ /// Note that the player's world will be locked during this time, which may
+ /// result in a deadlock if you try to access the world again while
/// in the function.
///
/// [`RegistryHolder`]: azalea_core::registry_holder::RegistryHolder
@@ -418,8 +415,8 @@ impl Client {
&self,
f: impl FnOnce(&azalea_core::registry_holder::RegistryHolder) -> R,
) -> R {
- let instance = self.world();
- let registries = &instance.read().registries;
+ let world = self.world();
+ let registries = &world.read().registries;
f(registries)
}