diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-05-03 20:57:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-03 20:57:27 -0500 |
| commit | 634cb8d72c6608512aedba19e5cd669104bc35ea (patch) | |
| tree | f8e76ce9eb43403d29cc0cbcf9a4f51522419dc2 /azalea-world | |
| parent | 1fb4418f2c9cbd004c64c2f23d2d0352ee12c0e5 (diff) | |
| download | azalea-drasl-634cb8d72c6608512aedba19e5cd669104bc35ea.tar.xz | |
Inventory (#48)
* start adding azalea-inventory
* design more of how inventories are defined
* start working on az-inv-macros
* inventory macro works
* start adding inventory codegen
* update some deps
* add inventory codegen
* manually write inventory menus
* put the inventories in Client
* start on containersetcontent
* inventory menu should hopefully work
* checks in containersetcontent
* format a comment
* move some variant matches
* inventory.rs
* inventory stuff
* more inventory stuff
* inventory/container tracking works
* start adding interact function
* sequence number
* start adding HitResultComponent
* implement traverse_blocks
* start adding clip
* add clip function
* update_hit_result_component
* start trying to fix
* fix
* make some stuff simpler
* clippy
* lever
* chest
* container handle
* fix ambiguity
* fix some doc tests
* move some container stuff from az-client to azalea
* clicking container
* start implementing simulate_click
* keep working on simulate click
* implement more of simulate_click
this is really boring
* inventory fixes
* start implementing shift clicking
* fix panic in azalea-chat i hope
* shift clicking implemented
* more inventory stuff
* fix items not showing in containers sometimes
* fix test
* fix all warnings
* remove a println
---------
Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea-world')
| -rw-r--r-- | azalea-world/Cargo.toml | 4 | ||||
| -rwxr-xr-x | azalea-world/README.md | 2 | ||||
| -rw-r--r-- | azalea-world/src/container.rs | 4 | ||||
| -rwxr-xr-x | azalea-world/src/entity/data.rs | 5 | ||||
| -rw-r--r-- | azalea-world/src/entity/info.rs | 18 | ||||
| -rw-r--r-- | azalea-world/src/entity/metadata.rs | 53 | ||||
| -rw-r--r-- | azalea-world/src/entity/mod.rs | 108 | ||||
| -rw-r--r-- | azalea-world/src/world.rs | 22 |
8 files changed, 143 insertions, 73 deletions
diff --git a/azalea-world/Cargo.toml b/azalea-world/Cargo.toml index 113125a4..81984900 100644 --- a/azalea-world/Cargo.toml +++ b/azalea-world/Cargo.toml @@ -15,6 +15,7 @@ azalea-chat = { path = "../azalea-chat", version = "^0.6.0" } azalea-core = { path = "../azalea-core", version = "^0.6.0", features = [ "bevy_ecs", ] } +azalea-inventory = { version = "0.1.0", path = "../azalea-inventory" } azalea-nbt = { path = "../azalea-nbt", version = "^0.6.0" } azalea-registry = { path = "../azalea-registry", version = "^0.6.0" } bevy_app = "0.10.0" @@ -30,3 +31,6 @@ uuid = "1.1.2" [profile.release] lto = true + +[dev-dependencies] +azalea-client = { path = "../azalea-client" } diff --git a/azalea-world/README.md b/azalea-world/README.md index 6f68ab42..9b237db0 100755 --- a/azalea-world/README.md +++ b/azalea-world/README.md @@ -1,3 +1 @@ -# Azalea World - The Minecraft world representation used in Azalea. diff --git a/azalea-world/src/container.rs b/azalea-world/src/container.rs index c8af8c99..2cf8da8e 100644 --- a/azalea-world/src/container.rs +++ b/azalea-world/src/container.rs @@ -8,7 +8,7 @@ use std::{ sync::{Arc, Weak}, }; -use crate::{ChunkStorage, Instance}; +use crate::{entity::WorldName, ChunkStorage, Instance}; /// A container of [`Instance`]s (aka worlds). Instances are stored as a Weak /// pointer here, so if no clients are using an instance it will be forgotten. @@ -37,7 +37,7 @@ impl InstanceContainer { } /// Get a world from the container. - pub fn get(&self, name: &ResourceLocation) -> Option<Arc<RwLock<Instance>>> { + pub fn get(&self, name: &WorldName) -> Option<Arc<RwLock<Instance>>> { self.worlds.get(name).and_then(|world| world.upgrade()) } diff --git a/azalea-world/src/entity/data.rs b/azalea-world/src/entity/data.rs index c761a786..31d4ca2f 100755 --- a/azalea-world/src/entity/data.rs +++ b/azalea-world/src/entity/data.rs @@ -4,7 +4,8 @@ use azalea_buf::{ BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, }; use azalea_chat::FormattedText; -use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot, Vec3}; +use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Vec3}; +use azalea_inventory::ItemSlot; use bevy_ecs::component::Component; use derive_more::Deref; use enum_as_inner::EnumAsInner; @@ -60,7 +61,7 @@ pub enum EntityDataValue { String(String), FormattedText(FormattedText), OptionalFormattedText(Option<FormattedText>), - ItemStack(Slot), + ItemStack(ItemSlot), Boolean(bool), Rotations(Rotations), BlockPos(BlockPos), diff --git a/azalea-world/src/entity/info.rs b/azalea-world/src/entity/info.rs index fdfe82c2..525b57fa 100644 --- a/azalea-world/src/entity/info.rs +++ b/azalea-world/src/entity/info.rs @@ -29,7 +29,7 @@ use std::{ }; use uuid::Uuid; -use super::Local; +use super::{Local, LookDirection}; /// A Bevy [`SystemSet`] for various types of entity updates. #[derive(SystemSet, Debug, Hash, Eq, PartialEq, Clone)] @@ -75,6 +75,7 @@ impl Plugin for EntityPlugin { debug_detect_updates_received_on_local_entities, add_dead, update_bounding_box, + clamp_look_direction, )) .init_resource::<EntityInfos>(); } @@ -218,10 +219,10 @@ fn update_entity_chunk_positions( ), Changed<entity::Position>, >, - world_container: Res<InstanceContainer>, + instance_container: Res<InstanceContainer>, ) { for (entity, pos, last_pos, world_name) in query.iter_mut() { - let world_lock = world_container.get(world_name).unwrap(); + let world_lock = instance_container.get(world_name).unwrap(); let mut world = world_lock.write(); let old_chunk = ChunkPos::from(*last_pos); @@ -285,11 +286,11 @@ fn debug_detect_updates_received_on_local_entities( fn remove_despawned_entities_from_indexes( mut commands: Commands, mut entity_infos: ResMut<EntityInfos>, - world_container: Res<InstanceContainer>, + instance_container: Res<InstanceContainer>, query: Query<(Entity, &EntityUuid, &Position, &WorldName, &LoadedBy), Changed<LoadedBy>>, ) { for (entity, uuid, position, world_name, loaded_by) in &query { - let world_lock = world_container.get(world_name).unwrap(); + let world_lock = instance_container.get(world_name).unwrap(); let mut world = world_lock.write(); // if the entity has no references left, despawn it @@ -322,6 +323,13 @@ fn remove_despawned_entities_from_indexes( } } +pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) { + for mut look_direction in &mut query { + look_direction.y_rot %= 360.0; + look_direction.x_rot = look_direction.x_rot.clamp(-90.0, 90.0) % 360.0; + } +} + impl Debug for EntityInfos { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("EntityInfos").finish() diff --git a/azalea-world/src/entity/metadata.rs b/azalea-world/src/entity/metadata.rs index f7b19744..ed7aa40c 100644 --- a/azalea-world/src/entity/metadata.rs +++ b/azalea-world/src/entity/metadata.rs @@ -8,7 +8,8 @@ use super::{ SnifferState, VillagerData, }; use azalea_chat::FormattedText; -use azalea_core::{BlockPos, Direction, Particle, Slot, Vec3}; +use azalea_core::{BlockPos, Direction, Particle, Vec3}; +use azalea_inventory::ItemSlot; use bevy_ecs::{bundle::Bundle, component::Component}; use derive_more::{Deref, DerefMut}; use thiserror::Error; @@ -2140,7 +2141,7 @@ impl Default for DrownedMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct EggItemStack(pub Slot); +pub struct EggItemStack(pub ItemSlot); #[derive(Component)] pub struct Egg; impl Egg { @@ -2186,7 +2187,7 @@ impl Default for EggMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - egg_item_stack: EggItemStack(Slot::Empty), + egg_item_stack: EggItemStack(ItemSlot::Empty), } } } @@ -2397,7 +2398,7 @@ impl Default for EnderDragonMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct EnderPearlItemStack(pub Slot); +pub struct EnderPearlItemStack(pub ItemSlot); #[derive(Component)] pub struct EnderPearl; impl EnderPearl { @@ -2443,7 +2444,7 @@ impl Default for EnderPearlMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - ender_pearl_item_stack: EnderPearlItemStack(Slot::Empty), + ender_pearl_item_stack: EnderPearlItemStack(ItemSlot::Empty), } } } @@ -2733,7 +2734,7 @@ impl Default for EvokerFangsMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct ExperienceBottleItemStack(pub Slot); +pub struct ExperienceBottleItemStack(pub ItemSlot); #[derive(Component)] pub struct ExperienceBottle; impl ExperienceBottle { @@ -2779,7 +2780,7 @@ impl Default for ExperienceBottleMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - experience_bottle_item_stack: ExperienceBottleItemStack(Slot::Empty), + experience_bottle_item_stack: ExperienceBottleItemStack(ItemSlot::Empty), } } } @@ -2830,7 +2831,7 @@ impl Default for ExperienceOrbMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct EyeOfEnderItemStack(pub Slot); +pub struct EyeOfEnderItemStack(pub ItemSlot); #[derive(Component)] pub struct EyeOfEnder; impl EyeOfEnder { @@ -2876,7 +2877,7 @@ impl Default for EyeOfEnderMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - eye_of_ender_item_stack: EyeOfEnderItemStack(Slot::Empty), + eye_of_ender_item_stack: EyeOfEnderItemStack(ItemSlot::Empty), } } } @@ -2934,7 +2935,7 @@ impl Default for FallingBlockMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct FireballItemStack(pub Slot); +pub struct FireballItemStack(pub ItemSlot); #[derive(Component)] pub struct Fireball; impl Fireball { @@ -2980,13 +2981,13 @@ impl Default for FireballMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - fireball_item_stack: FireballItemStack(Slot::Empty), + fireball_item_stack: FireballItemStack(ItemSlot::Empty), } } } #[derive(Component, Deref, DerefMut, Clone)] -pub struct FireworksItem(pub Slot); +pub struct FireworksItem(pub ItemSlot); #[derive(Component, Deref, DerefMut, Clone)] pub struct AttachedToTarget(pub OptionalUnsignedInt); #[derive(Component, Deref, DerefMut, Clone)] @@ -3044,7 +3045,7 @@ impl Default for FireworkRocketMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - fireworks_item: FireworksItem(Slot::Empty), + fireworks_item: FireworksItem(ItemSlot::Empty), attached_to_target: AttachedToTarget(OptionalUnsignedInt(None)), shot_at_angle: ShotAtAngle(false), } @@ -3521,7 +3522,7 @@ impl Default for GiantMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct ItemFrameItem(pub Slot); +pub struct ItemFrameItem(pub ItemSlot); #[derive(Component, Deref, DerefMut, Clone)] pub struct Rotation(pub i32); #[derive(Component)] @@ -3567,7 +3568,7 @@ impl Default for GlowItemFrameMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - item_frame_item: ItemFrameItem(Slot::Empty), + item_frame_item: ItemFrameItem(ItemSlot::Empty), rotation: Rotation(0), }, } @@ -4356,7 +4357,7 @@ impl Default for IronGolemMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct ItemItem(pub Slot); +pub struct ItemItem(pub ItemSlot); #[derive(Component)] pub struct Item; impl Item { @@ -4402,7 +4403,7 @@ impl Default for ItemMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - item_item: ItemItem(Slot::Empty), + item_item: ItemItem(ItemSlot::Empty), } } } @@ -4436,7 +4437,7 @@ pub struct ItemDisplayHeight(pub f32); #[derive(Component, Deref, DerefMut, Clone)] pub struct ItemDisplayGlowColorOverride(pub i32); #[derive(Component, Deref, DerefMut, Clone)] -pub struct ItemDisplayItemStack(pub Slot); +pub struct ItemDisplayItemStack(pub ItemSlot); #[derive(Component, Deref, DerefMut, Clone)] pub struct ItemDisplayItemDisplay(pub u8); #[derive(Component)] @@ -4580,7 +4581,7 @@ impl Default for ItemDisplayMetadataBundle { item_display_width: ItemDisplayWidth(0.0), item_display_height: ItemDisplayHeight(0.0), item_display_glow_color_override: ItemDisplayGlowColorOverride(-1), - item_display_item_stack: ItemDisplayItemStack(Slot::Empty), + item_display_item_stack: ItemDisplayItemStack(ItemSlot::Empty), item_display_item_display: ItemDisplayItemDisplay(Default::default()), } } @@ -4635,7 +4636,7 @@ impl Default for ItemFrameMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - item_frame_item: ItemFrameItem(Slot::Empty), + item_frame_item: ItemFrameItem(ItemSlot::Empty), rotation: Rotation(0), } } @@ -6192,7 +6193,7 @@ impl Default for PolarBearMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct PotionItemStack(pub Slot); +pub struct PotionItemStack(pub ItemSlot); #[derive(Component)] pub struct Potion; impl Potion { @@ -6238,7 +6239,7 @@ impl Default for PotionMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - potion_item_stack: PotionItemStack(Slot::Empty), + potion_item_stack: PotionItemStack(ItemSlot::Empty), } } } @@ -7070,7 +7071,7 @@ impl Default for SlimeMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct SmallFireballItemStack(pub Slot); +pub struct SmallFireballItemStack(pub ItemSlot); #[derive(Component)] pub struct SmallFireball; impl SmallFireball { @@ -7116,7 +7117,7 @@ impl Default for SmallFireballMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - small_fireball_item_stack: SmallFireballItemStack(Slot::Empty), + small_fireball_item_stack: SmallFireballItemStack(ItemSlot::Empty), } } } @@ -7281,7 +7282,7 @@ impl Default for SnowGolemMetadataBundle { } #[derive(Component, Deref, DerefMut, Clone)] -pub struct SnowballItemStack(pub Slot); +pub struct SnowballItemStack(pub ItemSlot); #[derive(Component)] pub struct Snowball; impl Snowball { @@ -7327,7 +7328,7 @@ impl Default for SnowballMetadataBundle { pose: Pose::default(), ticks_frozen: TicksFrozen(0), }, - snowball_item_stack: SnowballItemStack(Slot::Empty), + snowball_item_stack: SnowballItemStack(ItemSlot::Empty), } } } diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index 84c183ff..d1d29a5a 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -23,7 +23,8 @@ pub use data::*; use derive_more::{Deref, DerefMut}; pub use dimensions::{update_bounding_box, EntityDimensions}; pub use info::{ - EntityInfos, EntityPlugin, EntityUpdateSet, LoadedBy, PartialEntityInfos, RelativeEntityUpdate, + clamp_look_direction, EntityInfos, EntityPlugin, EntityUpdateSet, LoadedBy, PartialEntityInfos, + RelativeEntityUpdate, }; use std::fmt::Debug; use uuid::Uuid; @@ -38,19 +39,18 @@ impl std::hash::Hash for MinecraftEntityId { } } impl nohash_hasher::IsEnabled for MinecraftEntityId {} -pub fn set_rotation(physics: &mut Physics, y_rot: f32, x_rot: f32) { - physics.y_rot = y_rot % 360.0; - physics.x_rot = x_rot.clamp(-90.0, 90.0) % 360.0; - // TODO: minecraft also sets yRotO and xRotO to xRot and yRot ... but - // idk what they're used for so -} -pub fn move_relative(physics: &mut Physics, speed: f32, acceleration: &Vec3) { - let input_vector = input_vector(physics, speed, acceleration); +pub fn move_relative( + physics: &mut Physics, + direction: &LookDirection, + speed: f32, + acceleration: &Vec3, +) { + let input_vector = input_vector(direction, speed, acceleration); physics.delta += input_vector; } -pub fn input_vector(physics: &mut Physics, speed: f32, acceleration: &Vec3) -> Vec3 { +pub fn input_vector(direction: &LookDirection, speed: f32, acceleration: &Vec3) -> Vec3 { let distance = acceleration.length_squared(); if distance < 1.0E-7 { return Vec3::default(); @@ -61,8 +61,8 @@ pub fn input_vector(physics: &mut Physics, speed: f32, acceleration: &Vec3) -> V *acceleration } .scale(speed as f64); - let y_rot = f32::sin(physics.y_rot * 0.017453292f32); - let x_rot = f32::cos(physics.y_rot * 0.017453292f32); + let y_rot = f32::sin(direction.y_rot * 0.017453292f32); + let x_rot = f32::cos(direction.y_rot * 0.017453292f32); Vec3 { x: acceleration.x * (x_rot as f64) - acceleration.z * (y_rot as f64), y: acceleration.y, @@ -70,6 +70,20 @@ pub fn input_vector(physics: &mut Physics, speed: f32, acceleration: &Vec3) -> V } } +pub fn view_vector(look_direction: &LookDirection) -> Vec3 { + let x_rot = look_direction.x_rot * 0.017453292; + let y_rot = -look_direction.y_rot * 0.017453292; + let y_rot_cos = f32::cos(y_rot); + let y_rot_sin = f32::sin(y_rot); + let x_rot_cos = f32::cos(x_rot); + let x_rot_sin = f32::sin(x_rot); + Vec3 { + x: (y_rot_sin * x_rot_cos) as f64, + y: (-x_rot_sin) as f64, + z: (y_rot_cos * x_rot_cos) as f64, + } +} + /// Get the position of the block below the entity, but a little lower. pub fn on_pos_legacy(chunk_storage: &ChunkStorage, position: &Position) -> BlockPos { on_pos(0.2, chunk_storage, position) @@ -128,6 +142,11 @@ impl Debug for EntityUuid { /// automatically. #[derive(Component, Clone, Copy, Debug, Default, PartialEq, Deref, DerefMut)] pub struct Position(Vec3); +impl From<&Position> for Vec3 { + fn from(value: &Position) -> Self { + value.0 + } +} impl From<Position> for ChunkPos { fn from(value: Position) -> Self { ChunkPos::from(&value.0) @@ -149,9 +168,14 @@ impl From<&Position> for BlockPos { } } -/// The last position of the entity that was sent to the network. +/// The last position of the entity that was sent over the network. #[derive(Component, Clone, Copy, Debug, Default, PartialEq, Deref, DerefMut)] pub struct LastSentPosition(Vec3); +impl From<&LastSentPosition> for Vec3 { + fn from(value: &LastSentPosition) -> Self { + value.0 + } +} impl From<LastSentPosition> for ChunkPos { fn from(value: LastSentPosition) -> Self { ChunkPos::from(&value.0) @@ -182,9 +206,16 @@ pub struct WorldName(pub ResourceLocation); /// /// If this is true, the entity will try to jump every tick. (It's equivalent to /// the space key being held in vanilla.) -#[derive(Debug, Component, Deref, DerefMut)] +#[derive(Debug, Component, Clone, Deref, DerefMut)] pub struct Jumping(bool); +/// A component that contains the direction an entity is looking. +#[derive(Debug, Component, Clone, Default)] +pub struct LookDirection { + pub x_rot: f32, + pub y_rot: f32, +} + /// The physics data relating to the entity, such as position, velocity, and /// bounding box. #[derive(Debug, Component)] @@ -198,12 +229,6 @@ pub struct Physics { /// Z acceleration. pub zza: f32, - pub x_rot: f32, - pub y_rot: f32, - - pub x_rot_last: f32, - pub y_rot_last: f32, - pub on_ground: bool, pub last_on_ground: bool, @@ -237,10 +262,38 @@ pub fn add_dead(mut commands: Commands, query: Query<(Entity, &Health), Changed< } } +/// A component that contains the offset of the entity's eyes from the entity +/// coordinates. +/// +/// This is used to calculate the camera position for players, when spectating +/// an entity, and when raytracing from the entity. +#[derive(Component, Clone, Copy, Debug, PartialEq, Deref, DerefMut)] +pub struct EyeHeight(f32); +impl From<EyeHeight> for f32 { + fn from(value: EyeHeight) -> Self { + value.0 + } +} +impl From<EyeHeight> for f64 { + fn from(value: EyeHeight) -> Self { + value.0 as f64 + } +} +impl From<&EyeHeight> for f32 { + fn from(value: &EyeHeight) -> Self { + value.0 + } +} +impl From<&EyeHeight> for f64 { + fn from(value: &EyeHeight) -> Self { + value.0 as f64 + } +} + /// A component NewType for [`azalea_registry::EntityKind`]. /// /// Most of the time, you should be using `azalea_registry::EntityKind` -/// instead. +/// directly instead. #[derive(Component, Clone, Copy, Debug, PartialEq, Deref)] pub struct EntityKind(pub azalea_registry::EntityKind); @@ -254,6 +307,8 @@ pub struct EntityBundle { pub position: Position, pub last_sent_position: LastSentPosition, pub physics: Physics, + pub direction: LookDirection, + pub eye_height: EyeHeight, pub attributes: Attributes, pub jumping: Jumping, } @@ -265,11 +320,12 @@ impl EntityBundle { kind: azalea_registry::EntityKind, world_name: ResourceLocation, ) -> Self { - // TODO: get correct entity dimensions by having them codegened somewhere + // TODO: get correct entity dimensions by having them codegen'd somewhere let dimensions = EntityDimensions { width: 0.6, height: 1.8, }; + let eye_height = dimensions.height * 0.85; Self { kind: EntityKind(kind), @@ -284,12 +340,6 @@ impl EntityBundle { yya: 0., zza: 0., - x_rot: 0., - y_rot: 0., - - y_rot_last: 0., - x_rot_last: 0., - on_ground: false, last_on_ground: false, @@ -299,6 +349,8 @@ impl EntityBundle { has_impulse: false, }, + eye_height: EyeHeight(eye_height), + direction: LookDirection::default(), attributes: Attributes { // TODO: do the correct defaults for everything, some diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs index e8d25032..a2b351c2 100644 --- a/azalea-world/src/world.rs +++ b/azalea-world/src/world.rs @@ -59,11 +59,11 @@ pub fn deduplicate_entities( (Changed<MinecraftEntityId>, Without<Local>), >, mut loaded_by_query: Query<&mut LoadedBy>, - world_container: Res<InstanceContainer>, + instance_container: Res<InstanceContainer>, ) { // if this entity already exists, remove it for (new_entity, id, world_name) in query.iter_mut() { - if let Some(world_lock) = world_container.get(world_name) { + if let Some(world_lock) = instance_container.get(world_name) { let world = world_lock.write(); if let Some(old_entity) = world.entity_by_id.get(id) { if old_entity == &new_entity { @@ -104,11 +104,11 @@ pub fn deduplicate_local_entities( (Entity, &MinecraftEntityId, &WorldName), (Changed<MinecraftEntityId>, With<Local>), >, - world_container: Res<InstanceContainer>, + instance_container: Res<InstanceContainer>, ) { // if this entity already exists, remove the old one for (new_entity, id, world_name) in query.iter_mut() { - if let Some(world_lock) = world_container.get(world_name) { + if let Some(world_lock) = instance_container.get(world_name) { let world = world_lock.write(); if let Some(old_entity) = world.entity_by_id.get(id) { if old_entity == &new_entity { @@ -154,11 +154,11 @@ pub fn update_uuid_index( // mut commands: Commands, // partial_entity_infos: &mut PartialEntityInfos, // chunk: &ChunkPos, -// world_container: &WorldContainer, +// instance_container: &WorldContainer, // world_name: &WorldName, // mut query: Query<(&MinecraftEntityId, &mut ReferenceCount)>, // ) { -// let world_lock = world_container.get(world_name).unwrap(); +// let world_lock = instance_container.get(world_name).unwrap(); // let world = world_lock.read(); // if let Some(entities) = world.entities_by_chunk.get(chunk).cloned() { @@ -195,6 +195,12 @@ impl Instance { /// /// Note that this is sorted by `x+y+z` and not `x^2+y^2+z^2`, for /// optimization purposes. + /// + /// ``` + /// # fn example(client: &azalea_client::Client) { + /// client.world().read().find_block(client.position(), &azalea_registry::Block::Chest.into()); + /// # } + /// ``` pub fn find_block( &self, nearest_to: impl Into<BlockPos>, @@ -290,10 +296,10 @@ pub fn update_entity_by_id_index( (Entity, &MinecraftEntityId, &WorldName, Option<&Local>), Changed<MinecraftEntityId>, >, - world_container: Res<InstanceContainer>, + instance_container: Res<InstanceContainer>, ) { for (entity, id, world_name, local) in query.iter_mut() { - let world_lock = world_container.get(world_name).unwrap(); + let world_lock = instance_container.get(world_name).unwrap(); let mut world = world_lock.write(); if local.is_none() { if let Some(old_entity) = world.entity_by_id.get(id) { |
