Files
nbt-lib/README.MD
2024-02-07 03:45:28 +03:00

43 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# NBT Lib
![version: 2.0-SNAPSHOT](https://img.shields.io/badge/version-2.0--SNAPSHOT-a0a.svg?style=flat)
Библиотека для работы с NBT (Named Binary Tag).
## Примеры работы
**Создание тега типа String:**
```java
StringTag tag = new StringTag("Hello World!");
```
**Создание тега типа Compound:**
```java
CompoundTag tag = new CompoundTag()
.append("Seed", new LongTag(1234567890));
```
## Сериализация
Пример сериализации тега типа String в файл
```java
try (NbtOutputStream nbtOutputStream = new NbtOutputStream(new FileOutputStream("somefile.bin"))) {
nbtOutputStream.writeTag(new StringTag("hello!"));
}
```
По такому же принципу происходит и десериализация
```java
try (NbtInputStream nbtInputStream = new NbtInputStream(new FileInputStream("somefile.bin"))) {
TagValue tag = nbtInputStream.readTag();
if (tag.isString()) {
StringTag stringTag = tag.asString();
// ...
}
}
```