diff options
Diffstat (limited to 'src/nbtdsl.rs')
-rw-r--r-- | src/nbtdsl.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/nbtdsl.rs b/src/nbtdsl.rs new file mode 100644 index 0000000..bfa9090 --- /dev/null +++ b/src/nbtdsl.rs @@ -0,0 +1,82 @@ +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) + }; +}
\ No newline at end of file |