summaryrefslogtreecommitdiff
path: root/libnbtplusplus/README.md
blob: fdc96df533c6844f8192738008a7a1ee05499cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!--
SPDX-FileCopyrightText: 2013, 2015 ljfa-ag <ljfa-ag@web.de>

SPDX-License-Identifier: LGPL-3.0-or-later
-->

# libnbt++ 2

libnbt++ is a free C++ library for Minecraft's file format Named Binary Tag
(NBT). It can read and write compressed and uncompressed NBT files and
provides a code interface for working with NBT data.

----------

libnbt++2 is a remake of the old libnbt++ library with the goal of making it
more easily usable and fixing some problems. The old libnbt++ especially
suffered from a very convoluted syntax and boilerplate code needed to work
with NBT data.

## Building

This project uses CMake for building. Ensure you have CMake installed.

### Prerequisites
- C++11 compatible compiler
- CMake 3.15 or later
- ZLIB (optional, for compressed NBT support)

### Build Steps
1. Clone the repository:
   ```
   git clone https://github.com/PrismLauncher/libnbtplusplus.git
   cd libnbtplusplus
   ```

2. Create a build directory:
   ```
   mkdir build
   cd build
   ```

3. Configure with CMake:
   ```
   cmake ..
   ```
   Options:
   - `NBT_BUILD_SHARED=OFF` (default): Build static library
   - `NBT_USE_ZLIB=ON` (default): Enable zlib support
   - `NBT_BUILD_TESTS=ON` (default): Build tests

4. Build:
   ```
   cmake --build .
   ```

5. Install (optional):
   ```
   cmake --install .
   ```

## Usage

Include the headers and link against the library.

### Example
```cpp
#include <nbt_tags.h>
#include <fstream>
#include <iostream>

int main() {
    // Read an NBT file
    std::ifstream file("example.nbt", std::ios::binary);
    nbt::tag_compound root = nbt::io::read_compound(file).first;

    // Access data
    std::cout << root["some_key"].as<nbt::tag_string>() << std::endl;

    return 0;
}
```

## License

This project is licensed under the GNU General Public License v3.0. See the [COPYING](COPYING) file for details.