aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-12-05 10:59:05 -0600
committerGitHub <noreply@github.com>2023-12-05 10:59:05 -0600
commit7857a014b92e64361ee237ceae7ef1acc185ac46 (patch)
tree5d70ea6b41943493873810e6a03c3483ff90a235 /azalea-core/src
parentea3e8600126a58f5666d50fbf70dff8209d8979f (diff)
downloadazalea-drasl-7857a014b92e64361ee237ceae7ef1acc185ac46.tar.xz
1.20.3 (#110)
* 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
Diffstat (limited to 'azalea-core/src')
-rwxr-xr-xazalea-core/src/lib.rs1
-rw-r--r--azalea-core/src/objectives.rs33
-rw-r--r--azalea-core/src/registry_holder.rs23
-rwxr-xr-xazalea-core/src/resource_location.rs2
4 files changed, 52 insertions, 7 deletions
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index 511c897b..c1f991df 100755
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -12,6 +12,7 @@ pub mod difficulty;
pub mod direction;
pub mod game_type;
pub mod math;
+pub mod objectives;
pub mod particle;
pub mod position;
pub mod registry_holder;
diff --git a/azalea-core/src/objectives.rs b/azalea-core/src/objectives.rs
new file mode 100644
index 00000000..dd1534f2
--- /dev/null
+++ b/azalea-core/src/objectives.rs
@@ -0,0 +1,33 @@
+use std::{
+ fmt::{self, Display, Formatter},
+ str::FromStr,
+};
+
+use azalea_buf::McBuf;
+
+#[derive(Clone, Copy, Debug, McBuf)]
+pub enum ObjectiveCriteria {
+ Integer,
+ Hearts,
+}
+
+impl Display for ObjectiveCriteria {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ match self {
+ ObjectiveCriteria::Integer => write!(f, "integer"),
+ ObjectiveCriteria::Hearts => write!(f, "hearts"),
+ }
+ }
+}
+
+impl FromStr for ObjectiveCriteria {
+ type Err = ();
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "integer" => Ok(ObjectiveCriteria::Integer),
+ "hearts" => Ok(ObjectiveCriteria::Hearts),
+ _ => Err(()),
+ }
+ }
+}
diff --git a/azalea-core/src/registry_holder.rs b/azalea-core/src/registry_holder.rs
index 6d58f77a..1c21c890 100644
--- a/azalea-core/src/registry_holder.rs
+++ b/azalea-core/src/registry_holder.rs
@@ -28,7 +28,15 @@ impl RegistryHolder {
&self,
name: &ResourceLocation,
) -> Option<Result<T, simdnbt::DeserializeError>> {
- self.map.get(name).map(|nbt| T::from_compound(nbt.clone()))
+ // this is suboptimal, ideally simdnbt should just have a way to get the
+ // owned::NbtCompound as a borrow::NbtCompound
+
+ let nbt_owned_compound = self.map.get(name)?;
+ let mut nbt_bytes = Vec::new();
+ nbt_owned_compound.write(&mut nbt_bytes);
+ let nbt_borrow_compound =
+ simdnbt::borrow::NbtCompound::read(&mut Cursor::new(&nbt_bytes)).ok()?;
+ Some(T::from_compound(&nbt_borrow_compound))
}
/// Get the dimension type registry, or `None` if it doesn't exist. You
@@ -51,7 +59,10 @@ impl RegistryHolder {
impl McBufReadable for RegistryHolder {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
- let nbt_compound = NbtCompound::read_from(buf)?;
+ let nbt_tag = simdnbt::borrow::NbtTag::read(buf)?;
+ let nbt_compound = nbt_tag
+ .compound()
+ .ok_or_else(|| BufReadError::Custom("RegistryHolder must be a compound".to_string()))?;
Ok(RegistryHolder {
map: simdnbt::Deserialize::from_compound(nbt_compound)?,
})
@@ -193,12 +204,12 @@ pub enum MonsterSpawnLightLevel {
}
impl FromNbtTag for MonsterSpawnLightLevel {
- fn from_nbt_tag(tag: simdnbt::owned::NbtTag) -> Option<Self> {
+ fn from_nbt_tag(tag: &simdnbt::borrow::NbtTag) -> Option<Self> {
if let Some(value) = tag.int() {
Some(Self::Simple(value as u32))
} else if let Some(value) = tag.compound() {
- let kind = ResourceLocation::from_nbt_tag(value.get("type")?.clone())?;
- let value = MonsterSpawnLightLevelValues::from_nbt_tag(value.get("value")?.clone())?;
+ let kind = ResourceLocation::from_nbt_tag(value.get("type")?)?;
+ let value = MonsterSpawnLightLevelValues::from_nbt_tag(value.get("value")?)?;
Some(Self::Complex { kind, value })
} else {
None
@@ -251,7 +262,7 @@ pub enum BiomePrecipitation {
Snow,
}
impl FromNbtTag for BiomePrecipitation {
- fn from_nbt_tag(tag: NbtTag) -> Option<Self> {
+ fn from_nbt_tag(tag: &simdnbt::borrow::NbtTag) -> Option<Self> {
match tag.string()?.to_str().as_ref() {
"none" => Some(Self::None),
"rain" => Some(Self::Rain),
diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs
index e6a70247..f9f95004 100755
--- a/azalea-core/src/resource_location.rs
+++ b/azalea-core/src/resource_location.rs
@@ -100,7 +100,7 @@ impl<'de> Deserialize<'de> for ResourceLocation {
}
impl FromNbtTag for ResourceLocation {
- fn from_nbt_tag(tag: NbtTag) -> Option<Self> {
+ fn from_nbt_tag(tag: &simdnbt::borrow::NbtTag) -> Option<Self> {
tag.string().and_then(|s| s.to_str().parse().ok())
}
}