add From<Vec<bool/i32/i64/NbtItem>> for NbtList
This commit is contained in:
parent
b5dda9657a
commit
18d1f3f566
25
src/data.rs
25
src/data.rs
@ -71,6 +71,31 @@ impl NbtItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Vec<NbtItem>> for NbtList {
|
||||||
|
#[inline]
|
||||||
|
fn from(value: Vec<NbtItem>) -> Self { Self::List(Rc::new(RefCell::new(value))) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HashMap<Arc<str>, NbtItem>> for NbtList {
|
||||||
|
#[inline]
|
||||||
|
fn from(value: HashMap<Arc<str>, NbtItem>) -> Self { Self::Compound(Rc::new(RefCell::new(value))) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec<bool>> for NbtList {
|
||||||
|
#[inline]
|
||||||
|
fn from(value: Vec<bool>) -> Self { Self::BoolArray(Rc::new(RefCell::new(value))) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec<i32>> for NbtList {
|
||||||
|
#[inline]
|
||||||
|
fn from(value: Vec<i32>) -> Self { Self::IntArray(Rc::new(RefCell::new(value))) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec<i64>> for NbtList {
|
||||||
|
#[inline]
|
||||||
|
fn from(value: Vec<i64>) -> Self { Self::LongArray(Rc::new(RefCell::new(value))) }
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! export_data {
|
macro_rules! export_data {
|
||||||
($name:ident, $nbt_name:ident, $type:ty) => {
|
($name:ident, $nbt_name:ident, $type:ty) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
13
src/read.rs
13
src/read.rs
@ -108,8 +108,7 @@ pub mod read {
|
|||||||
[0x07] => {
|
[0x07] => {
|
||||||
// ByteArray
|
// ByteArray
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
let arr = Rc::new(RefCell::new(from_bool_array(value)));
|
vec.push(NbtItem::Array(NbtList::from(from_bool_array(value))));
|
||||||
vec.push(NbtItem::Array(NbtList::BoolArray(arr)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[0x08] => {
|
[0x08] => {
|
||||||
@ -121,6 +120,10 @@ pub mod read {
|
|||||||
[0x09] => {
|
[0x09] => {
|
||||||
// NbtList
|
// NbtList
|
||||||
// 要命 (虽说没 Compound 那么麻烦)
|
// 要命 (虽说没 Compound 那么麻烦)
|
||||||
|
// 直接递归就行
|
||||||
|
for _ in 0..len {
|
||||||
|
vec.push(NbtItem::Array(NbtList::from(read_nbt_list(value))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[0x0A] => {
|
[0x0A] => {
|
||||||
// Compound
|
// Compound
|
||||||
@ -129,15 +132,13 @@ pub mod read {
|
|||||||
[0x0B] => {
|
[0x0B] => {
|
||||||
// IntArray
|
// IntArray
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
let arr = Rc::new(RefCell::new(from_i32_array(value)));
|
vec.push(NbtItem::Array(NbtList::from(from_i32_array(value))));
|
||||||
vec.push(NbtItem::Array(NbtList::IntArray(arr)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[0x0C] => {
|
[0x0C] => {
|
||||||
// LongArray
|
// LongArray
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
let arr = Rc::new(RefCell::new(from_i64_array(value)));
|
vec.push(NbtItem::Array(NbtList::from(from_i64_array(value))));
|
||||||
vec.push(NbtItem::Array(NbtList::LongArray(arr)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
Reference in New Issue
Block a user