Use the nbt! macro from mc_protocol for creating NBT (Named Binary Tag) data for Minecraft protocol encoding.
Use the nbt! macro from mc_protocol for creating NBT data.
Use this skill when you need to:
use mc_protocol::nbt;
// Simple compound
let compound = nbt! {
"text" => "Hello",
"count" => 42i32,
"flag" => true,
};
// Convert to network bytes
let bytes = compound.to_network_bytes();
use mc_protocol::nbt;
let nested = nbt! {
"outer" => nbt! {
"inner" => 123i32,
},
};
i8 - Bytei16 - Shorti32 - Inti64 - Longf32 - Floatf64 - Double&str / String - Stringbool - Byte (0 or 1)NbtCompound - Nested compoundNbtList - List of same-type elementsFor Minecraft text components (used in chat, action bar, titles):
use mc_protocol::nbt;
// Simple text
let text_component = nbt! {
"text" => "Hello World",
};
// With color
let colored = nbt! {
"text" => "Red text",
"color" => "red",
};
nbt! macro instead of manual byte manipulation42i32, 1.0f32) for numeric literalsto_network_bytes() for protocol encoding (adds type tag, no root name)