Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Falcon
Falcon NBT
Named Binary Tag library for Minecraft written in C++17

C++17

What is this?

The NBT implementation used by Falcon, as a standalone library with no dependency on the protocol or the server.

  • Tag - a single NBT value of any of the 13 tag types. Compounds keep their insertion order.
  • NbtIo - reads and writes tags in three encodings selected with NbtVariant:
    • BigEndian - Java Edition layout
    • LittleEndian - Bedrock world storage and .dat files
    • Network - Bedrock packets: ints and longs are zigzag varints, strings and the root name use an unsigned varint length, every array and list length is a zigzag varint
  • BinaryStream / ReadOnlyBinaryStream - the byte buffer the codecs read from and write to, with EncodingSettings limits (maximum list size, byte array size and string length) for untrusted input
  • json::Value - the JSON parser shared by the libraries that depend on this one

Nesting is limited to NbtIo::MAX_DEPTH (16) levels below the root on both read and write.

Usage

The library is a plain CMake target named FalconNBT. The easiest way to use it is FetchContent:

include(FetchContent)

FetchContent_Declare(
    falcon_nbt
    GIT_REPOSITORY https://github.com/Falcon-MC/NBT.git
    GIT_TAG main
    GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(falcon_nbt)

target_link_libraries(your_target PRIVATE FalconNBT)
#include "Core/NBT/NbtIo.h"

Tag state = Tag::ofCompound();
state.putString("name", "minecraft:stone");
state.put("states", Tag::ofCompound());

BinaryStream stream;
NbtIo::writeTag(stream, state, NbtVariant::LittleEndian);

ReadOnlyBinaryStream input(stream.getBuffer());
Tag decoded = NbtIo::readTag(input, NbtVariant::LittleEndian);

Building

Only CMake 3.16+ and a C++17 compiler are required. Tests are built when the project is the top level project (FALCON_NBT_BUILD_TESTS).

cmake -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failure

License

LGPL-3.0, see LICENSE and COPYING.

About

NBT library for Falcon

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages