Resource icon

Uncategorized PneuJai's NBT API 1.0.5

Source of resources
Original
Copyright link
#
Supported version
  1. 1.16
  2. 1.15 (RTX)
  3. 1.14
  4. 1.13
  5. 1.12
  6. Earlier version
API加載
JavaScript:
const NBT = getShareData("pNbtAPI").NBT, NamedTag = getShareData("pNbtAPI").NamedTag, ByteTag = getShareData("pNbtAPI").ByteTag, ShortTag = getShareData("pNbtAPI").ShortTag, IntTag = getShareData("pNbtAPI").IntTag, LongTag = getShareData("pNbtAPI").LongTag, FloatTag = getShareData("pNbtAPI").FloatTag, DoubleTag = getShareData("pNbtAPI").DoubleTag, ByteArrayTag = getShareData("pNbtAPI").ByteArrayTag, StringTag = getShareData("pNbtAPI").StringTag, ListTag = getShareData("pNbtAPI").ListTag, CompoundTag = getShareData("pNbtAPI").CompoundTag, IntArrayTag = getShareData("pNbtAPI").IntArrayTag;
例子
JavaScript:
setPlayerItems('1d7983df-d68c-3569-9d80-ff52dd758083',JSON.stringify({"Offhand":NBT.createTag(9, "", [NBT.createTag(10, "", [NBT.createTag(1,"Count",  1), NBT.createTag(2, "Damage", 0), NBT.createTag(8, "Name", "minecraft:trident"), NBT.createTag(10, "tag", [NBT.createTag(9, "ench", [NBT.createTag(10, "", [NBT.createTag(2, "id", 7), NBT.createTag(2, "lvl", 8888)])])])])])}));
等同於
JavaScript:
setPlayerItems('1d7983df-d68c-3569-9d80-ff52dd758083', JSON.stringify({"Offhand":NBT.parseFromJSON({"tagType":"List","value":[{"tagType":"Compound","value":[{"tagType":"Byte","name":"Count","value":1},{"tagType":"Short","name":"Damage","value":0},{"tagType":"String","name":"Name","value":"minecraft:trident"},{"tagType":"Compound","name":"tag","value":[{"tagType":"List","name":"ench","value":[{"tagType":"Compound","value":[{"tagType":"Short","name":"id","value":7},{"tagType":"Short","name":"lvl","value":8888}]}]}]}]}]})}));
等同於
JavaScript:
setPlayerItems('1d7983df-d68c-3569-9d80-ff52dd758083', '{"Offhand":{"tt":9,"tv":[{"tt":10,"tv":[{"ck":"Count","cv":{"tt":1,"tv":1}},{"ck":"Damage","cv":{"tt":2,"tv":0}},{"ck":"Name","cv":{"tt":8,"tv":"minecraft:trident"}},{"ck":"tag","cv":{"tt":10,"tv":[{"ck":"ench","cv":{"tt":9,"tv":[{"tt":10,"tv":[{"ck":"id","cv":{"tt":2,"tv":7}},{"ck":"lvl","cv":{"tt":2,"tv":8888}}]}]}}]}}]}]}}');

NBT标签类型
1: Byte Tag
2: Short Tag
3: Int Tag
4: Long Tag
5: Float Tag
6: Double Tag
7: Byte Array Tag
8: String Tag
9: List Tag
10: Compound Tag
11: Int Array Tag

API接口定义
(1)createTag
// 函数名:NBT.createTag
// 功能:创建一个NBT标签
// 参数个数:3个
// 参数类型: 整型,字符串,由类型决定
// 参数详解:type - 标签数据类型,总计11种类型,name - NBT关键字(如果為空字符串,則不會創建 Compound_KEY和 Compound_VALUE),value - 标签值,由类型决定
// 返回值:创建的NBT标签
[例] NBT.createTag(1, "A simple byte tag", 0)

