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 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/block/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAI9B,MAAM,OAAO,KAAK;IACd,MAAM,CAAC,gBAAgB,GAAG,IAAI,GAAG,CAA4C;QACzE,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;QACxB,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;QACxB,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;QACxB,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC;QAClB,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC;QAC1B,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;QACpB,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;KACvB,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,MAAgB,EAAE,UAAwB;QAClE,KAAK,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;YAC/D,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChB,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;YAC1D,CAAC;QACL,CAAC;QAED,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAY;QACxB,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAY;QACxB,OAAO,IAAI,KAAK,kBAAkB,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAY;QACxB,OAAO,IAAI,KAAK,kBAAkB,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAY;QACrB,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,IAAY;QACzB,OAAO,IAAI,KAAK,mBAAmB,IAAI,IAAI,KAAK,oBAAoB,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAY;QACtB,OAAO,IAAI,KAAK,gBAAgB,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAY;QACtB,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC/C,CAAC","sourcesContent":["import { Banner } from './banner';\nimport { Barrel } from './barrel';\nimport { Beacon } from './beacon';\nimport { Bed } from './bed';\nimport { Beehive } from './beehive';\nimport { Bell } from './bell';\nimport { Coords3d } from '../types/coords';\nimport { Generic } from './generic';\nimport { NbtCompound } from '../nbt/nbt-compound';\nimport { Sign } from './sign';\n\nexport type BlockInstance = Banner | Barrel | Beacon | Bed | Beehive | Bell | Generic | Sign;\n\nexport class Block {\n static blockConstructor = new Map<(name: string) => boolean, typeof Generic>([\n [Block.isBanner, Banner],\n [Block.isBarrel, Barrel],\n [Block.isBeacon, Beacon],\n [Block.isBed, Bed],\n [Block.isBeehive, Beehive],\n [Block.isBell, Bell],\n [Block.isSign, Sign]\n ]);\n\n static create(name: string, coords: Coords3d, entityData?: NbtCompound): Generic {\n for (const [isBlock, blockConstructor] of Block.blockConstructor) {\n if (isBlock(name)) {\n return new blockConstructor(name, coords, entityData);\n }\n }\n\n return new Generic(name, coords, entityData);\n }\n\n static isBanner(name: string): boolean {\n return !!name.match(/^minecraft:.+_banner$/);\n }\n\n static isBarrel(name: string): boolean {\n return name === 'minecraft:barrel';\n }\n\n static isBeacon(name: string): boolean {\n return name === 'minecraft:beacon';\n }\n\n static isBed(name: string): boolean {\n return !!name.match(/^minecraft:.+_bed$/);\n }\n\n static isBeehive(name: string): boolean {\n return name === 'minecraft:beehive' || name === 'minecraft:bee_nest';\n }\n\n static isBell(name: string): boolean {\n return name === 'minecraft:bell';\n }\n\n static isSign(name: string): boolean {\n return !!name.match(/^minecraft:.+_sign$/);\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Coords3d } from '../types/coords';
|
|
2
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
3
|
+
export declare class Generic {
|
|
4
|
+
name: string;
|
|
5
|
+
coords: Coords3d;
|
|
6
|
+
entityData?: NbtCompound | undefined;
|
|
7
|
+
constructor(name: string, coords: Coords3d, entityData?: NbtCompound | undefined);
|
|
8
|
+
components(): NbtCompound | undefined;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/block/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,qBAAa,OAAO;IAEL,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,UAAU,CAAC,EAAE,WAAW;gBAFxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,EAChB,UAAU,CAAC,EAAE,WAAW,YAAA;IAGnC,UAAU,IAAI,WAAW,GAAG,SAAS;CAGxC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class Generic {
|
|
2
|
+
name;
|
|
3
|
+
coords;
|
|
4
|
+
entityData;
|
|
5
|
+
constructor(name, coords, entityData) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.coords = coords;
|
|
8
|
+
this.entityData = entityData;
|
|
9
|
+
}
|
|
10
|
+
components() {
|
|
11
|
+
return this.entityData?.findChild('components');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=generic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../src/block/generic.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,OAAO;IAEL;IACA;IACA;IAHX,YACW,IAAY,EACZ,MAAgB,EAChB,UAAwB;QAFxB,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAU;QAChB,eAAU,GAAV,UAAU,CAAc;IAChC,CAAC;IAEJ,UAAU;QACN,OAAO,IAAI,CAAC,UAAU,EAAE,SAAS,CAAc,YAAY,CAAC,CAAC;IACjE,CAAC;CACJ","sourcesContent":["import { Coords3d } from '../types/coords';\nimport { NbtCompound } from '../nbt/nbt-compound';\n\nexport class Generic {\n constructor(\n public name: string,\n public coords: Coords3d,\n public entityData?: NbtCompound\n ) {}\n\n components(): NbtCompound | undefined {\n return this.entityData?.findChild<NbtCompound>('components');\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Generic } from './generic';
|
|
2
|
+
import { Coords3d } from '../types/coords';
|
|
3
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
4
|
+
export declare class HasEntityData extends Generic {
|
|
5
|
+
entityData: NbtCompound;
|
|
6
|
+
constructor(name: string, coords: Coords3d, entityData?: NbtCompound);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=has-entity-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-entity-data.d.ts","sourceRoot":"","sources":["../../src/block/has-entity-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,qBAAa,aAAc,SAAQ,OAAO;IAC7B,UAAU,EAAE,WAAW,CAAC;gBAG7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,EAChB,UAAU,CAAC,EAAE,WAAW;CAS/B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Generic } from './generic';
|
|
2
|
+
export class HasEntityData extends Generic {
|
|
3
|
+
entityData;
|
|
4
|
+
constructor(name, coords, entityData) {
|
|
5
|
+
if (!entityData) {
|
|
6
|
+
throw new Error('Block is supposed to have entity data');
|
|
7
|
+
}
|
|
8
|
+
super(name, coords, entityData);
|
|
9
|
+
this.entityData = entityData;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=has-entity-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-entity-data.js","sourceRoot":"","sources":["../../src/block/has-entity-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,MAAM,OAAO,aAAc,SAAQ,OAAO;IAC7B,UAAU,CAAc;IAEjC,YACI,IAAY,EACZ,MAAgB,EAChB,UAAwB;QAExB,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC7D,CAAC;QAED,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;CACJ","sourcesContent":["import { Generic } from './generic';\nimport { Coords3d } from '../types/coords';\nimport { NbtCompound } from '../nbt/nbt-compound';\n\nexport class HasEntityData extends Generic {\n override entityData: NbtCompound;\n\n constructor(\n name: string,\n coords: Coords3d,\n entityData?: NbtCompound\n ) {\n if (!entityData) {\n throw new Error('Block is supposed to have entity data');\n }\n\n super(name, coords, entityData);\n this.entityData = entityData;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-name.d.ts","sourceRoot":"","sources":["../../../src/block/mixins/custom-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,qBAAa,UAAW,SAAQ,aAAa;IACzC,UAAU,IAAI,MAAM,GAAG,SAAS;CAGnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-name.js","sourceRoot":"","sources":["../../../src/block/mixins/custom-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,MAAM,OAAO,UAAW,SAAQ,aAAa;IACzC,UAAU;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAY,YAAY,CAAC,EAAE,IAAI,CAAC;IACpE,CAAC;CACJ","sourcesContent":["import { HasEntityData } from '../has-entity-data';\nimport { NbtString } from '../../nbt/nbt-string';\n\nexport class CustomName extends HasEntityData {\n customName(): string | undefined {\n return this.entityData.findChild<NbtString>('CustomName')?.data;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../../../src/block/mixins/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,qBAAa,IAAK,SAAQ,aAAa;IACnC,IAAI,IAAI,MAAM,GAAG,SAAS;CAG7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/block/mixins/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,MAAM,OAAO,IAAK,SAAQ,aAAa;IACnC,IAAI;QACA,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAY,MAAM,CAAC,EAAE,IAAI,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import { HasEntityData } from '../has-entity-data';\nimport { NbtString } from '../../nbt/nbt-string';\n\nexport class Lock extends HasEntityData {\n lock(): string | undefined {\n return this.entityData.findChild<NbtString>('Lock')?.data;\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixin function to combine multiple classes together.
|
|
3
|
+
*
|
|
4
|
+
* Described at https://catchts.com/oop-style#typed_inheritance
|
|
5
|
+
* Credits Wilco: https://stackoverflow.com/users/5291/wilco
|
|
6
|
+
* Credits @jcalz - https://stackoverflow.com/a/50375286
|
|
7
|
+
*
|
|
8
|
+
* Using the modified version where all classes extend a base class. The
|
|
9
|
+
* constructor is UNABLE to be modified by mixins.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
*
|
|
13
|
+
* export class Whatever extends Mixin(
|
|
14
|
+
* BaseClass,
|
|
15
|
+
* Mixin1,
|
|
16
|
+
* Mixin2,
|
|
17
|
+
* ...,
|
|
18
|
+
* class extends BaseClass {
|
|
19
|
+
* // class definition
|
|
20
|
+
* }
|
|
21
|
+
* ) {}
|
|
22
|
+
*/
|
|
23
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
24
|
+
type ClassType = new (...args: any[]) => any;
|
|
25
|
+
export declare function Mixin<T extends ClassType, R extends T[]>(BaseType: T, ...classRefs: [...R]): new (...args: ConstructorParameters<T>) => UnionToIntersection<InstanceType<[...R][number]>>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=mixin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../../../src/block/mixins/mixin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAC3E,CAAC,EAAE,MAAM,CAAC,KACT,IAAI,GACH,CAAC,GACD,KAAK,CAAC;AAEZ,KAAK,SAAS,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE7C,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,EACpD,QAAQ,EAAE,CAAC,EACX,GAAG,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,GACrB,KACC,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAChC,mBAAmB,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAgBrD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixin function to combine multiple classes together.
|
|
3
|
+
*
|
|
4
|
+
* Described at https://catchts.com/oop-style#typed_inheritance
|
|
5
|
+
* Credits Wilco: https://stackoverflow.com/users/5291/wilco
|
|
6
|
+
* Credits @jcalz - https://stackoverflow.com/a/50375286
|
|
7
|
+
*
|
|
8
|
+
* Using the modified version where all classes extend a base class. The
|
|
9
|
+
* constructor is UNABLE to be modified by mixins.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
*
|
|
13
|
+
* export class Whatever extends Mixin(
|
|
14
|
+
* BaseClass,
|
|
15
|
+
* Mixin1,
|
|
16
|
+
* Mixin2,
|
|
17
|
+
* ...,
|
|
18
|
+
* class extends BaseClass {
|
|
19
|
+
* // class definition
|
|
20
|
+
* }
|
|
21
|
+
* ) {}
|
|
22
|
+
*/
|
|
23
|
+
export function Mixin(BaseType, ...classRefs) {
|
|
24
|
+
const derived = class extends BaseType {
|
|
25
|
+
};
|
|
26
|
+
classRefs.forEach((classRef) => {
|
|
27
|
+
Object.getOwnPropertyNames(classRef.prototype).forEach((name) => {
|
|
28
|
+
const descriptor = Object.getOwnPropertyDescriptor(classRef.prototype, name);
|
|
29
|
+
if (name !== 'constructor' && descriptor) {
|
|
30
|
+
Object.defineProperty(derived.prototype, name, descriptor);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return derived;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=mixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin.js","sourceRoot":"","sources":["../../../src/block/mixins/mixin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH,MAAM,UAAU,KAAK,CACjB,QAAW,EACX,GAAG,SAAiB;IAIpB,MAAM,OAAO,GAAG,KAAM,SAAQ,QAAQ;KAAG,CAAC;IAC1C,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC3B,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAC9C,QAAQ,CAAC,SAAS,EAClB,IAAI,CACP,CAAC;YAEF,IAAI,IAAI,KAAK,aAAa,IAAI,UAAU,EAAE,CAAC;gBACvC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;YAC/D,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Mixin function to combine multiple classes together.\n *\n * Described at https://catchts.com/oop-style#typed_inheritance\n * Credits Wilco: https://stackoverflow.com/users/5291/wilco\n * Credits @jcalz - https://stackoverflow.com/a/50375286\n *\n * Using the modified version where all classes extend a base class. The\n * constructor is UNABLE to be modified by mixins.\n *\n * Usage:\n *\n * export class Whatever extends Mixin(\n * BaseClass,\n * Mixin1,\n * Mixin2,\n * ...,\n * class extends BaseClass {\n * // class definition\n * }\n * ) {}\n */\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I\n) => void\n ? I\n : never;\n\ntype ClassType = new (...args: any[]) => any;\n\nexport function Mixin<T extends ClassType, R extends T[]>(\n BaseType: T,\n ...classRefs: [...R]\n): new (\n ...args: ConstructorParameters<T>\n) => UnionToIntersection<InstanceType<[...R][number]>> {\n const derived = class extends BaseType {};\n classRefs.forEach((classRef) => {\n Object.getOwnPropertyNames(classRef.prototype).forEach((name) => {\n const descriptor = Object.getOwnPropertyDescriptor(\n classRef.prototype,\n name\n );\n\n if (name !== 'constructor' && descriptor) {\n Object.defineProperty(derived.prototype, name, descriptor);\n }\n });\n });\n\n return derived;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HasEntityData } from './has-entity-data';
|
|
2
|
+
type SignText = [string, string, string, string];
|
|
3
|
+
export declare class Sign extends HasEntityData {
|
|
4
|
+
backColor(): string | undefined;
|
|
5
|
+
backGlowingText(): boolean | undefined;
|
|
6
|
+
backText(): SignText | undefined;
|
|
7
|
+
frontColor(): string | undefined;
|
|
8
|
+
frontGlowingText(): boolean | undefined;
|
|
9
|
+
frontText(): SignText;
|
|
10
|
+
isWaxed(): boolean | undefined;
|
|
11
|
+
private isSignText;
|
|
12
|
+
private snbtToText;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/block/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAOlD,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD,qBAAa,IAAK,SAAQ,aAAa;IACnC,SAAS,IAAI,MAAM,GAAG,SAAS;IAK/B,eAAe,IAAI,OAAO,GAAG,SAAS;IActC,QAAQ,IAAI,QAAQ,GAAG,SAAS;IAchC,UAAU,IAAI,MAAM,GAAG,SAAS;IAShC,gBAAgB,IAAI,OAAO,GAAG,SAAS;IAcvC,SAAS,IAAI,QAAQ;IAyBrB,OAAO,IAAI,OAAO,GAAG,SAAS;IAY9B,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,UAAU;CAarB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { HasEntityData } from './has-entity-data';
|
|
2
|
+
import { Nbt } from '../nbt/nbt';
|
|
3
|
+
import { NbtTagType } from '../nbt/nbt-tag-type';
|
|
4
|
+
export class Sign extends HasEntityData {
|
|
5
|
+
backColor() {
|
|
6
|
+
// 1.20+
|
|
7
|
+
return this.entityData.findChild('back_text/color')?.data;
|
|
8
|
+
}
|
|
9
|
+
backGlowingText() {
|
|
10
|
+
// 1.20+
|
|
11
|
+
const byte = this.entityData.findChild('back_text/has_glowing_text');
|
|
12
|
+
if (byte) {
|
|
13
|
+
return byte.data !== 0;
|
|
14
|
+
}
|
|
15
|
+
// Up to 1.19
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
backText() {
|
|
19
|
+
// 1.20+
|
|
20
|
+
const backSnbt = this.entityData
|
|
21
|
+
.findChild('back_text/messages')
|
|
22
|
+
?.data.map((tag) => tag.data);
|
|
23
|
+
if (this.isSignText(backSnbt)) {
|
|
24
|
+
return this.snbtToText(backSnbt);
|
|
25
|
+
}
|
|
26
|
+
// Up to 1.19
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
frontColor() {
|
|
30
|
+
return (
|
|
31
|
+
// 1.20+
|
|
32
|
+
this.entityData.findChild('front_text/color')?.data ||
|
|
33
|
+
// Up to 1.19
|
|
34
|
+
this.entityData.findChild('Color')?.data);
|
|
35
|
+
}
|
|
36
|
+
frontGlowingText() {
|
|
37
|
+
const byte =
|
|
38
|
+
// 1.20+
|
|
39
|
+
this.entityData.findChild('front_text/has_glowing_text') ||
|
|
40
|
+
// Up to 1.19
|
|
41
|
+
this.entityData.findChild('GlowingText');
|
|
42
|
+
if (byte) {
|
|
43
|
+
return byte.data !== 0;
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
frontText() {
|
|
48
|
+
// 1.20+
|
|
49
|
+
const frontSnbt = this.entityData
|
|
50
|
+
.findChild('front_text/messages')
|
|
51
|
+
?.data.map((tag) => tag.data);
|
|
52
|
+
if (this.isSignText(frontSnbt)) {
|
|
53
|
+
return this.snbtToText(frontSnbt);
|
|
54
|
+
}
|
|
55
|
+
// Up to 1.19
|
|
56
|
+
const frontOldSnbt = [
|
|
57
|
+
this.entityData.findChild('Text1')?.data,
|
|
58
|
+
this.entityData.findChild('Text2')?.data,
|
|
59
|
+
this.entityData.findChild('Text3')?.data,
|
|
60
|
+
this.entityData.findChild('Text4')?.data,
|
|
61
|
+
].filter((tag) => !!tag);
|
|
62
|
+
if (this.isSignText(frontOldSnbt)) {
|
|
63
|
+
return this.snbtToText(frontOldSnbt);
|
|
64
|
+
}
|
|
65
|
+
throw new Error('Unknown format for sign text');
|
|
66
|
+
}
|
|
67
|
+
isWaxed() {
|
|
68
|
+
const tag = this.entityData.findChild('waxed');
|
|
69
|
+
if (!tag) {
|
|
70
|
+
// Up to 1.19
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// 1.20+
|
|
74
|
+
return tag.data !== 0;
|
|
75
|
+
}
|
|
76
|
+
isSignText(value) {
|
|
77
|
+
return value?.length === 4;
|
|
78
|
+
}
|
|
79
|
+
snbtToText(snbtList) {
|
|
80
|
+
return snbtList.map((snbt) => {
|
|
81
|
+
const tag = Nbt.fromSnbt(snbt);
|
|
82
|
+
// 1.20 and newer
|
|
83
|
+
if (tag.type === NbtTagType.STRING) {
|
|
84
|
+
return tag.data;
|
|
85
|
+
}
|
|
86
|
+
// Up to 1.19
|
|
87
|
+
return tag.findChild('text')?.data ?? '';
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=sign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/block/sign.ts"],"names":[],"mappings":"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","sourcesContent":["import { HasEntityData } from './has-entity-data';\nimport { Nbt } from '../nbt/nbt';\nimport { NbtByte } from '../nbt/nbt-byte';\nimport { NbtList } from '../nbt/nbt-list';\nimport { NbtString } from '../nbt/nbt-string';\nimport { NbtTagType } from '../nbt/nbt-tag-type';\n\ntype SignText = [string, string, string, string];\n\nexport class Sign extends HasEntityData {\n backColor(): string | undefined {\n // 1.20+\n return this.entityData.findChild<NbtString>('back_text/color')?.data;\n }\n\n backGlowingText(): boolean | undefined {\n // 1.20+\n const byte = this.entityData.findChild<NbtByte>(\n 'back_text/has_glowing_text'\n );\n\n if (byte) {\n return byte.data !== 0;\n }\n\n // Up to 1.19\n return;\n }\n\n backText(): SignText | undefined {\n // 1.20+\n const backSnbt = this.entityData\n .findChild<NbtList<NbtString>>('back_text/messages')\n ?.data.map((tag) => tag.data);\n\n if (this.isSignText(backSnbt)) {\n return this.snbtToText(backSnbt);\n }\n\n // Up to 1.19\n return;\n }\n\n frontColor(): string | undefined {\n return (\n // 1.20+\n this.entityData.findChild<NbtString>('front_text/color')?.data ||\n // Up to 1.19\n this.entityData.findChild<NbtString>('Color')?.data\n );\n }\n\n frontGlowingText(): boolean | undefined {\n const byte =\n // 1.20+\n this.entityData.findChild<NbtByte>('front_text/has_glowing_text') ||\n // Up to 1.19\n this.entityData.findChild<NbtByte>('GlowingText');\n\n if (byte) {\n return byte.data !== 0;\n }\n\n return;\n }\n\n frontText(): SignText {\n // 1.20+\n const frontSnbt = this.entityData\n .findChild<NbtList<NbtString>>('front_text/messages')\n ?.data.map((tag) => tag.data);\n\n if (this.isSignText(frontSnbt)) {\n return this.snbtToText(frontSnbt);\n }\n\n // Up to 1.19\n const frontOldSnbt = [\n this.entityData.findChild<NbtString>('Text1')?.data,\n this.entityData.findChild<NbtString>('Text2')?.data,\n this.entityData.findChild<NbtString>('Text3')?.data,\n this.entityData.findChild<NbtString>('Text4')?.data,\n ].filter((tag): tag is string => !!tag);\n\n if (this.isSignText(frontOldSnbt)) {\n return this.snbtToText(frontOldSnbt);\n }\n\n throw new Error('Unknown format for sign text');\n }\n\n isWaxed(): boolean | undefined {\n const tag = this.entityData.findChild<NbtByte>('waxed');\n\n if (!tag) {\n // Up to 1.19\n return;\n }\n\n // 1.20+\n return tag.data !== 0;\n }\n\n private isSignText(value?: string[]): value is SignText {\n return value?.length === 4;\n }\n\n private snbtToText(snbtList: SignText): SignText {\n return snbtList.map((snbt) => {\n const tag = Nbt.fromSnbt(snbt);\n\n // 1.20 and newer\n if (tag.type === NbtTagType.STRING) {\n return tag.data;\n }\n\n // Up to 1.19\n return tag.findChild<NbtString>('text')?.data ?? '';\n }) as SignText;\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from './block/banner';
|
|
2
|
+
export * from './block/barrel';
|
|
3
|
+
export * from './block/beacon';
|
|
4
|
+
export * from './block/bed';
|
|
5
|
+
export * from './block/beehive';
|
|
6
|
+
export * from './block/bell';
|
|
7
|
+
export * from './block/block';
|
|
8
|
+
export * from './block/generic';
|
|
9
|
+
export * from './block/has-entity-data';
|
|
10
|
+
export * from './block/mixins/custom-name';
|
|
11
|
+
export * from './block/mixins/lock';
|
|
12
|
+
export * from './block/mixins/mixin';
|
|
13
|
+
export * from './block/sign';
|
|
14
|
+
export * from './lib/anvil';
|
|
15
|
+
export * from './lib/binary-data';
|
|
16
|
+
export * from './lib/bit-data';
|
|
17
|
+
export * from './lib/block-data';
|
|
18
|
+
export * from './lib/chunk';
|
|
19
|
+
export * from './nbt/nbt';
|
|
20
|
+
export * from './nbt/nbt-base';
|
|
21
|
+
export * from './nbt/nbt-byte';
|
|
22
|
+
export * from './nbt/nbt-byte-array';
|
|
23
|
+
export * from './nbt/nbt-compound';
|
|
24
|
+
export * from './nbt/nbt-double';
|
|
25
|
+
export * from './nbt/nbt-end';
|
|
26
|
+
export * from './nbt/nbt-float';
|
|
27
|
+
export * from './nbt/nbt-int';
|
|
28
|
+
export * from './nbt/nbt-int-array';
|
|
29
|
+
export * from './nbt/nbt-list';
|
|
30
|
+
export * from './nbt/nbt-long';
|
|
31
|
+
export * from './nbt/nbt-long-array';
|
|
32
|
+
export * from './nbt/nbt-short';
|
|
33
|
+
export * from './nbt/nbt-string';
|
|
34
|
+
export * from './nbt/nbt-tag-type';
|
|
35
|
+
export * from './nbt/snbt-data';
|
|
36
|
+
export * from './nbt/snbt-parse';
|
|
37
|
+
export * from './nbt/snbt-to-nbt';
|
|
38
|
+
export * from './types/coords';
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from './block/banner';
|
|
2
|
+
export * from './block/barrel';
|
|
3
|
+
export * from './block/beacon';
|
|
4
|
+
export * from './block/bed';
|
|
5
|
+
export * from './block/beehive';
|
|
6
|
+
export * from './block/bell';
|
|
7
|
+
export * from './block/block';
|
|
8
|
+
export * from './block/generic';
|
|
9
|
+
export * from './block/has-entity-data';
|
|
10
|
+
export * from './block/mixins/custom-name';
|
|
11
|
+
export * from './block/mixins/lock';
|
|
12
|
+
export * from './block/mixins/mixin';
|
|
13
|
+
export * from './block/sign';
|
|
14
|
+
export * from './lib/anvil';
|
|
15
|
+
export * from './lib/binary-data';
|
|
16
|
+
export * from './lib/bit-data';
|
|
17
|
+
export * from './lib/block-data';
|
|
18
|
+
export * from './lib/chunk';
|
|
19
|
+
export * from './nbt/nbt';
|
|
20
|
+
export * from './nbt/nbt-base';
|
|
21
|
+
export * from './nbt/nbt-byte';
|
|
22
|
+
export * from './nbt/nbt-byte-array';
|
|
23
|
+
export * from './nbt/nbt-compound';
|
|
24
|
+
export * from './nbt/nbt-double';
|
|
25
|
+
export * from './nbt/nbt-end';
|
|
26
|
+
export * from './nbt/nbt-float';
|
|
27
|
+
export * from './nbt/nbt-int';
|
|
28
|
+
export * from './nbt/nbt-int-array';
|
|
29
|
+
export * from './nbt/nbt-list';
|
|
30
|
+
export * from './nbt/nbt-long';
|
|
31
|
+
export * from './nbt/nbt-long-array';
|
|
32
|
+
export * from './nbt/nbt-short';
|
|
33
|
+
export * from './nbt/nbt-string';
|
|
34
|
+
export * from './nbt/nbt-tag-type';
|
|
35
|
+
export * from './nbt/snbt-data';
|
|
36
|
+
export * from './nbt/snbt-parse';
|
|
37
|
+
export * from './nbt/snbt-to-nbt';
|
|
38
|
+
export * from './types/coords';
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC","sourcesContent":["export * from './block/banner';\nexport * from './block/barrel';\nexport * from './block/beacon';\nexport * from './block/bed';\nexport * from './block/beehive';\nexport * from './block/bell';\nexport * from './block/block';\nexport * from './block/generic';\nexport * from './block/has-entity-data';\nexport * from './block/mixins/custom-name';\nexport * from './block/mixins/lock';\nexport * from './block/mixins/mixin';\nexport * from './block/sign';\nexport * from './lib/anvil';\nexport * from './lib/binary-data';\nexport * from './lib/bit-data';\nexport * from './lib/block-data';\nexport * from './lib/chunk';\nexport * from './nbt/nbt';\nexport * from './nbt/nbt-base';\nexport * from './nbt/nbt-byte';\nexport * from './nbt/nbt-byte-array';\nexport * from './nbt/nbt-compound';\nexport * from './nbt/nbt-double';\nexport * from './nbt/nbt-end';\nexport * from './nbt/nbt-float';\nexport * from './nbt/nbt-int';\nexport * from './nbt/nbt-int-array';\nexport * from './nbt/nbt-list';\nexport * from './nbt/nbt-long';\nexport * from './nbt/nbt-long-array';\nexport * from './nbt/nbt-short';\nexport * from './nbt/nbt-string';\nexport * from './nbt/nbt-tag-type';\nexport * from './nbt/snbt-data';\nexport * from './nbt/snbt-parse';\nexport * from './nbt/snbt-to-nbt';\nexport * from './types/coords';\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BinaryData } from './binary-data';
|
|
2
|
+
import { Chunk } from './chunk';
|
|
3
|
+
import { Coords2d } from '../types/coords';
|
|
4
|
+
type LocationEntry = {
|
|
5
|
+
offset: number;
|
|
6
|
+
sectorCount: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Read and write Minecraft Anvil region files.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Anvil {
|
|
12
|
+
static fromBuffer(buffer: ArrayBufferLike): Anvil;
|
|
13
|
+
cachedLocationEntries: LocationEntry[] | null;
|
|
14
|
+
data: BinaryData;
|
|
15
|
+
constructor(data: ArrayBufferLike);
|
|
16
|
+
/**
|
|
17
|
+
* Returns the buffer that holds the Anvil data.
|
|
18
|
+
*/
|
|
19
|
+
buffer(): ArrayBufferLike;
|
|
20
|
+
/**
|
|
21
|
+
* Delete a chunk. The location is either given in X,Z chunk coordinates or
|
|
22
|
+
* passed in from a Chunk object.
|
|
23
|
+
*/
|
|
24
|
+
deleteChunk(chunkLocation: Coords2d | Chunk): void;
|
|
25
|
+
/**
|
|
26
|
+
* Parses all chunks in the Anvil blob. Chunk objects are read in the order
|
|
27
|
+
* they are stored in the location entry header sector.
|
|
28
|
+
*
|
|
29
|
+
* @returns Chunk[] a list of Chunk objects
|
|
30
|
+
*/
|
|
31
|
+
getAllChunks(): Chunk[];
|
|
32
|
+
getChunk(chunkCoords: Coords2d): Chunk | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Convert from chunk coordinates to region-relative chunk coordinates, and
|
|
35
|
+
* then to an index.
|
|
36
|
+
*/
|
|
37
|
+
private chunkCoordinatesToIndex;
|
|
38
|
+
/**
|
|
39
|
+
* Extracts data for a chunk present at the given offset in the Anvil blob.
|
|
40
|
+
* The offset is provided in sectors of SECTOR_SIZE bytes (as in the chunk
|
|
41
|
+
* location entries from the blob's first header sector).
|
|
42
|
+
*
|
|
43
|
+
* @param offset the chunk's offset in number of sectors from the Anvil blob's start.
|
|
44
|
+
*/
|
|
45
|
+
protected getChunkData(offset?: number): ArrayBufferLike;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the full list of chunk location entries from this Anvil blob.
|
|
48
|
+
* The pointer will be moved to the beginning of the first header sector at
|
|
49
|
+
* the start of this method and advanced to the end during reading.
|
|
50
|
+
*/
|
|
51
|
+
protected getLocationEntries(): LocationEntry[];
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=anvil.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anvil.d.ts","sourceRoot":"","sources":["../../src/lib/anvil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C,KAAK,aAAa,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC;AAWF;;GAEG;AACH,qBAAa,KAAK;IACd,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,KAAK;IAIjD,qBAAqB,EAAE,aAAa,EAAE,GAAG,IAAI,CAAQ;IACrD,IAAI,EAAE,UAAU,CAAC;gBAEL,IAAI,EAAE,eAAe;IAIjC;;OAEG;IACH,MAAM,IAAI,eAAe;IAIzB;;;OAGG;IACH,WAAW,CAAC,aAAa,EAAE,QAAQ,GAAG,KAAK,GAAG,IAAI;IAsBlD;;;;;OAKG;IACH,YAAY,IAAI,KAAK,EAAE;IAkBvB,QAAQ,CAAC,WAAW,EAAE,QAAQ,GAAG,KAAK,GAAG,SAAS;IAalD;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAgB/B;;;;;;OAMG;IACH,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe;IAqBxD;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,IAAI,aAAa,EAAE;CAmBlD"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { BinaryData } from './binary-data';
|
|
2
|
+
import { Chunk } from './chunk';
|
|
3
|
+
import { inflate } from 'pako';
|
|
4
|
+
import { Nbt } from '../nbt/nbt';
|
|
5
|
+
var CompressionType;
|
|
6
|
+
(function (CompressionType) {
|
|
7
|
+
CompressionType[CompressionType["GZIP"] = 1] = "GZIP";
|
|
8
|
+
CompressionType[CompressionType["ZLIB"] = 2] = "ZLIB";
|
|
9
|
+
CompressionType[CompressionType["NONE"] = 3] = "NONE";
|
|
10
|
+
})(CompressionType || (CompressionType = {}));
|
|
11
|
+
const LOCATION_ENTRIES_PER_FILE = 1024;
|
|
12
|
+
const SECTOR_SIZE = 4096;
|
|
13
|
+
/**
|
|
14
|
+
* Read and write Minecraft Anvil region files.
|
|
15
|
+
*/
|
|
16
|
+
export class Anvil {
|
|
17
|
+
static fromBuffer(buffer) {
|
|
18
|
+
return new Anvil(buffer);
|
|
19
|
+
}
|
|
20
|
+
cachedLocationEntries = null;
|
|
21
|
+
data;
|
|
22
|
+
constructor(data) {
|
|
23
|
+
this.data = new BinaryData(data);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the buffer that holds the Anvil data.
|
|
27
|
+
*/
|
|
28
|
+
buffer() {
|
|
29
|
+
return this.data.buffer();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Delete a chunk. The location is either given in X,Z chunk coordinates or
|
|
33
|
+
* passed in from a Chunk object.
|
|
34
|
+
*/
|
|
35
|
+
deleteChunk(chunkLocation) {
|
|
36
|
+
let index;
|
|
37
|
+
if (Array.isArray(chunkLocation)) {
|
|
38
|
+
index = this.chunkCoordinatesToIndex(chunkLocation);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const coords = chunkLocation.chunkCoordinates();
|
|
42
|
+
if (!coords) {
|
|
43
|
+
throw new Error('Chunk does not have coordinates');
|
|
44
|
+
}
|
|
45
|
+
index = this.chunkCoordinatesToIndex(coords);
|
|
46
|
+
}
|
|
47
|
+
// Clear cache before modifying location entries
|
|
48
|
+
this.cachedLocationEntries = null;
|
|
49
|
+
this.data.seek(index * 4);
|
|
50
|
+
this.data.setNByteInteger(0, 3);
|
|
51
|
+
this.data.setByte(0);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parses all chunks in the Anvil blob. Chunk objects are read in the order
|
|
55
|
+
* they are stored in the location entry header sector.
|
|
56
|
+
*
|
|
57
|
+
* @returns Chunk[] a list of Chunk objects
|
|
58
|
+
*/
|
|
59
|
+
getAllChunks() {
|
|
60
|
+
// Empty files can be written
|
|
61
|
+
if (this.data.byteLength() === 0) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const chunks = this.getLocationEntries()
|
|
65
|
+
.filter((x) => x.sectorCount > 0)
|
|
66
|
+
.map((offset) => {
|
|
67
|
+
const nbt = Nbt.fromBuffer(this.getChunkData(offset.offset));
|
|
68
|
+
return new Chunk(nbt);
|
|
69
|
+
});
|
|
70
|
+
return chunks;
|
|
71
|
+
}
|
|
72
|
+
// Gets a chunk using chunk coordinates.
|
|
73
|
+
getChunk(chunkCoords) {
|
|
74
|
+
const locationEntries = this.getLocationEntries();
|
|
75
|
+
const entry = locationEntries[this.chunkCoordinatesToIndex(chunkCoords)];
|
|
76
|
+
if (entry?.sectorCount > 0) {
|
|
77
|
+
const nbt = Nbt.fromBuffer(this.getChunkData(entry.offset));
|
|
78
|
+
return new Chunk(nbt);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Convert from chunk coordinates to region-relative chunk coordinates, and
|
|
84
|
+
* then to an index.
|
|
85
|
+
*/
|
|
86
|
+
chunkCoordinatesToIndex(chunkCoords) {
|
|
87
|
+
let regionChunkX = chunkCoords[0];
|
|
88
|
+
let regionChunkZ = chunkCoords[1];
|
|
89
|
+
const step = 4096 * 4096;
|
|
90
|
+
while (regionChunkX < 0) {
|
|
91
|
+
regionChunkX += step;
|
|
92
|
+
}
|
|
93
|
+
while (regionChunkZ < 0) {
|
|
94
|
+
regionChunkZ += step;
|
|
95
|
+
}
|
|
96
|
+
return (regionChunkX % 32) + (regionChunkZ % 32) * 32;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Extracts data for a chunk present at the given offset in the Anvil blob.
|
|
100
|
+
* The offset is provided in sectors of SECTOR_SIZE bytes (as in the chunk
|
|
101
|
+
* location entries from the blob's first header sector).
|
|
102
|
+
*
|
|
103
|
+
* @param offset the chunk's offset in number of sectors from the Anvil blob's start.
|
|
104
|
+
*/
|
|
105
|
+
getChunkData(offset) {
|
|
106
|
+
if (offset !== undefined) {
|
|
107
|
+
this.data.seek(offset * SECTOR_SIZE);
|
|
108
|
+
}
|
|
109
|
+
const length = this.data.getUInt();
|
|
110
|
+
const compressionType = this.data.getByte();
|
|
111
|
+
const data = this.data.getArrayBuffer(length - 1); // First byte is the compression type
|
|
112
|
+
if (compressionType === CompressionType.ZLIB ||
|
|
113
|
+
compressionType === CompressionType.GZIP) {
|
|
114
|
+
// Could be SharedArrayBuffer, but it won't get used again after
|
|
115
|
+
// inflation, so it being "shared" does not matter.
|
|
116
|
+
return inflate(data).buffer;
|
|
117
|
+
}
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Retrieves the full list of chunk location entries from this Anvil blob.
|
|
122
|
+
* The pointer will be moved to the beginning of the first header sector at
|
|
123
|
+
* the start of this method and advanced to the end during reading.
|
|
124
|
+
*/
|
|
125
|
+
getLocationEntries() {
|
|
126
|
+
if (this.cachedLocationEntries) {
|
|
127
|
+
return this.cachedLocationEntries;
|
|
128
|
+
}
|
|
129
|
+
this.data.seek(0);
|
|
130
|
+
const result = [];
|
|
131
|
+
for (let i = 0; i < LOCATION_ENTRIES_PER_FILE; i += 1) {
|
|
132
|
+
result.push({
|
|
133
|
+
offset: this.data.getNByteInteger(3),
|
|
134
|
+
sectorCount: this.data.getByte(),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
this.cachedLocationEntries = result;
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=anvil.js.map
|