MinecraftDotnet.NBT
1.1.0-dev.10
dotnet add package MinecraftDotnet.NBT --version 1.1.0-dev.10
NuGet\Install-Package MinecraftDotnet.NBT -Version 1.1.0-dev.10
<PackageReference Include="MinecraftDotnet.NBT" Version="1.1.0-dev.10" />
<PackageVersion Include="MinecraftDotnet.NBT" Version="1.1.0-dev.10" />
<PackageReference Include="MinecraftDotnet.NBT" />
paket add MinecraftDotnet.NBT --version 1.1.0-dev.10
#r "nuget: MinecraftDotnet.NBT, 1.1.0-dev.10"
#:package MinecraftDotnet.NBT@1.1.0-dev.10
#addin nuget:?package=MinecraftDotnet.NBT&version=1.1.0-dev.10&prerelease
#tool nuget:?package=MinecraftDotnet.NBT&version=1.1.0-dev.10&prerelease
NBT
An NBT (Named Binary Tag) parser and writer for C#. Fully compatible with Minecraft's NBT format.
Tags
All tags implement INbtTag. Names are not stored on tags themselves — they are used as keys inside a CompoundTag.
| Tag | C# Class | Type ID | C# Value Type |
|---|---|---|---|
TAG_End |
EmptyTag |
0 | (no value) |
TAG_Byte |
ByteTag |
1 | sbyte |
TAG_Short |
ShortTag |
2 | short |
TAG_Int |
IntegerTag |
3 | int |
TAG_Long |
LongTag |
4 | long |
TAG_Float |
FloatTag |
5 | float |
TAG_Double |
DoubleTag |
6 | double |
TAG_Byte_Array |
ArrayTag<sbyte> |
7 | sbyte[] |
TAG_String |
StringTag |
8 | string |
TAG_List |
ListTag / ListTag<T> |
9 | INbtTag[] |
TAG_Compound |
CompoundTag |
10 | keyed children |
TAG_Int_Array |
ArrayTag<int> |
11 | int[] |
TAG_Long_Array |
ArrayTag<long> |
12 | long[] |
Note:
BooleanTagis a convenience subclass ofByteTag(storestrueas0x01,falseas0x00). It is not a separate NBT type.
Primitive tags
new ByteTag((sbyte)127)
new ShortTag((short)1000)
new IntegerTag(42)
new LongTag(123456789L)
new FloatTag(3.14f)
new DoubleTag(2.718281828)
new StringTag("hello")
new BooleanTag(true)
new EmptyTag() // represents TAG_End
Array tags
ArrayTag<T> supports sbyte, int, and long:
new ArrayTag<sbyte>((sbyte)0, (sbyte)1, (sbyte)2) // TAG_Byte_Array
new ArrayTag<int>(1, 2, 3) // TAG_Int_Array
new ArrayTag<long>(100L, 200L, 300L) // TAG_Long_Array
List tag
All elements must be the same tag type. The generic ListTag<T> preserves the element type:
new ListTag<IntegerTag>(new IntegerTag(1), new IntegerTag(2), new IntegerTag(3))
new ListTag<StringTag>(new StringTag("a"), new StringTag("b"))
Compound tag
CompoundTag holds named children as ordered key-value pairs:
CompoundTag tag = new(
("name", new StringTag("Steve")),
("health", new FloatTag(20.0f)),
("score", new IntegerTag(100)),
("tags", new ListTag<StringTag>(new StringTag("player"))),
("inventory", new ArrayTag<int>(1, 2, 3))
);
// Access children by name
INbtTag? health = tag["health"];
// Add a child (returns a new CompoundTag — tags are immutable)
CompoundTag updated = tag.WithChild("level", new IntegerTag(5));
You can also construct a CompoundTag from a dictionary:
CompoundTag tag = new(new Dictionary<string, INbtTag?> {
["x"] = new DoubleTag(128.5),
["y"] = new DoubleTag(64.0),
["z"] = new DoubleTag(-32.0)
});
Serialising
CompoundTag tag = new(
("name", new StringTag("Test")),
("age", new IntegerTag(30)),
("scores", new ListTag<IntegerTag>(new IntegerTag(1), new IntegerTag(2))),
("data", new ArrayTag<sbyte>((sbyte)0, (sbyte)1, (sbyte)2))
);
byte[] bytes = tag.Serialise();
Deserialising
byte[] data = ...; // raw NBT bytes
INbtTag tag = NbtReader.ReadNbt(data);
// Cast to the expected type
CompoundTag compound = (CompoundTag)tag;
string name = compound["name"].GetString();
int age = compound["age"].GetInteger();
For NBT files that lack a root type prefix (implied root compound), pass impliedRoot: true:
INbtTag tag = NbtReader.ReadNbt(data, impliedRoot: true);
Compression
INbtTag tag = NbtReader.ReadNbt(data, compression: NbtCompressionType.ZLib);
// NbtCompressionType.None (default), NbtCompressionType.ZLib, NbtCompressionType.GZip
You can also construct an NbtReader directly from a Stream:
using FileStream fs = File.OpenRead("level.dat");
NbtReader reader = new(fs, NbtCompressionType.ZLib);
INbtTag tag = reader.ToTag(impliedRoot: true);
JSON conversion
Tags can be converted to/from JSON:
// Tag → JSON string
string json = tag.ToJsonString();
// Tag → JToken (Newtonsoft.Json)
JToken jtoken = tag.ToJson();
// JSON string → Tag
INbtTag tag = INbtTag.FromJson(json);
// JToken → Tag
INbtTag tag = INbtTag.FromJson(jtoken);
But be careful when expecting certain types because JSON types don't map 1-to-1 to NBT types,
when reading NBT that was deserialised from JSON try to use the helper methods in NbtTagExtensions instead.
These methods will try to convert the type to the closest equivalent NBT type.
Custom serialisable types
Implement CompoundTagSerialisable to make your own classes usable as NBT tags:
public class PlayerData : CompoundTagSerialisable {
public string Name { get; init; }
public int Health { get; init; }
public override CompoundTag SerialiseToTag() => new(
("name", new StringTag(Name)),
("health", new IntegerTag(Health))
);
}
// Use directly as an INbtTag
PlayerData player = new() { Name = "Steve", Health = 20 };
byte[] bytes = player.Serialise();
If you only need the interface without inheriting a base class, implement ICompoundTagSerialisable instead.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MinecraftDotnet.NBT:
| Package | Downloads |
|---|---|
|
MinecraftDotnet.Protocol
Library for interacting the Minecraft Java network protocol. As well as some other utils. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0-dev.10 | 50 | 8/21/2026 |
| 1.0.3-dev.9 | 167 | 4/16/2026 |
| 1.0.3-dev.8 | 65 | 4/15/2026 |
| 1.0.3-dev.7 | 90 | 4/15/2026 |
| 0.0.3-dev.6 | 69 | 4/14/2026 |
| 0.0.3-dev.5 | 71 | 4/14/2026 |
| 0.0.3-dev.4 | 67 | 4/11/2026 |
| 0.0.3-dev.3 | 66 | 4/11/2026 |
| 0.0.3-dev.2 | 305 | 10/26/2025 |
| 0.0.2-dev.174 | 135 | 10/26/2025 |
| 0.0.2-dev.173 | 151 | 10/24/2025 |
| 0.0.2-dev.172 | 147 | 10/17/2025 |
| 0.0.2-dev.171 | 153 | 10/14/2025 |
| 0.0.2-dev.170 | 171 | 10/7/2025 |
| 0.0.2-dev.169 | 240 | 9/15/2025 |
| 0.0.2-dev.168 | 126 | 9/12/2025 |
| 0.0.2-dev.167 | 155 | 9/11/2025 |
| 0.0.2-dev.166 | 166 | 9/10/2025 |
| 0.0.2-dev.165 | 154 | 9/9/2025 |
| 0.0.1 | 668 | 7/23/2025 |