aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-entity/src')
-rw-r--r--azalea-entity/src/plugin/components.rs10
-rw-r--r--azalea-entity/src/plugin/indexing.rs76
-rw-r--r--azalea-entity/src/plugin/mod.rs71
-rw-r--r--azalea-entity/src/plugin/relative_updates.rs6
4 files changed, 77 insertions, 86 deletions
diff --git a/azalea-entity/src/plugin/components.rs b/azalea-entity/src/plugin/components.rs
index abeab160..4698a808 100644
--- a/azalea-entity/src/plugin/components.rs
+++ b/azalea-entity/src/plugin/components.rs
@@ -1,7 +1,7 @@
use azalea_block::fluid_state::FluidKind;
use azalea_core::position::{BlockPos, ChunkPos, Vec3};
-use azalea_registry::{builtin::EntityKind, identifier::Identifier};
-use azalea_world::InstanceName;
+use azalea_registry::builtin::EntityKind;
+use azalea_world::WorldName;
use bevy_ecs::{bundle::Bundle, component::Component};
use derive_more::{Deref, DerefMut};
use uuid::Uuid;
@@ -18,7 +18,7 @@ use crate::{
pub struct EntityBundle {
pub kind: EntityKindComponent,
pub uuid: EntityUuid,
- pub world_name: InstanceName,
+ pub world_name: WorldName,
pub position: Position,
pub last_sent_position: LastSentPosition,
@@ -36,13 +36,13 @@ pub struct EntityBundle {
}
impl EntityBundle {
- pub fn new(uuid: Uuid, pos: Vec3, kind: EntityKind, world_name: Identifier) -> Self {
+ pub fn new(uuid: Uuid, pos: Vec3, kind: EntityKind, world_name: WorldName) -> Self {
let dimensions = EntityDimensions::from(kind);
Self {
kind: EntityKindComponent(kind),
uuid: EntityUuid(uuid),
- world_name: InstanceName(world_name),
+ world_name,
position: Position(pos),
chunk_pos: EntityChunkPos(ChunkPos::from(&pos)),
last_sent_position: LastSentPosition(pos),
diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs
index 3fba6b3c..9e539c23 100644
--- a/azalea-entity/src/plugin/indexing.rs
+++ b/azalea-entity/src/plugin/indexing.rs
@@ -6,7 +6,7 @@ use std::{
};
use azalea_core::{entity_id::MinecraftEntityId, position::ChunkPos};
-use azalea_world::{Instance, InstanceContainer, InstanceName};
+use azalea_world::{World, WorldName, Worlds};
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
use nohash_hasher::IntMap;
@@ -48,10 +48,10 @@ impl EntityUuidIndex {
/// An index of Minecraft entity IDs to Azalea ECS entities.
///
/// This is a `Component` so local players can keep track of entity IDs
-/// independently from the instance.
+/// independently from the world.
///
-/// If you need a per-instance instead of per-client version of this, you can
-/// use [`Instance::entity_by_id`].
+/// If you need a per-world instead of per-client version of this, you can
+/// use [`World::entity_by_id`].
#[derive(Component, Default)]
pub struct EntityIdIndex {
/// An index of entities by their MinecraftEntityId
@@ -105,7 +105,7 @@ impl EntityIdIndex {
} else {
// this is expected to happen when despawning entities if it was already
// despawned for another reason (like because the client received a
- // remove_entities packet, or if we're in a shared instance where entity ids are
+ // remove_entities packet, or if we're in a shared world where entity ids are
// different for each client)
trace!(
"Failed to remove {entity:?} from a client's EntityIdIndex (using EntityIdIndex::remove_by_ecs_entity). This may be expected behavior."
@@ -125,30 +125,30 @@ impl Debug for EntityUuidIndex {
#[derive(Component, Debug, Deref, DerefMut)]
pub struct EntityChunkPos(pub ChunkPos);
-/// Update the chunk position indexes in [`Instance::entities_by_chunk`].
+/// Update the chunk position indexes in [`World::entities_by_chunk`].
///
-/// [`Instance::entities_by_chunk`]: azalea_world::Instance::entities_by_chunk
+/// [`World::entities_by_chunk`]: azalea_world::World::entities_by_chunk
pub fn update_entity_chunk_positions(
- mut query: Query<(Entity, &Position, &InstanceName, &mut EntityChunkPos), Changed<Position>>,
- instance_container: Res<InstanceContainer>,
+ mut query: Query<(Entity, &Position, &WorldName, &mut EntityChunkPos), Changed<Position>>,
+ worlds: Res<Worlds>,
) {
- for (entity, pos, instance_name, mut entity_chunk_pos) in query.iter_mut() {
+ for (entity, pos, world_name, mut entity_chunk_pos) in query.iter_mut() {
let old_chunk = **entity_chunk_pos;
let new_chunk = ChunkPos::from(*pos);
if old_chunk != new_chunk {
**entity_chunk_pos = new_chunk;
if old_chunk != new_chunk {
- let Some(instance_lock) = instance_container.get(instance_name) else {
+ let Some(world_lock) = worlds.get(world_name) else {
continue;
};
- let mut instance = instance_lock.write();
+ let mut world = world_lock.write();
// move the entity from the old chunk to the new one
- if let Some(entities) = instance.entities_by_chunk.get_mut(&old_chunk) {
+ if let Some(entities) = world.entities_by_chunk.get_mut(&old_chunk) {
entities.remove(&entity);
}
- instance
+ world
.entities_by_chunk
.entry(new_chunk)
.or_default()
@@ -159,20 +159,20 @@ pub fn update_entity_chunk_positions(
}
}
-/// Insert new entities into [`Instance::entities_by_chunk`].
+/// Insert new entities into [`World::entities_by_chunk`].
pub fn insert_entity_chunk_position(
- query: Query<(Entity, &Position, &InstanceName), Added<EntityChunkPos>>,
- instance_container: Res<InstanceContainer>,
+ query: Query<(Entity, &Position, &WorldName), Added<EntityChunkPos>>,
+ worlds: Res<Worlds>,
) {
for (entity, pos, world_name) in query.iter() {
- let Some(instance_lock) = instance_container.get(world_name) else {
+ let Some(world_lock) = worlds.get(world_name) else {
// entity must've been despawned already
continue;
};
- let mut instance = instance_lock.write();
+ let mut world = world_lock.write();
let chunk = ChunkPos::from(*pos);
- instance
+ world
.entities_by_chunk
.entry(chunk)
.or_default()
@@ -185,26 +185,24 @@ pub fn insert_entity_chunk_position(
pub fn remove_despawned_entities_from_indexes(
mut commands: Commands,
mut entity_uuid_index: ResMut<EntityUuidIndex>,
- instance_container: Res<InstanceContainer>,
+ worlds: Res<Worlds>,
query: Query<
(
Entity,
&EntityUuid,
&MinecraftEntityId,
&Position,
- &InstanceName,
+ &WorldName,
&LoadedBy,
),
(Changed<LoadedBy>, Without<LocalEntity>),
>,
mut entity_id_index_query: Query<&mut EntityIdIndex>,
) {
- for (entity, uuid, minecraft_id, position, instance_name, loaded_by) in &query {
- let Some(instance_lock) = instance_container.get(instance_name) else {
- // the instance isn't even loaded by us, so we can safely delete the entity
- debug!(
- "Despawned entity {entity:?} because it's in an instance that isn't loaded anymore"
- );
+ for (entity, uuid, minecraft_id, position, world_name, loaded_by) in &query {
+ let Some(world_lock) = worlds.get(world_name) else {
+ // the world isn't even loaded by us, so we can safely delete the entity
+ debug!("Despawned entity {entity:?} because it's in a world that isn't loaded anymore");
if entity_uuid_index.entity_by_uuid.remove(uuid).is_none() {
warn!(
"Tried to remove entity {entity:?} from the uuid index but it was not there."
@@ -216,7 +214,7 @@ pub fn remove_despawned_entities_from_indexes(
continue;
};
- let mut instance = instance_lock.write();
+ let mut world = world_lock.write();
// if the entity is being loaded by any of our clients, don't despawn it
if !loaded_by.is_empty() {
@@ -225,17 +223,17 @@ pub fn remove_despawned_entities_from_indexes(
// remove the entity from the chunk index
let chunk = ChunkPos::from(position);
- match instance.entities_by_chunk.get_mut(&chunk) {
+ match world.entities_by_chunk.get_mut(&chunk) {
Some(entities_in_chunk) => {
if entities_in_chunk.remove(&entity) {
// remove the chunk if there's no entities in it anymore
if entities_in_chunk.is_empty() {
- instance.entities_by_chunk.remove(&chunk);
+ world.entities_by_chunk.remove(&chunk);
}
} else {
// search all the other chunks for it :(
let mut found_in_other_chunks = HashSet::new();
- for (other_chunk, entities_in_other_chunk) in &mut instance.entities_by_chunk {
+ for (other_chunk, entities_in_other_chunk) in &mut world.entities_by_chunk {
if entities_in_other_chunk.remove(&entity) {
found_in_other_chunks.insert(other_chunk);
}
@@ -253,7 +251,7 @@ pub fn remove_despawned_entities_from_indexes(
}
_ => {
let mut found_in_other_chunks = HashSet::new();
- for (other_chunk, entities_in_other_chunk) in &mut instance.entities_by_chunk {
+ for (other_chunk, entities_in_other_chunk) in &mut world.entities_by_chunk {
if entities_in_other_chunk.remove(&entity) {
found_in_other_chunks.insert(other_chunk);
}
@@ -273,9 +271,9 @@ pub fn remove_despawned_entities_from_indexes(
if entity_uuid_index.entity_by_uuid.remove(uuid).is_none() {
warn!("Tried to remove entity {entity:?} from the uuid index but it was not there.");
}
- if instance.entity_by_id.remove(minecraft_id).is_none() {
+ if world.entity_by_id.remove(minecraft_id).is_none() {
debug!(
- "Tried to remove entity {entity:?} from the per-instance entity id index but it was not there. This may be expected if you're in a shared instance."
+ "Tried to remove entity {entity:?} from the per-world entity id index but it was not there. This may be expected if you're in a shared world."
);
}
@@ -296,16 +294,16 @@ pub fn add_entity_to_indexes(
entity_uuid: Option<Uuid>,
entity_id_index: &mut EntityIdIndex,
entity_uuid_index: &mut EntityUuidIndex,
- instance: &mut Instance,
+ world: &mut World,
) {
// per-client id index
entity_id_index.insert(entity_id, ecs_entity);
- // per-instance id index
- instance.entity_by_id.insert(entity_id, ecs_entity);
+ // per-world id index
+ world.entity_by_id.insert(entity_id, ecs_entity);
if let Some(uuid) = entity_uuid {
- // per-instance uuid index
+ // per-world uuid index
entity_uuid_index.insert(uuid, ecs_entity);
}
}
diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs
index 03dda233..e40c24f2 100644
--- a/azalea-entity/src/plugin/mod.rs
+++ b/azalea-entity/src/plugin/mod.rs
@@ -11,7 +11,7 @@ use azalea_core::{
tick::GameTick,
};
use azalea_registry::{builtin::BlockKind, tags};
-use azalea_world::{ChunkStorage, InstanceContainer, InstanceName};
+use azalea_world::{ChunkStorage, WorldName, Worlds};
use bevy_app::{App, Plugin, PostUpdate, Update};
use bevy_ecs::prelude::*;
pub use components::*;
@@ -97,22 +97,17 @@ pub fn add_dead(mut commands: Commands, query: Query<(Entity, &Health), Changed<
}
pub fn update_fluid_on_eyes(
- mut query: Query<(
- &mut FluidOnEyes,
- &Position,
- &EntityDimensions,
- &InstanceName,
- )>,
- instance_container: Res<InstanceContainer>,
+ mut query: Query<(&mut FluidOnEyes, &Position, &EntityDimensions, &WorldName)>,
+ worlds: Res<Worlds>,
) {
- for (mut fluid_on_eyes, position, dimensions, instance_name) in query.iter_mut() {
- let Some(instance) = instance_container.get(instance_name) else {
+ for (mut fluid_on_eyes, position, dimensions, world_name) in query.iter_mut() {
+ let Some(world) = worlds.get(world_name) else {
continue;
};
let adjusted_eye_y = position.y + (dimensions.eye_height as f64) - 0.1111111119389534;
let eye_block_pos = BlockPos::from(position.with_y(adjusted_eye_y));
- let fluid_at_eye = instance
+ let fluid_at_eye = world
.read()
.get_fluid_state(eye_block_pos)
.unwrap_or_default();
@@ -126,10 +121,10 @@ pub fn update_fluid_on_eyes(
}
pub fn update_on_climbable(
- mut query: Query<(&mut OnClimbable, &Position, &InstanceName), With<LocalEntity>>,
- instance_container: Res<InstanceContainer>,
+ mut query: Query<(&mut OnClimbable, &Position, &WorldName), With<LocalEntity>>,
+ worlds: Res<Worlds>,
) {
- for (mut on_climbable, position, instance_name) in query.iter_mut() {
+ for (mut on_climbable, position, world_name) in query.iter_mut() {
// TODO: there's currently no gamemode component that can be accessed from here,
// maybe LocalGameMode should be replaced with two components, maybe called
// EntityGameMode and PreviousGameMode?
@@ -138,27 +133,27 @@ pub fn update_on_climbable(
// continue;
// }
- let Some(instance) = instance_container.get(instance_name) else {
+ let Some(world) = worlds.get(world_name) else {
continue;
};
- let instance = instance.read();
+ let world = world.read();
let block_pos = BlockPos::from(position);
- let block_state_at_feet = instance.get_block_state(block_pos).unwrap_or_default();
+ let block_state_at_feet = world.get_block_state(block_pos).unwrap_or_default();
let block_at_feet = Box::<dyn BlockTrait>::from(block_state_at_feet);
let registry_block_at_feet = block_at_feet.as_registry_block();
**on_climbable = tags::blocks::CLIMBABLE.contains(&registry_block_at_feet)
|| (tags::blocks::TRAPDOORS.contains(&registry_block_at_feet)
- && is_trapdoor_useable_as_ladder(block_state_at_feet, block_pos, &instance));
+ && is_trapdoor_usable_as_ladder(block_state_at_feet, block_pos, &world));
}
}
-fn is_trapdoor_useable_as_ladder(
+fn is_trapdoor_usable_as_ladder(
block_state: BlockState,
block_pos: BlockPos,
- instance: &azalea_world::Instance,
+ world: &azalea_world::World,
) -> bool {
// trapdoor must be open
if !block_state
@@ -169,9 +164,7 @@ fn is_trapdoor_useable_as_ladder(
}
// block below must be a ladder
- let block_below = instance
- .get_block_state(block_pos.down(1))
- .unwrap_or_default();
+ let block_below = world.get_block_state(block_pos.down(1)).unwrap_or_default();
let registry_block_below = Box::<dyn BlockTrait>::from(block_below).as_registry_block();
if registry_block_below != BlockKind::Ladder {
return false;
@@ -257,17 +250,17 @@ pub struct InLoadedChunk;
/// Update the [`InLoadedChunk`] component for all entities in the world.
pub fn update_in_loaded_chunk(
mut commands: bevy_ecs::system::Commands,
- query: Query<(Entity, &InstanceName, &Position)>,
- instance_container: Res<InstanceContainer>,
+ query: Query<(Entity, &WorldName, &Position)>,
+ worlds: Res<Worlds>,
) {
- for (entity, instance_name, position) in &query {
+ for (entity, world_name, position) in &query {
let player_chunk_pos = ChunkPos::from(position);
- let Some(instance_lock) = instance_container.get(instance_name) else {
+ let Some(world_lock) = worlds.get(world_name) else {
commands.entity(entity).remove::<InLoadedChunk>();
continue;
};
- let in_loaded_chunk = instance_lock.read().chunks.get(&player_chunk_pos).is_some();
+ let in_loaded_chunk = world_lock.read().chunks.get(&player_chunk_pos).is_some();
if in_loaded_chunk {
commands.entity(entity).insert(InLoadedChunk);
} else {
@@ -326,20 +319,20 @@ mod tests {
};
use azalea_core::position::{BlockPos, ChunkPos};
use azalea_registry::builtin::BlockKind;
- use azalea_world::{Chunk, ChunkStorage, Instance, PartialInstance};
+ use azalea_world::{Chunk, ChunkStorage, PartialWorld, World};
- use super::is_trapdoor_useable_as_ladder;
+ use super::is_trapdoor_usable_as_ladder;
#[test]
fn test_is_trapdoor_useable_as_ladder() {
- let mut partial_instance = PartialInstance::default();
+ let mut partial_world = PartialWorld::default();
let mut chunks = ChunkStorage::default();
- partial_instance.chunks.set(
+ partial_world.chunks.set(
&ChunkPos { x: 0, z: 0 },
Some(Chunk::default()),
&mut chunks,
);
- partial_instance.chunks.set_block_state(
+ partial_world.chunks.set_block_state(
BlockPos::new(0, 0, 0),
BlockKind::Stone.into(),
&chunks,
@@ -349,7 +342,7 @@ mod tests {
facing: FacingCardinal::East,
waterlogged: false,
};
- partial_instance
+ partial_world
.chunks
.set_block_state(BlockPos::new(0, 0, 0), ladder.into(), &chunks);
@@ -360,17 +353,17 @@ mod tests {
powered: false,
waterlogged: false,
};
- partial_instance
+ partial_world
.chunks
.set_block_state(BlockPos::new(0, 1, 0), trapdoor.into(), &chunks);
- let instance = Instance::from(chunks);
- let trapdoor_matches_ladder = is_trapdoor_useable_as_ladder(
- instance
+ let world = World::from(chunks);
+ let trapdoor_matches_ladder = is_trapdoor_usable_as_ladder(
+ world
.get_block_state(BlockPos::new(0, 1, 0))
.unwrap_or_default(),
BlockPos::new(0, 1, 0),
- &instance,
+ &world,
);
assert!(trapdoor_matches_ladder);
diff --git a/azalea-entity/src/plugin/relative_updates.rs b/azalea-entity/src/plugin/relative_updates.rs
index f80ccddc..53eb4c95 100644
--- a/azalea-entity/src/plugin/relative_updates.rs
+++ b/azalea-entity/src/plugin/relative_updates.rs
@@ -18,7 +18,7 @@
use std::sync::Arc;
use azalea_core::entity_id::MinecraftEntityId;
-use azalea_world::PartialInstance;
+use azalea_world::PartialWorld;
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
use parking_lot::RwLock;
@@ -38,13 +38,13 @@ use crate::LocalEntity;
/// other clients within render distance will get too. You usually don't need
/// this when the change isn't relative either.
pub struct RelativeEntityUpdate {
- pub partial_world: Arc<RwLock<PartialInstance>>,
+ pub partial_world: Arc<RwLock<PartialWorld>>,
// a function that takes the entity and updates it
pub update: Box<dyn FnOnce(&mut EntityWorldMut) + Send + Sync>,
}
impl RelativeEntityUpdate {
pub fn new(
- partial_world: Arc<RwLock<PartialInstance>>,
+ partial_world: Arc<RwLock<PartialWorld>>,
update: impl FnOnce(&mut EntityWorldMut) + Send + Sync + 'static,
) -> Self {
Self {