This repository has been archived by the owner on Jan 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b906438
commit 4970d95
Showing
13 changed files
with
255 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### kotlin ### | ||
.kotlin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 版本更新 (3.0.0开始算起): | ||
|
||
### 3.3.0 - 更新 | ||
- 修改了部分代码 | ||
- `get(String)Lio/github/xiefrish2021/api/ITag`方法修改成 `get(String)Lio/github/xiefrish2021/compound/NBTElement` | ||
- 添加了一些kotlin成分:如委托,语法糖 | ||
|
||
#### 3.2.0 - 更新 | ||
- 删除或合并了一些不必要的接口 | ||
- `NBT.newInstance()`用法更改为 `NBT.getInstance()` | ||
|
||
#### 3.1.0 - 更新 | ||
- 修改了SNBTReader里面readArray的会报unchecked的某条代码 | ||
- 把Compound,Array<V extends ITag>等等的接口迁移到了`xyz.frish2021.nbt.api`包 | ||
- 修改了NBT类的基本用法由`new NBT()` 修改成`NBT.newInstance()` 并且添加了单例模式 | ||
- `NBT.newInstance()` 添加了synchronized关键字以防止多次初始化影响线程安全 | ||
- 修复了生成IntArray和ByteArray的SNBT却生成成了List的SNBT。 | ||
|
||
#### 3.0.0 - 更新 | ||
- 重写了库的代码 | ||
- 允许通过Compound实例生成SNBT | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,7 @@ | |
|
||
NBT(全称:二进制命名标签(`N`amed`B`inary `T`ags))\ | ||
是Minecraft游戏存档及一些游戏数据的存储格式。\ | ||
作者:Frish2021 | ||
|
||
## (0) 3.2.0版本 - 更新内容 | ||
- 删除或合并了一些不必要的接口 | ||
- `NBT.newInstance()`用法更改为 `NBT.getInstance()` | ||
版本更新:[CHANGES.md](CHANGES.md) | ||
|
||
## (1) 用法 | ||
Maven | ||
|
@@ -92,19 +88,53 @@ public class NBTest { | |
|
||
### 读操作(NBT) | ||
#### 源码 | ||
java | ||
|
||
```java | ||
public class NBTest { | ||
public static void main(String[] args) { | ||
NBT nbt = new NBT.getInstance(); | ||
File output = new File("你要读取的NBT文件"); | ||
|
||
CompoundTag compound = nbt.readUnnamedNBT(output); | ||
System.out.println(compound.getString("test")); | ||
System.out.println(compound.getCompound("test1").getInt("test3")); | ||
|
||
try (InputStream is = new FileInputStream("你要读取的NBT文件")) { | ||
CompoundTag compound = nbt.readUnnamedNBT(is); | ||
System.out.println(compound.getString("test")); | ||
System.out.println(compound.getCompound("test1").getInt("test3")); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
kotlin (通过`compound[key]`方法) | ||
|
||
```kotlin | ||
fun main() { | ||
val nbt = NBT.getInstance() | ||
val compound = nbt.readUnnamedNBT(FileOutputStream("你要读取的NBT文件")) | ||
|
||
println(compound["test"].asString()); | ||
println(compound["test1"].asCompound()["test3"].asInt()); | ||
} | ||
``` | ||
|
||
kotlin (通过委托方法) | ||
|
||
```kotlin | ||
fun main() { | ||
val nbt = NBT.getInstance() | ||
val compound = nbt.readUnnamedNBT(FileOutputStream("你要读取的NBT文件")) | ||
|
||
val test: NBTElement by compound | ||
|
||
val test1: NBTElement by compound | ||
val test3: NBTElement by test1.asCompound() | ||
|
||
println(test.asString()); | ||
println(test3.asInt()); | ||
} | ||
``` | ||
|
||
被读取的NBT文件类容 | ||
```nbtt | ||
"": { | ||
|
@@ -125,6 +155,7 @@ Frish2021 | |
|
||
### 读操作(SNBT) | ||
#### 源码 | ||
java | ||
```java | ||
public class NBTest { | ||
public static void main(String[] args) { | ||
|
@@ -136,14 +167,17 @@ public class NBTest { | |
} | ||
``` | ||
|
||
kotlin 同理 | ||
|
||
#### 效果 | ||
控制台输出 | ||
``` | ||
Frish2021 | ||
``` | ||
|
||
### 新特性 - 生成SNBT | ||
### 生成SNBT | ||
#### 源码 | ||
java | ||
```java | ||
public class NBTest { | ||
public static void main(String[] args) { | ||
|
@@ -161,6 +195,7 @@ public class NBTest { | |
} | ||
} | ||
``` | ||
kotlin同理 | ||
|
||
#### 效果 | ||
控制台输出 | ||
|
@@ -174,17 +209,6 @@ public class NBTest { | |
邮件:`[email protected]` | ||
如果有BUG,请发布Issues. | ||
|
||
## (3) 历史更新 (3.0.0开始算起): | ||
#### 3.0.0 - 更新 | ||
- 重写了库的代码 | ||
- 允许通过Compound实例生成SNBT | ||
#### 3.1.0 - 更新 | ||
- 修改了SNBTReader里面readArray的会报unchecked的某条代码 | ||
- 把Compound,Array<V extends ITag>等等的接口迁移到了`xyz.frish2021.nbt.api`包 | ||
- 修改了NBT类的基本用法由`new NBT()` 修改成`NBT.newInstance()` 并且添加了单例模式 | ||
- `NBT.newInstance()` 添加了synchronized关键字以防止多次初始化影响线程安全 | ||
- 修复了生成IntArray和ByteArray的SNBT却生成成了List的SNBT。 | ||
|
||
## (4) 最后 | ||
## (3) 最后 | ||
该NBT库的其他用法就靠你自己发掘把 :)\ | ||
那些比如IntArray,ByteArray,List可以自己看test模块或者源码。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
} | ||
|
||
rootProject.name = "NBT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,4 @@ public enum TagType { | |
COMPOUND, | ||
INT_ARRAY, | ||
LONG_ARRAY; | ||
|
||
public int id() { | ||
return ordinal(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.xiefrish2021.compound | ||
|
||
import io.github.xiefrish2021.api.ITag | ||
import kotlin.reflect.KProperty | ||
|
||
interface Getter { | ||
operator fun get(key: String): NBTElement | ||
|
||
fun get(key: String, defaultValue: ITag): NBTElement | ||
|
||
operator fun getValue(nothing: Nothing?, property: KProperty<*>): NBTElement | ||
} |
Oops, something went wrong.