Skip to content
/ nbt.net Public

A serialization library for the NBT file format, created by Notch.

Notifications You must be signed in to change notification settings

c272/nbt.net

Repository files navigation

NBT.NET

A serialization library for the NBT file format created by Notch.

Overview

NBT.NET is a serialization library designed to work with Notch's "Named Binary Tag" format, created for Minecraft. It includes functions to deserialize NBT data into standard C# classes, as well as vice versa. The entire project is written on .NET Core 3.1 and can be retargeted to .NET Standard.

Usage

To deserialize a file into a specified C# class, you would first create classes with NBTItem and NBTCompound attributes, like so:

using NBT;
...

[NBTCompound]
public class ExampleNBT 
{
    [NBTItem]
    public int SomeInteger { get; set; }
    
    [NBTItem("nbtPropertyName")] //this sets the name to match from the nbt as "nbtPropertyName" rather than the C# property name
    public string SomeString { get; set; }
    
    [NBTItem("^[A-Za-z0-9]+_thing$", true)] //this sets the deserializer to match properties with the given regex
    public long[] RegexedProperty { get; set; }
}

After you define classes to hold the NBT data, you can deserialize like so:

byte[] nbtData = File.ReadAllBytes("level.dat");
ExampleNBT deserialized = NBT.Deserialize<ExampleNBT>(nbtData);

About

A serialization library for the NBT file format, created by Notch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages