Update README.MD
This commit is contained in:
125
README.MD
125
README.MD
@@ -1,16 +1,62 @@
|
|||||||
# NBT Lib
|
# NBT Lib
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
Библиотека для работы с NBT (Named Binary Tag)
|
Библиотека для работы с 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
|
### Maven
|
||||||
|
|
||||||
Добавляем сторонний репозитарий
|
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@@ -18,67 +64,34 @@
|
|||||||
<url>https://dmx-mc-project.gitlab.io/maven-repository/</url>
|
<url>https://dmx-mc-project.gitlab.io/maven-repository/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
```
|
|
||||||
|
|
||||||
Добавляем dependency к себе в проект
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mc-project</groupId>
|
<groupId>mc-project.nbt</groupId>
|
||||||
<artifactId>nbt-lib</artifactId>
|
<artifactId>nbt</artifactId>
|
||||||
<version>1.0-RC</version>
|
<version>1.1-RC</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mc-project.nbt.codec</groupId>
|
||||||
|
<artifactId>nbt-vanilla-codec</artifactId>
|
||||||
|
<version>1.1-RC</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle
|
### Gradle
|
||||||
|
|
||||||
Добавляем сторонний репозитарий
|
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://dmx-mc-project.gitlab.io/maven-repository/' }
|
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')
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Добавляем dependency к себе в проект
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
implementation (group: 'mc-project', name: 'nbt-lib', version: '1.0-RC')
|
|
||||||
```
|
|
||||||
|
|
||||||
## Использование
|
|
||||||
|
|
||||||
### Чтение
|
|
||||||
|
|
||||||
Для чтения NBT из потока (`InputStream`) используется класс `NbtInputStream`:
|
|
||||||
|
|
||||||
```java
|
|
||||||
NbtInputStream nbtInputStream = new NbtInputStream(inputStream);
|
|
||||||
Tag tag = nbtInputStream.readTag();
|
|
||||||
```
|
|
||||||
|
|
||||||
Если поток данных предполагается сжатым (GZip), то вторым параметром в конструкторе `NbtInputStream` указываем на это:
|
|
||||||
|
|
||||||
```java
|
|
||||||
NbtInputStream nbtInputStream = new NbtInputStream(inputStream, true);
|
|
||||||
Tag tag = nbtInputStream.readTag();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Запись
|
|
||||||
|
|
||||||
Для записи NBT в поток (`OutputStream`) используется класс `NbtOutputStream`:
|
|
||||||
|
|
||||||
```java
|
|
||||||
NbtOutputStream nbtOutputStream = new NbtOutputStream(outputStream);
|
|
||||||
nbtOutputStream.writeTag(new TagString("Hello world"));
|
|
||||||
```
|
|
||||||
|
|
||||||
Если необходимо сжатие данных (GZip), то вторым параметром в конструкторе `NbtOutputStream` указываем на это:
|
|
||||||
|
|
||||||
```java
|
|
||||||
NbtOutputStream nbtOutputStream = new NbtOutputStream(outputStream, true);
|
|
||||||
nbtOutputStream.writeTag(new TagString("Hello world"));
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user