aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/client.rs10
-rw-r--r--azalea-client/src/local_player.rs63
-rw-r--r--azalea-client/src/plugins/block_update.rs8
-rw-r--r--azalea-client/src/plugins/chunks.rs22
-rw-r--r--azalea-client/src/plugins/disconnect.rs6
-rw-r--r--azalea-client/src/plugins/interact/mod.rs12
-rw-r--r--azalea-client/src/plugins/interact/pick.rs12
-rw-r--r--azalea-client/src/plugins/inventory/equipment_effects.rs14
-rw-r--r--azalea-client/src/plugins/inventory/mod.rs12
-rw-r--r--azalea-client/src/plugins/join.rs11
-rw-r--r--azalea-client/src/plugins/mining.rs42
-rw-r--r--azalea-client/src/plugins/movement.rs18
-rw-r--r--azalea-client/src/plugins/packet/config/mod.rs10
-rw-r--r--azalea-client/src/plugins/packet/game/events.rs17
-rw-r--r--azalea-client/src/plugins/packet/game/mod.rs217
-rw-r--r--azalea-client/src/plugins/packet/mod.rs2
-rw-r--r--azalea-client/src/plugins/tick_counter.rs8
-rw-r--r--azalea-client/src/plugins/tick_end.rs4
-rw-r--r--azalea-client/src/test_utils/simulation.rs18
19 files changed, 249 insertions, 257 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index b7d01d58..90b1264c 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -11,7 +11,7 @@ use azalea_entity::{
EntityUpdateSystems, PlayerAbilities, indexing::EntityIdIndex, inventory::Inventory,
};
use azalea_physics::local_player::PhysicsState;
-use azalea_world::InstanceContainer;
+use azalea_world::Worlds;
use bevy_app::{App, AppExit, Plugin, PluginsState, SubApp, Update};
use bevy_ecs::{
message::MessageCursor,
@@ -29,7 +29,7 @@ use crate::{
connection::RawConnection,
cookies::ServerCookies,
interact::BlockStatePredictionHandler,
- local_player::{Hunger, InstanceHolder, PermissionLevel, TabList},
+ local_player::{Hunger, PermissionLevel, TabList, WorldHolder},
mining,
movement::LastSentLookDirection,
player::retroactively_add_game_profile_component,
@@ -43,7 +43,7 @@ use crate::{
#[derive(Bundle)]
pub struct LocalPlayerBundle {
pub raw_connection: RawConnection,
- pub instance_holder: InstanceHolder,
+ pub world_holder: WorldHolder,
pub metadata: azalea_entity::metadata::PlayerMetadataBundle,
}
@@ -56,7 +56,7 @@ pub struct LocalPlayerBundle {
/// If you want to filter for this, use [`InGameState`].
#[derive(Bundle, Default)]
pub struct JoinedClientBundle {
- // note that InstanceHolder isn't here because it's set slightly before we fully join the world
+ // note that WorldHolder isn't here because it's set slightly before we fully join the world
pub physics_state: PhysicsState,
pub inventory: Inventory,
pub tab_list: TabList,
@@ -98,7 +98,7 @@ impl Plugin for AzaleaPlugin {
.after(crate::join::handle_start_join_server_event),
),
)
- .init_resource::<InstanceContainer>()
+ .init_resource::<Worlds>()
.init_resource::<TabList>();
}
}
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index 9e44913c..444b2fcc 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -1,7 +1,7 @@
use std::{collections::HashMap, sync::Arc};
use azalea_core::game_type::GameMode;
-use azalea_world::{Instance, PartialInstance};
+use azalea_world::{PartialWorld, World};
use bevy_ecs::{component::Component, prelude::*};
use derive_more::{Deref, DerefMut};
use parking_lot::RwLock;
@@ -9,28 +9,29 @@ use uuid::Uuid;
use crate::{ClientInformation, player::PlayerInfo};
-/// A component that keeps strong references to our [`PartialInstance`] and
-/// [`Instance`] for local players.
+/// A component that keeps strong references to our [`PartialWorld`] and
+/// [`World`] for local players.
///
-/// This can also act as a convenience for accessing the player's Instance since
-/// the alternative is to look up the player's [`InstanceName`] in the
-/// [`InstanceContainer`].
+/// This can also act as a convenient way to access the player's `World`, since
+/// the alternative is to look up the player's [`WorldName`] in the [`Worlds`]
+/// resource.
///
-/// [`InstanceContainer`]: azalea_world::InstanceContainer
-/// [`InstanceName`]: azalea_world::InstanceName
+/// [`Worlds`]: azalea_world::Worlds
+/// [`WorldName`]: azalea_world::WorldName
#[derive(Clone, Component)]
-pub struct InstanceHolder {
- /// The partial instance is the world this client currently has loaded.
+pub struct WorldHolder {
+ /// The slice of the world that this client actually has loaded, based on
+ /// its render distance.
+ pub partial: Arc<RwLock<PartialWorld>>,
+ /// The combined [`PartialWorld`]s of all clients in the same world.
///
- /// It has a limited render distance.
- pub partial_instance: Arc<RwLock<PartialInstance>>,
- /// The combined [`PartialInstance`]s of all clients in the same instance
- /// (aka world/dimension).
- ///
- /// This is only relevant if you're using a shared world (i.e. a
- /// swarm).
- pub instance: Arc<RwLock<Instance>>,
+ /// The distinction between this and `partial` is mostly only relevant if
+ /// you're using a shared world (i.e. a swarm). If in doubt, prefer to use
+ /// the shared world.
+ pub shared: Arc<RwLock<World>>,
}
+#[deprecated = "renamed to `WorldHolder`."]
+pub type InstanceHolder = WorldHolder;
/// The gamemode of a local player. For a non-local player, you can look up the
/// player in the [`TabList`].
@@ -103,18 +104,18 @@ impl Hunger {
}
}
-impl InstanceHolder {
- /// Create a new `InstanceHolder` for the given entity.
+impl WorldHolder {
+ /// Create a new `WorldHolder` for the given entity.
///
- /// The partial instance will be created for you. The render distance will
+ /// The partial world will be created for you. The render distance will
/// be set to a default value, which you can change by creating a new
- /// partial_instance.
- pub fn new(entity: Entity, instance: Arc<RwLock<Instance>>) -> Self {
+ /// partial world.
+ pub fn new(entity: Entity, shared: Arc<RwLock<World>>) -> Self {
let client_information = ClientInformation::default();
- InstanceHolder {
- instance,
- partial_instance: Arc::new(RwLock::new(PartialInstance::new(
+ WorldHolder {
+ shared,
+ partial: Arc::new(RwLock::new(PartialWorld::new(
azalea_world::chunk_storage::calculate_chunk_storage_range(
client_information.view_distance.into(),
),
@@ -123,19 +124,19 @@ impl InstanceHolder {
}
}
- /// Reset the `Instance` to a new reference to an empty instance, but with
+ /// Reset the [`World`] to be a reference to an empty world, but with
/// the same registries as the current one.
///
/// This is used by Azalea when entering the config state.
pub fn reset(&mut self) {
- let registries = self.instance.read().registries.clone();
+ let registries = self.shared.read().registries.clone();
- let new_instance = Instance {
+ let new_world = World {
registries,
..Default::default()
};
- self.instance = Arc::new(RwLock::new(new_instance));
+ self.shared = Arc::new(RwLock::new(new_world));
- self.partial_instance.write().reset();
+ self.partial.write().reset();
}
}
diff --git a/azalea-client/src/plugins/block_update.rs b/azalea-client/src/plugins/block_update.rs
index 46e6b409..51dba728 100644
--- a/azalea-client/src/plugins/block_update.rs
+++ b/azalea-client/src/plugins/block_update.rs
@@ -5,7 +5,7 @@ use bevy_ecs::prelude::*;
use crate::{
chunks::handle_receive_chunk_event, interact::BlockStatePredictionHandler,
- local_player::InstanceHolder,
+ local_player::WorldHolder,
};
pub struct BlockUpdatePlugin;
@@ -34,12 +34,12 @@ pub struct QueuedServerBlockUpdates {
pub fn handle_block_update_event(
mut query: Query<(
&mut QueuedServerBlockUpdates,
- &InstanceHolder,
+ &WorldHolder,
&mut BlockStatePredictionHandler,
)>,
) {
- for (mut queued, instance_holder, mut prediction_handler) in query.iter_mut() {
- let world = instance_holder.instance.read();
+ for (mut queued, world_holder, mut prediction_handler) in query.iter_mut() {
+ let world = world_holder.shared.read();
for (pos, block_state) in queued.list.drain(..) {
if !prediction_handler.update_known_server_state(pos, block_state) {
world.chunks.set_block_state(pos, block_state);
diff --git a/azalea-client/src/plugins/chunks.rs b/azalea-client/src/plugins/chunks.rs
index d5014516..0937c2ef 100644
--- a/azalea-client/src/plugins/chunks.rs
+++ b/azalea-client/src/plugins/chunks.rs
@@ -17,7 +17,7 @@ use bevy_ecs::prelude::*;
use tracing::{error, trace};
use crate::{
- inventory::InventorySystems, local_player::InstanceHolder, packet::game::SendGamePacketEvent,
+ inventory::InventorySystems, local_player::WorldHolder, packet::game::SendGamePacketEvent,
respawn::perform_respawn,
};
@@ -66,42 +66,40 @@ pub struct ChunkBatchFinishedEvent {
pub fn handle_receive_chunk_event(
mut events: MessageReader<ReceiveChunkEvent>,
- mut query: Query<&InstanceHolder>,
+ mut query: Query<&WorldHolder>,
) {
for event in events.read() {
let pos = ChunkPos::new(event.packet.x, event.packet.z);
let local_player = query.get_mut(event.entity).unwrap();
- let mut instance = local_player.instance.write();
- let mut partial_instance = local_player.partial_instance.write();
+ let mut world = local_player.shared.write();
+ let mut partial_world = local_player.partial.write();
// OPTIMIZATION: if we already know about the chunk from the shared world (and
// not ourselves), then we don't need to parse it again. This is only used when
// we have a shared world, since we check that the chunk isn't currently owned
// by this client.
- let shared_chunk = instance.chunks.get(&pos);
- let this_client_has_chunk = partial_instance.chunks.limited_get(&pos).is_some();
+ let shared_chunk = world.chunks.get(&pos);
+ let this_client_has_chunk = partial_world.chunks.limited_get(&pos).is_some();
if !this_client_has_chunk && let Some(shared_chunk) = shared_chunk {
trace!("Skipping parsing chunk {pos:?} because we already know about it");
- partial_instance
- .chunks
- .limited_set(&pos, Some(shared_chunk));
+ partial_world.chunks.limited_set(&pos, Some(shared_chunk));
continue;
}
let heightmaps = &event.packet.chunk_data.heightmaps;
- if let Err(e) = partial_instance.chunks.replace_with_packet_data(
+ if let Err(e) = partial_world.chunks.replace_with_packet_data(
&pos,
&mut Cursor::new(&event.packet.chunk_data.data),
heightmaps,
- &mut instance.chunks,
+ &mut world.chunks,
) {
error!(
"Couldn't set chunk data: {e}. World height: {}",
- instance.chunks.height
+ world.chunks.height
);
}
}
diff --git a/azalea-client/src/plugins/disconnect.rs b/azalea-client/src/plugins/disconnect.rs
index 081c174e..be98383b 100644
--- a/azalea-client/src/plugins/disconnect.rs
+++ b/azalea-client/src/plugins/disconnect.rs
@@ -1,10 +1,10 @@
//! Disconnect a client from the server.
use azalea_chat::FormattedText;
+use azalea_core::entity_id::MinecraftEntityId;
use azalea_entity::{
EntityBundle, HasClientLoaded, InLoadedChunk, LocalEntity, metadata::PlayerMetadataBundle,
};
-use azalea_core::entity_id::MinecraftEntityId;
use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::prelude::*;
use derive_more::Deref;
@@ -14,7 +14,7 @@ use super::login::IsAuthenticated;
#[cfg(feature = "online-mode")]
use crate::chat_signing;
use crate::{
- client::JoinedClientBundle, connection::RawConnection, local_player::InstanceHolder,
+ client::JoinedClientBundle, connection::RawConnection, local_player::WorldHolder,
tick_counter::TicksConnected,
};
@@ -63,7 +63,7 @@ pub struct RemoveOnDisconnectBundle {
pub entity: EntityBundle,
pub minecraft_entity_id: MinecraftEntityId,
- pub instance_holder: InstanceHolder,
+ pub world_holder: WorldHolder,
pub player_metadata: PlayerMetadataBundle,
pub in_loaded_chunk: InLoadedChunk,
//// This makes it close the TCP connection.
diff --git a/azalea-client/src/plugins/interact/mod.rs b/azalea-client/src/plugins/interact/mod.rs
index d8f8b8b4..04986de7 100644
--- a/azalea-client/src/plugins/interact/mod.rs
+++ b/azalea-client/src/plugins/interact/mod.rs
@@ -30,7 +30,7 @@ use azalea_protocol::packets::game::{
s_swing::ServerboundSwing,
s_use_item_on::ServerboundUseItemOn,
};
-use azalea_world::Instance;
+use azalea_world::World;
use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use tracing::warn;
@@ -140,7 +140,7 @@ impl BlockStatePredictionHandler {
}
}
- pub fn end_prediction_up_to(&mut self, seq: u32, world: &Instance) {
+ pub fn end_prediction_up_to(&mut self, seq: u32, world: &World) {
let mut to_remove = Vec::new();
for (pos, state) in &self.server_state {
if state.seq > seq {
@@ -377,10 +377,10 @@ pub fn handle_entity_interact(
///
/// If this is false, then we can interact with the block.
///
-/// Passing the inventory, block position, and instance is necessary for the
-/// adventure mode check.
+/// The world, block position, and inventory are used for the adventure mode
+/// check.
pub fn check_is_interaction_restricted(
- instance: &Instance,
+ world: &World,
block_pos: BlockPos,
game_mode: &GameMode,
inventory: &Inventory,
@@ -393,7 +393,7 @@ pub fn check_is_interaction_restricted(
let held_item = inventory.held_item();
match &held_item {
ItemStack::Present(item) => {
- let block = instance.chunks.get_block_state(block_pos);
+ let block = world.chunks.get_block_state(block_pos);
let Some(block) = block else {
// block isn't loaded so just say that it is restricted
return true;
diff --git a/azalea-client/src/plugins/interact/pick.rs b/azalea-client/src/plugins/interact/pick.rs
index 8ffe47e8..1fed584a 100644
--- a/azalea-client/src/plugins/interact/pick.rs
+++ b/azalea-client/src/plugins/interact/pick.rs
@@ -17,7 +17,7 @@ use azalea_physics::{
clip::{BlockShapeType, ClipContext, FluidPickType},
collision::entity_collisions::{AabbQuery, get_entities},
};
-use azalea_world::{Instance, InstanceContainer, InstanceName};
+use azalea_world::{World, WorldName, Worlds};
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
@@ -37,13 +37,13 @@ pub fn update_hit_result_component(
&Position,
&EntityDimensions,
&LookDirection,
- &InstanceName,
+ &WorldName,
&Physics,
&Attributes,
),
With<LocalEntity>,
>,
- instance_container: Res<InstanceContainer>,
+ worlds: Res<Worlds>,
aabb_query: AabbQuery,
pickable_query: MaybePickableEntityQuery,
) {
@@ -63,7 +63,7 @@ pub fn update_hit_result_component(
let eye_position = position.up(dimensions.eye_height.into());
- let Some(world_lock) = instance_container.get(world_name) else {
+ let Some(world_lock) = worlds.get(world_name) else {
continue;
};
let world = world_lock.read();
@@ -117,7 +117,7 @@ pub struct PickOpts<'world, 'state, 'a, 'b, 'c> {
look_direction: LookDirection,
eye_position: Vec3,
aabb: &'a Aabb,
- world: &'a Instance,
+ world: &'a World,
entity_pick_range: f64,
block_pick_range: f64,
aabb_query: &'a AabbQuery<'world, 'state, 'b>,
@@ -246,7 +246,7 @@ struct PickEntityOpts<'world, 'state, 'a, 'b> {
source_entity: Entity,
eye_position: Vec3,
end_position: Vec3,
- world: &'a azalea_world::Instance,
+ world: &'a azalea_world::World,
pick_range_squared: f64,
predicate: &'a dyn Fn(Entity) -> bool,
aabb: &'a Aabb,
diff --git a/azalea-client/src/plugins/inventory/equipment_effects.rs b/azalea-client/src/plugins/inventory/equipment_effects.rs
index 47220bf2..d5897f48 100644
--- a/azalea-client/src/plugins/inventory/equipment_effects.rs
+++ b/azalea-client/src/plugins/inventory/equipment_effects.rs
@@ -19,7 +19,7 @@ use bevy_ecs::{
};
use tracing::{debug, error, warn};
-use crate::local_player::InstanceHolder;
+use crate::local_player::WorldHolder;
/// A component that contains the equipment slots that we had last tick.
///
@@ -91,9 +91,9 @@ pub struct EquipmentChange {
pub fn handle_equipment_changes(
equipment_changes: On<EquipmentChangesEvent>,
- mut query: Query<(&InstanceHolder, &mut LastEquipmentItems, &mut Attributes)>,
+ mut query: Query<(&WorldHolder, &mut LastEquipmentItems, &mut Attributes)>,
) {
- let Ok((instance_holder, mut last_equipment_items, mut attributes)) =
+ let Ok((world_holder, mut last_equipment_items, mut attributes)) =
query.get_mut(equipment_changes.entity)
else {
error!(
@@ -112,7 +112,7 @@ pub fn handle_equipment_changes(
// stopLocationBasedEffects
for (attribute, modifier) in
- collect_attribute_modifiers_from_item(slot, &change.old, instance_holder)
+ collect_attribute_modifiers_from_item(slot, &change.old, world_holder)
{
if let Some(attribute) = attributes.get_mut(attribute) {
attribute.remove(&modifier.id);
@@ -126,7 +126,7 @@ pub fn handle_equipment_changes(
// see ItemStack.forEachModifier in vanilla
for (attribute, modifier) in
- collect_attribute_modifiers_from_item(slot, &change.new, instance_holder)
+ collect_attribute_modifiers_from_item(slot, &change.new, world_holder)
{
if let Some(attribute) = attributes.get_mut(attribute) {
attribute.remove(&modifier.id);
@@ -144,7 +144,7 @@ pub fn handle_equipment_changes(
fn collect_attribute_modifiers_from_item(
slot: EquipmentSlot,
item: &ItemStack,
- instance_holder: &InstanceHolder,
+ world_holder: &WorldHolder,
) -> Vec<(azalea_registry::builtin::Attribute, AttributeModifier)> {
let mut modifiers = Vec::new();
@@ -161,7 +161,7 @@ fn collect_attribute_modifiers_from_item(
.get_component::<components::Enchantments>()
.unwrap_or_default();
if !enchants.levels.is_empty() {
- let registry_holder = &instance_holder.instance.read().registries;
+ let registry_holder = &world_holder.shared.read().registries;
for (enchant, &level) in &enchants.levels {
let Some((_enchant_id, enchant_definition)) = enchant.resolve(registry_holder) else {
warn!(
diff --git a/azalea-client/src/plugins/inventory/mod.rs b/azalea-client/src/plugins/inventory/mod.rs
index 740decb1..908ebe66 100644
--- a/azalea-client/src/plugins/inventory/mod.rs
+++ b/azalea-client/src/plugins/inventory/mod.rs
@@ -11,7 +11,7 @@ use azalea_protocol::packets::game::{
s_set_carried_item::ServerboundSetCarriedItem,
};
use azalea_registry::builtin::MenuKind;
-use azalea_world::{InstanceContainer, InstanceName};
+use azalea_world::{WorldName, Worlds};
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use indexmap::IndexMap;
@@ -167,10 +167,10 @@ pub struct ContainerClickEvent {
pub fn handle_container_click_event(
container_click: On<ContainerClickEvent>,
mut commands: Commands,
- mut query: Query<(Entity, &mut Inv, Option<&PlayerAbilities>, &InstanceName)>,
- instance_container: Res<InstanceContainer>,
+ mut query: Query<(Entity, &mut Inv, Option<&PlayerAbilities>, &WorldName)>,
+ worlds: Res<Worlds>,
) {
- let (entity, mut inventory, player_abilities, instance_name) =
+ let (entity, mut inventory, player_abilities, world_name) =
query.get_mut(container_click.entity).unwrap();
if inventory.id != container_click.window_id {
error!(
@@ -180,7 +180,7 @@ pub fn handle_container_click_event(
return;
}
- let Some(instance) = instance_container.get(instance_name) else {
+ let Some(world) = worlds.get(world_name) else {
return;
};
@@ -191,7 +191,7 @@ pub fn handle_container_click_event(
);
let new_slots = inventory.menu().slots();
- let registry_holder = &instance.read().registries;
+ let registry_holder = &world.read().registries;
// see which slots changed after clicking and put them in the map the server
// uses this to check if we desynced
diff --git a/azalea-client/src/plugins/join.rs b/azalea-client/src/plugins/join.rs
index c254bc26..a6c9c586 100644
--- a/azalea-client/src/plugins/join.rs
+++ b/azalea-client/src/plugins/join.rs
@@ -11,7 +11,7 @@ use azalea_protocol::{
login::{ClientboundLoginPacket, ServerboundHello, ServerboundLoginPacket},
},
};
-use azalea_world::Instance;
+use azalea_world::World;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_tasks::{IoTaskPool, Task, futures_lite::future};
@@ -23,6 +23,7 @@ use crate::{
LocalPlayerBundle,
account::Account,
connection::RawConnection,
+ local_player::WorldHolder,
packet::login::{InLoginState, SendLoginPacketEvent},
};
@@ -204,12 +205,12 @@ pub fn poll_create_connection_task(
let (read_conn, write_conn) = conn.into_split();
let (read_conn, write_conn) = (read_conn.raw, write_conn.raw);
- let instance = Instance::default();
- let instance_holder = crate::local_player::InstanceHolder::new(
+ let world = World::default();
+ let world_holder = WorldHolder::new(
entity,
// default to an empty world, it'll be set correctly later when we
// get the login packet
- Arc::new(RwLock::new(instance)),
+ Arc::new(RwLock::new(world)),
);
entity_mut.insert((
@@ -220,7 +221,7 @@ pub fn poll_create_connection_task(
write_conn,
ConnectionProtocol::Login,
),
- instance_holder,
+ world_holder,
metadata: azalea_entity::metadata::PlayerMetadataBundle::default(),
},
InLoginState,
diff --git a/azalea-client/src/plugins/mining.rs b/azalea-client/src/plugins/mining.rs
index e9dcbe59..35b01a6a 100644
--- a/azalea-client/src/plugins/mining.rs
+++ b/azalea-client/src/plugins/mining.rs
@@ -8,7 +8,7 @@ use azalea_inventory::ItemStack;
use azalea_physics::{PhysicsSystems, collision::BlockWithShape};
use azalea_protocol::packets::game::s_player_action::{self, ServerboundPlayerAction};
use azalea_registry::builtin::{BlockKind, ItemKind};
-use azalea_world::{InstanceContainer, InstanceName};
+use azalea_world::{Worlds, WorldName};
use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
@@ -20,7 +20,7 @@ use crate::{
check_is_interaction_restricted, pick::HitResultComponent,
},
inventory::InventorySystems,
- local_player::{InstanceHolder, LocalGameMode, PermissionLevel},
+ local_player::{LocalGameMode, PermissionLevel, WorldHolder},
movement::MoveEventsSystems,
packet::game::SendGamePacketEvent,
};
@@ -219,7 +219,7 @@ pub fn handle_mining_queued(
query: Query<(
Entity,
&MiningQueued,
- &InstanceHolder,
+ &WorldHolder,
&LocalGameMode,
&Inventory,
&ActiveEffects,
@@ -240,7 +240,7 @@ pub fn handle_mining_queued(
for (
entity,
mining_queued,
- instance_holder,
+ world_holder,
game_mode,
inventory,
active_effects,
@@ -261,9 +261,9 @@ pub fn handle_mining_queued(
trace!("handle_mining_queued {mining_queued:?}");
commands.entity(entity).remove::<MiningQueued>();
- let instance = instance_holder.instance.read();
+ let world = world_holder.shared.read();
if check_is_interaction_restricted(
- &instance,
+ &world,
mining_queued.position,
&game_mode.current,
inventory,
@@ -320,7 +320,7 @@ pub fn handle_mining_queued(
));
}
- let target_block_state = instance
+ let target_block_state = world
.get_block_state(mining_queued.position)
.unwrap_or_default();
@@ -472,7 +472,7 @@ pub struct FinishMiningBlockEvent {
pub fn handle_finish_mining_block_observer(
finish_mining_block: On<FinishMiningBlockEvent>,
mut query: Query<(
- &InstanceName,
+ &WorldName,
&LocalGameMode,
&Inventory,
&PlayerAbilities,
@@ -480,12 +480,12 @@ pub fn handle_finish_mining_block_observer(
&Position,
&mut BlockStatePredictionHandler,
)>,
- instances: Res<InstanceContainer>,
+ worlds: Res<Worlds>,
) {
let event = finish_mining_block.event();
let (
- instance_name,
+ world_name,
game_mode,
inventory,
abilities,
@@ -493,9 +493,9 @@ pub fn handle_finish_mining_block_observer(
player_pos,
mut prediction_handler,
) = query.get_mut(finish_mining_block.entity).unwrap();
- let instance_lock = instances.get(instance_name).unwrap();
- let instance = instance_lock.read();
- if check_is_interaction_restricted(&instance, event.position, &game_mode.current, inventory) {
+ let world_lock = worlds.get(world_name).unwrap();
+ let world = world_lock.read();
+ if check_is_interaction_restricted(&world, event.position, &game_mode.current, inventory) {
return;
}
@@ -508,7 +508,7 @@ pub fn handle_finish_mining_block_observer(
}
}
- let Some(block_state) = instance.get_block_state(event.position) else {
+ let Some(block_state) = world.get_block_state(event.position) else {
return;
};
@@ -528,7 +528,7 @@ pub fn handle_finish_mining_block_observer(
// when we break a waterlogged block we want to keep the water there
let fluid_state = FluidState::from(block_state);
let block_state_for_fluid = BlockState::from(fluid_state);
- let old_state = instance
+ let old_state = world
.set_block_state(event.position, block_state_for_fluid)
.unwrap_or_default();
prediction_handler.retain_known_server_state(event.position, old_state, **player_pos);
@@ -581,7 +581,7 @@ pub fn decrement_mine_delay(mut query: Query<&mut MineDelay>) {
pub fn continue_mining_block(
mut query: Query<(
Entity,
- &InstanceName,
+ &WorldName,
&LocalGameMode,
&Inventory,
&MineBlockPos,
@@ -598,11 +598,11 @@ pub fn continue_mining_block(
)>,
mut commands: Commands,
mut mine_block_progress_events: MessageWriter<MineBlockProgressEvent>,
- instances: Res<InstanceContainer>,
+ worlds: Res<Worlds>,
) {
for (
entity,
- instance_name,
+ world_name,
game_mode,
inventory,
current_mining_pos,
@@ -644,9 +644,9 @@ pub fn continue_mining_block(
)
{
trace!("continue mining block at {:?}", mining.pos);
- let instance_lock = instances.get(instance_name).unwrap();
- let instance = instance_lock.read();
- let target_block_state = instance.get_block_state(mining.pos).unwrap_or_default();
+ let world_lock = worlds.get(world_name).unwrap();
+ let world = world_lock.read();
+ let target_block_state = world.get_block_state(mining.pos).unwrap_or_default();
trace!("target_block_state: {target_block_state:?}");
diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs
index 40cc108e..94b996a0 100644
--- a/azalea-client/src/plugins/movement.rs
+++ b/azalea-client/src/plugins/movement.rs
@@ -31,12 +31,12 @@ use azalea_protocol::{
},
};
use azalea_registry::builtin::EntityKind;
-use azalea_world::Instance;
+use azalea_world::World;
use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use crate::{
- local_player::{Hunger, InstanceHolder, LocalGameMode},
+ local_player::{Hunger, LocalGameMode, WorldHolder},
packet::game::SendGamePacketEvent,
};
@@ -296,7 +296,7 @@ pub fn local_player_ai_step(
&PlayerAbilities,
&metadata::Swimming,
&metadata::SleepingPos,
- &InstanceHolder,
+ &WorldHolder,
&Position,
Option<&Hunger>,
Option<&LastSentInput>,
@@ -316,7 +316,7 @@ pub fn local_player_ai_step(
abilities,
swimming,
sleeping_pos,
- instance_holder,
+ world_holder,
position,
hunger,
last_sent_input,
@@ -333,7 +333,7 @@ pub fn local_player_ai_step(
let is_passenger = false;
let is_sleeping = sleeping_pos.is_some();
- let world = instance_holder.instance.read();
+ let world = world_holder.shared.read();
let ctx = CanPlayerFitCtx {
world: &world,
entity,
@@ -587,16 +587,16 @@ pub fn update_pose(
&Physics,
&PhysicsState,
&LocalGameMode,
- &InstanceHolder,
+ &WorldHolder,
&Position,
)>,
aabb_query: AabbQuery,
collidable_entity_query: CollidableEntityQuery,
) {
- for (entity, mut pose, physics, physics_state, game_mode, instance_holder, position) in
+ for (entity, mut pose, physics, physics_state, game_mode, world_holder, position) in
query.iter_mut()
{
- let world = instance_holder.instance.read();
+ let world = world_holder.shared.read();
let world = &*world;
let ctx = CanPlayerFitCtx {
world,
@@ -642,7 +642,7 @@ pub fn update_pose(
}
struct CanPlayerFitCtx<'world, 'state, 'a, 'b> {
- world: &'a Instance,
+ world: &'a World,
entity: Entity,
position: Position,
aabb_query: &'a AabbQuery<'world, 'state, 'b>,
diff --git a/azalea-client/src/plugins/packet/config/mod.rs b/azalea-client/src/plugins/packet/config/mod.rs
index 27dae837..f59b8c23 100644
--- a/azalea-client/src/plugins/packet/config/mod.rs
+++ b/azalea-client/src/plugins/packet/config/mod.rs
@@ -17,7 +17,7 @@ use crate::{
connection::RawConnection,
cookies::{RequestCookieEvent, StoreCookieEvent},
disconnect::DisconnectEvent,
- local_player::InstanceHolder,
+ local_player::WorldHolder,
packet::game::{KeepAliveEvent, ResourcePackEvent},
};
@@ -69,12 +69,12 @@ pub struct ConfigPacketHandler<'a> {
}
impl ConfigPacketHandler<'_> {
pub fn registry_data(&mut self, p: &ClientboundRegistryData) {
- as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
- let instance_holder = query.get_mut(self.player).unwrap();
- let mut instance = instance_holder.instance.write();
+ as_system::<Query<&WorldHolder>>(self.ecs, |mut query| {
+ let world_holder = query.get_mut(self.player).unwrap();
+ let mut world = world_holder.shared.write();
// add the new registry data
- instance
+ world
.registries
.append(p.registry_id.clone(), p.entries.clone());
});
diff --git a/azalea-client/src/plugins/packet/game/events.rs b/azalea-client/src/plugins/packet/game/events.rs
index 535bd519..bc070ec8 100644
--- a/azalea-client/src/plugins/packet/game/events.rs
+++ b/azalea-client/src/plugins/packet/game/events.rs
@@ -5,8 +5,7 @@ use azalea_protocol::packets::{
Packet,
game::{ClientboundGamePacket, ClientboundPlayerCombatKill, ServerboundGamePacket},
};
-use azalea_registry::identifier::Identifier;
-use azalea_world::Instance;
+use azalea_world::{World, WorldName};
use bevy_ecs::prelude::*;
use parking_lot::RwLock;
use tracing::{error, trace};
@@ -138,16 +137,18 @@ pub struct ResourcePackEvent {
pub prompt: Option<FormattedText>,
}
-/// An instance (aka world, dimension) was loaded by a client.
+/// A world instance (aka dimension) was loaded by a client.
///
-/// Since the instance is given to you as a weak reference, it won't be able to
-/// be `upgrade`d if all local players leave it.
+/// Since the world is given to you as a weak reference, it won't be able to be
+/// `upgrade`d if all local players unload it.
#[derive(Clone, Debug, Message)]
-pub struct InstanceLoadedEvent {
+pub struct WorldLoadedEvent {
pub entity: Entity,
- pub name: Identifier,
- pub instance: Weak<RwLock<Instance>>,
+ pub name: WorldName,
+ pub world: Weak<RwLock<World>>,
}
+#[deprecated = "renamed to `WorldLoadedEvent`."]
+pub type InstanceLoadedEvent = WorldLoadedEvent;
/// A Bevy trigger that's sent when our client receives a [`ClientboundPing`]
/// packet in the game state.
diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs
index f93a02ea..6489c899 100644
--- a/azalea-client/src/plugins/packet/game/mod.rs
+++ b/azalea-client/src/plugins/packet/game/mod.rs
@@ -19,7 +19,7 @@ use azalea_protocol::{
packets::{ConnectionProtocol, game::*},
};
use azalea_registry::builtin::EntityKind;
-use azalea_world::{InstanceContainer, InstanceName, PartialInstance};
+use azalea_world::{PartialWorld, WorldName, Worlds};
use bevy_ecs::{prelude::*, system::SystemState};
pub use events::*;
use tracing::{debug, error, trace, warn};
@@ -34,7 +34,7 @@ use crate::{
disconnect::DisconnectEvent,
interact::BlockStatePredictionHandler,
inventory::{ClientsideCloseContainerEvent, MenuOpenedEvent, SetContainerContentEvent},
- local_player::{Hunger, InstanceHolder, LocalGameMode, TabList},
+ local_player::{Hunger, LocalGameMode, TabList, WorldHolder},
movement::{KnockbackData, KnockbackEvent},
packet::{as_system, declare_packet_handlers},
player::{GameProfileComponent, PlayerInfo},
@@ -207,15 +207,15 @@ impl GamePacketHandler<'_> {
(
&GameProfileComponent,
&ClientInformation,
- Option<&mut InstanceName>,
+ Option<&mut WorldName>,
Option<&mut LoadedBy>,
&mut EntityIdIndex,
- &mut InstanceHolder,
+ &mut WorldHolder,
),
With<LocalEntity>,
>,
- MessageWriter<InstanceLoadedEvent>,
- ResMut<InstanceContainer>,
+ MessageWriter<WorldLoadedEvent>,
+ ResMut<Worlds>,
ResMut<EntityUuidIndex>,
Query<&mut LoadedBy, Without<LocalEntity>>,
)>(
@@ -223,33 +223,31 @@ impl GamePacketHandler<'_> {
|(
mut commands,
mut query,
- mut instance_loaded_events,
- mut instance_container,
+ mut world_loaded_events,
+ mut worlds,
mut entity_uuid_index,
mut loaded_by_query,
)| {
let (
game_profile,
client_information,
- instance_name,
+ world_name,
loaded_by,
mut entity_id_index,
- mut instance_holder,
+ mut world_holder,
) = query.get_mut(self.player).unwrap();
- let new_instance_name = p.common.dimension.clone();
+ let new_world_name = WorldName(p.common.dimension.clone());
- if let Some(mut instance_name) = instance_name {
- **instance_name = new_instance_name.clone();
+ if let Some(mut world_name) = world_name {
+ *world_name = new_world_name.clone();
} else {
- commands
- .entity(self.player)
- .insert(InstanceName(new_instance_name.clone()));
+ commands.entity(self.player).insert(new_world_name.clone());
}
- let weak_instance;
+ let weak_world;
{
- let client_registries = &instance_holder.instance.read().registries;
+ let client_registries = &world_holder.shared.read().registries;
let Some((_dimension_type, dimension_data)) =
p.common.dimension_type(client_registries)
@@ -257,46 +255,44 @@ impl GamePacketHandler<'_> {
return;
};
- // add this world to the instance_container (or don't if it's already
- // there)
- weak_instance = instance_container.get_or_insert(
- new_instance_name.clone(),
+ // add this world to the `worlds` (or don't, if it's already there)
+ weak_world = worlds.get_or_insert(
+ new_world_name.clone(),
dimension_data.height,
dimension_data.min_y,
client_registries,
);
- instance_loaded_events.write(InstanceLoadedEvent {
+ world_loaded_events.write(WorldLoadedEvent {
entity: self.player,
- name: new_instance_name.clone(),
- instance: Arc::downgrade(&weak_instance),
+ name: new_world_name.clone(),
+ world: Arc::downgrade(&weak_world),
});
}
- // set the partial_world to an empty world
- // (when we add chunks or entities those will be in the
- // instance_container)
+ // set the partial world to an empty world (when we add chunks or entities those
+ // will be in the `worlds`)
- *instance_holder.partial_instance.write() = PartialInstance::new(
+ *world_holder.partial.write() = PartialWorld::new(
azalea_world::chunk_storage::calculate_chunk_storage_range(
client_information.view_distance.into(),
),
- // this argument makes it so other clients don't update this player entity
- // in a shared instance
+ // this argument makes it so other clients don't update this player entity in a
+ // shared world
Some(self.player),
);
{
- let client_registries = instance_holder.instance.read().registries.clone();
- let shared_registries = &mut weak_instance.write().registries;
- // add the registries from this instance to the weak instance
+ let client_registries = world_holder.shared.read().registries.clone();
+ let shared_registries = &mut weak_world.write().registries;
+ // add the registries from this world to the weak world
shared_registries.extend(client_registries);
}
- instance_holder.instance = weak_instance;
+ world_holder.shared = weak_world;
let entity_bundle = EntityBundle::new(
game_profile.uuid,
Vec3::ZERO,
EntityKind::Player,
- new_instance_name,
+ new_world_name,
);
let entity_id = p.player_id;
// insert our components into the ecs :)
@@ -316,7 +312,7 @@ impl GamePacketHandler<'_> {
Some(game_profile.uuid),
&mut entity_id_index,
&mut entity_uuid_index,
- &mut instance_holder.instance.write(),
+ &mut world_holder.shared.write(),
);
// every entity is now unloaded by this player
@@ -532,9 +528,9 @@ impl GamePacketHandler<'_> {
pub fn set_chunk_cache_center(&mut self, p: &ClientboundSetChunkCacheCenter) {
debug!("Got chunk cache center packet {p:?}");
- as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
- let instance_holder = query.get_mut(self.player).unwrap();
- let mut partial_world = instance_holder.partial_instance.write();
+ as_system::<Query<&WorldHolder>>(self.ecs, |mut query| {
+ let world_holder = query.get_mut(self.player).unwrap();
+ let mut partial_world = world_holder.partial.write();
partial_world
.chunks
@@ -564,10 +560,10 @@ impl GamePacketHandler<'_> {
as_system::<(
Commands,
- Query<(&mut EntityIdIndex, Option<&InstanceName>, Option<&TabList>)>,
+ Query<(&mut EntityIdIndex, Option<&WorldName>, Option<&TabList>)>,
Query<&mut LoadedBy>,
Query<Entity>,
- Res<InstanceContainer>,
+ Res<Worlds>,
ResMut<EntityUuidIndex>,
)>(
self.ecs,
@@ -576,22 +572,22 @@ impl GamePacketHandler<'_> {
mut query,
mut loaded_by_query,
entity_query,
- instance_container,
+ worlds,
mut entity_uuid_index,
)| {
- let (mut entity_id_index, instance_name, tab_list) =
+ let (mut entity_id_index, world_name, tab_list) =
query.get_mut(self.player).unwrap();
let entity_id = p.id;
- let Some(instance_name) = instance_name else {
+ let Some(world_name) = world_name else {
warn!("got add player packet but we haven't gotten a login packet yet");
return;
};
// check if the entity already exists, and if it does then only add to LoadedBy
- let instance = instance_container.get(instance_name).unwrap();
- if let Some(&ecs_entity) = instance.read().entity_by_id.get(&entity_id) {
+ let world = worlds.get(world_name).unwrap();
+ if let Some(&ecs_entity) = world.read().entity_by_id.get(&entity_id) {
// entity already exists
let Ok(mut loaded_by) = loaded_by_query.get_mut(ecs_entity) else {
// LoadedBy for this entity isn't in the ecs! figure out what went wrong
@@ -621,7 +617,7 @@ impl GamePacketHandler<'_> {
// entity doesn't exist in the global index!
- let bundle = p.as_entity_bundle((**instance_name).clone());
+ let bundle = p.as_entity_bundle(world_name.to_owned());
let mut spawned =
commands.spawn((entity_id, LoadedBy(HashSet::from([self.player])), bundle));
let ecs_entity: Entity = spawned.id();
@@ -636,7 +632,7 @@ impl GamePacketHandler<'_> {
Some(p.uuid),
&mut entity_id_index,
&mut entity_uuid_index,
- &mut instance.write(),
+ &mut world.write(),
);
// add the GameProfileComponent if the uuid is in the tab list
@@ -659,12 +655,12 @@ impl GamePacketHandler<'_> {
pub fn set_entity_data(&mut self, p: &ClientboundSetEntityData) {
as_system::<(
Commands,
- Query<(&EntityIdIndex, &InstanceHolder)>,
+ Query<(&EntityIdIndex, &WorldHolder)>,
// this is a separate query since it's applied on the entity id that's being updated
// instead of the player that received the packet
Query<&EntityKindComponent>,
)>(self.ecs, |(mut commands, query, entity_kind_query)| {
- let (entity_id_index, instance_holder) = query.get(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get(self.player).unwrap();
let entity = entity_id_index.get_by_minecraft_entity(p.id);
@@ -693,7 +689,7 @@ impl GamePacketHandler<'_> {
// we use RelativeEntityUpdate because it makes sure changes aren't made
// multiple times
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity| {
let entity_id = entity.id();
entity.world_scope(|world| {
@@ -720,10 +716,10 @@ impl GamePacketHandler<'_> {
// vanilla servers use this packet for knockback, but note that the Explode
// packet is also sometimes used by servers for knockback
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, query)| {
- let (entity_id_index, instance_holder) = query.get(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get(self.player).unwrap();
let Some(entity) = entity_id_index.get_by_minecraft_entity(p.id) else {
// note that this log (and some other ones like the one in RemoveEntities)
@@ -742,7 +738,7 @@ impl GamePacketHandler<'_> {
let data = KnockbackData::Set(p.delta.to_vec3());
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity_mut| {
entity_mut
.world_scope(|world| world.trigger(KnockbackEvent { entity, data }));
@@ -790,10 +786,10 @@ impl GamePacketHandler<'_> {
pub fn teleport_entity(&mut self, p: &ClientboundTeleportEntity) {
debug!("Got teleport entity packet {p:?}");
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, mut query)| {
- let (entity_id_index, instance_holder) = query.get_mut(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get_mut(self.player).unwrap();
let Some(entity) = entity_id_index.get_by_minecraft_entity(p.id) else {
warn!("Got teleport entity packet for unknown entity id {}", p.id);
@@ -804,7 +800,7 @@ impl GamePacketHandler<'_> {
let change = p.change.clone();
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity| {
let entity_id = entity.id();
entity.world_scope(move |world| {
@@ -835,10 +831,10 @@ impl GamePacketHandler<'_> {
pub fn rotate_head(&mut self, _p: &ClientboundRotateHead) {}
pub fn move_entity_pos(&mut self, p: &ClientboundMoveEntityPos) {
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, mut query)| {
- let (entity_id_index, instance_holder) = query.get_mut(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get_mut(self.player).unwrap();
debug!("Got move entity pos packet {p:?}");
@@ -851,7 +847,7 @@ impl GamePacketHandler<'_> {
let new_delta = p.delta.clone();
let new_on_ground = p.on_ground;
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity_mut| {
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
let new_pos = physics.vec_delta_codec.decode(&new_delta);
@@ -874,10 +870,10 @@ impl GamePacketHandler<'_> {
}
pub fn move_entity_pos_rot(&mut self, p: &ClientboundMoveEntityPosRot) {
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, mut query)| {
- let (entity_id_index, instance_holder) = query.get_mut(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get_mut(self.player).unwrap();
debug!("Got move entity pos rot packet {p:?}");
@@ -901,7 +897,7 @@ impl GamePacketHandler<'_> {
let new_on_ground = p.on_ground;
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity_mut| {
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
let new_position = physics.vec_delta_codec.decode(&new_delta);
@@ -924,10 +920,10 @@ impl GamePacketHandler<'_> {
}
pub fn move_entity_rot(&mut self, p: &ClientboundMoveEntityRot) {
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, mut query)| {
- let (entity_id_index, instance_holder) = query.get_mut(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get_mut(self.player).unwrap();
let entity = entity_id_index.get_by_minecraft_entity(p.entity_id);
if let Some(entity) = entity {
@@ -938,7 +934,7 @@ impl GamePacketHandler<'_> {
let new_on_ground = p.on_ground;
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity_mut| {
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
physics.set_on_ground(new_on_ground);
@@ -1113,10 +1109,10 @@ impl GamePacketHandler<'_> {
let mob_effect = p.mob_effect;
let effect_data = &p.data;
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, query)| {
- let (entity_id_index, instance_holder) = query.get(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get(self.player).unwrap();
let Some(entity) = entity_id_index.get_by_minecraft_entity(p.entity_id) else {
debug!(
@@ -1126,10 +1122,10 @@ impl GamePacketHandler<'_> {
return;
};
- let partial_instance = instance_holder.partial_instance.clone();
+ let partial_world = world_holder.partial.clone();
let effect_data = effect_data.clone();
commands.entity(entity).queue(RelativeEntityUpdate::new(
- partial_instance,
+ partial_world,
move |entity| {
if let Some(mut active_effects) = entity.get_mut::<ActiveEffects>() {
active_effects.insert(mob_effect, effect_data.clone());
@@ -1147,11 +1143,11 @@ impl GamePacketHandler<'_> {
pub fn award_stats(&mut self, _p: &ClientboundAwardStats) {}
pub fn block_changed_ack(&mut self, p: &ClientboundBlockChangedAck) {
- as_system::<Query<(&InstanceHolder, &mut BlockStatePredictionHandler)>>(
+ as_system::<Query<(&WorldHolder, &mut BlockStatePredictionHandler)>>(
self.ecs,
|mut query| {
let (local_player, mut prediction_handler) = query.get_mut(self.player).unwrap();
- let world = local_player.instance.read();
+ let world = local_player.shared.read();
prediction_handler.end_prediction_up_to(p.seq, &world);
},
);
@@ -1277,12 +1273,12 @@ impl GamePacketHandler<'_> {
pub fn forget_level_chunk(&mut self, p: &ClientboundForgetLevelChunk) {
debug!("Got forget level chunk packet {p:?}");
- as_system::<Query<&InstanceHolder>>(self.ecs, |mut query| {
+ as_system::<Query<&WorldHolder>>(self.ecs, |mut query| {
let local_player = query.get_mut(self.player).unwrap();
- let mut partial_instance = local_player.partial_instance.write();
+ let mut partial_world = local_player.partial.write();
- partial_instance.chunks.limited_set(&p.pos, None);
+ partial_world.chunks.limited_set(&p.pos, None);
});
}
@@ -1355,10 +1351,10 @@ impl GamePacketHandler<'_> {
let mob_effect = p.effect;
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, query)| {
- let (entity_id_index, instance_holder) = query.get(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get(self.player).unwrap();
let Some(entity) = entity_id_index.get_by_minecraft_entity(p.entity_id) else {
debug!(
@@ -1368,9 +1364,9 @@ impl GamePacketHandler<'_> {
return;
};
- let partial_instance = instance_holder.partial_instance.clone();
+ let partial_world = world_holder.partial.clone();
commands.entity(entity).queue(RelativeEntityUpdate::new(
- partial_instance,
+ partial_world,
move |entity| {
if let Some(mut active_effects) = entity.get_mut::<ActiveEffects>() {
active_effects.remove(mob_effect);
@@ -1405,71 +1401,67 @@ impl GamePacketHandler<'_> {
Commands,
Query<
(
- &mut InstanceHolder,
+ &mut WorldHolder,
&GameProfileComponent,
&ClientInformation,
- Option<&mut InstanceName>,
+ Option<&mut WorldName>,
),
With<LocalEntity>,
>,
MessageWriter<_>,
- ResMut<InstanceContainer>,
+ ResMut<Worlds>,
Query<&mut LoadedBy, Without<LocalEntity>>,
)>(
self.ecs,
- |(mut commands, mut query, mut events, mut instance_container, mut loaded_by_query)| {
- let Ok((mut instance_holder, game_profile, client_information, instance_name)) =
+ |(mut commands, mut query, mut events, mut worlds, mut loaded_by_query)| {
+ let Ok((mut world_holder, game_profile, client_information, world_name)) =
query.get_mut(self.player)
else {
warn!("Got respawn packet but player doesn't have the required components");
return;
};
- let new_instance_name = p.common.dimension.clone();
+ let new_world_name = WorldName(p.common.dimension.clone());
- if let Some(mut instance_name) = instance_name {
- **instance_name = new_instance_name.clone();
+ if let Some(mut world_name) = world_name {
+ *world_name = new_world_name.clone();
} else {
- commands
- .entity(self.player)
- .insert(InstanceName(new_instance_name.clone()));
+ commands.entity(self.player).insert(new_world_name.clone());
}
- let weak_instance;
+ let weak_world;
{
- let client_registries = &instance_holder.instance.read().registries;
+ let client_registries = &world_holder.shared.read().registries;
let Some((_dimension_type, dimension_data)) =
p.common.dimension_type(client_registries)
else {
return;
};
- // add this world to the instance_container (or don't if it's already
- // there)
- weak_instance = instance_container.get_or_insert(
- new_instance_name.clone(),
+ // add this world to the `worlds` (or don't if it's already there)
+ weak_world = worlds.get_or_insert(
+ new_world_name.clone(),
dimension_data.height,
dimension_data.min_y,
client_registries,
);
- events.write(InstanceLoadedEvent {
+ events.write(WorldLoadedEvent {
entity: self.player,
- name: new_instance_name.clone(),
- instance: Arc::downgrade(&weak_instance),
+ name: new_world_name.clone(),
+ world: Arc::downgrade(&weak_world),
});
}
- // set the partial_world to an empty world
- // (when we add chunks or entities those will be in the
- // instance_container)
+ // set the partial world to an empty world (when we add chunks or entities,
+ // those will be in the `worlds`)
- *instance_holder.partial_instance.write() = PartialInstance::new(
+ *world_holder.partial.write() = PartialWorld::new(
azalea_world::chunk_storage::calculate_chunk_storage_range(
client_information.view_distance.into(),
),
Some(self.player),
);
- instance_holder.instance = weak_instance;
+ world_holder.shared = weak_world;
// every entity is now unloaded by this player
for mut loaded_by in &mut loaded_by_query.iter_mut() {
@@ -1481,7 +1473,7 @@ impl GamePacketHandler<'_> {
game_profile.uuid,
Vec3::ZERO,
EntityKind::Player,
- new_instance_name,
+ new_world_name,
);
// update the local gamemode and metadata things
commands.entity(self.player).insert((
@@ -1502,11 +1494,10 @@ impl GamePacketHandler<'_> {
pub fn start_configuration(&mut self, _p: &ClientboundStartConfiguration) {
debug!("Got start configuration packet");
- as_system::<(Commands, Query<(&mut RawConnection, &mut InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&mut RawConnection, &mut WorldHolder)>)>(
self.ecs,
|(mut commands, mut query)| {
- let Some((mut raw_conn, mut instance_holder)) = query.get_mut(self.player).ok()
- else {
+ let Some((mut raw_conn, mut world_holder)) = query.get_mut(self.player).ok() else {
warn!("Got start configuration packet but player doesn't have a RawConnection");
return;
};
@@ -1523,16 +1514,16 @@ impl GamePacketHandler<'_> {
.remove::<crate::JoinedClientBundle>()
.remove::<EntityBundle>();
- instance_holder.reset();
+ world_holder.reset();
},
);
}
pub fn entity_position_sync(&mut self, p: &ClientboundEntityPositionSync) {
- as_system::<(Commands, Query<(&EntityIdIndex, &InstanceHolder)>)>(
+ as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
self.ecs,
|(mut commands, mut query)| {
- let (entity_id_index, instance_holder) = query.get_mut(self.player).unwrap();
+ let (entity_id_index, world_holder) = query.get_mut(self.player).unwrap();
let Some(entity) = entity_id_index.get_by_minecraft_entity(p.id) else {
debug!("Got teleport entity packet for unknown entity id {}", p.id);
@@ -1544,7 +1535,7 @@ impl GamePacketHandler<'_> {
let new_look_direction = p.values.look_direction;
commands.entity(entity).queue(RelativeEntityUpdate::new(
- instance_holder.partial_instance.clone(),
+ world_holder.partial.clone(),
move |entity_mut| {
let is_local_entity = entity_mut.get::<LocalEntity>().is_some();
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
diff --git a/azalea-client/src/plugins/packet/mod.rs b/azalea-client/src/plugins/packet/mod.rs
index 9d842dc6..63a94ee0 100644
--- a/azalea-client/src/plugins/packet/mod.rs
+++ b/azalea-client/src/plugins/packet/mod.rs
@@ -45,7 +45,7 @@ impl Plugin for PacketPlugin {
.add_message::<game::DeathEvent>()
.add_message::<game::KeepAliveEvent>()
.add_message::<game::ResourcePackEvent>()
- .add_message::<game::InstanceLoadedEvent>()
+ .add_message::<game::WorldLoadedEvent>()
.add_message::<login::ReceiveCustomQueryEvent>();
}
}
diff --git a/azalea-client/src/plugins/tick_counter.rs b/azalea-client/src/plugins/tick_counter.rs
index e4b5f0a4..fba8bc1c 100644
--- a/azalea-client/src/plugins/tick_counter.rs
+++ b/azalea-client/src/plugins/tick_counter.rs
@@ -1,6 +1,6 @@
use azalea_core::tick::GameTick;
use azalea_physics::PhysicsSystems;
-use azalea_world::InstanceName;
+use azalea_world::WorldName;
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
@@ -27,9 +27,9 @@ impl Plugin for TickCounterPlugin {
}
}
-/// Increment the [`TicksConnected`] component on every entity
-/// that lives in an instance.
-pub fn increment_counter(mut query: Query<&mut TicksConnected, With<InstanceName>>) {
+/// Increment the [`TicksConnected`] component for every entity that's in any
+/// world.
+pub fn increment_counter(mut query: Query<&mut TicksConnected, With<WorldName>>) {
for mut counter in &mut query {
counter.0 += 1;
}
diff --git a/azalea-client/src/plugins/tick_end.rs b/azalea-client/src/plugins/tick_end.rs
index 15cd2e59..6df46c78 100644
--- a/azalea-client/src/plugins/tick_end.rs
+++ b/azalea-client/src/plugins/tick_end.rs
@@ -4,7 +4,7 @@ use azalea_core::tick::GameTick;
use azalea_entity::LocalEntity;
use azalea_physics::PhysicsSystems;
use azalea_protocol::packets::game::ServerboundClientTickEnd;
-use azalea_world::InstanceName;
+use azalea_world::WorldName;
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
@@ -27,7 +27,7 @@ impl Plugin for TickEndPlugin {
}
pub fn game_tick_packet(
- query: Query<Entity, (With<LocalEntity>, With<InstanceName>)>,
+ query: Query<Entity, (With<LocalEntity>, With<WorldName>)>,
mut commands: Commands,
) {
for entity in query.iter() {
diff --git a/azalea-client/src/test_utils/simulation.rs b/azalea-client/src/test_utils/simulation.rs
index 0e480b92..ce4c919d 100644
--- a/azalea-client/src/test_utils/simulation.rs
+++ b/azalea-client/src/test_utils/simulation.rs
@@ -31,7 +31,7 @@ use azalea_registry::{
data::{Biome, DimensionKind},
identifier::Identifier,
};
-use azalea_world::{Chunk, Instance, Section, palette::PalettedContainer};
+use azalea_world::{Chunk, Section, World, palette::PalettedContainer};
use bevy_app::App;
use bevy_ecs::{
component::Mutable,
@@ -45,7 +45,7 @@ use uuid::Uuid;
use crate::{
InConfigState, LocalPlayerBundle, connection::RawConnection, disconnect::DisconnectEvent,
- local_player::InstanceHolder, packet::game::SendGamePacketEvent, player::GameProfileComponent,
+ local_player::WorldHolder, packet::game::SendGamePacketEvent, player::GameProfileComponent,
};
/// A way to simulate a client in a server, used for some internal tests.
@@ -175,15 +175,15 @@ impl Simulation {
}
pub fn chunk(&self, chunk_pos: ChunkPos) -> Option<Arc<RwLock<Chunk>>> {
- self.component::<InstanceHolder>()
- .instance
+ self.component::<WorldHolder>()
+ .shared
.read()
.chunks
.get(&chunk_pos)
}
pub fn get_block_state(&self, pos: BlockPos) -> Option<BlockState> {
- self.component::<InstanceHolder>()
- .instance
+ self.component::<WorldHolder>()
+ .shared
.read()
.get_block_state(pos)
}
@@ -287,12 +287,12 @@ fn create_local_player_bundle(
let raw_connection = RawConnection::new_networkless(connection_protocol);
- let instance = Instance::default();
- let instance_holder = InstanceHolder::new(entity, Arc::new(RwLock::new(instance)));
+ let world = World::default();
+ let world_holder = WorldHolder::new(entity, Arc::new(RwLock::new(world)));
let local_player_bundle = LocalPlayerBundle {
raw_connection,
- instance_holder,
+ world_holder,
metadata: PlayerMetadataBundle::default(),
};