0fd6a130221caa2b33529599c312fc219bc89dff
NBT Lib
Библиотека для работы с NBT (Named Binary Tag).
Начиная с версии 1.1-RC разделена на две составляющие: теги и кодеки. Последние занимаются (де)сериализацией тегов.
Примеры работы с NBT
Создание тега типа String:
TagString tagString = new TagString();
tagString.setValue("hello!");
или в одну строчку
TagString tagString = new TagString("hello!");
Создание тега типа Compound:
TagCompound tagCompound = new TagCompound();
tagCompound.getValue().add(new TagLong("Seed", 1234567890));
Сериализация NBT
Сериализация в бинарный формат Minecraft Vanilla выполняется библиотекой nbt-vanilla-codec.
Пример сериализации тега типа String в файл
NbtOutputStream nbtOutputStream = new NbtOutputStream(new FileOutputStream("somefile.bin"));
nbtOutputStream.writeTag(new TagString("hello!"));
nbtOutputStream.close();
По такому же принципу происходит и десериализация
NbtInputStream nbtInputStream = new NbtInputStream(new FileInputStream("somefile.bin"));
Tag tag = nbtInputStream.readTag();
nbtInputStream.close();
if (tag.getType() == TypeTag.STRING) {
TagString tagString = tag.asTagString();
}
Подключение к проекту
Maven
<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
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')
}
Description
Languages
Java
100%