Files
nbt-lib/README.MD
2020-04-29 12:27:56 +03:00

98 lines
2.6 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: v1.1-RC](https://img.shields.io/badge/version-v1.1--RC-a0a.svg?style=flat)
![coverage: 93%](https://img.shields.io/badge/coverage-93%25-darkgreen.svg?style=flat)
Библиотека для работы с 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
<repositories>
<repository>
<id>mc-project-repository</id>
<url>https://dmx-mc-project.gitlab.io/maven-repository/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>mc-project.nbt</groupId>
<artifactId>nbt</artifactId>
<version>1.1-RC</version>
</dependency>
<dependency>
<groupId>mc-project.nbt.codec</groupId>
<artifactId>nbt-vanilla-codec</artifactId>
<version>1.1-RC</version>
</dependency>
</dependencies>
```
### 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')
}
```