diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2026-01-12 02:09:41 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-12 02:09:41 -0600 |
| commit | 1accbac964168af5fa0d87cb170389f0a9d01363 (patch) | |
| tree | 1509b26c19beaa23a492289f6bf00d3958be44d5 | |
| parent | 58339b9d229592dee40e15b8648fe4075cc391f4 (diff) | |
| download | azalea-drasl-1accbac964168af5fa0d87cb170389f0a9d01363.tar.xz | |
Make Bevy dependencies optional in azalea-protocol (#303)
* Make Bevy dependencies optional in azalea-protocol
* derive serde traits on Direction again
* update docs for types that may not have Component
82 files changed, 563 insertions, 486 deletions
@@ -403,6 +403,7 @@ dependencies = [ "azalea-registry", "bevy_ecs", "crc32c", + "derive_more", "indexmap", "nohash-hasher", "num-traits", @@ -521,7 +522,6 @@ dependencies = [ "azalea-inventory", "azalea-protocol-macros", "azalea-registry", - "azalea-world", "bevy_ecs", "flate2", "futures", @@ -92,26 +92,26 @@ tracing-subscriber = "0.3.22" uuid = "1.19.0" radix-heap = "0.4.2" -azalea-block-macros = { path = "azalea-block/azalea-block-macros", version = "0.15.0" } -azalea-block = { path = "azalea-block", version = "0.15.0" } +azalea-block-macros = { path = "azalea-block/azalea-block-macros", version = "0.15.0", default-features = false } +azalea-block = { path = "azalea-block", version = "0.15.0", default-features = false } azalea-auth = { path = "azalea-auth", version = "0.15.0", default-features = false } -azalea-brigadier = { path = "azalea-brigadier", version = "0.15.0" } -azalea-buf-macros = { path = "azalea-buf/azalea-buf-macros", version = "0.15.0" } -azalea-buf = { path = "azalea-buf", version = "0.15.0" } -azalea-chat = { path = "azalea-chat", version = "0.15.0" } +azalea-brigadier = { path = "azalea-brigadier", version = "0.15.0", default-features = false } +azalea-buf-macros = { path = "azalea-buf/azalea-buf-macros", version = "0.15.0", default-features = false } +azalea-buf = { path = "azalea-buf", version = "0.15.0", default-features = false } +azalea-chat = { path = "azalea-chat", version = "0.15.0", default-features = false } azalea-client = { path = "azalea-client", version = "0.15.0", default-features = false } -azalea-core = { path = "azalea-core", version = "0.15.0" } -azalea-crypto = { path = "azalea-crypto", version = "0.15.0" } -azalea-entity = { path = "azalea-entity", version = "0.15.0" } -azalea-inventory-macros = { path = "azalea-inventory/azalea-inventory-macros", version = "0.15.0" } -azalea-inventory = { path = "azalea-inventory", version = "0.15.0" } -azalea-language = { path = "azalea-language", version = "0.15.0" } -azalea-physics = { path = "azalea-physics", version = "0.15.0" } -azalea-protocol-macros = { path = "azalea-protocol/azalea-protocol-macros", version = "0.15.0" } +azalea-core = { path = "azalea-core", version = "0.15.0", default-features = false } +azalea-crypto = { path = "azalea-crypto", version = "0.15.0", default-features = false } +azalea-entity = { path = "azalea-entity", version = "0.15.0", default-features = false } +azalea-inventory-macros = { path = "azalea-inventory/azalea-inventory-macros", version = "0.15.0", default-features = false } +azalea-inventory = { path = "azalea-inventory", version = "0.15.0", default-features = false } +azalea-language = { path = "azalea-language", version = "0.15.0", default-features = false } +azalea-physics = { path = "azalea-physics", version = "0.15.0", default-features = false } +azalea-protocol-macros = { path = "azalea-protocol/azalea-protocol-macros", version = "0.15.0", default-features = false } azalea-protocol = { path = "azalea-protocol", version = "0.15.0", default-features = false } -azalea-registry-macros = { path = "azalea-registry/azalea-registry-macros", version = "0.15.0" } -azalea-registry = { path = "azalea-registry", version = "0.15.0" } -azalea-world = { path = "azalea-world", version = "0.15.0" } +azalea-registry-macros = { path = "azalea-registry/azalea-registry-macros", version = "0.15.0", default-features = false } +azalea-registry = { path = "azalea-registry", version = "0.15.0", default-features = false } +azalea-world = { path = "azalea-world", version = "0.15.0", default-features = false } [workspace.lints.clippy] # https://users.rust-lang.org/t/to-string-vs-to-owned-for-string-literals/1441 diff --git a/azalea-client/Cargo.toml b/azalea-client/Cargo.toml index 5dc05151..b6ed7f12 100644 --- a/azalea-client/Cargo.toml +++ b/azalea-client/Cargo.toml @@ -17,7 +17,7 @@ azalea-crypto.workspace = true azalea-entity.workspace = true azalea-inventory.workspace = true azalea-physics.workspace = true -azalea-protocol = { workspace = true, features = ["connecting"] } +azalea-protocol = { workspace = true, features = ["connecting", "bevy_ecs"] } azalea-registry.workspace = true azalea-world.workspace = true bevy_app.workspace = true diff --git a/azalea-client/src/plugins/disconnect.rs b/azalea-client/src/plugins/disconnect.rs index 8c5036e1..081c174e 100644 --- a/azalea-client/src/plugins/disconnect.rs +++ b/azalea-client/src/plugins/disconnect.rs @@ -4,7 +4,7 @@ use azalea_chat::FormattedText; use azalea_entity::{ EntityBundle, HasClientLoaded, InLoadedChunk, LocalEntity, metadata::PlayerMetadataBundle, }; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use bevy_app::{App, Plugin, PostUpdate}; use bevy_ecs::prelude::*; use derive_more::Deref; diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs index c9473ebf..40cc108e 100644 --- a/azalea-client/src/plugins/movement.rs +++ b/azalea-client/src/plugins/movement.rs @@ -1,4 +1,5 @@ use azalea_core::{ + entity_id::MinecraftEntityId, game_type::GameMode, position::{Vec2, Vec3}, tick::GameTick, @@ -30,7 +31,7 @@ use azalea_protocol::{ }, }; use azalea_registry::builtin::EntityKind; -use azalea_world::{Instance, MinecraftEntityId}; +use azalea_world::Instance; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs index 93057ef4..f93a02ea 100644 --- a/azalea-client/src/plugins/packet/game/mod.rs +++ b/azalea-client/src/plugins/packet/game/mod.rs @@ -3,6 +3,7 @@ mod events; use std::{collections::HashSet, sync::Arc}; use azalea_core::{ + entity_id::MinecraftEntityId, game_type::GameMode, position::{ChunkPos, Vec3}, }; @@ -18,7 +19,7 @@ use azalea_protocol::{ packets::{ConnectionProtocol, game::*}, }; use azalea_registry::builtin::EntityKind; -use azalea_world::{InstanceContainer, InstanceName, MinecraftEntityId, PartialInstance}; +use azalea_world::{InstanceContainer, InstanceName, PartialInstance}; use bevy_ecs::{prelude::*, system::SystemState}; pub use events::*; use tracing::{debug, error, trace, warn}; diff --git a/azalea-client/src/test_utils/simulation.rs b/azalea-client/src/test_utils/simulation.rs index a6bc22ab..0e480b92 100644 --- a/azalea-client/src/test_utils/simulation.rs +++ b/azalea-client/src/test_utils/simulation.rs @@ -5,6 +5,7 @@ use azalea_block::BlockState; use azalea_buf::AzaleaWrite; use azalea_core::{ delta::LpVec3, + entity_id::MinecraftEntityId, game_type::{GameMode, OptionalGameType}, position::{BlockPos, ChunkPos, Vec3}, tick::GameTick, @@ -30,7 +31,7 @@ use azalea_registry::{ data::{Biome, DimensionKind}, identifier::Identifier, }; -use azalea_world::{Chunk, Instance, MinecraftEntityId, Section, palette::PalettedContainer}; +use azalea_world::{Chunk, Instance, Section, palette::PalettedContainer}; use bevy_app::App; use bevy_ecs::{ component::Mutable, diff --git a/azalea-client/tests/simulation/move_and_despawn_entity.rs b/azalea-client/tests/simulation/move_and_despawn_entity.rs index 6c334a47..f05c64f4 100644 --- a/azalea-client/tests/simulation/move_and_despawn_entity.rs +++ b/azalea-client/tests/simulation/move_and_despawn_entity.rs @@ -8,7 +8,7 @@ use azalea_protocol::{ }, }; use azalea_registry::builtin::EntityKind; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[test] fn test_move_and_despawn_entity() { diff --git a/azalea-client/tests/simulation/move_despawned_entity.rs b/azalea-client/tests/simulation/move_despawned_entity.rs index 7a171dae..48c22bf6 100644 --- a/azalea-client/tests/simulation/move_despawned_entity.rs +++ b/azalea-client/tests/simulation/move_despawned_entity.rs @@ -3,7 +3,7 @@ use azalea_core::position::ChunkPos; use azalea_entity::metadata::Cow; use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundMoveEntityRot}; use azalea_registry::builtin::EntityKind; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use bevy_ecs::query::With; use tracing::Level; diff --git a/azalea-client/tests/simulation/teleport_movement.rs b/azalea-client/tests/simulation/teleport_movement.rs index 06a8f0b6..ff06ebb5 100644 --- a/azalea-client/tests/simulation/teleport_movement.rs +++ b/azalea-client/tests/simulation/teleport_movement.rs @@ -16,7 +16,7 @@ use azalea_protocol::{ }, }; use azalea_registry::builtin::BlockKind; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[test] fn test_teleport_movement() { diff --git a/azalea-core/Cargo.toml b/azalea-core/Cargo.toml index bdb80667..ff2f8732 100644 --- a/azalea-core/Cargo.toml +++ b/azalea-core/Cargo.toml @@ -10,9 +10,9 @@ repository.workspace = true azalea-buf.workspace = true azalea-registry.workspace = true bevy_ecs = { workspace = true, optional = true } +serde = { workspace = true, optional = true } nohash-hasher.workspace = true num-traits.workspace = true -serde.workspace = true simdnbt.workspace = true tracing.workspace = true azalea-chat = { workspace = true, features = ["simdnbt"] } @@ -20,9 +20,11 @@ indexmap.workspace = true crc32c.workspace = true thiserror.workspace = true uuid.workspace = true +derive_more = { workspace = true, features = ["deref", "deref_mut"] } [features] bevy_ecs = ["dep:bevy_ecs"] +serde = ["dep:serde"] strict_registry = [] [lints] diff --git a/azalea-core/src/attribute_modifier_operation.rs b/azalea-core/src/attribute_modifier_operation.rs index 8418ff22..ab135080 100644 --- a/azalea-core/src/attribute_modifier_operation.rs +++ b/azalea-core/src/attribute_modifier_operation.rs @@ -1,11 +1,11 @@ use std::str::FromStr; use azalea_buf::AzBuf; -use serde::Serialize; use simdnbt::{FromNbtTag, borrow::NbtTag}; -#[derive(AzBuf, Clone, Copy, Debug, PartialEq, Serialize)] -#[serde(rename_all = "snake_case")] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(AzBuf, Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))] pub enum AttributeModifierOperation { AddValue, AddMultipliedBase, diff --git a/azalea-core/src/data_registry.rs b/azalea-core/src/data_registry.rs index 90628f47..bf1a9c1a 100644 --- a/azalea-core/src/data_registry.rs +++ b/azalea-core/src/data_registry.rs @@ -5,7 +5,7 @@ use azalea_registry::{ }; use simdnbt::owned::NbtCompound; -use crate::registry_holder::{self, RegistryDeserializesTo, RegistryHolder}; +use crate::registry_holder::{RegistryDeserializesTo, RegistryHolder}; pub trait DataRegistryWithKey: DataRegistry { fn key<'s, 'a: 's>( @@ -63,8 +63,8 @@ macro_rules! define_default_deserializes_to { } define_deserializes_to! { - data::DimensionKind => registry_holder::dimension_type::DimensionKindElement, - data::Enchantment => registry_holder::enchantment::EnchantmentData, + data::DimensionKind => crate::registry_holder::dimension_type::DimensionKindElement, + data::Enchantment => crate::registry_holder::enchantment::EnchantmentData, } define_default_deserializes_to! { diff --git a/azalea-core/src/direction.rs b/azalea-core/src/direction.rs index b53df448..5902ffea 100644 --- a/azalea-core/src/direction.rs +++ b/azalea-core/src/direction.rs @@ -2,9 +2,8 @@ use azalea_buf::AzBuf; use crate::position::{BlockPos, Vec3, Vec3i}; -#[derive( - Clone, Copy, Debug, AzBuf, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, -)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[derive(Clone, Copy, Debug, AzBuf, Default, Eq, PartialEq)] pub enum Direction { #[default] Down = 0, @@ -91,7 +90,8 @@ impl Direction { /// /// Note that azalea_block has a similar enum named `FacingCardinal` that is /// used for block states. -#[derive(AzBuf, Clone, Copy, Debug, serde::Deserialize, Eq, Hash, PartialEq, serde::Serialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(AzBuf, Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum CardinalDirection { North, South, diff --git a/azalea-core/src/entity_id.rs b/azalea-core/src/entity_id.rs new file mode 100644 index 00000000..c66d3a2e --- /dev/null +++ b/azalea-core/src/entity_id.rs @@ -0,0 +1,78 @@ +use std::{ + fmt::{self, Display}, + hash::{Hash, Hasher}, + io::{self, Cursor}, +}; + +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use derive_more::{Deref, DerefMut}; + +// note: this is here instead of in azalea-entity because azalea-world depends +// on it. and this isn't in azalea-world so azalea-protocol doesn't need to +// depend on azalea-world. + +/// An entity ID used by Minecraft. +/// +/// These IDs are picked by the server. Some server software (like Bungeecord) +/// may pick entity IDs per-player, so you should avoid relying on them for +/// identifying IDs (especially if you're using a shared world -- i.e. a swarm). +/// +/// You might find [`Entity`] more useful, since that's an ID decided by us that +/// is likely to be correct across shared worlds. You could also use the +/// `EntityUuid` from `azalea_entity`, that one is unlikely to change even +/// across server restarts. +/// +/// This serializes as a i32. Usually it's a VarInt in the protocol, but not +/// always. If you do need it to serialize as a VarInt, make sure to use use the +/// `#[var]` attribute. +/// +/// [`Entity`]: bevy_ecs::entity::Entity +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Copy, Debug, Default, Deref, DerefMut, Eq, PartialEq)] +pub struct MinecraftEntityId(pub i32); + +impl Hash for MinecraftEntityId { + fn hash<H: Hasher>(&self, hasher: &mut H) { + hasher.write_i32(self.0); + } +} +impl nohash_hasher::IsEnabled for MinecraftEntityId {} + +// we can't have the default be #[var] because mojang doesn't use varints for +// entities sometimes :( +impl AzaleaRead for MinecraftEntityId { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + i32::azalea_read(buf).map(MinecraftEntityId) + } +} +impl AzaleaWrite for MinecraftEntityId { + fn azalea_write(&self, buf: &mut impl io::Write) -> io::Result<()> { + i32::azalea_write(&self.0, buf) + } +} +impl AzaleaReadVar for MinecraftEntityId { + fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + i32::azalea_read_var(buf).map(MinecraftEntityId) + } +} +impl AzaleaWriteVar for MinecraftEntityId { + fn azalea_write_var(&self, buf: &mut impl io::Write) -> io::Result<()> { + i32::azalea_write_var(&self.0, buf) + } +} +impl Display for MinecraftEntityId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "eid({})", self.0) + } +} +impl From<i32> for MinecraftEntityId { + fn from(id: i32) -> Self { + Self(id) + } +} +impl From<u32> for MinecraftEntityId { + fn from(id: u32) -> Self { + Self(id as i32) + } +} diff --git a/azalea-core/src/filterable.rs b/azalea-core/src/filterable.rs index fe9a553d..1c9766b6 100644 --- a/azalea-core/src/filterable.rs +++ b/azalea-core/src/filterable.rs @@ -4,13 +4,12 @@ use std::{ }; use azalea_buf::{AzaleaRead, AzaleaReadLimited, AzaleaReadVar, AzaleaWrite}; -use serde::Serialize; /// Used for written books. -#[derive(Serialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct Filterable<T> { pub raw: T, - #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub filtered: Option<T>, } diff --git a/azalea-core/src/heightmap_kind.rs b/azalea-core/src/heightmap_kind.rs new file mode 100644 index 00000000..07100a77 --- /dev/null +++ b/azalea-core/src/heightmap_kind.rs @@ -0,0 +1,50 @@ +// (wg stands for worldgen) + +use std::{ + fmt::{self, Display}, + str::FromStr, +}; + +use azalea_buf::AzBuf; + +/// A type of world heightmap. +/// +/// See `azalea_world::heightmap` for more info. +#[derive(AzBuf, Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub enum HeightmapKind { + WorldSurfaceWg, + WorldSurface, + OceanFloorWg, + OceanFloor, + MotionBlocking, + MotionBlockingNoLeaves, +} + +impl FromStr for HeightmapKind { + type Err = (); + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "WORLD_SURFACE_WG" => Ok(HeightmapKind::WorldSurfaceWg), + "WORLD_SURFACE" => Ok(HeightmapKind::WorldSurface), + "OCEAN_FLOOR_WG" => Ok(HeightmapKind::OceanFloorWg), + "OCEAN_FLOOR" => Ok(HeightmapKind::OceanFloor), + "MOTION_BLOCKING" => Ok(HeightmapKind::MotionBlocking), + "MOTION_BLOCKING_NO_LEAVES" => Ok(HeightmapKind::MotionBlockingNoLeaves), + _ => Err(()), + } + } +} + +impl Display for HeightmapKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + HeightmapKind::WorldSurfaceWg => write!(f, "WORLD_SURFACE_WG"), + HeightmapKind::WorldSurface => write!(f, "WORLD_SURFACE"), + HeightmapKind::OceanFloorWg => write!(f, "OCEAN_FLOOR_WG"), + HeightmapKind::OceanFloor => write!(f, "OCEAN_FLOOR"), + HeightmapKind::MotionBlocking => write!(f, "MOTION_BLOCKING"), + HeightmapKind::MotionBlockingNoLeaves => write!(f, "MOTION_BLOCKING_NO_LEAVES"), + } + } +} diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs index d61690aa..e07f9d88 100644 --- a/azalea-core/src/lib.rs +++ b/azalea-core/src/lib.rs @@ -5,20 +5,26 @@ pub mod aabb; pub mod attribute_modifier_operation; pub mod bitset; +#[cfg(feature = "serde")] pub mod checksum; +#[cfg(feature = "serde")] pub mod codec_utils; pub mod color; pub mod cursor3d; +#[cfg(feature = "serde")] pub mod data_registry; pub mod delta; pub mod difficulty; pub mod direction; +pub mod entity_id; pub mod filterable; pub mod game_type; +pub mod heightmap_kind; pub mod hit_result; pub mod math; pub mod objectives; pub mod position; +#[cfg(feature = "serde")] pub mod registry_holder; #[doc(hidden)] pub mod resource_location { diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 80b189ce..6da037ff 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -14,10 +14,11 @@ use std::{ use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; use azalea_registry::identifier::Identifier; -use serde::{Serialize, Serializer}; +#[cfg(feature = "serde")] +use serde::Serializer; use simdnbt::borrow::NbtTag; -use crate::{codec_utils::IntArray, direction::Direction, math}; +use crate::{direction::Direction, math}; macro_rules! vec3_impl { ($name:ident, $type:ty) => { @@ -305,7 +306,8 @@ macro_rules! vec3_impl { /// Used to represent an exact position in the world where an entity could be. /// /// For blocks, [`BlockPos`] is used instead. -#[derive(AzBuf, Clone, Copy, Debug, Default, serde::Deserialize, PartialEq, serde::Serialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)] pub struct Vec3 { pub x: f64, pub y: f64, @@ -484,15 +486,19 @@ impl BlockPos { (self - other).length() } } +#[cfg(feature = "serde")] impl serde::Serialize for BlockPos { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer, { // makes sure it gets serialized correctly for the checksum + + use crate::codec_utils::IntArray; IntArray([self.x, self.y, self.z]).serialize(serializer) } } +#[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for BlockPos { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where @@ -753,7 +759,8 @@ impl From<ChunkSectionBlockPos> for u16 { impl nohash_hasher::IsEnabled for ChunkSectionBlockPos {} /// A block pos with an attached world -#[derive(Clone, Debug, PartialEq, Serialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Clone, Debug, PartialEq)] pub struct GlobalPos { // this is actually a ResourceKey in Minecraft, but i don't think it matters? pub dimension: Identifier, @@ -911,7 +918,8 @@ impl fmt::Display for Vec3 { } /// A 2D vector. -#[derive(AzBuf, Clone, Copy, Debug, Default, simdnbt::Deserialize, PartialEq, Serialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)] pub struct Vec2 { pub x: f32, pub y: f32, diff --git a/azalea-core/src/sound.rs b/azalea-core/src/sound.rs index 418707b9..e7e0f207 100644 --- a/azalea-core/src/sound.rs +++ b/azalea-core/src/sound.rs @@ -1,8 +1,8 @@ use azalea_buf::AzBuf; use azalea_registry::identifier::Identifier; -use serde::Serialize; -#[derive(AzBuf, Clone, Debug, simdnbt::Deserialize, PartialEq, Serialize)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(AzBuf, Clone, Debug, simdnbt::Deserialize, PartialEq)] pub struct CustomSound { pub sound_id: Identifier, pub range: Option<f32>, diff --git a/azalea-entity/Cargo.toml b/azalea-entity/Cargo.toml index 0e62cbd4..1140d4b8 100644 --- a/azalea-entity/Cargo.toml +++ b/azalea-entity/Cargo.toml @@ -13,9 +13,9 @@ azalea-chat = { workspace = true, features = ["azalea-buf"] } azalea-core.workspace = true azalea-inventory.workspace = true azalea-registry.workspace = true -azalea-world.workspace = true -bevy_app.workspace = true -bevy_ecs.workspace = true +azalea-world = { workspace = true, optional = true } +bevy_app = { workspace = true, optional = true } +bevy_ecs = { workspace = true, optional = true } derive_more.workspace = true enum-as-inner.workspace = true nohash-hasher.workspace = true @@ -24,5 +24,8 @@ thiserror.workspace = true tracing.workspace = true uuid.workspace = true +[features] +bevy_ecs = ["dep:bevy_ecs", "dep:bevy_app", "dep:azalea-world"] + [lints] workspace = true diff --git a/azalea-entity/src/attributes.rs b/azalea-entity/src/attributes.rs index b26f61ba..69e98a7b 100644 --- a/azalea-entity/src/attributes.rs +++ b/azalea-entity/src/attributes.rs @@ -7,14 +7,14 @@ use std::collections::{HashMap, hash_map}; use azalea_core::attribute_modifier_operation::AttributeModifierOperation; use azalea_inventory::components::AttributeModifier; use azalea_registry::{builtin::Attribute, identifier::Identifier}; -use bevy_ecs::component::Component; use thiserror::Error; -/// A component that contains the current attribute values for an entity. +/// The current attribute values for an entity. /// /// Each attribute can have multiple modifiers, and these modifiers are the /// result of things like sprinting or enchantments. -#[derive(Clone, Component, Debug)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Debug)] pub struct Attributes { pub movement_speed: AttributeInstance, pub sneaking_speed: AttributeInstance, diff --git a/azalea-entity/src/data.rs b/azalea-entity/src/data.rs index c9e98b0d..0b973bcb 100644 --- a/azalea-entity/src/data.rs +++ b/azalea-entity/src/data.rs @@ -13,7 +13,6 @@ use azalea_core::{ }; use azalea_inventory::{ItemStack, components}; use azalea_registry::builtin::{VillagerKind, VillagerProfession}; -use bevy_ecs::component::Component; use derive_more::Deref; use enum_as_inner::EnumAsInner; use uuid::Uuid; @@ -154,7 +153,8 @@ pub struct Rotations { pub z: f32, } -#[derive(AzBuf, Clone, Component, Copy, Debug, Default, Eq, PartialEq)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(AzBuf, Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum Pose { #[default] Standing = 0, diff --git a/azalea-entity/src/dimensions.rs b/azalea-entity/src/dimensions.rs index 87eced8a..6c527ab6 100644 --- a/azalea-entity/src/dimensions.rs +++ b/azalea-entity/src/dimensions.rs @@ -1,11 +1,11 @@ use azalea_core::{aabb::Aabb, position::Vec3}; use azalea_registry::builtin::EntityKind; -use bevy_ecs::component::Component; use crate::Pose; -/// A component that contains the size of an entity and their eye height. -#[derive(Clone, Component, Debug, Default)] +/// The size of an entity and its eye height. +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Debug, Default)] pub struct EntityDimensions { pub width: f32, pub height: f32, diff --git a/azalea-entity/src/effects.rs b/azalea-entity/src/effects.rs index ae7ae8a1..39074ebd 100644 --- a/azalea-entity/src/effects.rs +++ b/azalea-entity/src/effects.rs @@ -6,7 +6,6 @@ use std::{ use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; use azalea_core::bitset::FixedBitSet; use azalea_registry::builtin::MobEffect; -use bevy_ecs::component::Component; /// Data about an active mob effect. #[derive(AzBuf, Clone, Debug, Default, PartialEq)] @@ -63,8 +62,9 @@ impl AzaleaWrite for MobEffectFlags { } } -/// An ECS component that stores the active mob effects on an entity. -#[derive(Clone, Component, Debug, Default)] +/// The active mob effects on an entity. +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Debug, Default)] pub struct ActiveEffects(pub HashMap<MobEffect, MobEffectData>); impl ActiveEffects { pub fn insert(&mut self, effect: MobEffect, data: MobEffectData) { diff --git a/azalea-entity/src/inventory.rs b/azalea-entity/src/inventory.rs index aa13865e..fe3921ef 100644 --- a/azalea-entity/src/inventory.rs +++ b/azalea-entity/src/inventory.rs @@ -10,12 +10,13 @@ use azalea_inventory::{ QuickCraftStatusKind, QuickMoveClick, ThrowClick, }, }; -use bevy_ecs::prelude::*; use crate::PlayerAbilities; -/// A component present on all local players that have an inventory. -#[derive(Clone, Component, Debug)] +/// A local player's inventory and related data, including the container that +/// they may have opened. +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Debug)] pub struct Inventory { /// The player's inventory menu. This is guaranteed to be a `Menu::Player`. /// diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs index 40f80930..87e249c1 100644 --- a/azalea-entity/src/lib.rs +++ b/azalea-entity/src/lib.rs @@ -6,9 +6,11 @@ mod data; pub mod dimensions; mod effects; pub mod inventory; +#[cfg(feature = "bevy_ecs")] pub mod metadata; pub mod mining; pub mod particle; +#[cfg(feature = "bevy_ecs")] mod plugin; pub mod vec_delta_codec; @@ -19,25 +21,23 @@ use std::{ }; pub use attributes::Attributes; -use azalea_block::{BlockState, fluid_state::FluidKind}; +use azalea_block::fluid_state::FluidKind; use azalea_buf::AzBuf; use azalea_core::{ aabb::Aabb, math, position::{BlockPos, ChunkPos, Vec3}, }; -use azalea_registry::{builtin::EntityKind, identifier::Identifier}; -use azalea_world::{ChunkStorage, InstanceName}; -use bevy_ecs::{bundle::Bundle, component::Component}; +use azalea_registry::builtin::EntityKind; pub use data::*; use derive_more::{Deref, DerefMut}; pub use effects::{ActiveEffects, MobEffectData}; -use plugin::indexing::EntityChunkPos; use uuid::Uuid; use vec_delta_codec::VecDeltaCodec; use self::attributes::AttributeInstance; use crate::dimensions::EntityDimensions; +#[cfg(feature = "bevy_ecs")] pub use crate::plugin::*; pub fn move_relative( @@ -84,53 +84,12 @@ pub fn view_vector(look_direction: LookDirection) -> Vec3 { } } -/// 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) -} - -// int x = Mth.floor(this.position.x); -// int y = Mth.floor(this.position.y - (double)var1); -// int z = Mth.floor(this.position.z); -// BlockPos var5 = new BlockPos(x, y, z); -// if (this.level.getBlockState(var5).isAir()) { -// BlockPos var6 = var5.below(); -// BlockState var7 = this.level.getBlockState(var6); -// if (var7.is(BlockTags.FENCES) || var7.is(BlockTags.WALLS) || -// var7.getBlock() instanceof FenceGateBlock) { return var6; -// } -// } -// return var5; -pub fn on_pos(offset: f32, chunk_storage: &ChunkStorage, pos: Position) -> BlockPos { - let x = pos.x.floor() as i32; - let y = (pos.y - offset as f64).floor() as i32; - let z = pos.z.floor() as i32; - let pos = BlockPos { x, y, z }; - - // TODO: check if block below is a fence, wall, or fence gate - let block_pos = pos.down(1); - let block_state = chunk_storage.get_block_state(block_pos); - if block_state == Some(BlockState::AIR) { - let block_pos_below = block_pos.down(1); - let block_state_below = chunk_storage.get_block_state(block_pos_below); - if let Some(_block_state_below) = block_state_below { - // if block_state_below.is_fence() - // || block_state_below.is_wall() - // || block_state_below.is_fence_gate() - // { - // return block_pos_below; - // } - } - } - - pos -} - /// The Minecraft UUID of the entity. /// /// For players, this is their actual player UUID, and for other entities it's /// just random. -#[derive(Clone, Component, Copy, Default, Deref, DerefMut, PartialEq)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Copy, Default, Deref, DerefMut, PartialEq)] pub struct EntityUuid(Uuid); impl EntityUuid { pub fn new(uuid: Uuid) -> Self { @@ -145,12 +104,13 @@ impl Debug for EntityUuid { /// The position of the entity right now. /// -/// You are free to change the value of this component; there's systems that -/// update the indexes automatically. +/// If this is being used as an ECS component then you are free to modify it, +/// because there are systems that will update the indexes automatically. /// /// Its value is set to a default of [`Vec3::ZERO`] when it receives the login /// packet, its true position may be set ticks later. -#[derive(Clone, Component, Copy, Debug, Default, Deref, DerefMut, PartialEq)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Copy, Debug, Default, Deref, DerefMut, PartialEq)] pub struct Position(Vec3); impl Position { pub fn new(pos: Vec3) -> Self { @@ -183,50 +143,12 @@ impl From<&Position> for BlockPos { } } -/// The second most recent position of the entity that was sent over the -/// network. -/// -/// This is currently only updated for our own local player entities. -#[derive(Clone, Component, Copy, Debug, Default, Deref, DerefMut, PartialEq)] -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) - } -} -impl From<LastSentPosition> for BlockPos { - fn from(value: LastSentPosition) -> Self { - BlockPos::from(&value.0) - } -} -impl From<&LastSentPosition> for ChunkPos { - fn from(value: &LastSentPosition) -> Self { - ChunkPos::from(value.0) - } -} -impl From<&LastSentPosition> for BlockPos { - fn from(value: &LastSentPosition) -> Self { - BlockPos::from(value.0) - } -} - -/// A component for entities that can jump. -/// -/// If this is true, the entity will try to jump every tick. It's equivalent to -/// the space key being held in vanilla. -#[derive(Clone, Component, Copy, Debug, Default, Deref, DerefMut, Eq, PartialEq)] -pub struct Jumping(pub bool); - -/// A component that contains the direction an entity is looking, in degrees. +/// The direction that an entity is looking, in degrees. /// /// To avoid flagging anticheats, consider using [`Self::update`] when updating /// the values of this struct. -#[derive(AzBuf, Clone, Component, Copy, Debug, Default, PartialEq)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)] pub struct LookDirection { /// Left and right. AKA yaw. In degrees. y_rot: f32, @@ -237,7 +159,7 @@ pub struct LookDirection { impl LookDirection { /// Create a new look direction and clamp the `x_rot` to the allowed values. pub fn new(y_rot: f32, x_rot: f32) -> Self { - apply_clamp_look_direction(Self { y_rot, x_rot }) + Self { y_rot, x_rot }.clamped() } /// Returns yaw (left and right) in degrees. /// @@ -303,6 +225,14 @@ impl LookDirection { self.y_rot += delta_y_rot; self.x_rot += delta_x_rot; } + + /// Force the [`Self::x_rot`] to be between -90 and 90 degrees, and return + /// the new look direction. + #[must_use] + pub fn clamped(mut self) -> Self { + self.x_rot = self.x_rot.clamp(-90., 90.); + self + } } impl From<LookDirection> for (f32, f32) { @@ -326,7 +256,8 @@ impl Eq for LookDirection {} /// The physics data relating to the entity, such as position, velocity, and /// bounding box. -#[derive(Clone, Component, Debug, Default)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Debug, Default)] pub struct Physics { /// How fast the entity is moving. Sometimes referred to as the delta /// movement. @@ -454,69 +385,6 @@ impl Physics { } } -/// Marker component for entities that are dead. -/// -/// "Dead" means that the entity has 0 health. -#[derive(Clone, Component, Copy, Default)] -pub struct Dead; - -/// A component NewType for [`EntityKind`]. -/// -/// Most of the time, you should be using `azalea_registry::EntityKind` -/// directly instead. -#[derive(Clone, Component, Copy, Debug, Deref, PartialEq)] -pub struct EntityKindComponent(pub EntityKind); - -/// A bundle of components that every entity has. -/// -/// This doesn't contain metadata; that has to be added separately. -#[derive(Bundle)] -pub struct EntityBundle { - pub kind: EntityKindComponent, - pub uuid: EntityUuid, - pub world_name: InstanceName, - pub position: Position, - pub last_sent_position: LastSentPosition, - - pub chunk_pos: EntityChunkPos, - - pub physics: Physics, - pub direction: LookDirection, - pub dimensions: EntityDimensions, - pub attributes: Attributes, - pub jumping: Jumping, - pub crouching: Crouching, - pub fluid_on_eyes: FluidOnEyes, - pub on_climbable: OnClimbable, - pub active_effects: ActiveEffects, -} - -impl EntityBundle { - pub fn new(uuid: Uuid, pos: Vec3, kind: EntityKind, world_name: Identifier) -> Self { - let dimensions = EntityDimensions::from(kind); - - Self { - kind: EntityKindComponent(kind), - uuid: EntityUuid(uuid), - world_name: InstanceName(world_name), - position: Position(pos), - chunk_pos: EntityChunkPos(ChunkPos::from(&pos)), - last_sent_position: LastSentPosition(pos), - physics: Physics::new(&dimensions, pos), - dimensions, - direction: LookDirection::default(), - - attributes: Attributes::new(EntityKind::Player), - - jumping: Jumping(false), - crouching: Crouching(false), - fluid_on_eyes: FluidOnEyes(FluidKind::Empty), - on_climbable: OnClimbable(false), - active_effects: ActiveEffects::default(), - } - } -} - impl Attributes { pub fn new(_entity_kind: EntityKind) -> Self { // TODO: do the correct defaults for everything, some @@ -534,43 +402,12 @@ impl Attributes { } } -/// A marker component that signifies that this entity is "local" and shouldn't -/// be updated by other clients. +/// The abilities that a player has, such as flying or being able to instantly +/// break blocks. /// -/// If this is for a client then all of our clients will have this. -/// -/// This component is not removed from clients when they disconnect. -#[derive(Clone, Component, Copy, Debug, Default)] -pub struct LocalEntity; - -#[derive(Clone, Component, Copy, Debug, Deref, DerefMut, PartialEq)] -pub struct FluidOnEyes(FluidKind); - -impl FluidOnEyes { - pub fn new(fluid: FluidKind) -> Self { - Self(fluid) - } -} - -#[derive(Clone, Component, Copy, Debug, Deref, DerefMut, PartialEq)] -pub struct OnClimbable(bool); - -/// A component that indicates whether the player is currently sneaking. -/// -/// If the entity isn't a local player, then this is just a shortcut for -/// checking if the [`Pose`] is `Crouching`. -/// -/// If you need to modify this value, use -/// `azalea_client::PhysicsState::trying_to_crouch` or `Client::set_crouching` -/// instead. -#[derive(Clone, Component, Copy, Default, Deref, DerefMut)] -pub struct Crouching(bool); - -/// A component that contains the abilities the player has, like flying -/// or instantly breaking blocks. -/// -/// This is only present on local players. -#[derive(Clone, Component, Debug, Default)] +/// This should only be present on local players. +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Debug, Default)] pub struct PlayerAbilities { pub invulnerable: bool, pub flying: bool, @@ -583,3 +420,9 @@ pub struct PlayerAbilities { /// Used for the fov pub walking_speed: f32, } + +/// The type of fluid that is at an entity's eye position, while also accounting +/// for fluid height. +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(Clone, Copy, Debug, Deref, DerefMut, PartialEq)] +pub struct FluidOnEyes(FluidKind); diff --git a/azalea-entity/src/particle.rs b/azalea-entity/src/particle.rs index ca3ac211..397346cf 100644 --- a/azalea-entity/src/particle.rs +++ b/azalea-entity/src/particle.rs @@ -1,16 +1,15 @@ use azalea_block::BlockState; use azalea_buf::AzBuf; -use azalea_core::{color::RgbColor, position::BlockPos}; +use azalea_core::{color::RgbColor, entity_id::MinecraftEntityId, position::BlockPos}; use azalea_inventory::ItemStack; use azalea_registry::builtin::ParticleKind; -use azalea_world::MinecraftEntityId; -use bevy_ecs::component::Component; // the order of this enum must be kept in sync with ParticleKind, otherwise // we get errors parsing particles. /// A [`ParticleKind`] with data potentially attached to it. -#[derive(AzBuf, Clone, Component, Debug, PartialEq)] +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(AzBuf, Clone, Debug, PartialEq)] pub enum Particle { AngryVillager, Block(BlockParticle), diff --git a/azalea-entity/src/plugin/components.rs b/azalea-entity/src/plugin/components.rs new file mode 100644 index 00000000..abeab160 --- /dev/null +++ b/azalea-entity/src/plugin/components.rs @@ -0,0 +1,151 @@ +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 bevy_ecs::{bundle::Bundle, component::Component}; +use derive_more::{Deref, DerefMut}; +use uuid::Uuid; + +use crate::{ + ActiveEffects, Attributes, EntityUuid, FluidOnEyes, LookDirection, Physics, Position, + dimensions::EntityDimensions, indexing::EntityChunkPos, +}; + +/// A bundle of components that every entity has. +/// +/// This doesn't contain metadata; that has to be added separately. +#[derive(Bundle)] +pub struct EntityBundle { + pub kind: EntityKindComponent, + pub uuid: EntityUuid, + pub world_name: InstanceName, + pub position: Position, + pub last_sent_position: LastSentPosition, + + pub chunk_pos: EntityChunkPos, + + pub physics: Physics, + pub direction: LookDirection, + pub dimensions: EntityDimensions, + pub attributes: Attributes, + pub jumping: Jumping, + pub crouching: Crouching, + pub fluid_on_eyes: FluidOnEyes, + pub on_climbable: OnClimbable, + pub active_effects: ActiveEffects, +} + +impl EntityBundle { + pub fn new(uuid: Uuid, pos: Vec3, kind: EntityKind, world_name: Identifier) -> Self { + let dimensions = EntityDimensions::from(kind); + + Self { + kind: EntityKindComponent(kind), + uuid: EntityUuid(uuid), + world_name: InstanceName(world_name), + position: Position(pos), + chunk_pos: EntityChunkPos(ChunkPos::from(&pos)), + last_sent_position: LastSentPosition(pos), + physics: Physics::new(&dimensions, pos), + dimensions, + direction: LookDirection::default(), + + attributes: Attributes::new(EntityKind::Player), + + jumping: Jumping(false), + crouching: Crouching(false), + fluid_on_eyes: FluidOnEyes(FluidKind::Empty), + on_climbable: OnClimbable(false), + active_effects: ActiveEffects::default(), + } + } +} + +/// Marker component for entities that are dead. +/// +/// "Dead" means that the entity has 0 health. +#[derive(Clone, Component, Copy, Default)] +pub struct Dead; + +/// A component NewType for [`EntityKind`]. +/// +/// Most of the time, you should be using `azalea_registry::EntityKind` +/// directly instead. +#[derive(Clone, Component, Copy, Debug, Deref, PartialEq)] +pub struct EntityKindComponent(pub EntityKind); + +/// A marker component that signifies that this entity is "local" and shouldn't +/// be updated by other clients. +/// +/// If this is for a client then all of our clients will have this. +/// +/// This component is not removed from clients when they disconnect. +#[derive(Clone, Component, Copy, Debug, Default)] +pub struct LocalEntity; + +impl FluidOnEyes { + pub fn new(fluid: FluidKind) -> Self { + Self(fluid) + } +} + +#[derive(Clone, Component, Copy, Debug, Deref, DerefMut, PartialEq)] +pub struct OnClimbable(bool); + +/// A component that indicates whether the player is currently sneaking. +/// +/// If the entity isn't a local player, then this is just a shortcut for +/// checking if the [`Pose`] is `Crouching`. +/// +/// If you need to modify this value, use +/// `azalea_client::PhysicsState::trying_to_crouch` or `Client::set_crouching` +/// instead. +/// +/// [`Pose`]: crate::data::Pose +#[derive(Clone, Component, Copy, Default, Deref, DerefMut)] +pub struct Crouching(bool); + +/// A component that indicates whether the client has loaded. +/// +/// This is updated by a system in `azalea-client`. +#[derive(Component)] +pub struct HasClientLoaded; + +/// The second most recent position of the entity that was sent over the +/// network. +/// +/// This is currently only updated for our own local player entities. +#[derive(Clone, Copy, Component, Debug, Default, Deref, DerefMut, PartialEq)] +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) + } +} +impl From<LastSentPosition> for BlockPos { + fn from(value: LastSentPosition) -> Self { + BlockPos::from(&value.0) + } +} +impl From<&LastSentPosition> for ChunkPos { + fn from(value: &LastSentPosition) -> Self { + ChunkPos::from(value.0) + } +} +impl From<&LastSentPosition> for BlockPos { + fn from(value: &LastSentPosition) -> Self { + BlockPos::from(value.0) + } +} + +/// A component for entities that can jump. +/// +/// If this is true, the entity will try to jump every tick. It's equivalent to +/// the space key being held in vanilla. +#[derive(Clone, Copy, Component, Debug, Default, Deref, DerefMut, Eq, PartialEq)] +pub struct Jumping(pub bool); diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs index edceccc7..3fba6b3c 100644 --- a/azalea-entity/src/plugin/indexing.rs +++ b/azalea-entity/src/plugin/indexing.rs @@ -5,8 +5,8 @@ use std::{ fmt::{self, Debug}, }; -use azalea_core::position::ChunkPos; -use azalea_world::{Instance, InstanceContainer, InstanceName, MinecraftEntityId}; +use azalea_core::{entity_id::MinecraftEntityId, position::ChunkPos}; +use azalea_world::{Instance, InstanceContainer, InstanceName}; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; use nohash_hasher::IntMap; diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index 855b2899..03dda233 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -1,3 +1,4 @@ +mod components; pub mod indexing; mod relative_updates; @@ -5,21 +6,22 @@ use std::collections::HashSet; use azalea_block::{BlockState, BlockTrait, fluid_state::FluidKind, properties}; use azalea_core::{ + entity_id::MinecraftEntityId, position::{BlockPos, ChunkPos}, tick::GameTick, }; use azalea_registry::{builtin::BlockKind, tags}; -use azalea_world::{InstanceContainer, InstanceName, MinecraftEntityId}; +use azalea_world::{ChunkStorage, InstanceContainer, InstanceName}; use bevy_app::{App, Plugin, PostUpdate, Update}; use bevy_ecs::prelude::*; +pub use components::*; use derive_more::{Deref, DerefMut}; use indexing::EntityUuidIndex; pub use relative_updates::RelativeEntityUpdate; use tracing::debug; use crate::{ - Crouching, Dead, EntityKindComponent, FluidOnEyes, LocalEntity, LookDirection, OnClimbable, - Physics, Pose, Position, + FluidOnEyes, LookDirection, Physics, Pose, Position, dimensions::{EntityDimensions, calculate_dimensions}, metadata::Health, }; @@ -197,14 +199,9 @@ pub struct LoadedBy(pub HashSet<Entity>); pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) { for mut look_direction in &mut query { - *look_direction = apply_clamp_look_direction(*look_direction); + *look_direction = look_direction.clamped(); } } -pub fn apply_clamp_look_direction(mut look_direction: LookDirection) -> LookDirection { - look_direction.x_rot = look_direction.x_rot.clamp(-90., 90.); - - look_direction -} /// Sets the position of the entity. /// @@ -279,11 +276,47 @@ pub fn update_in_loaded_chunk( } } -/// A component that indicates whether the client has loaded. -/// -/// This is updated by a system in `azalea-client`. -#[derive(Component)] -pub struct HasClientLoaded; +/// 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) +} + +// int x = Mth.floor(this.position.x); +// int y = Mth.floor(this.position.y - (double)var1); +// int z = Mth.floor(this.position.z); +// BlockPos var5 = new BlockPos(x, y, z); +// if (this.level.getBlockState(var5).isAir()) { +// BlockPos var6 = var5.below(); +// BlockState var7 = this.level.getBlockState(var6); +// if (var7.is(BlockTags.FENCES) || var7.is(BlockTags.WALLS) || +// var7.getBlock() instanceof FenceGateBlock) { return var6; +// } +// } +// return var5; +pub fn on_pos(offset: f32, chunk_storage: &ChunkStorage, pos: Position) -> BlockPos { + let x = pos.x.floor() as i32; + let y = (pos.y - offset as f64).floor() as i32; + let z = pos.z.floor() as i32; + let pos = BlockPos { x, y, z }; + + // TODO: check if block below is a fence, wall, or fence gate + let block_pos = pos.down(1); + let block_state = chunk_storage.get_block_state(block_pos); + if block_state == Some(BlockState::AIR) { + let block_pos_below = block_pos.down(1); + let block_state_below = chunk_storage.get_block_state(block_pos_below); + if let Some(_block_state_below) = block_state_below { + // if block_state_below.is_fence() + // || block_state_below.is_wall() + // || block_state_below.is_fence_gate() + // { + // return block_pos_below; + // } + } + } + + pos +} #[cfg(test)] mod tests { diff --git a/azalea-entity/src/plugin/relative_updates.rs b/azalea-entity/src/plugin/relative_updates.rs index 3917c946..f80ccddc 100644 --- a/azalea-entity/src/plugin/relative_updates.rs +++ b/azalea-entity/src/plugin/relative_updates.rs @@ -17,7 +17,8 @@ use std::sync::Arc; -use azalea_world::{MinecraftEntityId, PartialInstance}; +use azalea_core::entity_id::MinecraftEntityId; +use azalea_world::PartialInstance; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; use parking_lot::RwLock; diff --git a/azalea-inventory/Cargo.toml b/azalea-inventory/Cargo.toml index c5c5e314..7e26ff8c 100644 --- a/azalea-inventory/Cargo.toml +++ b/azalea-inventory/Cargo.toml @@ -10,7 +10,7 @@ repository.workspace = true azalea-auth.workspace = true azalea-buf.workspace = true azalea-chat = { workspace = true, features = ["azalea-buf"] } -azalea-core.workspace = true +azalea-core = { workspace = true, features = ["serde"] } azalea-inventory-macros.workspace = true azalea-registry = { workspace = true, features = ["serde"] } indexmap.workspace = true diff --git a/azalea-physics/Cargo.toml b/azalea-physics/Cargo.toml index 68c3fbe8..33a669c1 100644 --- a/azalea-physics/Cargo.toml +++ b/azalea-physics/Cargo.toml @@ -12,7 +12,7 @@ uuid.workspace = true [dependencies] azalea-block.workspace = true azalea-core.workspace = true -azalea-entity.workspace = true +azalea-entity = { workspace = true, features = ["bevy_ecs"] } azalea-inventory.workspace = true azalea-registry.workspace = true azalea-world.workspace = true diff --git a/azalea-physics/tests/physics.rs b/azalea-physics/tests/physics.rs index 57747692..42dcf809 100644 --- a/azalea-physics/tests/physics.rs +++ b/azalea-physics/tests/physics.rs @@ -5,6 +5,7 @@ use azalea_block::{ properties::WaterLevel, }; use azalea_core::{ + entity_id::MinecraftEntityId, position::{BlockPos, ChunkPos, Vec3}, registry_holder::RegistryHolder, tick::GameTick, @@ -15,7 +16,7 @@ use azalea_registry::{ builtin::{BlockKind, EntityKind}, identifier::Identifier, }; -use azalea_world::{Chunk, Instance, InstanceContainer, MinecraftEntityId, PartialInstance}; +use azalea_world::{Chunk, Instance, InstanceContainer, PartialInstance}; use bevy_app::App; use parking_lot::RwLock; use uuid::Uuid; diff --git a/azalea-protocol/Cargo.toml b/azalea-protocol/Cargo.toml index 5a321120..59991274 100644 --- a/azalea-protocol/Cargo.toml +++ b/azalea-protocol/Cargo.toml @@ -17,14 +17,13 @@ azalea-block.workspace = true azalea-brigadier = { workspace = true, features = ["azalea-buf"] } azalea-buf.workspace = true azalea-chat = { workspace = true, features = ["numbers", "azalea-buf"] } -azalea-core.workspace = true +azalea-core = { workspace = true } azalea-crypto = { workspace = true, features = ["signing"] } -azalea-entity.workspace = true +azalea-entity = { workspace = true } azalea-inventory.workspace = true azalea-protocol-macros.workspace = true azalea-registry.workspace = true -azalea-world.workspace = true -bevy_ecs.workspace = true +bevy_ecs = { workspace = true, optional = true } # byteorder.workspace = true flate2.workspace = true futures.workspace = true @@ -47,6 +46,7 @@ reqwest = { workspace = true, optional = true, features = ["socks"] } default = ["online-mode"] connecting = [] online-mode = ["azalea-auth/online-mode", "dep:reqwest"] +bevy_ecs = ["dep:bevy_ecs", "azalea-entity/bevy_ecs", "azalea-core/bevy_ecs"] [lints] workspace = true diff --git a/azalea-protocol/src/common/client_information.rs b/azalea-protocol/src/common/client_information.rs index 68a9956a..189f1019 100644 --- a/azalea-protocol/src/common/client_information.rs +++ b/azalea-protocol/src/common/client_information.rs @@ -3,13 +3,13 @@ use std::io::{self, Cursor}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite}; use azalea_core::bitset::FixedBitSet; use azalea_entity::HumanoidArm; -use bevy_ecs::component::Component; -/// A component that contains some of the "settings" for this client that are -/// sent to the server, such as render distance. +/// Some of the "settings" for this client that are sent to the server, +/// including render distance. /// -/// This is only present on local players. -#[derive(AzBuf, Clone, Component, Debug, Eq, PartialEq)] +/// This should only be present on local players. +#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))] +#[derive(AzBuf, Clone, Debug, Eq, PartialEq)] pub struct ClientInformation { /// The locale of the client, formatted like "en_us". pub language: String, diff --git a/azalea-protocol/src/packets/game/c_add_entity.rs b/azalea-protocol/src/packets/game/c_add_entity.rs index 52a429d5..19f229ee 100644 --- a/azalea-protocol/src/packets/game/c_add_entity.rs +++ b/azalea-protocol/src/packets/game/c_add_entity.rs @@ -1,9 +1,9 @@ use azalea_buf::AzBuf; -use azalea_core::{delta::LpVec3, position::Vec3}; -use azalea_entity::{EntityBundle, metadata::apply_default_metadata}; +use azalea_core::{delta::LpVec3, entity_id::MinecraftEntityId, position::Vec3}; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::{builtin::EntityKind, identifier::Identifier}; -use azalea_world::MinecraftEntityId; +use azalea_registry::builtin::EntityKind; +#[cfg(feature = "bevy_ecs")] +use azalea_registry::identifier::Identifier; use uuid::Uuid; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] @@ -35,12 +35,14 @@ impl ClientboundAddEntity { /// /// You must apply the metadata after inserting the bundle with /// [`Self::apply_metadata`]. - pub fn as_entity_bundle(&self, world_name: Identifier) -> EntityBundle { - EntityBundle::new(self.uuid, self.position, self.entity_type, world_name) + #[cfg(feature = "bevy_ecs")] + pub fn as_entity_bundle(&self, world_name: Identifier) -> azalea_entity::EntityBundle { + azalea_entity::EntityBundle::new(self.uuid, self.position, self.entity_type, world_name) } /// Apply the default metadata for the given entity. + #[cfg(feature = "bevy_ecs")] pub fn apply_metadata(&self, entity: &mut bevy_ecs::system::EntityCommands) { - apply_default_metadata(entity, self.entity_type); + azalea_entity::metadata::apply_default_metadata(entity, self.entity_type); } } diff --git a/azalea-protocol/src/packets/game/c_animate.rs b/azalea-protocol/src/packets/game/c_animate.rs index 112b990b..6f3b5a07 100644 --- a/azalea-protocol/src/packets/game/c_animate.rs +++ b/azalea-protocol/src/packets/game/c_animate.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundAnimate { diff --git a/azalea-protocol/src/packets/game/c_block_destruction.rs b/azalea-protocol/src/packets/game/c_block_destruction.rs index e41e42b0..35503b75 100644 --- a/azalea-protocol/src/packets/game/c_block_destruction.rs +++ b/azalea-protocol/src/packets/game/c_block_destruction.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::position::BlockPos; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundBlockDestruction { diff --git a/azalea-protocol/src/packets/game/c_damage_event.rs b/azalea-protocol/src/packets/game/c_damage_event.rs index e296b3da..76ceb8ec 100644 --- a/azalea-protocol/src/packets/game/c_damage_event.rs +++ b/azalea-protocol/src/packets/game/c_damage_event.rs @@ -3,7 +3,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar}; use azalea_core::position::Vec3; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundDamageEvent { diff --git a/azalea-protocol/src/packets/game/c_debug_entity_value.rs b/azalea-protocol/src/packets/game/c_debug_entity_value.rs index 61706382..5dd4e32d 100644 --- a/azalea-protocol/src/packets/game/c_debug_entity_value.rs +++ b/azalea-protocol/src/packets/game/c_debug_entity_value.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use crate::common::debug_subscription::DebugSubscriptionUpdate; diff --git a/azalea-protocol/src/packets/game/c_entity_event.rs b/azalea-protocol/src/packets/game/c_entity_event.rs index cde6fd6c..5ca12e36 100644 --- a/azalea-protocol/src/packets/game/c_entity_event.rs +++ b/azalea-protocol/src/packets/game/c_entity_event.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundEntityEvent { diff --git a/azalea-protocol/src/packets/game/c_entity_position_sync.rs b/azalea-protocol/src/packets/game/c_entity_position_sync.rs index b18248fc..5bbe33bc 100644 --- a/azalea-protocol/src/packets/game/c_entity_position_sync.rs +++ b/azalea-protocol/src/packets/game/c_entity_position_sync.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use crate::common::movements::PositionMoveRotation; diff --git a/azalea-protocol/src/packets/game/c_hurt_animation.rs b/azalea-protocol/src/packets/game/c_hurt_animation.rs index 698176e4..cd81b80b 100644 --- a/azalea-protocol/src/packets/game/c_hurt_animation.rs +++ b/azalea-protocol/src/packets/game/c_hurt_animation.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundHurtAnimation { diff --git a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs index 6519c4a4..00489513 100644 --- a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs +++ b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs @@ -1,9 +1,9 @@ use std::sync::Arc; use azalea_buf::AzBuf; +use azalea_core::heightmap_kind::HeightmapKind; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::builtin::BlockEntityKind; -use azalea_world::heightmap::HeightmapKind; use simdnbt::owned::Nbt; use super::c_light_update::ClientboundLightUpdatePacketData; diff --git a/azalea-protocol/src/packets/game/c_login.rs b/azalea-protocol/src/packets/game/c_login.rs index ce243a55..26aede88 100644 --- a/azalea-protocol/src/packets/game/c_login.rs +++ b/azalea-protocol/src/packets/game/c_login.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_registry::identifier::Identifier; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use crate::packets::common::CommonPlayerSpawnInfo; diff --git a/azalea-protocol/src/packets/game/c_mount_screen_open.rs b/azalea-protocol/src/packets/game/c_mount_screen_open.rs index 78600250..fbc66f4c 100644 --- a/azalea-protocol/src/packets/game/c_mount_screen_open.rs +++ b/azalea-protocol/src/packets/game/c_mount_screen_open.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundMountScreenOpen { diff --git a/azalea-protocol/src/packets/game/c_move_entity_pos.rs b/azalea-protocol/src/packets/game/c_move_entity_pos.rs index 3f4b005a..f01faaad 100644 --- a/azalea-protocol/src/packets/game/c_move_entity_pos.rs +++ b/azalea-protocol/src/packets/game/c_move_entity_pos.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::delta::PositionDelta8; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundMoveEntityPos { diff --git a/azalea-protocol/src/packets/game/c_move_entity_pos_rot.rs b/azalea-protocol/src/packets/game/c_move_entity_pos_rot.rs index 81f2a63a..047eb638 100644 --- a/azalea-protocol/src/packets/game/c_move_entity_pos_rot.rs +++ b/azalea-protocol/src/packets/game/c_move_entity_pos_rot.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::delta::PositionDelta8; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; /// This packet is sent by the server when an entity moves less then 8 blocks. #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] diff --git a/azalea-protocol/src/packets/game/c_move_entity_rot.rs b/azalea-protocol/src/packets/game/c_move_entity_rot.rs index 6ccd44fe..4d0645b3 100644 --- a/azalea-protocol/src/packets/game/c_move_entity_rot.rs +++ b/azalea-protocol/src/packets/game/c_move_entity_rot.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundMoveEntityRot { diff --git a/azalea-protocol/src/packets/game/c_move_minecart_along_track.rs b/azalea-protocol/src/packets/game/c_move_minecart_along_track.rs index 61cb5ba8..68b9f6f9 100644 --- a/azalea-protocol/src/packets/game/c_move_minecart_along_track.rs +++ b/azalea-protocol/src/packets/game/c_move_minecart_along_track.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::position::Vec3; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundMoveMinecartAlongTrack { diff --git a/azalea-protocol/src/packets/game/c_player_combat_kill.rs b/azalea-protocol/src/packets/game/c_player_combat_kill.rs index 3d2f7d7b..047e4c88 100644 --- a/azalea-protocol/src/packets/game/c_player_combat_kill.rs +++ b/azalea-protocol/src/packets/game/c_player_combat_kill.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; /// Used to send a respawn screen. #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] diff --git a/azalea-protocol/src/packets/game/c_projectile_power.rs b/azalea-protocol/src/packets/game/c_projectile_power.rs index eae4c885..c38ca50a 100644 --- a/azalea-protocol/src/packets/game/c_projectile_power.rs +++ b/azalea-protocol/src/packets/game/c_projectile_power.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundProjectilePower { diff --git a/azalea-protocol/src/packets/game/c_remove_entities.rs b/azalea-protocol/src/packets/game/c_remove_entities.rs index 71749052..9e1d9c07 100644 --- a/azalea-protocol/src/packets/game/c_remove_entities.rs +++ b/azalea-protocol/src/packets/game/c_remove_entities.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundRemoveEntities { diff --git a/azalea-protocol/src/packets/game/c_remove_mob_effect.rs b/azalea-protocol/src/packets/game/c_remove_mob_effect.rs index d5190e53..169ed863 100644 --- a/azalea-protocol/src/packets/game/c_remove_mob_effect.rs +++ b/azalea-protocol/src/packets/game/c_remove_mob_effect.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::builtin::MobEffect; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundRemoveMobEffect { diff --git a/azalea-protocol/src/packets/game/c_rotate_head.rs b/azalea-protocol/src/packets/game/c_rotate_head.rs index 3ced78cb..e1f8ee30 100644 --- a/azalea-protocol/src/packets/game/c_rotate_head.rs +++ b/azalea-protocol/src/packets/game/c_rotate_head.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundRotateHead { diff --git a/azalea-protocol/src/packets/game/c_set_camera.rs b/azalea-protocol/src/packets/game/c_set_camera.rs index f2b44f0b..c71a9535 100644 --- a/azalea-protocol/src/packets/game/c_set_camera.rs +++ b/azalea-protocol/src/packets/game/c_set_camera.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetCamera { diff --git a/azalea-protocol/src/packets/game/c_set_entity_data.rs b/azalea-protocol/src/packets/game/c_set_entity_data.rs index 6e738f5f..d9effc37 100644 --- a/azalea-protocol/src/packets/game/c_set_entity_data.rs +++ b/azalea-protocol/src/packets/game/c_set_entity_data.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_entity::EntityMetadataItems; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetEntityData { diff --git a/azalea-protocol/src/packets/game/c_set_entity_link.rs b/azalea-protocol/src/packets/game/c_set_entity_link.rs index 127b09a3..88a128cd 100644 --- a/azalea-protocol/src/packets/game/c_set_entity_link.rs +++ b/azalea-protocol/src/packets/game/c_set_entity_link.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetEntityLink { diff --git a/azalea-protocol/src/packets/game/c_set_entity_motion.rs b/azalea-protocol/src/packets/game/c_set_entity_motion.rs index f6219888..c55857c3 100644 --- a/azalea-protocol/src/packets/game/c_set_entity_motion.rs +++ b/azalea-protocol/src/packets/game/c_set_entity_motion.rs @@ -1,7 +1,7 @@ use azalea_buf::AzBuf; use azalea_core::delta::LpVec3; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetEntityMotion { diff --git a/azalea-protocol/src/packets/game/c_set_equipment.rs b/azalea-protocol/src/packets/game/c_set_equipment.rs index d6b1c735..7d7ceac9 100644 --- a/azalea-protocol/src/packets/game/c_set_equipment.rs +++ b/azalea-protocol/src/packets/game/c_set_equipment.rs @@ -3,7 +3,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; use azalea_inventory::{ItemStack, components::EquipmentSlot}; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetEquipment { diff --git a/azalea-protocol/src/packets/game/c_set_passengers.rs b/azalea-protocol/src/packets/game/c_set_passengers.rs index ade63267..b6aefb68 100644 --- a/azalea-protocol/src/packets/game/c_set_passengers.rs +++ b/azalea-protocol/src/packets/game/c_set_passengers.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundSetPassengers { diff --git a/azalea-protocol/src/packets/game/c_sound_entity.rs b/azalea-protocol/src/packets/game/c_sound_entity.rs index 2b405201..8133ee20 100644 --- a/azalea-protocol/src/packets/game/c_sound_entity.rs +++ b/azalea-protocol/src/packets/game/c_sound_entity.rs @@ -2,7 +2,7 @@ use azalea_buf::AzBuf; use azalea_core::sound::CustomSound; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::builtin::SoundEvent; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use super::c_sound::SoundSource; diff --git a/azalea-protocol/src/packets/game/c_take_item_entity.rs b/azalea-protocol/src/packets/game/c_take_item_entity.rs index 0ab5e832..b46c8c3a 100644 --- a/azalea-protocol/src/packets/game/c_take_item_entity.rs +++ b/azalea-protocol/src/packets/game/c_take_item_entity.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundTakeItemEntity { diff --git a/azalea-protocol/src/packets/game/c_teleport_entity.rs b/azalea-protocol/src/packets/game/c_teleport_entity.rs index b025338b..ee0e5302 100644 --- a/azalea-protocol/src/packets/game/c_teleport_entity.rs +++ b/azalea-protocol/src/packets/game/c_teleport_entity.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use crate::common::movements::{PositionMoveRotation, RelativeMovements}; diff --git a/azalea-protocol/src/packets/game/c_update_attributes.rs b/azalea-protocol/src/packets/game/c_update_attributes.rs index 8fb95c28..7c8e9e12 100644 --- a/azalea-protocol/src/packets/game/c_update_attributes.rs +++ b/azalea-protocol/src/packets/game/c_update_attributes.rs @@ -2,7 +2,7 @@ use azalea_buf::AzBuf; use azalea_inventory::components::AttributeModifier; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::builtin::Attribute; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundUpdateAttributes { diff --git a/azalea-protocol/src/packets/game/c_update_mob_effect.rs b/azalea-protocol/src/packets/game/c_update_mob_effect.rs index df07fdfc..382c42bd 100644 --- a/azalea-protocol/src/packets/game/c_update_mob_effect.rs +++ b/azalea-protocol/src/packets/game/c_update_mob_effect.rs @@ -2,7 +2,7 @@ use azalea_buf::AzBuf; use azalea_entity::MobEffectData; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::builtin::MobEffect; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, ClientboundGamePacket, Clone, Debug, PartialEq)] pub struct ClientboundUpdateMobEffect { diff --git a/azalea-protocol/src/packets/game/s_entity_tag_query.rs b/azalea-protocol/src/packets/game/s_entity_tag_query.rs index 00ef5c03..2ccec59e 100644 --- a/azalea-protocol/src/packets/game/s_entity_tag_query.rs +++ b/azalea-protocol/src/packets/game/s_entity_tag_query.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, Clone, Debug, PartialEq, ServerboundGamePacket)] pub struct ServerboundEntityTagQuery { diff --git a/azalea-protocol/src/packets/game/s_interact.rs b/azalea-protocol/src/packets/game/s_interact.rs index fc2cd11e..d368354f 100644 --- a/azalea-protocol/src/packets/game/s_interact.rs +++ b/azalea-protocol/src/packets/game/s_interact.rs @@ -3,7 +3,7 @@ use std::io::{self, Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar}; use azalea_core::position::Vec3; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use crate::packets::BufReadError; diff --git a/azalea-protocol/src/packets/game/s_pick_item_from_entity.rs b/azalea-protocol/src/packets/game/s_pick_item_from_entity.rs index a68e7ab7..e337f1da 100644 --- a/azalea-protocol/src/packets/game/s_pick_item_from_entity.rs +++ b/azalea-protocol/src/packets/game/s_pick_item_from_entity.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, Clone, Debug, PartialEq, ServerboundGamePacket)] pub struct ServerboundPickItemFromEntity { diff --git a/azalea-protocol/src/packets/game/s_player_command.rs b/azalea-protocol/src/packets/game/s_player_command.rs index 2e4e83df..533fde30 100644 --- a/azalea-protocol/src/packets/game/s_player_command.rs +++ b/azalea-protocol/src/packets/game/s_player_command.rs @@ -1,6 +1,6 @@ use azalea_buf::AzBuf; use azalea_protocol_macros::ServerboundGamePacket; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; #[derive(AzBuf, Clone, Debug, PartialEq, ServerboundGamePacket)] pub struct ServerboundPlayerCommand { diff --git a/azalea-world/Cargo.toml b/azalea-world/Cargo.toml index 31e42a80..9e1a2729 100644 --- a/azalea-world/Cargo.toml +++ b/azalea-world/Cargo.toml @@ -13,7 +13,7 @@ criterion.workspace = true [dependencies] azalea-block.workspace = true azalea-buf.workspace = true -azalea-core = { workspace = true, features = ["bevy_ecs"] } +azalea-core = { workspace = true, features = ["serde", "bevy_ecs"] } azalea-registry.workspace = true bevy_ecs.workspace = true derive_more = { workspace = true, features = ["deref", "deref_mut"] } diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 65dbbb7a..3f8c4e2d 100644 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -12,18 +12,19 @@ use azalea_block::{ fluid_state::FluidState, }; use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; -use azalea_core::position::{ - BlockPos, ChunkBiomePos, ChunkBlockPos, ChunkPos, ChunkSectionBiomePos, ChunkSectionBlockPos, +use azalea_core::{ + heightmap_kind::HeightmapKind, + position::{ + BlockPos, ChunkBiomePos, ChunkBlockPos, ChunkPos, ChunkSectionBiomePos, + ChunkSectionBlockPos, + }, }; use azalea_registry::data::Biome; use nohash_hasher::IntMap; use parking_lot::RwLock; use tracing::{debug, trace, warn}; -use crate::{ - heightmap::{Heightmap, HeightmapKind}, - palette::PalettedContainer, -}; +use crate::{heightmap::Heightmap, palette::PalettedContainer}; const SECTION_HEIGHT: u32 = 16; diff --git a/azalea-world/src/heightmap.rs b/azalea-world/src/heightmap.rs index 033fa569..bae11cea 100644 --- a/azalea-world/src/heightmap.rs +++ b/azalea-world/src/heightmap.rs @@ -1,33 +1,20 @@ -use std::{ - fmt::{self, Display}, - str::FromStr, -}; - use azalea_block::{BlockState, BlockTrait}; -use azalea_buf::AzBuf; -use azalea_core::{math, position::ChunkBlockPos}; +use azalea_core::{heightmap_kind::HeightmapKind as HeightmapKind_, math, position::ChunkBlockPos}; use azalea_registry::tags::blocks::LEAVES; use tracing::warn; use crate::{BitStorage, Section, chunk_storage::get_block_state_from_sections}; -// (wg stands for worldgen) - -#[derive(AzBuf, Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub enum HeightmapKind { - WorldSurfaceWg, - WorldSurface, - OceanFloorWg, - OceanFloor, - MotionBlocking, - MotionBlockingNoLeaves, -} +// TODO: when removing this deprecated marker, also rename `HeightmapKind_` back +// to `HeightmapKind`. +#[deprecated = "moved to `azalea_core::heightmap_kind::HeightmapKind`."] +pub type HeightmapKind = azalea_core::heightmap_kind::HeightmapKind; #[derive(Clone, Debug)] pub struct Heightmap { pub data: BitStorage, pub min_y: i32, - pub kind: HeightmapKind, + pub kind: HeightmapKind_, } fn blocks_motion(block_state: BlockState) -> bool { @@ -43,25 +30,24 @@ fn motion_blocking(block_state: BlockState) -> bool { .unwrap_or_default() } -impl HeightmapKind { - pub fn is_opaque(self, block_state: BlockState) -> bool { - let block = Box::<dyn BlockTrait>::from(block_state); - let registry_block = block.as_registry_block(); - match self { - HeightmapKind::WorldSurfaceWg => !block_state.is_air(), - HeightmapKind::WorldSurface => !block_state.is_air(), - HeightmapKind::OceanFloorWg => blocks_motion(block_state), - HeightmapKind::OceanFloor => blocks_motion(block_state), - HeightmapKind::MotionBlocking => motion_blocking(block_state), - HeightmapKind::MotionBlockingNoLeaves => { - motion_blocking(block_state) && !LEAVES.contains(®istry_block) - } +pub fn is_heightmap_opaque(heightmap: HeightmapKind_, block_state: BlockState) -> bool { + let block = Box::<dyn BlockTrait>::from(block_state); + let registry_block = block.as_registry_block(); + type K = HeightmapKind_; + match heightmap { + K::WorldSurfaceWg => !block_state.is_air(), + K::WorldSurface => !block_state.is_air(), + K::OceanFloorWg => blocks_motion(block_state), + K::OceanFloor => blocks_motion(block_state), + K::MotionBlocking => motion_blocking(block_state), + K::MotionBlockingNoLeaves => { + motion_blocking(block_state) && !LEAVES.contains(®istry_block) } } } impl Heightmap { - pub fn new(kind: HeightmapKind, dimension_height: u32, min_y: i32, data: Box<[u64]>) -> Self { + pub fn new(kind: HeightmapKind_, dimension_height: u32, min_y: i32, data: Box<[u64]>) -> Self { let bits = math::ceil_log2(dimension_height + 1); let mut bit_storage = BitStorage::new(bits as usize, 16 * 16, None) .expect("data is empty, so this can't fail"); @@ -113,7 +99,7 @@ impl Heightmap { if pos.y <= first_available_y - 2 { return false; } - if self.kind.is_opaque(block_state) { + if is_heightmap_opaque(self.kind, block_state) { // increase y if pos.y >= first_available_y { self.set_height(pos.x, pos.z, pos.y + 1); @@ -122,7 +108,8 @@ impl Heightmap { } else if first_available_y - 1 == pos.y { // decrease y for y in (self.min_y..pos.y).rev() { - if self.kind.is_opaque( + if is_heightmap_opaque( + self.kind, get_block_state_from_sections( sections, &ChunkBlockPos::new(pos.x, y, pos.z), @@ -161,32 +148,3 @@ impl Heightmap { }) } } - -impl FromStr for HeightmapKind { - type Err = (); - - fn from_str(s: &str) -> Result<Self, Self::Err> { - match s { - "WORLD_SURFACE_WG" => Ok(HeightmapKind::WorldSurfaceWg), - "WORLD_SURFACE" => Ok(HeightmapKind::WorldSurface), - "OCEAN_FLOOR_WG" => Ok(HeightmapKind::OceanFloorWg), - "OCEAN_FLOOR" => Ok(HeightmapKind::OceanFloor), - "MOTION_BLOCKING" => Ok(HeightmapKind::MotionBlocking), - "MOTION_BLOCKING_NO_LEAVES" => Ok(HeightmapKind::MotionBlockingNoLeaves), - _ => Err(()), - } - } -} - -impl Display for HeightmapKind { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - HeightmapKind::WorldSurfaceWg => write!(f, "WORLD_SURFACE_WG"), - HeightmapKind::WorldSurface => write!(f, "WORLD_SURFACE"), - HeightmapKind::OceanFloorWg => write!(f, "OCEAN_FLOOR_WG"), - HeightmapKind::OceanFloor => write!(f, "OCEAN_FLOOR"), - HeightmapKind::MotionBlocking => write!(f, "MOTION_BLOCKING"), - HeightmapKind::MotionBlockingNoLeaves => write!(f, "MOTION_BLOCKING_NO_LEAVES"), - } - } -} diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs index 26856fff..a6ee1a63 100644 --- a/azalea-world/src/world.rs +++ b/azalea-world/src/world.rs @@ -1,22 +1,16 @@ use std::{ collections::{HashMap, HashSet}, - fmt::{self, Debug, Display}, - hash::{Hash, Hasher}, - io::{self, Cursor}, + fmt::{self, Debug}, }; use azalea_block::{BlockState, fluid_state::FluidState}; -use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_core::{ position::{BlockPos, ChunkPos}, registry_holder::RegistryHolder, }; use azalea_registry::data::Biome; -use bevy_ecs::{component::Component, entity::Entity}; -use derive_more::{Deref, DerefMut}; +use bevy_ecs::entity::Entity; use nohash_hasher::IntMap; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use crate::{ChunkStorage, PartialChunkStorage}; @@ -50,70 +44,8 @@ impl PartialInstance { } } -/// An entity ID used by Minecraft. -/// -/// These IDs are picked by the server. Some server software (like Bungeecord) -/// may pick entity IDs per-player, so you should avoid relying on them for -/// identifying IDs (especially if you're using a shared world -- i.e. a swarm). -/// -/// You might find [`Entity`] more useful, since that's an ID decided by us that -/// is likely to be correct across shared worlds. You could also use the -/// `EntityUuid` from `azalea_entity`, that one is unlikely to change even -/// across server restarts. -/// -/// This serializes as a i32. Usually it's a VarInt in the protocol, but not -/// always. If you do need it to serialize as a VarInt, make sure to use use the -/// `#[var]` attribute. -/// -/// [`Entity`]: bevy_ecs::entity::Entity -#[derive(Clone, Component, Copy, Debug, Default, Deref, DerefMut, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -pub struct MinecraftEntityId(pub i32); - -impl Hash for MinecraftEntityId { - fn hash<H: Hasher>(&self, hasher: &mut H) { - hasher.write_i32(self.0); - } -} -impl nohash_hasher::IsEnabled for MinecraftEntityId {} - -// we can't have the default be #[var] because mojang doesn't use varints for -// entities sometimes :( -impl AzaleaRead for MinecraftEntityId { - fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - i32::azalea_read(buf).map(MinecraftEntityId) - } -} -impl AzaleaWrite for MinecraftEntityId { - fn azalea_write(&self, buf: &mut impl io::Write) -> io::Result<()> { - i32::azalea_write(&self.0, buf) - } -} -impl AzaleaReadVar for MinecraftEntityId { - fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - i32::azalea_read_var(buf).map(MinecraftEntityId) - } -} -impl AzaleaWriteVar for MinecraftEntityId { - fn azalea_write_var(&self, buf: &mut impl io::Write) -> io::Result<()> { - i32::azalea_write_var(&self.0, buf) - } -} -impl Display for MinecraftEntityId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "eid({})", self.0) - } -} -impl From<i32> for MinecraftEntityId { - fn from(id: i32) -> Self { - Self(id) - } -} -impl From<u32> for MinecraftEntityId { - fn from(id: u32) -> Self { - Self(id as i32) - } -} +#[deprecated = "moved to `azalea_core::entity_id::MinecraftEntityId`."] +pub type MinecraftEntityId = azalea_core::entity_id::MinecraftEntityId; /// Keep track of certain metadatas that are only relevant for this partial /// world. @@ -129,7 +61,7 @@ pub struct PartialEntityInfos { /// /// This is used for shared worlds (i.e. swarms), to make sure we don't /// update entities twice on accident. - pub updates_received: IntMap<MinecraftEntityId, u32>, + pub updates_received: IntMap<azalea_core::entity_id::MinecraftEntityId, u32>, // ^ note: using MinecraftEntityId for entity ids is acceptable here since // there's no chance of collisions } @@ -164,7 +96,7 @@ pub struct Instance { /// instead use `azalea_entity::EntityIdIndex`, since some servers may /// give different entity IDs for the same entities to different /// players. - pub entity_by_id: IntMap<MinecraftEntityId, Entity>, + pub entity_by_id: IntMap<azalea_core::entity_id::MinecraftEntityId, Entity>, pub registries: RegistryHolder, } diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs index fd6506d0..f884898f 100644 --- a/azalea/src/client_impl/mod.rs +++ b/azalea/src/client_impl/mod.rs @@ -13,7 +13,10 @@ use azalea_client::{ start_ecs_runner, tick_counter::TicksConnected, }; -use azalea_core::data_registry::{DataRegistryWithKey, ResolvableDataRegistry}; +use azalea_core::{ + data_registry::{DataRegistryWithKey, ResolvableDataRegistry}, + entity_id::MinecraftEntityId, +}; use azalea_entity::indexing::{EntityIdIndex, EntityUuidIndex}; use azalea_protocol::{ address::{ResolvableAddr, ResolvedAddr}, @@ -22,7 +25,7 @@ use azalea_protocol::{ resolve::ResolveError, }; use azalea_registry::{DataRegistryKeyRef, identifier::Identifier}; -use azalea_world::{Instance, InstanceName, MinecraftEntityId, PartialInstance}; +use azalea_world::{Instance, InstanceName, PartialInstance}; use bevy_app::App; use bevy_ecs::{ entity::Entity, diff --git a/azalea/src/entity_ref/shared_impls.rs b/azalea/src/entity_ref/shared_impls.rs index 5e2255c5..f6aa332e 100644 --- a/azalea/src/entity_ref/shared_impls.rs +++ b/azalea/src/entity_ref/shared_impls.rs @@ -1,8 +1,8 @@ -use azalea_core::position::Vec3; +use azalea_core::{entity_id::MinecraftEntityId, position::Vec3}; use azalea_entity::{ Attributes, Dead, EntityUuid, Physics, Position, dimensions::EntityDimensions, metadata::Health, }; -use azalea_world::{InstanceName, MinecraftEntityId}; +use azalea_world::InstanceName; use uuid::Uuid; use super::EntityRef; diff --git a/azalea/src/events.rs b/azalea/src/events.rs index 0920dbd8..18d24773 100644 --- a/azalea/src/events.rs +++ b/azalea/src/events.rs @@ -4,10 +4,10 @@ use std::sync::Arc; use azalea_chat::FormattedText; -use azalea_core::{position::ChunkPos, tick::GameTick}; +use azalea_core::{entity_id::MinecraftEntityId, position::ChunkPos, tick::GameTick}; use azalea_entity::{Dead, InLoadedChunk}; use azalea_protocol::packets::game::c_player_combat_kill::ClientboundPlayerCombatKill; -use azalea_world::{InstanceName, MinecraftEntityId}; +use azalea_world::InstanceName; use bevy_app::{App, Plugin, PreUpdate, Update}; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; diff --git a/azalea/src/nearest_entity.rs b/azalea/src/nearest_entity.rs index 6e94e331..bf3f2fdb 100644 --- a/azalea/src/nearest_entity.rs +++ b/azalea/src/nearest_entity.rs @@ -1,5 +1,6 @@ +use azalea_core::entity_id::MinecraftEntityId; use azalea_entity::Position; -use azalea_world::{InstanceName, MinecraftEntityId}; +use azalea_world::InstanceName; use bevy_ecs::{ prelude::Entity, query::{QueryFilter, With}, diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 957cef37..ca5e4f36 100644 --- a/azalea/src/pathfinder/simulation.rs +++ b/azalea/src/pathfinder/simulation.rs @@ -6,13 +6,15 @@ use azalea_client::{ PhysicsState, interact::BlockStatePredictionHandler, local_player::LocalGameMode, mining::MineBundle, }; -use azalea_core::{game_type::GameMode, position::Vec3, tick::GameTick}; +use azalea_core::{ + entity_id::MinecraftEntityId, game_type::GameMode, position::Vec3, tick::GameTick, +}; use azalea_entity::{ Attributes, LookDirection, Physics, Position, dimensions::EntityDimensions, inventory::Inventory, }; use azalea_registry::{builtin::EntityKind, identifier::Identifier}; -use azalea_world::{ChunkStorage, Instance, InstanceContainer, MinecraftEntityId, PartialInstance}; +use azalea_world::{ChunkStorage, Instance, InstanceContainer, PartialInstance}; use bevy_app::App; use bevy_ecs::prelude::*; use parking_lot::RwLock; diff --git a/azalea/src/swarm/events.rs b/azalea/src/swarm/events.rs index 107a676a..ee5859ca 100644 --- a/azalea/src/swarm/events.rs +++ b/azalea/src/swarm/events.rs @@ -1,5 +1,5 @@ use azalea_client::local_player::InstanceHolder; -use azalea_world::MinecraftEntityId; +use azalea_core::entity_id::MinecraftEntityId; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; |
