Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 1.34 KB

README.md

File metadata and controls

36 lines (28 loc) · 1.34 KB

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);