aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-09 13:29:59 -0600
committerGitHub <noreply@github.com>2025-12-09 13:29:59 -0600
commit26d619c9a329087a23d6577ee74bd764f50cd773 (patch)
tree8020fe902257764a23a445c6ed9987ea4848189d /azalea-protocol/src/packets
parent84cd261118c9d1e3145d4d1751c0d22098cd8cd8 (diff)
downloadazalea-drasl-26d619c9a329087a23d6577ee74bd764f50cd773.tar.xz
Enchantments (#286)
* start implementing enchants * store parsed registries * more work on enchants * implement deserializer for some entity effects * mostly working definitions for enchants * fix tests * detect equipment changes * fix errors * update changelog * fix some imports * remove outdated todo * add basic test for enchants applying attributes * use git simdnbt
Diffstat (limited to 'azalea-protocol/src/packets')
-rw-r--r--azalea-protocol/src/packets/common.rs24
-rw-r--r--azalea-protocol/src/packets/game/c_container_set_slot.rs4
-rw-r--r--azalea-protocol/src/packets/game/c_set_equipment.rs27
-rw-r--r--azalea-protocol/src/packets/game/c_update_attributes.rs2
4 files changed, 12 insertions, 45 deletions
diff --git a/azalea-protocol/src/packets/common.rs b/azalea-protocol/src/packets/common.rs
index fcbf0b05..eb377683 100644
--- a/azalea-protocol/src/packets/common.rs
+++ b/azalea-protocol/src/packets/common.rs
@@ -4,7 +4,7 @@ use azalea_core::{
game_type::{GameMode, OptionalGameType},
identifier::Identifier,
position::GlobalPos,
- registry_holder::{DimensionTypeElement, RegistryHolder},
+ registry_holder::{RegistryHolder, dimension_type::DimensionTypeElement},
};
use tracing::error;
@@ -24,27 +24,15 @@ pub struct CommonPlayerSpawnInfo {
pub sea_level: i32,
}
impl CommonPlayerSpawnInfo {
- pub fn dimension_type(
+ pub fn dimension_type<'a>(
&self,
- registry_holder: &RegistryHolder,
- ) -> Option<(Identifier, DimensionTypeElement)> {
- let dimension_res = self
- .dimension_type
- .resolve_and_deserialize::<DimensionTypeElement>(registry_holder);
- let Some(dimension_res) = dimension_res else {
+ registry_holder: &'a RegistryHolder,
+ ) -> Option<(&'a Identifier, &'a DimensionTypeElement)> {
+ let dimension_res = self.dimension_type.resolve(registry_holder);
+ let Some((dimension_type, dimension_data)) = dimension_res else {
error!("Couldn't resolve dimension_type {:?}", self.dimension_type);
return None;
};
- let (dimension_type, dimension_data) = match dimension_res {
- Ok(d) => d,
- Err(err) => {
- error!(
- "Couldn't deserialize dimension_type {:?}: {err:?}",
- self.dimension_type
- );
- return None;
- }
- };
Some((dimension_type, dimension_data))
}
diff --git a/azalea-protocol/src/packets/game/c_container_set_slot.rs b/azalea-protocol/src/packets/game/c_container_set_slot.rs
index 73670439..571d8e82 100644
--- a/azalea-protocol/src/packets/game/c_container_set_slot.rs
+++ b/azalea-protocol/src/packets/game/c_container_set_slot.rs
@@ -6,8 +6,12 @@ use azalea_protocol_macros::ClientboundGamePacket;
pub struct ClientboundContainerSetSlot {
#[var]
pub container_id: i32,
+ /// An identifier used by the server to track client inventory desyncs.
#[var]
pub state_id: u32,
+ /// The slot index.
+ ///
+ /// See https://minecraft.wiki/w/Java_Edition_protocol/Inventory.
pub slot: u16,
pub item_stack: ItemStack,
}
diff --git a/azalea-protocol/src/packets/game/c_set_equipment.rs b/azalea-protocol/src/packets/game/c_set_equipment.rs
index b52672b0..0ef3d8e1 100644
--- a/azalea-protocol/src/packets/game/c_set_equipment.rs
+++ b/azalea-protocol/src/packets/game/c_set_equipment.rs
@@ -1,7 +1,7 @@
use std::io::{self, Cursor, Write};
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
-use azalea_inventory::ItemStack;
+use azalea_inventory::{ItemStack, components::EquipmentSlot};
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_world::MinecraftEntityId;
@@ -54,28 +54,3 @@ impl AzaleaWrite for EquipmentSlots {
Ok(())
}
}
-
-#[derive(Clone, Debug, Copy, AzBuf, PartialEq)]
-pub enum EquipmentSlot {
- MainHand = 0,
- OffHand = 1,
- Feet = 2,
- Legs = 3,
- Chest = 4,
- Head = 5,
-}
-
-impl EquipmentSlot {
- #[must_use]
- pub fn from_byte(byte: u8) -> Option<Self> {
- match byte {
- 0 => Some(EquipmentSlot::MainHand),
- 1 => Some(EquipmentSlot::OffHand),
- 2 => Some(EquipmentSlot::Feet),
- 3 => Some(EquipmentSlot::Legs),
- 4 => Some(EquipmentSlot::Chest),
- 5 => Some(EquipmentSlot::Head),
- _ => None,
- }
- }
-}
diff --git a/azalea-protocol/src/packets/game/c_update_attributes.rs b/azalea-protocol/src/packets/game/c_update_attributes.rs
index 39c921b0..d11b08cb 100644
--- a/azalea-protocol/src/packets/game/c_update_attributes.rs
+++ b/azalea-protocol/src/packets/game/c_update_attributes.rs
@@ -1,5 +1,5 @@
use azalea_buf::AzBuf;
-use azalea_entity::attributes::AttributeModifier;
+use azalea_inventory::components::AttributeModifier;
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::Attribute;
use azalea_world::MinecraftEntityId;