aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/position.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2026-01-12 02:09:41 -0600
committerGitHub <noreply@github.com>2026-01-12 02:09:41 -0600
commit1accbac964168af5fa0d87cb170389f0a9d01363 (patch)
tree1509b26c19beaa23a492289f6bf00d3958be44d5 /azalea-core/src/position.rs
parent58339b9d229592dee40e15b8648fe4075cc391f4 (diff)
downloadazalea-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
Diffstat (limited to 'azalea-core/src/position.rs')
-rw-r--r--azalea-core/src/position.rs18
1 files changed, 13 insertions, 5 deletions
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,