mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
* 23w40a * 23w41a * 23w42a * 23w43a * 23w44a * serialize FormattedText as nbt in network * use azalea-nbt/serde in azalea-chat * 23w45a * fix 23w45a to compile * handle Object in codegen * 1.20.3-pre2 * remove unused clientbound_resource_pack_packet.rs * merge main and make azalea-chat use simdnbt * 1.20.3-rc1 * fix tests * use simdnbt 0.3 * fix ServerboundSetJigsawBlockPacket * 1.20.3
46 lines
1.2 KiB
Rust
Executable file
46 lines
1.2 KiB
Rust
Executable file
use crate::{style::Style, FormattedText};
|
|
use serde::Serialize;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Eq, Hash)]
|
|
pub struct BaseComponent {
|
|
// implements mutablecomponent
|
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
|
pub siblings: Vec<FormattedText>,
|
|
#[serde(flatten)]
|
|
pub style: Style,
|
|
}
|
|
|
|
impl BaseComponent {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
siblings: Vec::new(),
|
|
style: Style::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "simdnbt")]
|
|
impl simdnbt::Serialize for BaseComponent {
|
|
fn to_compound(self) -> simdnbt::owned::NbtCompound {
|
|
let mut compound = simdnbt::owned::NbtCompound::new();
|
|
if !self.siblings.is_empty() {
|
|
compound.insert(
|
|
"extra",
|
|
simdnbt::owned::NbtList::from(
|
|
self.siblings
|
|
.into_iter()
|
|
.map(|component| component.to_compound())
|
|
.collect::<Vec<_>>(),
|
|
),
|
|
);
|
|
}
|
|
compound.extend(self.style.to_compound());
|
|
compound
|
|
}
|
|
}
|
|
|
|
impl Default for BaseComponent {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|