(2)parseFromJSON
// 函数名:NBT.parseFromJSON
// 功能:從JSON创建一个NBT标签
// 参数个数:1个
// 参数类型: JSON
// 参数详解:tags - JSON化的NBT标签
// 返回值: 创建的NBT标签
[例] NBT.parseFromJSON({"tagType": "Byte", "name": "A simple byte tag", "value": 0)

(3)parseToJSON
// 函数名:parseToJSON
// 類別:ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag, ByteArrayTag, StringTag, ListTag, CompoundTag, IntArrayTag
// 功能:從NBT标签创建一个JSON
// 参数个数:0个
// 返回值: 创建的JSON
[例] let o = new ByteTag("A simple byte tag", 0).parseToJSON()

(4)parseFromNBTString
// 函数名:NBT.parseFromNBTString
// 功能:從字符串创建一个NBT标签
// 参数个数:1个
// 参数类型: 字符串
// 参数详解:text - 字符串化的NBT标签
// 返回值: 创建的NBT标签
[例] NBT.parseFromNBTString('{"tt":9,"tv":[{"tt":10,"tv":[{"ck":"Count","cv":{"tt":1,"tv":1}},{"ck":"Damage","cv":{"tt":2,"tv":0}},{"ck":"Name","cv":{"tt":8,"tv":"minecraft:trident"}},{"ck":"tag","cv":{"tt":10,"tv":[{"ck":"ench","cv":{"tt":9,"tv":[{"tt":10,"tv":[{"ck":"id","cv":{"tt":2,"tv":7}},{"ck":"lvl","cv":{"tt":2,"tv":8888}}]}]}}]}}]}]}')

(5)toString
// 函数名:toString
// 類別:ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag, ByteArrayTag, StringTag, ListTag, CompoundTag, IntArrayTag
// 功能:從NBT标签创建一个字符串
// 参数个数:0个
// 返回值: 创建的字符串
[例] let t = new ByteTag("A simple byte tag", 0).toString()

(6)getValue
// 函数名:getValue
// 類別:ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag, ByteArrayTag, StringTag, ListTag, CompoundTag, IntArrayTag
// 功能:獲取NBT标签的值
// 参数个数:0个
// 返回值: NBT标签的值
[例] let i = new ByteTag("A simple byte tag", 0).getValue()
// 类似函数:getName(), getType()

(7)setValue
// 函数名:setValue
// 類別:ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag, ByteArrayTag, StringTag, ListTag, CompoundTag, IntArrayTag
// 功能:修改NBT标签的值
// 参数个数:1个
// 参数类型: 由类型决定
// 参数详解:value - 标签值,由类型决定
[例] let i = new ByteTag("A simple byte tag", 0).setValue(1)
// 类似函数:setName(name)

(8)getNamedTagEntry
// 函数名:getNamedTagEntry
// 類別:ListTag, CompoundTag
// 功能:以关键字查找List Tag和Compound Tag的子NBT标签
// 参数个数:1个
// 参数类型: 字符串
// 参数详解:name - NBT关键字
// 返回值: 找到的NBT标签
[例] let o = new ListTag("", [new ByteTag("byte", 10)]).getNamedTagEntry("byte")

(9)removeNamedTagEntry
// 函数名:removeNamedTagEntry
// 類別:ListTag, CompoundTag
// 功能:以关键字移除List Tag和Compound Tag的子NBT标签
// 参数个数:1个
// 参数类型: 字符串
// 参数详解:name - NBT关键字
[例] let o = new ListTag("", [new ByteTag("byte", 10)]).removeNamedTagEntry("byte")

(10)push
// 函数名:push
// 類別:ListTag, CompoundTag
// 功能:在List Tag和Compound Tag的新增子NBT标签
// 参数个数:1个
// 参数类型: NBT
// 参数详解:tag - NBT标签
[例] let o = new ListTag().push(NBT.createTag(1, "new tag", 0))
// 类似函数:pop(), shift(), unshift(tag), first(), last(), set(offset, value), get(offset), remove(offset), isset(offset), empty(offset), offsetExists(offset), offsetGet(offset), offsetSet(offset, value), offsetUnset(offset)

其他的懶得寫了,自己去發掘吧,反正沒有大用途
  • Like
Reactions: YanBing Online
Author
Pneu Jai
Downloads
325
Views
1,348
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Pneu Jai

Share this resource

Latest updates

  1. It wants a title so here I give it one

    - New method: parseFromNBTString (under class NBT) - New methods: getNamedTagEntry...