Skip to content

Commit

Permalink
feat: Add support for booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
SzczurekYT authored and Norbiros committed Mar 27, 2024
1 parent 850c0ea commit 0db1d75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/nbt/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ impl NbtCompound {
.and_then(|tag| tag.extract_double())
}

pub fn get_bool(&self, name: &str) -> Option<bool> {
self.child_tags.get(name).and_then(|tag| tag.extract_bool())
}

pub fn get_string(&self, name: &str) -> Option<&String> {
self.child_tags
.get(name)
Expand Down
13 changes: 13 additions & 0 deletions src/nbt/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ impl NbtTag {
}
}

pub fn extract_bool(&self) -> Option<bool> {
match self {
NbtTag::Byte(byte) => Some(*byte != 0),
_ => None,
}
}

pub fn extract_byte_array(&self) -> Option<&Vec<u8>> {
match self {
NbtTag::ByteArray(byte_array) => Some(byte_array),
Expand Down Expand Up @@ -254,3 +261,9 @@ impl From<&str> for NbtTag {
NbtTag::String(value.to_string())
}
}

impl From<bool> for NbtTag {
fn from(value: bool) -> Self {
NbtTag::Byte(value as i8)
}
}

0 comments on commit 0db1d75

Please sign in to comment.