mca-json 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +14 -0
- package/.prettierrc +4 -0
- package/README.md +373 -0
- package/dist/bin/mca-chunks.d.ts +3 -0
- package/dist/bin/mca-chunks.d.ts.map +1 -0
- package/dist/bin/mca-chunks.js +43 -0
- package/dist/bin/mca-chunks.js.map +1 -0
- package/dist/bin/mca-find-chunks-with-signs.d.ts +3 -0
- package/dist/bin/mca-find-chunks-with-signs.d.ts.map +1 -0
- package/dist/bin/mca-find-chunks-with-signs.js +79 -0
- package/dist/bin/mca-find-chunks-with-signs.js.map +1 -0
- package/dist/bin/mca-json.d.ts +3 -0
- package/dist/bin/mca-json.d.ts.map +1 -0
- package/dist/bin/mca-json.js +73 -0
- package/dist/bin/mca-json.js.map +1 -0
- package/dist/bin/mca-trim-chunks-without-signs.d.ts +3 -0
- package/dist/bin/mca-trim-chunks-without-signs.d.ts.map +1 -0
- package/dist/bin/mca-trim-chunks-without-signs.js +117 -0
- package/dist/bin/mca-trim-chunks-without-signs.js.map +1 -0
- package/dist/bin/nbt-get-player-location.d.ts +3 -0
- package/dist/bin/nbt-get-player-location.d.ts.map +1 -0
- package/dist/bin/nbt-get-player-location.js +83 -0
- package/dist/bin/nbt-get-player-location.js.map +1 -0
- package/dist/bin/nbt-json.d.ts +3 -0
- package/dist/bin/nbt-json.d.ts.map +1 -0
- package/dist/bin/nbt-json.js +64 -0
- package/dist/bin/nbt-json.js.map +1 -0
- package/dist/block/banner.d.ts +13 -0
- package/dist/block/banner.d.ts.map +1 -0
- package/dist/block/banner.js +28 -0
- package/dist/block/banner.js.map +1 -0
- package/dist/block/barrel.d.ts +17 -0
- package/dist/block/barrel.d.ts.map +1 -0
- package/dist/block/barrel.js +21 -0
- package/dist/block/barrel.js.map +1 -0
- package/dist/block/beacon.d.ts +14 -0
- package/dist/block/beacon.d.ts.map +1 -0
- package/dist/block/beacon.js +14 -0
- package/dist/block/beacon.js.map +1 -0
- package/dist/block/bed.d.ts +4 -0
- package/dist/block/bed.d.ts.map +1 -0
- package/dist/block/bed.js +4 -0
- package/dist/block/bed.js.map +1 -0
- package/dist/block/beehive.d.ts +9 -0
- package/dist/block/beehive.d.ts.map +1 -0
- package/dist/block/beehive.js +10 -0
- package/dist/block/beehive.js.map +1 -0
- package/dist/block/bell.d.ts +4 -0
- package/dist/block/bell.d.ts.map +1 -0
- package/dist/block/bell.js +4 -0
- package/dist/block/bell.js.map +1 -0
- package/dist/block/block.d.ts +23 -0
- package/dist/block/block.d.ts.map +1 -0
- package/dist/block/block.js +49 -0
- package/dist/block/block.js.map +1 -0
- package/dist/block/generic.d.ts +10 -0
- package/dist/block/generic.d.ts.map +1 -0
- package/dist/block/generic.js +14 -0
- package/dist/block/generic.js.map +1 -0
- package/dist/block/has-entity-data.d.ts +8 -0
- package/dist/block/has-entity-data.d.ts.map +1 -0
- package/dist/block/has-entity-data.js +12 -0
- package/dist/block/has-entity-data.js.map +1 -0
- package/dist/block/mixins/custom-name.d.ts +5 -0
- package/dist/block/mixins/custom-name.d.ts.map +1 -0
- package/dist/block/mixins/custom-name.js +7 -0
- package/dist/block/mixins/custom-name.js.map +1 -0
- package/dist/block/mixins/lock.d.ts +5 -0
- package/dist/block/mixins/lock.d.ts.map +1 -0
- package/dist/block/mixins/lock.js +7 -0
- package/dist/block/mixins/lock.js.map +1 -0
- package/dist/block/mixins/mixin.d.ts +27 -0
- package/dist/block/mixins/mixin.d.ts.map +1 -0
- package/dist/block/mixins/mixin.js +36 -0
- package/dist/block/mixins/mixin.js.map +1 -0
- package/dist/block/sign.d.ts +15 -0
- package/dist/block/sign.d.ts.map +1 -0
- package/dist/block/sign.js +91 -0
- package/dist/block/sign.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/anvil.d.ts +54 -0
- package/dist/lib/anvil.d.ts.map +1 -0
- package/dist/lib/anvil.js +141 -0
- package/dist/lib/anvil.js.map +1 -0
- package/dist/lib/binary-data.d.ts +48 -0
- package/dist/lib/binary-data.d.ts.map +1 -0
- package/dist/lib/binary-data.js +188 -0
- package/dist/lib/binary-data.js.map +1 -0
- package/dist/lib/bit-data.d.ts +16 -0
- package/dist/lib/bit-data.d.ts.map +1 -0
- package/dist/lib/bit-data.js +75 -0
- package/dist/lib/bit-data.js.map +1 -0
- package/dist/lib/block-data.d.ts +20 -0
- package/dist/lib/block-data.d.ts.map +1 -0
- package/dist/lib/block-data.js +125 -0
- package/dist/lib/block-data.js.map +1 -0
- package/dist/lib/chunk.d.ts +112 -0
- package/dist/lib/chunk.d.ts.map +1 -0
- package/dist/lib/chunk.js +299 -0
- package/dist/lib/chunk.js.map +1 -0
- package/dist/nbt/nbt-base.d.ts +20 -0
- package/dist/nbt/nbt-base.d.ts.map +1 -0
- package/dist/nbt/nbt-base.js +30 -0
- package/dist/nbt/nbt-base.js.map +1 -0
- package/dist/nbt/nbt-byte-array.d.ts +13 -0
- package/dist/nbt/nbt-byte-array.d.ts.map +1 -0
- package/dist/nbt/nbt-byte-array.js +30 -0
- package/dist/nbt/nbt-byte-array.js.map +1 -0
- package/dist/nbt/nbt-byte.d.ts +13 -0
- package/dist/nbt/nbt-byte.d.ts.map +1 -0
- package/dist/nbt/nbt-byte.js +25 -0
- package/dist/nbt/nbt-byte.js.map +1 -0
- package/dist/nbt/nbt-compound.d.ts +15 -0
- package/dist/nbt/nbt-compound.d.ts.map +1 -0
- package/dist/nbt/nbt-compound.js +68 -0
- package/dist/nbt/nbt-compound.js.map +1 -0
- package/dist/nbt/nbt-double.d.ts +13 -0
- package/dist/nbt/nbt-double.d.ts.map +1 -0
- package/dist/nbt/nbt-double.js +25 -0
- package/dist/nbt/nbt-double.js.map +1 -0
- package/dist/nbt/nbt-end.d.ts +11 -0
- package/dist/nbt/nbt-end.d.ts.map +1 -0
- package/dist/nbt/nbt-end.js +22 -0
- package/dist/nbt/nbt-end.js.map +1 -0
- package/dist/nbt/nbt-float.d.ts +13 -0
- package/dist/nbt/nbt-float.d.ts.map +1 -0
- package/dist/nbt/nbt-float.js +25 -0
- package/dist/nbt/nbt-float.js.map +1 -0
- package/dist/nbt/nbt-int-array.d.ts +13 -0
- package/dist/nbt/nbt-int-array.d.ts.map +1 -0
- package/dist/nbt/nbt-int-array.js +30 -0
- package/dist/nbt/nbt-int-array.js.map +1 -0
- package/dist/nbt/nbt-int.d.ts +13 -0
- package/dist/nbt/nbt-int.d.ts.map +1 -0
- package/dist/nbt/nbt-int.js +25 -0
- package/dist/nbt/nbt-int.js.map +1 -0
- package/dist/nbt/nbt-list.d.ts +17 -0
- package/dist/nbt/nbt-list.d.ts.map +1 -0
- package/dist/nbt/nbt-list.js +70 -0
- package/dist/nbt/nbt-list.js.map +1 -0
- package/dist/nbt/nbt-long-array.d.ts +13 -0
- package/dist/nbt/nbt-long-array.d.ts.map +1 -0
- package/dist/nbt/nbt-long-array.js +32 -0
- package/dist/nbt/nbt-long-array.js.map +1 -0
- package/dist/nbt/nbt-long.d.ts +13 -0
- package/dist/nbt/nbt-long.d.ts.map +1 -0
- package/dist/nbt/nbt-long.js +25 -0
- package/dist/nbt/nbt-long.js.map +1 -0
- package/dist/nbt/nbt-short.d.ts +13 -0
- package/dist/nbt/nbt-short.d.ts.map +1 -0
- package/dist/nbt/nbt-short.js +25 -0
- package/dist/nbt/nbt-short.js.map +1 -0
- package/dist/nbt/nbt-string.d.ts +13 -0
- package/dist/nbt/nbt-string.d.ts.map +1 -0
- package/dist/nbt/nbt-string.js +27 -0
- package/dist/nbt/nbt-string.js.map +1 -0
- package/dist/nbt/nbt-tag-type.d.ts +16 -0
- package/dist/nbt/nbt-tag-type.d.ts.map +1 -0
- package/dist/nbt/nbt-tag-type.js +17 -0
- package/dist/nbt/nbt-tag-type.js.map +1 -0
- package/dist/nbt/nbt.d.ts +11 -0
- package/dist/nbt/nbt.d.ts.map +1 -0
- package/dist/nbt/nbt.js +57 -0
- package/dist/nbt/nbt.js.map +1 -0
- package/dist/nbt/snbt-data.d.ts +18 -0
- package/dist/nbt/snbt-data.d.ts.map +1 -0
- package/dist/nbt/snbt-data.js +34 -0
- package/dist/nbt/snbt-data.js.map +1 -0
- package/dist/nbt/snbt-parse.d.ts +3 -0
- package/dist/nbt/snbt-parse.d.ts.map +1 -0
- package/dist/nbt/snbt-parse.js +201 -0
- package/dist/nbt/snbt-parse.js.map +1 -0
- package/dist/nbt/snbt-to-nbt.d.ts +7 -0
- package/dist/nbt/snbt-to-nbt.d.ts.map +1 -0
- package/dist/nbt/snbt-to-nbt.js +178 -0
- package/dist/nbt/snbt-to-nbt.js.map +1 -0
- package/dist/types/coords.d.ts +3 -0
- package/dist/types/coords.d.ts.map +1 -0
- package/dist/types/coords.js +2 -0
- package/dist/types/coords.js.map +1 -0
- package/package.json +28 -0
- package/src/bin/mca-chunks.ts +54 -0
- package/src/bin/mca-find-chunks-with-signs.ts +109 -0
- package/src/bin/mca-json.ts +96 -0
- package/src/bin/mca-trim-chunks-without-signs.ts +146 -0
- package/src/bin/nbt-get-player-location.ts +102 -0
- package/src/bin/nbt-json.ts +85 -0
- package/src/block/banner.ts +50 -0
- package/src/block/barrel.ts +34 -0
- package/src/block/beacon.ts +20 -0
- package/src/block/bed.ts +3 -0
- package/src/block/beehive.ts +17 -0
- package/src/block/bell.ts +3 -0
- package/src/block/block.ts +62 -0
- package/src/block/generic.ts +14 -0
- package/src/block/has-entity-data.ts +20 -0
- package/src/block/mixins/custom-name.ts +8 -0
- package/src/block/mixins/lock.ts +8 -0
- package/src/block/mixins/mixin.ts +53 -0
- package/src/block/sign.ts +121 -0
- package/src/index.ts +38 -0
- package/src/lib/anvil.ts +178 -0
- package/src/lib/binary-data.ts +247 -0
- package/src/lib/bit-data.ts +101 -0
- package/src/lib/block-data.ts +180 -0
- package/src/lib/chunk.ts +389 -0
- package/src/nbt/nbt-base.ts +38 -0
- package/src/nbt/nbt-byte-array.ts +38 -0
- package/src/nbt/nbt-byte.ts +31 -0
- package/src/nbt/nbt-compound.ts +95 -0
- package/src/nbt/nbt-double.ts +31 -0
- package/src/nbt/nbt-end.ts +27 -0
- package/src/nbt/nbt-float.ts +31 -0
- package/src/nbt/nbt-int-array.ts +38 -0
- package/src/nbt/nbt-int.ts +31 -0
- package/src/nbt/nbt-list.ts +103 -0
- package/src/nbt/nbt-long-array.ts +40 -0
- package/src/nbt/nbt-long.ts +31 -0
- package/src/nbt/nbt-short.ts +31 -0
- package/src/nbt/nbt-string.ts +35 -0
- package/src/nbt/nbt-tag-type.ts +15 -0
- package/src/nbt/nbt.ts +70 -0
- package/src/nbt/snbt-data.ts +70 -0
- package/src/nbt/snbt-parse.ts +256 -0
- package/src/nbt/snbt-to-nbt.ts +219 -0
- package/src/types/coords.ts +2 -0
- package/src/types/neodoc.d.ts +28 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { NbtBase } from './nbt-base';
|
|
3
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
4
|
+
const debugLogFromBinaryData = debug('nbt:string:from-binary-data');
|
|
5
|
+
export class NbtString extends NbtBase {
|
|
6
|
+
static fromBinaryData(bd, name) {
|
|
7
|
+
name ??= NbtString.readName(bd);
|
|
8
|
+
const length = bd.getUShort();
|
|
9
|
+
const data = bd.getString(length);
|
|
10
|
+
debugLogFromBinaryData(`STRING, name ${name}, length ${length}, data ${data}`);
|
|
11
|
+
return new NbtString(data, name);
|
|
12
|
+
}
|
|
13
|
+
constructor(data, name) {
|
|
14
|
+
super(NbtTagType.STRING, data, name);
|
|
15
|
+
}
|
|
16
|
+
toObject() {
|
|
17
|
+
return {
|
|
18
|
+
type: this.type,
|
|
19
|
+
string: this.data,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
toSnbt() {
|
|
23
|
+
// This always works but doesn't always produce the shortest string
|
|
24
|
+
return JSON.stringify(this.data);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=nbt-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-string.js","sourceRoot":"","sources":["../../src/nbt/nbt-string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,sBAAsB,GAAG,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAEpE,MAAM,OAAO,SAAU,SAAQ,OAAe;IAC1C,MAAM,CAAC,cAAc,CAAC,EAAc,EAAE,IAAa;QAC/C,IAAI,KAAK,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,sBAAsB,CAClB,gBAAgB,IAAI,YAAY,MAAM,UAAU,IAAI,EAAE,CACzD,CAAC;QAEF,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,YAAY,IAAY,EAAE,IAAa;QACnC,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,QAAQ;QACJ,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,IAAI;SACpB,CAAC;IACN,CAAC;IAED,MAAM;QACF,mEAAmE;QACnE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACJ","sourcesContent":["import debug from 'debug';\nimport { BinaryData } from '../lib/binary-data';\nimport { NbtBase } from './nbt-base';\nimport { NbtTagType } from './nbt-tag-type';\n\nconst debugLogFromBinaryData = debug('nbt:string:from-binary-data');\n\nexport class NbtString extends NbtBase<string> {\n static fromBinaryData(bd: BinaryData, name?: string): NbtString {\n name ??= NbtString.readName(bd);\n const length = bd.getUShort();\n const data = bd.getString(length);\n debugLogFromBinaryData(\n `STRING, name ${name}, length ${length}, data ${data}`\n );\n\n return new NbtString(data, name);\n }\n\n constructor(data: string, name?: string) {\n super(NbtTagType.STRING, data, name);\n }\n\n toObject() {\n return {\n type: this.type,\n string: this.data,\n };\n }\n\n toSnbt() {\n // This always works but doesn't always produce the shortest string\n return JSON.stringify(this.data);\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum NbtTagType {
|
|
2
|
+
END = 0,
|
|
3
|
+
BYTE = 1,
|
|
4
|
+
SHORT = 2,
|
|
5
|
+
INT = 3,
|
|
6
|
+
LONG = 4,
|
|
7
|
+
FLOAT = 5,
|
|
8
|
+
DOUBLE = 6,
|
|
9
|
+
BYTE_ARRAY = 7,
|
|
10
|
+
STRING = 8,
|
|
11
|
+
LIST = 9,
|
|
12
|
+
COMPOUND = 10,
|
|
13
|
+
INT_ARRAY = 11,
|
|
14
|
+
LONG_ARRAY = 12
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=nbt-tag-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-tag-type.d.ts","sourceRoot":"","sources":["../../src/nbt/nbt-tag-type.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IAClB,GAAG,IAAI;IACP,IAAI,IAAI;IACR,KAAK,IAAI;IACT,GAAG,IAAI;IACP,IAAI,IAAI;IACR,KAAK,IAAI;IACT,MAAM,IAAI;IACV,UAAU,IAAI;IACd,MAAM,IAAI;IACV,IAAI,IAAI;IACR,QAAQ,KAAK;IACb,SAAS,KAAK;IACd,UAAU,KAAK;CAClB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var NbtTagType;
|
|
2
|
+
(function (NbtTagType) {
|
|
3
|
+
NbtTagType[NbtTagType["END"] = 0] = "END";
|
|
4
|
+
NbtTagType[NbtTagType["BYTE"] = 1] = "BYTE";
|
|
5
|
+
NbtTagType[NbtTagType["SHORT"] = 2] = "SHORT";
|
|
6
|
+
NbtTagType[NbtTagType["INT"] = 3] = "INT";
|
|
7
|
+
NbtTagType[NbtTagType["LONG"] = 4] = "LONG";
|
|
8
|
+
NbtTagType[NbtTagType["FLOAT"] = 5] = "FLOAT";
|
|
9
|
+
NbtTagType[NbtTagType["DOUBLE"] = 6] = "DOUBLE";
|
|
10
|
+
NbtTagType[NbtTagType["BYTE_ARRAY"] = 7] = "BYTE_ARRAY";
|
|
11
|
+
NbtTagType[NbtTagType["STRING"] = 8] = "STRING";
|
|
12
|
+
NbtTagType[NbtTagType["LIST"] = 9] = "LIST";
|
|
13
|
+
NbtTagType[NbtTagType["COMPOUND"] = 10] = "COMPOUND";
|
|
14
|
+
NbtTagType[NbtTagType["INT_ARRAY"] = 11] = "INT_ARRAY";
|
|
15
|
+
NbtTagType[NbtTagType["LONG_ARRAY"] = 12] = "LONG_ARRAY";
|
|
16
|
+
})(NbtTagType || (NbtTagType = {}));
|
|
17
|
+
//# sourceMappingURL=nbt-tag-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-tag-type.js","sourceRoot":"","sources":["../../src/nbt/nbt-tag-type.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAcX;AAdD,WAAY,UAAU;IAClB,yCAAO,CAAA;IACP,2CAAQ,CAAA;IACR,6CAAS,CAAA;IACT,yCAAO,CAAA;IACP,2CAAQ,CAAA;IACR,6CAAS,CAAA;IACT,+CAAU,CAAA;IACV,uDAAc,CAAA;IACd,+CAAU,CAAA;IACV,2CAAQ,CAAA;IACR,oDAAa,CAAA;IACb,sDAAc,CAAA;IACd,wDAAe,CAAA;AACnB,CAAC,EAdW,UAAU,KAAV,UAAU,QAcrB","sourcesContent":["export enum NbtTagType {\n END = 0,\n BYTE = 1,\n SHORT = 2,\n INT = 3,\n LONG = 4,\n FLOAT = 5,\n DOUBLE = 6,\n BYTE_ARRAY = 7,\n STRING = 8,\n LIST = 9,\n COMPOUND = 10,\n INT_ARRAY = 11,\n LONG_ARRAY = 12,\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BinaryData } from '../lib/binary-data';
|
|
2
|
+
import { NbtBase } from '../nbt/nbt-base';
|
|
3
|
+
export declare const fromBinaryData: {
|
|
4
|
+
[key: number]: (bd: BinaryData, name?: string) => NbtBase<any>;
|
|
5
|
+
};
|
|
6
|
+
export declare class Nbt {
|
|
7
|
+
static fromBuffer(data: ArrayBufferLike): NbtBase<any>;
|
|
8
|
+
static fromSnbt(snbt: string): NbtBase<any>;
|
|
9
|
+
static getTag(bd: BinaryData): NbtBase<any>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=nbt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt.d.ts","sourceRoot":"","sources":["../../src/nbt/nbt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAkB1C,eAAO,MAAM,cAAc,EAAE;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAelE,CAAC;AAEF,qBAAa,GAAG;IACZ,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IAOtD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAc3C,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC;CAU9C"}
|
package/dist/nbt/nbt.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BinaryData } from '../lib/binary-data';
|
|
2
|
+
import { NbtByte } from '../nbt/nbt-byte';
|
|
3
|
+
import { NbtByteArray } from '../nbt/nbt-byte-array';
|
|
4
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
5
|
+
import { NbtDouble } from '../nbt/nbt-double';
|
|
6
|
+
import { NbtEnd } from '../nbt/nbt-end';
|
|
7
|
+
import { NbtFloat } from '../nbt/nbt-float';
|
|
8
|
+
import { NbtInt } from '../nbt/nbt-int';
|
|
9
|
+
import { NbtIntArray } from '../nbt/nbt-int-array';
|
|
10
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
11
|
+
import { NbtLong } from '../nbt/nbt-long';
|
|
12
|
+
import { NbtLongArray } from '../nbt/nbt-long-array';
|
|
13
|
+
import { NbtShort } from '../nbt/nbt-short';
|
|
14
|
+
import { NbtString } from '../nbt/nbt-string';
|
|
15
|
+
import { NbtTagType } from '../nbt/nbt-tag-type';
|
|
16
|
+
import { snbtParse } from './snbt-parse';
|
|
17
|
+
import { snbtToNbt } from './snbt-to-nbt';
|
|
18
|
+
export const fromBinaryData = {
|
|
19
|
+
[NbtTagType.BYTE_ARRAY]: NbtByteArray.fromBinaryData,
|
|
20
|
+
[NbtTagType.BYTE]: NbtByte.fromBinaryData,
|
|
21
|
+
[NbtTagType.COMPOUND]: NbtCompound.fromBinaryData,
|
|
22
|
+
[NbtTagType.DOUBLE]: NbtDouble.fromBinaryData,
|
|
23
|
+
[NbtTagType.END]: NbtEnd.fromBinaryData,
|
|
24
|
+
[NbtTagType.FLOAT]: NbtFloat.fromBinaryData,
|
|
25
|
+
[NbtTagType.INT_ARRAY]: NbtIntArray.fromBinaryData,
|
|
26
|
+
[NbtTagType.INT]: NbtInt.fromBinaryData,
|
|
27
|
+
[NbtTagType.LIST]: NbtList.fromBinaryData,
|
|
28
|
+
[NbtTagType.LONG_ARRAY]: NbtLongArray.fromBinaryData,
|
|
29
|
+
[NbtTagType.LONG]: NbtLong.fromBinaryData,
|
|
30
|
+
[NbtTagType.SHORT]: NbtShort.fromBinaryData,
|
|
31
|
+
[NbtTagType.STRING]: NbtString.fromBinaryData,
|
|
32
|
+
};
|
|
33
|
+
export class Nbt {
|
|
34
|
+
static fromBuffer(data) {
|
|
35
|
+
const bd = new BinaryData(data);
|
|
36
|
+
bd.seek(0);
|
|
37
|
+
return Nbt.getTag(bd);
|
|
38
|
+
}
|
|
39
|
+
static fromSnbt(snbt) {
|
|
40
|
+
const snbtData = snbtParse(snbt);
|
|
41
|
+
const token = snbtToNbt(snbtData);
|
|
42
|
+
if (snbtData.remainingLength()) {
|
|
43
|
+
const nextToken = snbtData.token();
|
|
44
|
+
throw new Error(`Extra, unparsed SNBT tokens leftover starting with ${nextToken.type}, "${nextToken.content}" at position ${snbtData.currentPosition()}`);
|
|
45
|
+
}
|
|
46
|
+
return token;
|
|
47
|
+
}
|
|
48
|
+
static getTag(bd) {
|
|
49
|
+
const type = bd.getByte();
|
|
50
|
+
const reader = fromBinaryData[type];
|
|
51
|
+
if (!reader) {
|
|
52
|
+
throw new Error(`Invalid NBT tag ID ${type}`);
|
|
53
|
+
}
|
|
54
|
+
return reader(bd);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=nbt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt.js","sourceRoot":"","sources":["../../src/nbt/nbt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;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\nimport { NbtBase } from '../nbt/nbt-base';\nimport { NbtByte } from '../nbt/nbt-byte';\nimport { NbtByteArray } from '../nbt/nbt-byte-array';\nimport { NbtCompound } from '../nbt/nbt-compound';\nimport { NbtDouble } from '../nbt/nbt-double';\nimport { NbtEnd } from '../nbt/nbt-end';\nimport { NbtFloat } from '../nbt/nbt-float';\nimport { NbtInt } from '../nbt/nbt-int';\nimport { NbtIntArray } from '../nbt/nbt-int-array';\nimport { NbtList } from '../nbt/nbt-list';\nimport { NbtLong } from '../nbt/nbt-long';\nimport { NbtLongArray } from '../nbt/nbt-long-array';\nimport { NbtShort } from '../nbt/nbt-short';\nimport { NbtString } from '../nbt/nbt-string';\nimport { NbtTagType } from '../nbt/nbt-tag-type';\nimport { snbtParse } from './snbt-parse';\nimport { snbtToNbt } from './snbt-to-nbt';\n\nexport const fromBinaryData: {\n [key: number]: (bd: BinaryData, name?: string) => NbtBase<any>;\n} = {\n [NbtTagType.BYTE_ARRAY]: NbtByteArray.fromBinaryData,\n [NbtTagType.BYTE]: NbtByte.fromBinaryData,\n [NbtTagType.COMPOUND]: NbtCompound.fromBinaryData,\n [NbtTagType.DOUBLE]: NbtDouble.fromBinaryData,\n [NbtTagType.END]: NbtEnd.fromBinaryData,\n [NbtTagType.FLOAT]: NbtFloat.fromBinaryData,\n [NbtTagType.INT_ARRAY]: NbtIntArray.fromBinaryData,\n [NbtTagType.INT]: NbtInt.fromBinaryData,\n [NbtTagType.LIST]: NbtList.fromBinaryData,\n [NbtTagType.LONG_ARRAY]: NbtLongArray.fromBinaryData,\n [NbtTagType.LONG]: NbtLong.fromBinaryData,\n [NbtTagType.SHORT]: NbtShort.fromBinaryData,\n [NbtTagType.STRING]: NbtString.fromBinaryData,\n};\n\nexport class Nbt {\n static fromBuffer(data: ArrayBufferLike): NbtBase<any> {\n const bd = new BinaryData(data);\n bd.seek(0);\n\n return Nbt.getTag(bd);\n }\n\n static fromSnbt(snbt: string): NbtBase<any> {\n const snbtData = snbtParse(snbt);\n const token = snbtToNbt(snbtData);\n\n if (snbtData.remainingLength()) {\n const nextToken = snbtData.token();\n throw new Error(\n `Extra, unparsed SNBT tokens leftover starting with ${nextToken.type}, \"${nextToken.content}\" at position ${snbtData.currentPosition()}`\n );\n }\n\n return token;\n }\n\n static getTag(bd: BinaryData): NbtBase<any> {\n const type = bd.getByte();\n const reader = fromBinaryData[type];\n\n if (!reader) {\n throw new Error(`Invalid NBT tag ID ${type}`);\n }\n\n return reader(bd);\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SnbtTokenType = 'BYTE' | 'BYTE_ARRAY_START' | 'COLON' | 'COMMA' | 'COMPOUND_END' | 'COMPOUND_START' | 'DOUBLE' | 'FLOAT' | 'INT' | 'INT_ARRAY_START' | 'LIST_END' | 'LIST_START' | 'LONG' | 'LONG_ARRAY_START' | 'SHORT' | 'STRING' | 'WHITESPACE';
|
|
2
|
+
export interface SnbtToken {
|
|
3
|
+
content: string;
|
|
4
|
+
offset: number;
|
|
5
|
+
type: SnbtTokenType;
|
|
6
|
+
}
|
|
7
|
+
export declare class SnbtData {
|
|
8
|
+
position: number;
|
|
9
|
+
data: SnbtToken[];
|
|
10
|
+
addToken(offset: number, type: SnbtTokenType, content: string): void;
|
|
11
|
+
currentPosition(): number;
|
|
12
|
+
remainingLength(): number;
|
|
13
|
+
seek(offset: number): void;
|
|
14
|
+
showToken(token?: SnbtToken): string;
|
|
15
|
+
step(offset: number): void;
|
|
16
|
+
token(): SnbtToken;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=snbt-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snbt-data.d.ts","sourceRoot":"","sources":["../../src/nbt/snbt-data.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACnB,MAAM,GACN,kBAAkB,GAClB,OAAO,GACP,OAAO,GACP,cAAc,GACd,gBAAgB,GAChB,QAAQ,GACR,OAAO,GACP,KAAK,GACL,iBAAiB,GACjB,UAAU,GACV,YAAY,GACZ,MAAM,GACN,kBAAkB,GAClB,OAAO,GACP,QAAQ,GACR,YAAY,CAAC;AAEnB,MAAM,WAAW,SAAS;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;CACvB;AAED,qBAAa,QAAQ;IACjB,QAAQ,SAAK;IACb,IAAI,EAAE,SAAS,EAAE,CAAM;IAEvB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM;IAI7D,eAAe;IAIf,eAAe;IAIf,IAAI,CAAC,MAAM,EAAE,MAAM;IAInB,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS;IAQ3B,IAAI,CAAC,MAAM,EAAE,MAAM;IAInB,KAAK;CAYR"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class SnbtData {
|
|
2
|
+
position = 0;
|
|
3
|
+
data = [];
|
|
4
|
+
addToken(offset, type, content) {
|
|
5
|
+
this.data.push({ type, content, offset });
|
|
6
|
+
}
|
|
7
|
+
currentPosition() {
|
|
8
|
+
return this.position;
|
|
9
|
+
}
|
|
10
|
+
remainingLength() {
|
|
11
|
+
return this.data.length - this.position;
|
|
12
|
+
}
|
|
13
|
+
seek(offset) {
|
|
14
|
+
this.position = offset;
|
|
15
|
+
}
|
|
16
|
+
showToken(token) {
|
|
17
|
+
if (!token) {
|
|
18
|
+
return 'undefined';
|
|
19
|
+
}
|
|
20
|
+
return `${token.type} at ${token.offset}: "${token.content}"`;
|
|
21
|
+
}
|
|
22
|
+
step(offset) {
|
|
23
|
+
this.position += offset;
|
|
24
|
+
}
|
|
25
|
+
token() {
|
|
26
|
+
if (this.position >= this.data.length) {
|
|
27
|
+
throw new Error(`Ran out of tokens at position ${this.position} - previous token was ${this.showToken(this.data[this.position - 1])}`);
|
|
28
|
+
}
|
|
29
|
+
const token = this.data[this.position];
|
|
30
|
+
this.position += 1;
|
|
31
|
+
return token;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=snbt-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snbt-data.js","sourceRoot":"","sources":["../../src/nbt/snbt-data.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,QAAQ;IACjB,QAAQ,GAAG,CAAC,CAAC;IACb,IAAI,GAAgB,EAAE,CAAC;IAEvB,QAAQ,CAAC,MAAc,EAAE,IAAmB,EAAE,OAAe;QACzD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,eAAe;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,eAAe;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,MAAc;QACf,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,KAAiB;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,WAAW,CAAC;QACvB,CAAC;QAED,OAAO,GAAG,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,MAAM,KAAK,CAAC,OAAO,GAAG,CAAC;IAClE,CAAC;IAED,IAAI,CAAC,MAAc;QACf,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC;IAC5B,CAAC;IAED,KAAK;QACD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACX,iCAAiC,IAAI,CAAC,QAAQ,yBAAyB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CACxH,CAAC;QACN,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;QAEnB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["export type SnbtTokenType =\n | 'BYTE'\n | 'BYTE_ARRAY_START'\n | 'COLON'\n | 'COMMA'\n | 'COMPOUND_END'\n | 'COMPOUND_START'\n | 'DOUBLE'\n | 'FLOAT'\n | 'INT'\n | 'INT_ARRAY_START'\n | 'LIST_END'\n | 'LIST_START'\n | 'LONG'\n | 'LONG_ARRAY_START'\n | 'SHORT'\n | 'STRING'\n | 'WHITESPACE'; // For logging, but not made into tokens\n\nexport interface SnbtToken {\n content: string;\n offset: number;\n type: SnbtTokenType;\n}\n\nexport class SnbtData {\n position = 0;\n data: SnbtToken[] = [];\n\n addToken(offset: number, type: SnbtTokenType, content: string) {\n this.data.push({ type, content, offset });\n }\n\n currentPosition() {\n return this.position;\n }\n\n remainingLength() {\n return this.data.length - this.position;\n }\n\n seek(offset: number) {\n this.position = offset;\n }\n\n showToken(token?: SnbtToken) {\n if (!token) {\n return 'undefined';\n }\n\n return `${token.type} at ${token.offset}: \"${token.content}\"`;\n }\n\n step(offset: number) {\n this.position += offset;\n }\n\n token() {\n if (this.position >= this.data.length) {\n throw new Error(\n `Ran out of tokens at position ${this.position} - previous token was ${this.showToken(this.data[this.position - 1])}`\n );\n }\n\n const token = this.data[this.position];\n this.position += 1;\n\n return token;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snbt-parse.d.ts","sourceRoot":"","sources":["../../src/nbt/snbt-parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AA0OtD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,YAoBrC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { SnbtData } from './snbt-data';
|
|
3
|
+
const debugLog = debug('snbt:parse');
|
|
4
|
+
function testParsers(snbtData, str, tokenParsers, pos) {
|
|
5
|
+
for (const { type, pattern, callback } of tokenParsers) {
|
|
6
|
+
const match = str.match(pattern);
|
|
7
|
+
if (match) {
|
|
8
|
+
debugLog(`Matched ${type} at position ${pos}: ${match[0]}`);
|
|
9
|
+
return callback(pos, type, snbtData, match);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const tokenParsers = [
|
|
15
|
+
{
|
|
16
|
+
type: 'WHITESPACE',
|
|
17
|
+
pattern: /^\s+/,
|
|
18
|
+
callback: (_pos, _type, _snbtData, matches) => {
|
|
19
|
+
return matches[0].length;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'COLON',
|
|
24
|
+
pattern: /^:/,
|
|
25
|
+
callback: (pos, type, snbtData) => {
|
|
26
|
+
snbtData.addToken(pos, type, ':');
|
|
27
|
+
return 1;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: 'COMMA',
|
|
32
|
+
pattern: /^,/,
|
|
33
|
+
callback: (pos, type, snbtData) => {
|
|
34
|
+
snbtData.addToken(pos, type, ',');
|
|
35
|
+
return 1;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: 'BYTE_ARRAY_START',
|
|
40
|
+
pattern: /^\[\s*[bB]\s*;/,
|
|
41
|
+
callback: (pos, type, snbtData) => {
|
|
42
|
+
snbtData.addToken(pos, type, '[');
|
|
43
|
+
return 3;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'INT_ARRAY_START',
|
|
48
|
+
pattern: /^\[\s*[iI]\s*;/,
|
|
49
|
+
callback: (pos, type, snbtData) => {
|
|
50
|
+
snbtData.addToken(pos, type, '[');
|
|
51
|
+
return 3;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'LONG_ARRAY_START',
|
|
56
|
+
pattern: /^\[\s*[lL]\s*;/,
|
|
57
|
+
callback: (pos, type, snbtData) => {
|
|
58
|
+
snbtData.addToken(pos, type, '[');
|
|
59
|
+
return 3;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'COMPOUND_START',
|
|
64
|
+
pattern: /^\{/,
|
|
65
|
+
callback: (pos, type, snbtData) => {
|
|
66
|
+
snbtData.addToken(pos, type, '{');
|
|
67
|
+
return 1;
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: 'COMPOUND_END',
|
|
72
|
+
pattern: /^\}/,
|
|
73
|
+
callback: (pos, type, snbtData) => {
|
|
74
|
+
snbtData.addToken(pos, type, '}');
|
|
75
|
+
return 1;
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'LIST_START',
|
|
80
|
+
pattern: /^\[/,
|
|
81
|
+
callback: (pos, type, snbtData) => {
|
|
82
|
+
snbtData.addToken(pos, type, '[');
|
|
83
|
+
return 1;
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: 'LIST_END',
|
|
88
|
+
pattern: /^\]/,
|
|
89
|
+
callback: (pos, type, snbtData) => {
|
|
90
|
+
snbtData.addToken(pos, type, ']');
|
|
91
|
+
return 1;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
// Byte - true / false converts to 1 / 0
|
|
96
|
+
type: 'BYTE',
|
|
97
|
+
pattern: anchorPattern('([tT][rR][uU][eE]|[fF][aA][lL][sS][eE])'),
|
|
98
|
+
callback: (pos, type, snbtData, matches) => {
|
|
99
|
+
snbtData.addToken(pos, type, matches[0].toLowerCase() === 'true' ? '1' : '0');
|
|
100
|
+
return matches[0].length;
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
// Byte - number with a suffix
|
|
105
|
+
type: 'BYTE',
|
|
106
|
+
pattern: anchorPattern('[-+]?[0-9]+[bB]'),
|
|
107
|
+
callback: (pos, type, snbtData, matches) => {
|
|
108
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
109
|
+
return matches[0].length;
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
// Double - there's another without the D later
|
|
114
|
+
type: 'DOUBLE',
|
|
115
|
+
pattern: anchorPattern('[-+]?[0-9.]+[dD]'),
|
|
116
|
+
callback: (pos, type, snbtData, matches) => {
|
|
117
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
118
|
+
return matches[0].length;
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: 'FLOAT',
|
|
123
|
+
pattern: anchorPattern('[-+]?[0-9.]+[fF]'),
|
|
124
|
+
callback: (pos, type, snbtData, matches) => {
|
|
125
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
126
|
+
return matches[0].length;
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: 'LONG',
|
|
131
|
+
pattern: anchorPattern('[-+]?[0-9]+[lL]'),
|
|
132
|
+
callback: (pos, type, snbtData, matches) => {
|
|
133
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
134
|
+
return matches[0].length;
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: 'SHORT',
|
|
139
|
+
pattern: anchorPattern('[-+]?[0-9]+[sS]'),
|
|
140
|
+
callback: (pos, type, snbtData, matches) => {
|
|
141
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
142
|
+
return matches[0].length;
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
// Double - this must come after other suffixed number types but before
|
|
147
|
+
// Int's matcher
|
|
148
|
+
type: 'DOUBLE',
|
|
149
|
+
pattern: anchorPattern('[-+]?[0-9.]+'),
|
|
150
|
+
callback: (pos, type, snbtData, matches) => {
|
|
151
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
152
|
+
return matches[0].length;
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
// Int - this must come after all other number types
|
|
157
|
+
type: 'INT',
|
|
158
|
+
pattern: anchorPattern('[-+]?[0-9]+'),
|
|
159
|
+
callback: (pos, type, snbtData, matches) => {
|
|
160
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
161
|
+
return matches[0].length;
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
// String - single or double quotes
|
|
166
|
+
type: 'STRING',
|
|
167
|
+
pattern: /^([\"'])(?:\\.|.)*?\1/,
|
|
168
|
+
callback: (pos, type, snbtData, matches) => {
|
|
169
|
+
const chunk = JSON.parse(`"${matches[0].slice(1, -1)}"`);
|
|
170
|
+
snbtData.addToken(pos, type, chunk);
|
|
171
|
+
return matches[0].length;
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
// String - not quoted and all else failed
|
|
176
|
+
type: 'STRING',
|
|
177
|
+
pattern: anchorPattern('^[-0-9a-zA-Z_.+]+'),
|
|
178
|
+
callback: (pos, type, snbtData, matches) => {
|
|
179
|
+
snbtData.addToken(pos, type, matches[0]);
|
|
180
|
+
return matches[0].length;
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
// Creates a regular expression that will start at the beginning of the string
|
|
185
|
+
// and conclude with an "end of token" marker at the end.
|
|
186
|
+
function anchorPattern(pattern) {
|
|
187
|
+
return new RegExp(`^${pattern}\s*(?:$|,|}|]|:)`);
|
|
188
|
+
}
|
|
189
|
+
export function snbtParse(snbt) {
|
|
190
|
+
const snbtData = new SnbtData();
|
|
191
|
+
let pos = 0;
|
|
192
|
+
while (pos < snbt.length) {
|
|
193
|
+
const increment = testParsers(snbtData, snbt.slice(pos), tokenParsers, pos);
|
|
194
|
+
if (!increment) {
|
|
195
|
+
throw new Error(`Unexpected token at position ${pos}`);
|
|
196
|
+
}
|
|
197
|
+
pos += increment;
|
|
198
|
+
}
|
|
199
|
+
return snbtData;
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=snbt-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snbt-parse.js","sourceRoot":"","sources":["../../src/nbt/snbt-parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAiB,MAAM,aAAa,CAAC;AAEtD,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AAarC,SAAS,WAAW,CAChB,QAAkB,EAClB,GAAW,EACX,YAA2B,EAC3B,GAAW;IAEX,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,YAAY,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEjC,IAAI,KAAK,EAAE,CAAC;YACR,QAAQ,CAAC,WAAW,IAAI,gBAAgB,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAE5D,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,YAAY,GAAkB;IAChC;QACI,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YAC1C,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC7B,CAAC;KACJ;IACD;QACI,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,IAAI;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S,CAAC;IACrB,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC","sourcesContent":["import debug from 'debug';\nimport { SnbtData, SnbtTokenType } from './snbt-data';\n\nconst debugLog = debug('snbt:parse');\n\ninterface TokenParser {\n type: SnbtTokenType;\n pattern: RegExp;\n callback: (\n offset: number,\n type: SnbtTokenType,\n snbtData: SnbtData,\n match: RegExpMatchArray\n ) => number;\n}\n\nfunction testParsers(\n snbtData: SnbtData,\n str: string,\n tokenParsers: TokenParser[],\n pos: number\n) {\n for (const { type, pattern, callback } of tokenParsers) {\n const match = str.match(pattern);\n\n if (match) {\n debugLog(`Matched ${type} at position ${pos}: ${match[0]}`);\n\n return callback(pos, type, snbtData, match);\n }\n }\n\n return false;\n}\n\nconst tokenParsers: TokenParser[] = [\n {\n type: 'WHITESPACE',\n pattern: /^\\s+/,\n callback: (_pos, _type, _snbtData, matches) => {\n return matches[0].length;\n },\n },\n {\n type: 'COLON',\n pattern: /^:/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, ':');\n\n return 1;\n },\n },\n {\n type: 'COMMA',\n pattern: /^,/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, ',');\n\n return 1;\n },\n },\n {\n type: 'BYTE_ARRAY_START',\n pattern: /^\\[\\s*[bB]\\s*;/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, '[');\n\n return 3;\n },\n },\n {\n type: 'INT_ARRAY_START',\n pattern: /^\\[\\s*[iI]\\s*;/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, '[');\n\n return 3;\n },\n },\n {\n type: 'LONG_ARRAY_START',\n pattern: /^\\[\\s*[lL]\\s*;/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, '[');\n\n return 3;\n },\n },\n {\n type: 'COMPOUND_START',\n pattern: /^\\{/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, '{');\n\n return 1;\n },\n },\n {\n type: 'COMPOUND_END',\n pattern: /^\\}/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, '}');\n\n return 1;\n },\n },\n {\n type: 'LIST_START',\n pattern: /^\\[/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, '[');\n\n return 1;\n },\n },\n {\n type: 'LIST_END',\n pattern: /^\\]/,\n callback: (pos, type, snbtData) => {\n snbtData.addToken(pos, type, ']');\n\n return 1;\n },\n },\n {\n // Byte - true / false converts to 1 / 0\n type: 'BYTE',\n pattern: anchorPattern('([tT][rR][uU][eE]|[fF][aA][lL][sS][eE])'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(\n pos,\n type,\n matches[0].toLowerCase() === 'true' ? '1' : '0'\n );\n\n return matches[0].length;\n },\n },\n {\n // Byte - number with a suffix\n type: 'BYTE',\n pattern: anchorPattern('[-+]?[0-9]+[bB]'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n // Double - there's another without the D later\n type: 'DOUBLE',\n pattern: anchorPattern('[-+]?[0-9.]+[dD]'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n type: 'FLOAT',\n pattern: anchorPattern('[-+]?[0-9.]+[fF]'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n type: 'LONG',\n pattern: anchorPattern('[-+]?[0-9]+[lL]'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n type: 'SHORT',\n pattern: anchorPattern('[-+]?[0-9]+[sS]'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n // Double - this must come after other suffixed number types but before\n // Int's matcher\n type: 'DOUBLE',\n pattern: anchorPattern('[-+]?[0-9.]+'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n // Int - this must come after all other number types\n type: 'INT',\n pattern: anchorPattern('[-+]?[0-9]+'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n {\n // String - single or double quotes\n type: 'STRING',\n pattern: /^([\\\"'])(?:\\\\.|.)*?\\1/,\n callback: (pos, type, snbtData, matches) => {\n const chunk = JSON.parse(`\"${matches[0].slice(1, -1)}\"`);\n snbtData.addToken(pos, type, chunk);\n\n return matches[0].length;\n },\n },\n {\n // String - not quoted and all else failed\n type: 'STRING',\n pattern: anchorPattern('^[-0-9a-zA-Z_.+]+'),\n callback: (pos, type, snbtData, matches) => {\n snbtData.addToken(pos, type, matches[0]);\n\n return matches[0].length;\n },\n },\n];\n\n// Creates a regular expression that will start at the beginning of the string\n// and conclude with an \"end of token\" marker at the end.\nfunction anchorPattern(pattern: string) {\n return new RegExp(`^${pattern}\\s*(?:$|,|}|]|:)`);\n}\n\nexport function snbtParse(snbt: string) {\n const snbtData = new SnbtData();\n let pos = 0;\n\n while (pos < snbt.length) {\n const increment = testParsers(\n snbtData,\n snbt.slice(pos),\n tokenParsers,\n pos\n );\n\n if (!increment) {\n throw new Error(`Unexpected token at position ${pos}`);\n }\n\n pos += increment;\n }\n\n return snbtData;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NbtBase } from '../nbt/nbt-base';
|
|
2
|
+
import { SnbtData, SnbtToken } from './snbt-data';
|
|
3
|
+
export declare const fromSnbtData: {
|
|
4
|
+
[key: string]: (token: SnbtToken, snbtData: SnbtData) => NbtBase<any>;
|
|
5
|
+
};
|
|
6
|
+
export declare function snbtToNbt(snbtData: SnbtData): NbtBase<any>;
|
|
7
|
+
//# sourceMappingURL=snbt-to-nbt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snbt-to-nbt.d.ts","sourceRoot":"","sources":["../../src/nbt/snbt-to-nbt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAa1C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,YAAY,EAAE;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAczE,CAAC;AAEF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAS1D"}
|