Giter Site home page Giter Site logo

netherite.nbt's Introduction

MineSharp.Nbt

This is the "fork" of fNbt (90% rewritten so idk if its called a fork anymore)

Named Binary Tag (NBT) library for modern C#

Features:

  • Implicit casts and initializer syntax allow for better code (example below)
  • Non-complicated straightforward API:
    • NbtDocument.FromBinary(byte[])
    • NbtDocument.FromBinary(Stream)
    • byte[] NbtDocument.ToBinary()
  • Newtonsoft.JSON-like NbtConvert
  • gzip + zlib support

TODO

  • endian support
  • more docs

EXAMPLES

Implicit casts and initializer syntax

Accessing tags (long/strongly-typed style)

    int intVal = myCompoundTag.Get<NbtInt>("intTagsName");
    string listItem = myStringList.Get<NbtString>(0);
    byte nestedVal = myCompTag.Get<NbtCompound>("nestedTag")
                              .Get<NbtByte>("someByteTag");

Accessing tags (shortcut style)

    int intVal = myCompoundTag["intTagsName"];
    string listItem = myStringList[0];
    byte nestedVal = myCompTag["nestedTag"]["someByteTag"];

Iterating over all tags in a compound/list

    foreach(NbtTag tag in myCompoundTag.Tags)
	{
        Console.WriteLine(tag.Name + " = " + tag.TagType);
    }
    foreach(string tagName in myCompoundTag.Tags.Keys)
	{
        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);
    }

Constructing a new document

    var serverInfo = new NbtCompound("Server");
    serverInfo.Add( new NbtString("Name", "BestServerEver") );
    serverInfo.Add( new NbtInt("Players", 15) );
    serverInfo.Add( new NbtInt("MaxPlayers", 20) );

Constructing using collection initializer notation

    var nbt = new NbtDocument {
        { "someInt", 123 },
        { "byteList", {
            new NbtByte(1),
            new NbtByte(2),
            new NbtByte(3)
        } },
        {
			"nestedCompound",
			{
				{ "pi", (double)3.14 }
       		}
		}
    };

Pretty-printing

    Console.WriteLine(myNbt.ToString());

netherite.nbt's People

Contributors

aphistic avatar ddevault avatar flori-schwa avatar mstefarov avatar thealan404 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.