aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-buf/src/read.rs10
-rw-r--r--azalea-buf/src/write.rs8
-rw-r--r--azalea-entity/src/data.rs12
-rw-r--r--azalea-entity/src/metadata.rs14
-rw-r--r--azalea-entity/src/particle.rs4
-rw-r--r--azalea-inventory/src/operations.rs2
-rw-r--r--azalea-inventory/src/slot.rs26
-rw-r--r--codegen/lib/code/entity.py2
8 files changed, 50 insertions, 28 deletions
diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs
index 7cea9695..f4d6a951 100644
--- a/azalea-buf/src/read.rs
+++ b/azalea-buf/src/read.rs
@@ -285,11 +285,21 @@ impl AzaleaRead for String {
read_utf_with_len(buf, MAX_STRING_LENGTH.into())
}
}
+impl AzaleaRead for Box<str> {
+ fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
+ String::azalea_read(buf).map(Into::into)
+ }
+}
impl AzaleaReadLimited for String {
fn azalea_read_limited(buf: &mut Cursor<&[u8]>, limit: usize) -> Result<Self, BufReadError> {
read_utf_with_len(buf, limit as u32)
}
}
+impl AzaleaReadLimited for Box<str> {
+ fn azalea_read_limited(buf: &mut Cursor<&[u8]>, limit: usize) -> Result<Self, BufReadError> {
+ String::azalea_read_limited(buf, limit).map(Into::into)
+ }
+}
impl AzaleaRead for u32 {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
diff --git a/azalea-buf/src/write.rs b/azalea-buf/src/write.rs
index 8c2d88ea..4fcce7a0 100644
--- a/azalea-buf/src/write.rs
+++ b/azalea-buf/src/write.rs
@@ -126,7 +126,13 @@ impl AzaleaWrite for Vec<u8> {
impl AzaleaWrite for String {
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
- write_utf_with_len(buf, self, MAX_STRING_LENGTH.into())
+ self.as_str().azalea_write(buf)
+ }
+}
+
+impl AzaleaWrite for Box<str> {
+ fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
+ (&**self).azalea_write(buf)
}
}
diff --git a/azalea-entity/src/data.rs b/azalea-entity/src/data.rs
index fab78795..c9e98b0d 100644
--- a/azalea-entity/src/data.rs
+++ b/azalea-entity/src/data.rs
@@ -65,9 +65,9 @@ pub enum EntityDataValue {
Int(#[var] i32),
Long(#[var] i64),
Float(f32),
- String(String),
- FormattedText(FormattedText),
- OptionalFormattedText(Option<FormattedText>),
+ String(Box<str>),
+ FormattedText(Box<FormattedText>),
+ OptionalFormattedText(Option<Box<FormattedText>>),
ItemStack(ItemStack),
Boolean(bool),
Rotations(Rotations),
@@ -79,7 +79,7 @@ pub enum EntityDataValue {
/// If this is air, that means it's absent,
OptionalBlockState(azalea_block::BlockState),
Particle(Particle),
- Particles(Vec<Particle>),
+ Particles(Box<[Particle]>),
VillagerData(VillagerData),
// 0 for absent; 1 + actual value otherwise. Used for entity IDs.
OptionalUnsignedInt(OptionalUnsignedInt),
@@ -92,7 +92,7 @@ pub enum EntityDataValue {
PigVariant(azalea_registry::data::PigVariant),
ChickenVariant(azalea_registry::data::ChickenVariant),
ZombieNautilusVariant(azalea_registry::data::ZombieNautilusVariant),
- OptionalGlobalPos(Option<GlobalPos>),
+ OptionalGlobalPos(Option<Box<GlobalPos>>),
PaintingVariant(azalea_registry::data::PaintingVariant),
SnifferState(SnifferStateKind),
ArmadilloState(ArmadilloStateKind),
@@ -104,6 +104,8 @@ pub enum EntityDataValue {
HumanoidArm(HumanoidArm),
}
+const _: () = assert!(size_of::<EntityDataValue>() == 24);
+
#[derive(Clone, Debug, PartialEq)]
pub struct OptionalUnsignedInt(pub Option<u32>);
diff --git a/azalea-entity/src/metadata.rs b/azalea-entity/src/metadata.rs
index 03b5ad69..d076e403 100644
--- a/azalea-entity/src/metadata.rs
+++ b/azalea-entity/src/metadata.rs
@@ -250,7 +250,7 @@ pub struct FallFlying(pub bool);
pub struct AirSupply(pub i32);
/// A metadata field for [AbstractEntity].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
-pub struct CustomName(pub Option<FormattedText>);
+pub struct CustomName(pub Option<Box<FormattedText>>);
/// A metadata field for [AbstractEntity].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
pub struct CustomNameVisible(pub bool);
@@ -2718,7 +2718,7 @@ impl Default for ItemDisplayMetadataBundle {
/// A metadata field for [TextDisplay].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
-pub struct Text(pub FormattedText);
+pub struct Text(pub Box<FormattedText>);
/// A metadata field for [TextDisplay].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
pub struct LineWidth(pub i32);
@@ -2824,7 +2824,7 @@ pub struct AbstractLivingUsingItem(pub bool);
pub struct Health(pub f32);
/// A metadata field for [AbstractLiving].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
-pub struct EffectParticles(pub Vec<Particle>);
+pub struct EffectParticles(pub Box<[Particle]>);
/// A metadata field for [AbstractLiving].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
pub struct EffectAmbience(pub bool);
@@ -3256,7 +3256,7 @@ pub struct Profile(pub components::Profile);
pub struct Immovable(pub bool);
/// A metadata field for [Mannequin].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
-pub struct Description(pub Option<FormattedText>);
+pub struct Description(pub Option<Box<FormattedText>>);
/// The marker component for entities of type `minecraft:mannequin`.
///
/// # Metadata
@@ -12295,10 +12295,10 @@ impl Default for ChestMinecartMetadataBundle {
/// A metadata field for [CommandBlockMinecart].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
-pub struct CommandName(pub String);
+pub struct CommandName(pub Box<str>);
/// A metadata field for [CommandBlockMinecart].
#[derive(Component, Deref, DerefMut, Clone, PartialEq)]
-pub struct LastOutput(pub FormattedText);
+pub struct LastOutput(pub Box<FormattedText>);
/// The marker component for entities of type
/// `minecraft:command_block_minecart`.
///
@@ -12359,7 +12359,7 @@ impl Default for CommandBlockMinecartMetadataBundle {
Self {
_marker: CommandBlockMinecart,
parent: Default::default(),
- command_name: CommandName("".to_owned()),
+ command_name: CommandName("".into()),
last_output: LastOutput(Default::default()),
}
}
diff --git a/azalea-entity/src/particle.rs b/azalea-entity/src/particle.rs
index a85d2565..14dad4cc 100644
--- a/azalea-entity/src/particle.rs
+++ b/azalea-entity/src/particle.rs
@@ -60,7 +60,7 @@ pub enum Particle {
Heart,
InstantEffect,
Item(ItemParticle),
- Vibration(VibrationParticle),
+ Vibration(Box<VibrationParticle>),
Trail,
ItemSlime,
ItemCobweb,
@@ -183,7 +183,7 @@ impl From<ParticleKind> for Particle {
ParticleKind::Heart => Self::Heart,
ParticleKind::InstantEffect => Self::InstantEffect,
ParticleKind::Item => Self::Item(ItemParticle::default()),
- ParticleKind::Vibration => Self::Vibration(VibrationParticle::default()),
+ ParticleKind::Vibration => Self::Vibration(Box::new(VibrationParticle::default())),
ParticleKind::ItemSlime => Self::ItemSlime,
ParticleKind::ItemSnowball => Self::ItemSnowball,
ParticleKind::LargeSmoke => Self::LargeSmoke,
diff --git a/azalea-inventory/src/operations.rs b/azalea-inventory/src/operations.rs
index 41fca533..afaaf2ef 100644
--- a/azalea-inventory/src/operations.rs
+++ b/azalea-inventory/src/operations.rs
@@ -702,7 +702,7 @@ impl Menu {
// get the target slot again but mut this time so we can update it
let target_slot = self.slot_mut(target_slot_index).unwrap();
- *target_slot = ItemStack::Present(new_target_slot_data);
+ *target_slot = ItemStack::from(new_target_slot_data);
item_slot.update_empty();
}
diff --git a/azalea-inventory/src/slot.rs b/azalea-inventory/src/slot.rs
index c077812c..78f0cbf8 100644
--- a/azalea-inventory/src/slot.rs
+++ b/azalea-inventory/src/slot.rs
@@ -169,7 +169,7 @@ impl ItemStackData {
ItemStackData {
count,
kind: item,
- component_patch: DataComponentPatch::default(),
+ component_patch: Default::default(),
}
}
@@ -224,7 +224,7 @@ impl AzaleaRead for ItemStack {
} else {
let kind = ItemKind::azalea_read(buf)?;
let component_patch = DataComponentPatch::azalea_read(buf)?;
- Ok(ItemStack::Present(ItemStackData {
+ Ok(ItemStack::from(ItemStackData {
count,
kind,
component_patch,
@@ -283,7 +283,7 @@ impl From<(ItemKind, i32)> for ItemStackData {
/// and Azalea does not implement that yet.
#[derive(Default)]
pub struct DataComponentPatch {
- components: IndexMap<DataComponentKind, Option<DataComponentUnion>>,
+ components: Box<IndexMap<DataComponentKind, Option<DataComponentUnion>>>,
}
impl DataComponentPatch {
@@ -366,7 +366,7 @@ impl DataComponentPatch {
impl Drop for DataComponentPatch {
fn drop(&mut self) {
// the component values are ManuallyDrop since they're in a union
- for (kind, component) in &mut self.components {
+ for (kind, component) in self.components.iter_mut() {
if let Some(component) = component {
// SAFETY: we got the kind and component from the map
unsafe { component.drop_as(*kind) };
@@ -396,7 +396,9 @@ impl AzaleaRead for DataComponentPatch {
components.insert(component_kind, None);
}
- Ok(DataComponentPatch { components })
+ Ok(DataComponentPatch {
+ components: Box::new(components),
+ })
}
}
@@ -416,7 +418,7 @@ impl AzaleaWrite for DataComponentPatch {
components_without_data_count.azalea_write_var(buf)?;
let mut component_buf = Vec::new();
- for (kind, component) in &self.components {
+ for (kind, component) in self.components.iter() {
if let Some(component) = component {
kind.azalea_write(buf)?;
@@ -427,7 +429,7 @@ impl AzaleaWrite for DataComponentPatch {
}
}
- for (kind, component) in &self.components {
+ for (kind, component) in self.components.iter() {
if component.is_none() {
kind.azalea_write(buf)?;
}
@@ -440,13 +442,15 @@ impl AzaleaWrite for DataComponentPatch {
impl Clone for DataComponentPatch {
fn clone(&self) -> Self {
let mut components = IndexMap::with_capacity(self.components.len());
- for (kind, component) in &self.components {
+ for (kind, component) in self.components.iter() {
components.insert(
*kind,
component.as_ref().map(|c| unsafe { c.clone_as(*kind) }),
);
}
- DataComponentPatch { components }
+ DataComponentPatch {
+ components: Box::new(components),
+ }
}
}
impl Debug for DataComponentPatch {
@@ -459,7 +463,7 @@ impl PartialEq for DataComponentPatch {
if self.components.len() != other.components.len() {
return false;
}
- for (kind, component) in &self.components {
+ for (kind, component) in self.components.iter() {
let Some(other_component) = other.components.get(kind) else {
return false;
};
@@ -487,7 +491,7 @@ impl Serialize for DataComponentPatch {
S: serde::Serializer,
{
let mut s = serializer.serialize_map(Some(self.components.len()))?;
- for (kind, component) in &self.components {
+ for (kind, component) in self.components.iter() {
if let Some(component) = component {
unsafe { component.serialize_entry_as(&mut s, *kind) }?;
} else {
diff --git a/codegen/lib/code/entity.py b/codegen/lib/code/entity.py
index 75ca72e5..1297b9f6 100644
--- a/codegen/lib/code/entity.py
+++ b/codegen/lib/code/entity.py
@@ -557,7 +557,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
default = "true" if default else "false"
elif type_name == "String":
string_escaped = default.replace('"', '\\"')
- default = f'"{string_escaped}".to_owned()'
+ default = f'"{string_escaped}".into()'
elif type_name == "BlockPos":
default = f"BlockPos::new{default}"
elif type_name == "OptionalBlockPos": # Option<BlockPos>