aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-08-10 11:06:31 -1345
committermat <git@matdoes.dev>2025-08-10 14:21:34 -1030
commit827277555d44c606b16df91e1e724f3f0ab9e0a8 (patch)
treefdc3803b322f6df07c2e052251cb59eed3575a5d
parent5bd7a4b11a37670a093fb68e0f5fb6fe8246191e (diff)
downloadazalea-drasl-827277555d44c606b16df91e1e724f3f0ab9e0a8.tar.xz
use Vec3f32 in entity metadata to fix parsing Vector3 values
-rw-r--r--CHANGELOG.md1
-rw-r--r--azalea-core/src/position.rs26
-rw-r--r--azalea-entity/src/data.rs4
-rw-r--r--azalea-entity/src/metadata.rs22
-rw-r--r--azalea-inventory/tests/components.rs2
-rw-r--r--azalea-protocol/src/packets/game/c_set_entity_data.rs13
-rw-r--r--codegen/lib/code/entity.py4
7 files changed, 56 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0484dc69..6c79ac58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ is breaking anyways, semantic versioning is not followed.
- `azalea-chat` now correctly handles arrays of integers in the `with` field. (@qwqawawow)
- Inventories now use the correct max stack sizes.
- Clients now send the correct data component checksums when interacting with items.
+- Fix parsing some metadata fields of Display entities.
## [0.13.0+mc1.21.5] - 2025-06-15
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index 8ba381a5..9aebd80b 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -361,6 +361,32 @@ impl Vec3 {
}
}
+/// A lower precision [`Vec3`], used for some fields in entity metadata.
+#[derive(Clone, Copy, Debug, Default, PartialEq, AzBuf)]
+pub struct Vec3f32 {
+ pub x: f32,
+ pub y: f32,
+ pub z: f32,
+}
+impl From<Vec3f32> for Vec3 {
+ fn from(v: Vec3f32) -> Self {
+ Vec3 {
+ x: v.x as f64,
+ y: v.y as f64,
+ z: v.z as f64,
+ }
+ }
+}
+impl From<Vec3> for Vec3f32 {
+ fn from(v: Vec3) -> Self {
+ Vec3f32 {
+ x: v.x as f32,
+ y: v.y as f32,
+ z: v.z as f32,
+ }
+ }
+}
+
/// The coordinates of a block in the world.
///
/// For entities (if the coordinates are floating-point), use [`Vec3`] instead.
diff --git a/azalea-entity/src/data.rs b/azalea-entity/src/data.rs
index 24e31713..436c6571 100644
--- a/azalea-entity/src/data.rs
+++ b/azalea-entity/src/data.rs
@@ -6,7 +6,7 @@ use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar,
use azalea_chat::FormattedText;
use azalea_core::{
direction::Direction,
- position::{BlockPos, GlobalPos, Vec3},
+ position::{BlockPos, GlobalPos, Vec3f32},
};
use azalea_inventory::ItemStack;
use bevy_ecs::component::Component;
@@ -92,7 +92,7 @@ pub enum EntityDataValue {
PaintingVariant(azalea_registry::PaintingVariant),
SnifferState(SnifferStateKind),
ArmadilloState(ArmadilloStateKind),
- Vector3(Vec3),
+ Vector3(Vec3f32),
Quaternion(Quaternion),
}
diff --git a/azalea-entity/src/metadata.rs b/azalea-entity/src/metadata.rs
index c20233cc..422eabd8 100644
--- a/azalea-entity/src/metadata.rs
+++ b/azalea-entity/src/metadata.rs
@@ -6,7 +6,7 @@
use azalea_chat::FormattedText;
use azalea_core::{
direction::Direction,
- position::{BlockPos, Vec3},
+ position::{BlockPos, Vec3f32},
};
use azalea_inventory::ItemStack;
use azalea_registry::DataRegistry;
@@ -1189,9 +1189,9 @@ pub struct TransformationInterpolationDuration(pub i32);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct PosRotInterpolationDuration(pub i32);
#[derive(Component, Deref, DerefMut, Clone)]
-pub struct Translation(pub Vec3);
+pub struct Translation(pub Vec3f32);
#[derive(Component, Deref, DerefMut, Clone)]
-pub struct Scale(pub Vec3);
+pub struct Scale(pub Vec3f32);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct LeftRotation(pub Quaternion);
#[derive(Component, Deref, DerefMut, Clone)]
@@ -1265,12 +1265,12 @@ impl Default for BlockDisplayMetadataBundle {
TransformationInterpolationStartDeltaTicks(0),
transformation_interpolation_duration: TransformationInterpolationDuration(0),
pos_rot_interpolation_duration: PosRotInterpolationDuration(0),
- translation: Translation(Vec3 {
+ translation: Translation(Vec3f32 {
x: 0.0,
y: 0.0,
z: 0.0,
}),
- scale: Scale(Vec3 {
+ scale: Scale(Vec3f32 {
x: 1.0,
y: 1.0,
z: 1.0,
@@ -5249,12 +5249,12 @@ impl Default for ItemDisplayMetadataBundle {
TransformationInterpolationStartDeltaTicks(0),
transformation_interpolation_duration: TransformationInterpolationDuration(0),
pos_rot_interpolation_duration: PosRotInterpolationDuration(0),
- translation: Translation(Vec3 {
+ translation: Translation(Vec3f32 {
x: 0.0,
y: 0.0,
z: 0.0,
}),
- scale: Scale(Vec3 {
+ scale: Scale(Vec3f32 {
x: 1.0,
y: 1.0,
z: 1.0,
@@ -9190,12 +9190,12 @@ impl Default for TextDisplayMetadataBundle {
TransformationInterpolationStartDeltaTicks(0),
transformation_interpolation_duration: TransformationInterpolationDuration(0),
pos_rot_interpolation_duration: PosRotInterpolationDuration(0),
- translation: Translation(Vec3 {
+ translation: Translation(Vec3f32 {
x: 0.0,
y: 0.0,
z: 0.0,
}),
- scale: Scale(Vec3 {
+ scale: Scale(Vec3f32 {
x: 1.0,
y: 1.0,
z: 1.0,
@@ -11424,12 +11424,12 @@ impl Default for AbstractDisplayMetadataBundle {
TransformationInterpolationStartDeltaTicks(0),
transformation_interpolation_duration: TransformationInterpolationDuration(0),
pos_rot_interpolation_duration: PosRotInterpolationDuration(0),
- translation: Translation(Vec3 {
+ translation: Translation(Vec3f32 {
x: 0.0,
y: 0.0,
z: 0.0,
}),
- scale: Scale(Vec3 {
+ scale: Scale(Vec3f32 {
x: 1.0,
y: 1.0,
z: 1.0,
diff --git a/azalea-inventory/tests/components.rs b/azalea-inventory/tests/components.rs
index 6c20436c..add66778 100644
--- a/azalea-inventory/tests/components.rs
+++ b/azalea-inventory/tests/components.rs
@@ -188,7 +188,7 @@ fn test_lodestone_tracker_checksum() {
#[test]
fn test_pot_decorations_checksum() {
let c = PotDecorations {
- items: [Item::Stick, Item::Brick, Item::Brick, Item::Brick],
+ items: vec![Item::Stick, Item::Brick, Item::Brick, Item::Brick],
};
assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 1951715383);
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 2691d04b..fea83941 100644
--- a/azalea-protocol/src/packets/game/c_set_entity_data.rs
+++ b/azalea-protocol/src/packets/game/c_set_entity_data.rs
@@ -48,4 +48,17 @@ mod tests {
assert_eq!(buf.position(), contents.len() as u64);
}
+
+ #[test]
+ fn test_read_6b6t_entity_data() {
+ let contents = [
+ 254, 180, 160, 8, 11, 33, 190, 230, 102, 102, 0, 0, 0, 0, 191, 0, 0, 0, 12, 33, 63,
+ 102, 102, 102, 63, 25, 153, 154, 63, 102, 102, 102, 23, 14, 234, 64, 255,
+ ];
+ let mut buf = Cursor::new(contents.as_slice());
+ let packet = ClientboundSetEntityData::azalea_read(&mut buf).unwrap();
+ println!("{packet:?}");
+
+ assert_eq!(buf.position(), contents.len() as u64);
+ }
}
diff --git a/codegen/lib/code/entity.py b/codegen/lib/code/entity.py
index 41a94991..d4b43d58 100644
--- a/codegen/lib/code/entity.py
+++ b/codegen/lib/code/entity.py
@@ -111,7 +111,7 @@ def generate_entity_metadata(burger_entities_data: dict, mappings: Mappings):
use azalea_chat::FormattedText;
use azalea_core::{
direction::Direction,
- position::{BlockPos, Vec3},
+ position::{BlockPos, Vec3f32},
};
use azalea_inventory::ItemStack;
use azalea_registry::DataRegistry;
@@ -522,7 +522,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
elif type_name == "Quaternion":
default = f"Quaternion {{ x: {float(default['x'])}, y: {float(default['y'])}, z: {float(default['z'])}, w: {float(default['w'])} }}"
elif type_name == "Vector3":
- default = f"Vec3 {{ x: {float(default['x'])}, y: {float(default['y'])}, z: {float(default['z'])} }}"
+ default = f"Vec3f32 {{ x: {float(default['x'])}, y: {float(default['y'])}, z: {float(default['z'])} }}"
elif type_name == "Byte":
# in 1.19.4 TextOpacity is a -1 by default
if default < 0: