# NBT Lib


Библиотека для работы с NBT (Named Binary Tag).
Начиная с версии `1.1-RC` разделена на две составляющие: теги и кодеки. Последние занимаются (де)сериализацией тегов.
## Примеры работы с NBT
**Создание тега типа String:**
```java
TagString tagString = new TagString();
tagString.setValue("hello!");
```
или в одну строчку
```java
TagString tagString = new TagString("hello!");
```
**Создание тега типа Compound:**
```java
TagCompound tagCompound = new TagCompound();
tagCompound.getValue().add(new TagLong("Seed", 1234567890));
```
## Сериализация NBT
Сериализация в бинарный формат Minecraft Vanilla выполняется библиотекой `nbt-vanilla-codec`.
Пример сериализации тега типа String в файл
```java
NbtOutputStream nbtOutputStream = new NbtOutputStream(new FileOutputStream("somefile.bin"));
nbtOutputStream.writeTag(new TagString("hello!"));
nbtOutputStream.close();
```
По такому же принципу происходит и десериализация
```java
NbtInputStream nbtInputStream = new NbtInputStream(new FileInputStream("somefile.bin"));
Tag tag = nbtInputStream.readTag();
nbtInputStream.close();
if (tag.getType() == TypeTag.STRING) {
TagString tagString = tag.asTagString();
}
```
## Подключение к проекту
### Maven
```xml
mc-project-repository
https://dmx-mc-project.gitlab.io/maven-repository/
mc-project.nbt
nbt
1.1-RC
mc-project.nbt.codec
nbt-vanilla-codec
1.1-RC
```
### Gradle
```groovy
repositories {
maven {
name 'mc-project'
url 'https://dmx-mc-project.gitlab.io/maven-repository/'
}
}
dependencies {
implementation (group: 'mc-project.nbt', name: 'nbt', version: '1.1-RC')
implementation (group: 'mc-project.nbt.codec', name: 'nbt-vanilla-codec', version: '1.1-RC')
}
```