use mcproto_rs::nbt::Tag; pub trait ShittyToNbt { fn to_nbt(self) -> Tag; } impl ShittyToNbt for String { fn to_nbt(self) -> Tag { Tag::String(self) } } impl ShittyToNbt for &str { fn to_nbt(self) -> Tag { Tag::String(self.into()) } } impl ShittyToNbt for i32 { fn to_nbt(self) -> Tag { Tag::Int(self) } } impl ShittyToNbt for i64 { fn to_nbt(self) -> Tag { Tag::Long(self) } } impl ShittyToNbt for bool { fn to_nbt(self) -> Tag { Tag::Byte(if self { 1 } else { 0 }) } } impl ShittyToNbt for Tag { fn to_nbt(self) -> Tag { self } } impl ShittyToNbt for f32 { fn to_nbt(self) -> Tag { Tag::Float(self) } } impl ShittyToNbt for f64 { fn to_nbt(self) -> Tag { Tag::Double(self) } } #[macro_export] macro_rules! nbt { ( {$($name:literal :: $value:tt),* $(,)? } ) => { Tag::Compound(vec![ $( nbt!($value).with_name($name) ),* ]) }; { $($name:literal :: $value:tt),* $(,)? } => { Tag::Compound(vec![ $( nbt!($value).with_name($name) ),* ]) }; ([ $($value:tt),* $(,)? ]) => { Tag::List(vec![ $( nbt!($value) ),* ]) }; (($e:expr)) => { $crate::nbtdsl::ShittyToNbt::to_nbt($e) }; }