Named Binary Tag (NBT) is a structured binary file format used by Minecraft. fNbt is a small library, written in C# for .NET 3.5+. It provides functionality to create, load, traverse, modify, and save NBT files and streams.
Current released version is 0.6.4 (6 July 2018).
fNbt is based in part on Erik Davidson's (aphistic's) original LibNbt library, now completely rewritten by Matvei Stefarov (fragmer).
Note that fNbt.Test.dll and nunit.framework.dll do NOT need to be bundled with applications that use fNbt; they are only used for testing.
ICollection<T>
and List tags implement IList<T>
, for easy traversal and LINQ integration.Latest version of fNbt requires .NET Framework 3.5+ (client or full profile).
Package @ NuGet: https://www.nuget.org/packages/fNbt/
Compiled binary: https://fcraft.net/fnbt/fNbt_v0.6.4.zip
SHA1: 600853530fd538e614b6cb4722ced81917e9615d
Amalgamation (single source file):
var myFile = new NbtFile();
myFile.LoadFromFile("somefile.nbt.gz");
var myCompoundTag = myFile.RootTag;
int intVal = myCompoundTag.Get<NbtInt>("intTagsName").Value;
string listItem = myStringList.Get<NbtString>(0).Value;
byte nestedVal = myCompTag.Get<NbtCompound>("nestedTag")
.Get<NbtByte>("someByteTag")
.Value;
int intVal = myCompoundTag["intTagsName"].IntValue;
string listItem = myStringList[0].StringValue;
byte nestedVal = myCompTag["nestedTag"]["someByteTag"].ByteValue;
foreach( NbtTag tag in myCompoundTag.Values ){
Console.WriteLine( tag.Name + " = " + tag.TagType );
}
foreach( string tagName in myCompoundTag.Names ){
Console.WriteLine( tagName );
}
for( int i = 0; i < myListTag.Count; i++ ){
Console.WriteLine( myListTag[i] );
}
foreach( NbtInt intItem in myIntList.ToArray<NbtInt>() ){
Console.WriteLine( intItem.Value );
}
var serverInfo = new NbtCompound("Server");
serverInfo.Add( new NbtString("Name", "BestServerEver") );
serverInfo.Add( new NbtInt("Players", 15) );
serverInfo.Add( new NbtInt("MaxPlayers", 20) );
var serverFile = new NbtFile(serverInfo);
serverFile.SaveToFile( "server.nbt", NbtCompression.None );
var compound = new NbtCompound("root"){
new NbtInt("someInt", 123),
new NbtList("byteList") {
new NbtByte(1),
new NbtByte(2),
new NbtByte(3)
},
new NbtCompound("nestedCompound") {
new NbtDouble("pi", 3.14)
}
};
Console.WriteLine( myFile.ToString("\t") ); // tabs
Console.WriteLine( myRandomTag.ToString(" ") ); // spaces
Online reference can be found at http://www.fcraft.net/fnbt/v0.6.4/
fNbt v0.5.0+ is licensed under 3-Clause BSD license; see docs/LICENSE. LibNbt2012 up to and including v0.4.1 kept LibNbt's original license (LGPLv3).
If you need .NET 2.0 support, stick to using fNbt version 0.5.1. Note that this 0.5.x branch of fNbt is no longer supported or updated.
Compiled binary: https://fcraft.net/fnbt/fNbt_v0.5.1.zip
Amalgamation (single source file):