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,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Chunk is a 16 x 383 x 16 portion of a Minecraft world. It's stored as NBT
|
|
3
|
+
* data in sections of 16 blocks in the Y axis. The Y axis range is from -64 to
|
|
4
|
+
* 320.
|
|
5
|
+
*
|
|
6
|
+
* This class helps manipulate the chunk data.
|
|
7
|
+
*/
|
|
8
|
+
import { BlockInstance } from '../block/block';
|
|
9
|
+
import { Coords2d, Coords3d } from '../types/coords';
|
|
10
|
+
import { NbtBase } from '../nbt/nbt-base';
|
|
11
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
12
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
13
|
+
export declare class Chunk {
|
|
14
|
+
private dataVersion;
|
|
15
|
+
private parsedSections;
|
|
16
|
+
private rootNbt;
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a new chunk object from a given NBT tag.
|
|
19
|
+
*
|
|
20
|
+
* @param root the NBT tag containing the chunk's data
|
|
21
|
+
*/
|
|
22
|
+
constructor(root: NbtBase<any>);
|
|
23
|
+
/**
|
|
24
|
+
* Gets the block entity list tag.
|
|
25
|
+
*/
|
|
26
|
+
blockEntities(): NbtList<NbtCompound> | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Gets a block's entity data
|
|
29
|
+
*/
|
|
30
|
+
blockEntityData(coords: Coords3d): NbtCompound | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the chunk's location in chunk coordinates.
|
|
33
|
+
*
|
|
34
|
+
* Returns a tuple of the chunk's X and Z coordinates.
|
|
35
|
+
*/
|
|
36
|
+
chunkCoordinates(): Coords2d | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Returns a unique id for this chunk. It's just the chunk's X and Z
|
|
39
|
+
* coordinates in number of chunks from the world's origin.
|
|
40
|
+
*/
|
|
41
|
+
chunkKey(): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Returns an instance of a block at a given location using world
|
|
44
|
+
* coordinates.
|
|
45
|
+
*/
|
|
46
|
+
getBlock(coords: Coords3d): BlockInstance;
|
|
47
|
+
/**
|
|
48
|
+
* Finds all blocks by a given name. Provides [X, Y, Z] real-world coordinates.
|
|
49
|
+
*/
|
|
50
|
+
findBlocksByName(name: string): Coords3d[];
|
|
51
|
+
/**
|
|
52
|
+
* See how long the chunk has been inhabited. This number increases by 1
|
|
53
|
+
* for each game tick, which is 20 times per second when a player is
|
|
54
|
+
* nearby. It can also advance slowly when players are farther away.
|
|
55
|
+
*
|
|
56
|
+
* On newly created chunks, this value does not match what is expected. Use
|
|
57
|
+
* this with caution.
|
|
58
|
+
*/
|
|
59
|
+
inhabitedTime(): bigint | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Converts the chunk data to a JSON object.
|
|
62
|
+
*/
|
|
63
|
+
toObject(): any;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a list of unique block names in the chunk as a Set.
|
|
66
|
+
*/
|
|
67
|
+
uniqueBlockNames(): Set<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the chunk's location in real-world coordinates.
|
|
70
|
+
*
|
|
71
|
+
* Returns a tuple of the starting block's world X and Z coordinates. The
|
|
72
|
+
* chunk contains the range from X to X+15 (going East), Y to Y+15 (going
|
|
73
|
+
* up), and Z to Z+15 (going South).
|
|
74
|
+
*/
|
|
75
|
+
worldCoordinates(): Coords2d | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the given NBT tag is a valid chunk root tag.
|
|
78
|
+
* @param tag the tag to check.
|
|
79
|
+
*/
|
|
80
|
+
private isValidChunkRoot;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the given NBT tag is a valid chunk section tag, containing a list of chunk sections.
|
|
83
|
+
*/
|
|
84
|
+
private isValidChunkSection;
|
|
85
|
+
/**
|
|
86
|
+
* Returns a list of names within a palette tag.
|
|
87
|
+
*/
|
|
88
|
+
private paletteNameList;
|
|
89
|
+
/**
|
|
90
|
+
* Parses a section tag into BlockData.
|
|
91
|
+
*
|
|
92
|
+
* Uses a cached version if available;
|
|
93
|
+
*/
|
|
94
|
+
private parseSection;
|
|
95
|
+
/**
|
|
96
|
+
* Finds the BlockStates tag in a section.
|
|
97
|
+
*/
|
|
98
|
+
private sectionBlockStates;
|
|
99
|
+
/**
|
|
100
|
+
* Finds the block palette in a section.
|
|
101
|
+
*/
|
|
102
|
+
private sectionPalette;
|
|
103
|
+
/**
|
|
104
|
+
* Returns all sections
|
|
105
|
+
*/
|
|
106
|
+
private sectionsTag;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the Y coordinate of a section, which goes from 0 to 256. If you want the world coordinate, pass true to get -128 to 4031.
|
|
109
|
+
*/
|
|
110
|
+
private sectionY;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/lib/chunk.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAS,aAAa,EAAE,MAAM,gBAAgB,CA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;;OAEG;IACH,OAAO,CAAC,WAAW;IAcnB;;OAEG;IACH,OAAO,CAAC,QAAQ;CAenB"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Chunk is a 16 x 383 x 16 portion of a Minecraft world. It's stored as NBT
|
|
3
|
+
* data in sections of 16 blocks in the Y axis. The Y axis range is from -64 to
|
|
4
|
+
* 320.
|
|
5
|
+
*
|
|
6
|
+
* This class helps manipulate the chunk data.
|
|
7
|
+
*/
|
|
8
|
+
import { Block } from '../block/block';
|
|
9
|
+
import { BlockData } from './block-data';
|
|
10
|
+
import { NbtTagType } from '../nbt/nbt-tag-type';
|
|
11
|
+
export class Chunk {
|
|
12
|
+
dataVersion;
|
|
13
|
+
parsedSections = new Map();
|
|
14
|
+
rootNbt;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new chunk object from a given NBT tag.
|
|
17
|
+
*
|
|
18
|
+
* @param root the NBT tag containing the chunk's data
|
|
19
|
+
*/
|
|
20
|
+
constructor(root) {
|
|
21
|
+
if (!this.isValidChunkRoot(root)) {
|
|
22
|
+
throw new Error('Invalid chunk root tag');
|
|
23
|
+
}
|
|
24
|
+
this.rootNbt = root;
|
|
25
|
+
// 1.2.1 does not have this tag.
|
|
26
|
+
this.dataVersion = root.findChild('DataVersion')?.data ?? 0;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Gets the block entity list tag.
|
|
30
|
+
*/
|
|
31
|
+
blockEntities() {
|
|
32
|
+
return (
|
|
33
|
+
// 1.18+
|
|
34
|
+
this.rootNbt.findChild('block_entities') ||
|
|
35
|
+
// up to 1.17
|
|
36
|
+
this.rootNbt.findChild('Level/TileEntities'));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets a block's entity data
|
|
40
|
+
*/
|
|
41
|
+
blockEntityData(coords) {
|
|
42
|
+
return this.blockEntities()?.data.find((tag) => {
|
|
43
|
+
const x = tag.findChild('x');
|
|
44
|
+
const y = tag.findChild('y');
|
|
45
|
+
const z = tag.findChild('z');
|
|
46
|
+
return (x?.data === coords[0] &&
|
|
47
|
+
y?.data === coords[1] &&
|
|
48
|
+
z?.data === coords[2]);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the chunk's location in chunk coordinates.
|
|
53
|
+
*
|
|
54
|
+
* Returns a tuple of the chunk's X and Z coordinates.
|
|
55
|
+
*/
|
|
56
|
+
chunkCoordinates() {
|
|
57
|
+
const x =
|
|
58
|
+
// 1.18+
|
|
59
|
+
this.rootNbt.findChild('xPos') ||
|
|
60
|
+
// up to 1.17
|
|
61
|
+
this.rootNbt.findChild('Level/xPos');
|
|
62
|
+
const z =
|
|
63
|
+
// 1.18+
|
|
64
|
+
this.rootNbt.findChild('zPos') ||
|
|
65
|
+
// up to 1.17
|
|
66
|
+
this.rootNbt.findChild('Level/zPos');
|
|
67
|
+
if (typeof x?.data !== 'number' || typeof z?.data !== 'number') {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
return [x.data, z.data];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns a unique id for this chunk. It's just the chunk's X and Z
|
|
74
|
+
* coordinates in number of chunks from the world's origin.
|
|
75
|
+
*/
|
|
76
|
+
chunkKey() {
|
|
77
|
+
const coords = this.chunkCoordinates();
|
|
78
|
+
if (!coords) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return `${coords[0]},${coords[1]}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns an instance of a block at a given location using world
|
|
85
|
+
* coordinates.
|
|
86
|
+
*/
|
|
87
|
+
getBlock(coords) {
|
|
88
|
+
const sectionY = Math.floor(coords[1] / 16);
|
|
89
|
+
const sectionsTag = this.sectionsTag();
|
|
90
|
+
if (!sectionsTag) {
|
|
91
|
+
throw new Error('Invalid chunk - no sections found');
|
|
92
|
+
}
|
|
93
|
+
const section = sectionsTag.data.find((section) => this.sectionY(section) === sectionY);
|
|
94
|
+
if (!section) {
|
|
95
|
+
throw new Error('Block not found in any sections');
|
|
96
|
+
}
|
|
97
|
+
const blockData = this.parseSection(section);
|
|
98
|
+
const [xWorld, zWorld] = this.worldCoordinates() || [0, 0];
|
|
99
|
+
const xChunk = coords[0] - xWorld;
|
|
100
|
+
const zChunk = coords[2] - zWorld;
|
|
101
|
+
if (xChunk < 0 || xChunk > 15) {
|
|
102
|
+
throw new Error('X coordinate out of bounds');
|
|
103
|
+
}
|
|
104
|
+
if (zChunk < 0 || zChunk > 15) {
|
|
105
|
+
throw new Error('Z coordinate out of bounds');
|
|
106
|
+
}
|
|
107
|
+
const index = blockData.chunkCoordinatesToIndex([
|
|
108
|
+
xChunk,
|
|
109
|
+
coords[1] % 16,
|
|
110
|
+
zChunk,
|
|
111
|
+
]);
|
|
112
|
+
const name = blockData.getBlockByIndex(index);
|
|
113
|
+
return Block.create(name, coords, this.blockEntityData(coords));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Finds all blocks by a given name. Provides [X, Y, Z] real-world coordinates.
|
|
117
|
+
*/
|
|
118
|
+
findBlocksByName(name) {
|
|
119
|
+
const sectionsTag = this.sectionsTag();
|
|
120
|
+
if (!sectionsTag) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
return sectionsTag.data.flatMap((section) => {
|
|
124
|
+
const yWorld = this.sectionY(section, true);
|
|
125
|
+
const [xWorld, zWorld] = this.worldCoordinates() || [0, 0];
|
|
126
|
+
const palette = this.sectionPalette(section);
|
|
127
|
+
if (palette === undefined) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
// // If it's not in the palette, we can skip processing.
|
|
131
|
+
if (!this.paletteNameList(palette).includes(name)) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const blockData = this.parseSection(section);
|
|
135
|
+
return blockData.findBlocksByName(name).map((index) => {
|
|
136
|
+
const chunkCoordinates = blockData.indexToChunkCoordinates(index);
|
|
137
|
+
return [
|
|
138
|
+
xWorld + chunkCoordinates[0],
|
|
139
|
+
yWorld + chunkCoordinates[1],
|
|
140
|
+
zWorld + chunkCoordinates[2],
|
|
141
|
+
];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* See how long the chunk has been inhabited. This number increases by 1
|
|
147
|
+
* for each game tick, which is 20 times per second when a player is
|
|
148
|
+
* nearby. It can also advance slowly when players are farther away.
|
|
149
|
+
*
|
|
150
|
+
* On newly created chunks, this value does not match what is expected. Use
|
|
151
|
+
* this with caution.
|
|
152
|
+
*/
|
|
153
|
+
inhabitedTime() {
|
|
154
|
+
return (
|
|
155
|
+
// 1.18+
|
|
156
|
+
this.rootNbt.findChild('InhabitedTime')?.data ||
|
|
157
|
+
// up to 1.17
|
|
158
|
+
this.rootNbt.findChild('Level/InhabitedTime')?.data);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Converts the chunk data to a JSON object.
|
|
162
|
+
*/
|
|
163
|
+
toObject() {
|
|
164
|
+
return this.rootNbt.toObject();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Returns a list of unique block names in the chunk as a Set.
|
|
168
|
+
*/
|
|
169
|
+
uniqueBlockNames() {
|
|
170
|
+
const sectionsTag = this.sectionsTag();
|
|
171
|
+
if (!sectionsTag) {
|
|
172
|
+
return new Set();
|
|
173
|
+
}
|
|
174
|
+
const names = sectionsTag.data.flatMap((section) => {
|
|
175
|
+
const palette = this.sectionPalette(section);
|
|
176
|
+
if (!palette) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
return this.paletteNameList(palette);
|
|
180
|
+
});
|
|
181
|
+
return new Set(names);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Gets the chunk's location in real-world coordinates.
|
|
185
|
+
*
|
|
186
|
+
* Returns a tuple of the starting block's world X and Z coordinates. The
|
|
187
|
+
* chunk contains the range from X to X+15 (going East), Y to Y+15 (going
|
|
188
|
+
* up), and Z to Z+15 (going South).
|
|
189
|
+
*/
|
|
190
|
+
worldCoordinates() {
|
|
191
|
+
const result = this.chunkCoordinates();
|
|
192
|
+
if (!result) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
return [result[0] * 16, result[1] * 16];
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Checks if the given NBT tag is a valid chunk root tag.
|
|
199
|
+
* @param tag the tag to check.
|
|
200
|
+
*/
|
|
201
|
+
isValidChunkRoot(nbt) {
|
|
202
|
+
return nbt.isCompound('');
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Checks if the given NBT tag is a valid chunk section tag, containing a list of chunk sections.
|
|
206
|
+
*/
|
|
207
|
+
isValidChunkSection(nbt) {
|
|
208
|
+
if (!nbt.isList(NbtTagType.COMPOUND)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
// Java uses "sections", unsure what uses "Sections"
|
|
212
|
+
if (nbt.name.toLowerCase() === 'sections') {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Returns a list of names within a palette tag.
|
|
219
|
+
*/
|
|
220
|
+
paletteNameList(palette) {
|
|
221
|
+
if (!palette.isList(NbtTagType.COMPOUND)) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
return palette.data.map((tag) => {
|
|
225
|
+
const name = tag.findChild('Name');
|
|
226
|
+
return name?.data ?? '';
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Parses a section tag into BlockData.
|
|
231
|
+
*
|
|
232
|
+
* Uses a cached version if available;
|
|
233
|
+
*/
|
|
234
|
+
parseSection(section) {
|
|
235
|
+
if (this.parsedSections.has(section)) {
|
|
236
|
+
return this.parsedSections.get(section);
|
|
237
|
+
}
|
|
238
|
+
const palette = this.sectionPalette(section);
|
|
239
|
+
if (!palette) {
|
|
240
|
+
throw new Error('Invalid chunk section - no palette found');
|
|
241
|
+
}
|
|
242
|
+
const blockStates = this.sectionBlockStates(section);
|
|
243
|
+
if (!blockStates) {
|
|
244
|
+
throw new Error('Invalid chunk section - no block states found');
|
|
245
|
+
}
|
|
246
|
+
const blockData = BlockData.fromPaletteBlockStates(this.dataVersion, palette, blockStates);
|
|
247
|
+
this.parsedSections.set(section, blockData);
|
|
248
|
+
return blockData;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Finds the BlockStates tag in a section.
|
|
252
|
+
*/
|
|
253
|
+
sectionBlockStates(section) {
|
|
254
|
+
return (
|
|
255
|
+
// 1.18+
|
|
256
|
+
section.findChild('block_states/data') ||
|
|
257
|
+
// up to 1.17
|
|
258
|
+
section.findChild('BlockStates'));
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Finds the block palette in a section.
|
|
262
|
+
*/
|
|
263
|
+
sectionPalette(section) {
|
|
264
|
+
return (
|
|
265
|
+
// 1.18+
|
|
266
|
+
section.findChild('block_states/palette') ||
|
|
267
|
+
// up to 1.17
|
|
268
|
+
section.findChild('Palette'));
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Returns all sections
|
|
272
|
+
*/
|
|
273
|
+
sectionsTag() {
|
|
274
|
+
const section =
|
|
275
|
+
// 1.18+
|
|
276
|
+
this.rootNbt.findChild('sections') ||
|
|
277
|
+
// up to 1.17
|
|
278
|
+
this.rootNbt.findChild('Level/Sections');
|
|
279
|
+
if (section && this.isValidChunkSection(section)) {
|
|
280
|
+
return section;
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Returns the Y coordinate of a section, which goes from 0 to 256. If you want the world coordinate, pass true to get -128 to 4031.
|
|
286
|
+
*/
|
|
287
|
+
sectionY(section, useWorldCoordinate = false) {
|
|
288
|
+
const ySection = section.findChild('Y')?.data || 0;
|
|
289
|
+
if (!useWorldCoordinate) {
|
|
290
|
+
return ySection;
|
|
291
|
+
}
|
|
292
|
+
let yWorld = ySection * 16;
|
|
293
|
+
if (yWorld >= 4032) {
|
|
294
|
+
yWorld -= 4096;
|
|
295
|
+
}
|
|
296
|
+
return yWorld;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=chunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/lib/chunk.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAiB,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,OAAO,KAAK;IACN,WAAW,CAAS;IACpB,cAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;IACnD,OAAO,CAAc;IAE7B;;;;OAIG;IACH,YAAY,IAAkB;QAC1B,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,gCAAgC;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAS,aAAa,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC;IACxE,CAAC;IAED;;OAEG;IACH,aAAa;QACT,OAAO;QACH,QAAQ;QACR,IAAI,CAAC,OAAO,CAAC,SAAS,CAAuB,gBAAgB,CAAC;YAC9D,aAAa;YACb,IAAI,CAAC,OAAO,CAAC,SAAS,CAAuB,oBAAoB,CAAC,CACrE,CAAC;IACN,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,MAAgB;QAC5B,OAAO,IAAI,CAAC,aAAa,EAAE,EAA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CAAC;QACpB,CAAC;QAED,IAAI,MAAM,GAAG,QAAQ,GAAG,EAAE,CAAC;QAE3B,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,IAAI,CAAC;QACnB,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ","sourcesContent":["/**\n * A Chunk is a 16 x 383 x 16 portion of a Minecraft world. It's stored as NBT\n * data in sections of 16 blocks in the Y axis. The Y axis range is from -64 to\n * 320.\n *\n * This class helps manipulate the chunk data.\n */\n\nimport { Block, BlockInstance } from '../block/block';\nimport { BlockData } from './block-data';\nimport { Coords2d, Coords3d } from '../types/coords';\nimport { NbtBase } from '../nbt/nbt-base';\nimport { NbtCompound } from '../nbt/nbt-compound';\nimport { NbtInt } from '../nbt/nbt-int';\nimport { NbtList } from '../nbt/nbt-list';\nimport { NbtLong } from '../nbt/nbt-long';\nimport { NbtLongArray } from '../nbt/nbt-long-array';\nimport { NbtString } from '../nbt/nbt-string';\nimport { NbtTagType } from '../nbt/nbt-tag-type';\n\nexport class Chunk {\n private dataVersion: number;\n private parsedSections = new Map<NbtCompound, BlockData>();\n private rootNbt: NbtCompound;\n\n /**\n * Constructs a new chunk object from a given NBT tag.\n *\n * @param root the NBT tag containing the chunk's data\n */\n constructor(root: NbtBase<any>) {\n if (!this.isValidChunkRoot(root)) {\n throw new Error('Invalid chunk root tag');\n }\n\n this.rootNbt = root;\n\n // 1.2.1 does not have this tag.\n this.dataVersion = root.findChild<NbtInt>('DataVersion')?.data ?? 0;\n }\n\n /**\n * Gets the block entity list tag.\n */\n blockEntities(): NbtList<NbtCompound> | undefined {\n return (\n // 1.18+\n this.rootNbt.findChild<NbtList<NbtCompound>>('block_entities') ||\n // up to 1.17\n this.rootNbt.findChild<NbtList<NbtCompound>>('Level/TileEntities')\n );\n }\n\n /**\n * Gets a block's entity data\n */\n blockEntityData(coords: Coords3d): NbtCompound | undefined {\n return this.blockEntities()?.data.find((tag: NbtCompound) => {\n const x = tag.findChild<NbtInt>('x');\n const y = tag.findChild<NbtInt>('y');\n const z = tag.findChild<NbtInt>('z');\n\n return (\n x?.data === coords[0] &&\n y?.data === coords[1] &&\n z?.data === coords[2]\n );\n });\n }\n\n /**\n * Gets the chunk's location in chunk coordinates.\n *\n * Returns a tuple of the chunk's X and Z coordinates.\n */\n chunkCoordinates(): Coords2d | undefined {\n const x =\n // 1.18+\n this.rootNbt.findChild<NbtInt>('xPos') ||\n // up to 1.17\n this.rootNbt.findChild<NbtInt>('Level/xPos');\n const z =\n // 1.18+\n this.rootNbt.findChild<NbtInt>('zPos') ||\n // up to 1.17\n this.rootNbt.findChild<NbtInt>('Level/zPos');\n\n if (typeof x?.data !== 'number' || typeof z?.data !== 'number') {\n return;\n }\n\n return [x.data, z.data];\n }\n\n /**\n * Returns a unique id for this chunk. It's just the chunk's X and Z\n * coordinates in number of chunks from the world's origin.\n */\n chunkKey(): string | undefined {\n const coords = this.chunkCoordinates();\n\n if (!coords) {\n return;\n }\n\n return `${coords[0]},${coords[1]}`;\n }\n\n /**\n * Returns an instance of a block at a given location using world\n * coordinates.\n */\n getBlock(coords: Coords3d): BlockInstance {\n const sectionY = Math.floor(coords[1] / 16);\n const sectionsTag = this.sectionsTag();\n\n if (!sectionsTag) {\n throw new Error('Invalid chunk - no sections found');\n }\n\n const section = sectionsTag.data.find(\n (section) => this.sectionY(section) === sectionY\n );\n\n if (!section) {\n throw new Error('Block not found in any sections');\n }\n\n const blockData = this.parseSection(section);\n const [xWorld, zWorld] = this.worldCoordinates() || [0, 0];\n const xChunk = coords[0] - xWorld;\n const zChunk = coords[2] - zWorld;\n\n if (xChunk < 0 || xChunk > 15) {\n throw new Error('X coordinate out of bounds');\n }\n\n if (zChunk < 0 || zChunk > 15) {\n throw new Error('Z coordinate out of bounds');\n }\n\n const index = blockData.chunkCoordinatesToIndex([\n xChunk,\n coords[1] % 16,\n zChunk,\n ]);\n const name = blockData.getBlockByIndex(index);\n\n return Block.create(name, coords, this.blockEntityData(coords));\n }\n\n /**\n * Finds all blocks by a given name. Provides [X, Y, Z] real-world coordinates.\n */\n findBlocksByName(name: string): Coords3d[] {\n const sectionsTag = this.sectionsTag();\n\n if (!sectionsTag) {\n return [];\n }\n\n return sectionsTag.data.flatMap((section) => {\n const yWorld = this.sectionY(section, true);\n const [xWorld, zWorld] = this.worldCoordinates() || [0, 0];\n const palette = this.sectionPalette(section);\n\n if (palette === undefined) {\n return [];\n }\n\n // // If it's not in the palette, we can skip processing.\n if (!this.paletteNameList(palette).includes(name)) {\n return [];\n }\n\n const blockData = this.parseSection(section);\n\n return blockData.findBlocksByName(name).map((index): Coords3d => {\n const chunkCoordinates =\n blockData.indexToChunkCoordinates(index);\n\n return [\n xWorld + chunkCoordinates[0],\n yWorld + chunkCoordinates[1],\n zWorld + chunkCoordinates[2],\n ];\n });\n });\n }\n\n /**\n * See how long the chunk has been inhabited. This number increases by 1\n * for each game tick, which is 20 times per second when a player is\n * nearby. It can also advance slowly when players are farther away.\n *\n * On newly created chunks, this value does not match what is expected. Use\n * this with caution.\n */\n inhabitedTime(): bigint | undefined {\n return (\n // 1.18+\n this.rootNbt.findChild<NbtLong>('InhabitedTime')?.data ||\n // up to 1.17\n this.rootNbt.findChild<NbtLong>('Level/InhabitedTime')?.data\n );\n }\n\n /**\n * Converts the chunk data to a JSON object.\n */\n toObject(): any {\n return this.rootNbt.toObject();\n }\n\n /**\n * Returns a list of unique block names in the chunk as a Set.\n */\n uniqueBlockNames(): Set<string> {\n const sectionsTag = this.sectionsTag();\n\n if (!sectionsTag) {\n return new Set();\n }\n\n const names = sectionsTag.data.flatMap((section) => {\n const palette = this.sectionPalette(section);\n\n if (!palette) {\n return [];\n }\n\n return this.paletteNameList(palette);\n });\n\n return new Set(names);\n }\n\n /**\n * Gets the chunk's location in real-world coordinates.\n *\n * Returns a tuple of the starting block's world X and Z coordinates. The\n * chunk contains the range from X to X+15 (going East), Y to Y+15 (going\n * up), and Z to Z+15 (going South).\n */\n worldCoordinates(): Coords2d | undefined {\n const result = this.chunkCoordinates();\n\n if (!result) {\n return;\n }\n\n return [result[0] * 16, result[1] * 16];\n }\n\n /**\n * Checks if the given NBT tag is a valid chunk root tag.\n * @param tag the tag to check.\n */\n private isValidChunkRoot(nbt: NbtBase<any>): nbt is NbtCompound {\n return nbt.isCompound('');\n }\n\n /**\n * Checks if the given NBT tag is a valid chunk section tag, containing a list of chunk sections.\n */\n private isValidChunkSection(\n nbt: NbtBase<any>\n ): nbt is NbtList<NbtCompound> {\n if (!nbt.isList(NbtTagType.COMPOUND)) {\n return false;\n }\n\n // Java uses \"sections\", unsure what uses \"Sections\"\n if (nbt.name.toLowerCase() === 'sections') {\n return true;\n }\n\n return false;\n }\n\n /**\n * Returns a list of names within a palette tag.\n */\n private paletteNameList(palette: NbtBase<any>): string[] {\n if (!palette.isList(NbtTagType.COMPOUND)) {\n return [];\n }\n\n return (palette as NbtList<NbtCompound>).data.map((tag) => {\n const name = tag.findChild<NbtString>('Name');\n\n return name?.data ?? '';\n });\n }\n\n /**\n * Parses a section tag into BlockData.\n *\n * Uses a cached version if available;\n */\n private parseSection(section: NbtCompound): BlockData {\n if (this.parsedSections.has(section)) {\n return this.parsedSections.get(section)!;\n }\n\n const palette = this.sectionPalette(section);\n\n if (!palette) {\n throw new Error('Invalid chunk section - no palette found');\n }\n\n const blockStates = this.sectionBlockStates(section);\n\n if (!blockStates) {\n throw new Error('Invalid chunk section - no block states found');\n }\n\n const blockData = BlockData.fromPaletteBlockStates(\n this.dataVersion,\n palette,\n blockStates\n );\n this.parsedSections.set(section, blockData);\n\n return blockData;\n }\n\n /**\n * Finds the BlockStates tag in a section.\n */\n private sectionBlockStates(section: NbtCompound): NbtLongArray | undefined {\n return (\n // 1.18+\n section.findChild<NbtLongArray>('block_states/data') ||\n // up to 1.17\n section.findChild<NbtLongArray>('BlockStates')\n );\n }\n\n /**\n * Finds the block palette in a section.\n */\n private sectionPalette(\n section: NbtCompound\n ): NbtList<NbtCompound> | undefined {\n return (\n // 1.18+\n section.findChild<NbtList<NbtCompound>>('block_states/palette') ||\n // up to 1.17\n section.findChild<NbtList<NbtCompound>>('Palette')\n );\n }\n\n /**\n * Returns all sections\n */\n private sectionsTag(): NbtList<NbtCompound> | undefined {\n const section =\n // 1.18+\n this.rootNbt.findChild<NbtList<NbtCompound>>('sections') ||\n // up to 1.17\n this.rootNbt.findChild<NbtList<NbtCompound>>('Level/Sections');\n\n if (section && this.isValidChunkSection(section)) {\n return section;\n }\n\n return;\n }\n\n /**\n * Returns the Y coordinate of a section, which goes from 0 to 256. If you want the world coordinate, pass true to get -128 to 4031.\n */\n private sectionY(section: NbtCompound, useWorldCoordinate = false): number {\n const ySection = section.findChild<NbtInt>('Y')?.data || 0;\n\n if (!useWorldCoordinate) {\n return ySection;\n }\n\n let yWorld = ySection * 16;\n\n if (yWorld >= 4032) {\n yWorld -= 4096;\n }\n\n return yWorld;\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BinaryData } from '../lib/binary-data';
|
|
2
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
3
|
+
export declare abstract class NbtBase<T> {
|
|
4
|
+
type: NbtTagType;
|
|
5
|
+
data: T;
|
|
6
|
+
name: string;
|
|
7
|
+
static readName(bd: BinaryData): string;
|
|
8
|
+
constructor(type: NbtTagType, data: T, name?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Search for a child by path. Use '/' as separators.
|
|
11
|
+
*
|
|
12
|
+
* nbt.findChild('Level/Sections/0/BlockStates')
|
|
13
|
+
*/
|
|
14
|
+
findChild<T extends NbtBase<any>>(_path: string): T | undefined;
|
|
15
|
+
isCompound(_name?: string): boolean;
|
|
16
|
+
isList(_subtype?: NbtTagType): boolean;
|
|
17
|
+
abstract toObject(): any;
|
|
18
|
+
abstract toSnbt(): string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=nbt-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-base.d.ts","sourceRoot":"","sources":["../../src/nbt/nbt-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,8BAAsB,OAAO,CAAC,CAAC;IAQhB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,CAAC;IACP,IAAI;IATf,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,UAAU;gBAOnB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,CAAC,EACP,IAAI,SAAK;IAGpB;;;;OAIG;IACH,SAAS,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAK/D,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO;IAInC,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,OAAO;IAItC,QAAQ,CAAC,QAAQ,IAAI,GAAG;IAExB,QAAQ,CAAC,MAAM,IAAI,MAAM;CAC5B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class NbtBase {
|
|
2
|
+
type;
|
|
3
|
+
data;
|
|
4
|
+
name;
|
|
5
|
+
static readName(bd) {
|
|
6
|
+
const nameLength = bd.getUShort();
|
|
7
|
+
return bd.getString(nameLength);
|
|
8
|
+
}
|
|
9
|
+
constructor(type, data, name = '') {
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.name = name;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Search for a child by path. Use '/' as separators.
|
|
16
|
+
*
|
|
17
|
+
* nbt.findChild('Level/Sections/0/BlockStates')
|
|
18
|
+
*/
|
|
19
|
+
findChild(_path) {
|
|
20
|
+
// By default, most elements do not have children.
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
isCompound(_name) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
isList(_subtype) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=nbt-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-base.js","sourceRoot":"","sources":["../../src/nbt/nbt-base.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,OAAO;IAQd;IACA;IACA;IATX,MAAM,CAAC,QAAQ,CAAC,EAAc;QAC1B,MAAM,UAAU,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;QAElC,OAAO,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,YACW,IAAgB,EAChB,IAAO,EACP,OAAO,EAAE;QAFT,SAAI,GAAJ,IAAI,CAAY;QAChB,SAAI,GAAJ,IAAI,CAAG;QACP,SAAI,GAAJ,IAAI,CAAK;IACjB,CAAC;IAEJ;;;;OAIG;IACH,SAAS,CAAyB,KAAa;QAC3C,kDAAkD;QAClD,OAAO;IACX,CAAC;IAED,UAAU,CAAC,KAAc;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,QAAqB;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;CAKJ","sourcesContent":["import { BinaryData } from '../lib/binary-data';\nimport { NbtTagType } from './nbt-tag-type';\n\nexport abstract class NbtBase<T> {\n static readName(bd: BinaryData) {\n const nameLength = bd.getUShort();\n\n return bd.getString(nameLength);\n }\n\n constructor(\n public type: NbtTagType,\n public data: T,\n public name = '',\n ) {}\n\n /**\n * Search for a child by path. Use '/' as separators.\n *\n * nbt.findChild('Level/Sections/0/BlockStates')\n */\n findChild<T extends NbtBase<any>>(_path: string): T | undefined {\n // By default, most elements do not have children.\n return;\n }\n\n isCompound(_name?: string): boolean {\n return false;\n }\n\n isList(_subtype?: NbtTagType): boolean {\n return false;\n }\n\n abstract toObject(): any;\n\n abstract toSnbt(): string;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BinaryData } from '../lib/binary-data';
|
|
2
|
+
import { NbtBase } from './nbt-base';
|
|
3
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
4
|
+
export declare class NbtByteArray extends NbtBase<number[]> {
|
|
5
|
+
static fromBinaryData(bd: BinaryData, name?: string): NbtByteArray;
|
|
6
|
+
constructor(data: number[], name?: string);
|
|
7
|
+
toObject(): {
|
|
8
|
+
type: NbtTagType;
|
|
9
|
+
byteArray: number[];
|
|
10
|
+
};
|
|
11
|
+
toSnbt(): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=nbt-byte-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-byte-array.d.ts","sourceRoot":"","sources":["../../src/nbt/nbt-byte-array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,qBAAa,YAAa,SAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;IAC/C,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY;gBAetD,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM;IAIzC,QAAQ;;;;IAOR,MAAM;CAGT"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { NbtBase } from './nbt-base';
|
|
3
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
4
|
+
const debugLogFromBinaryData = debug('nbt:byte-array:from-binary-data');
|
|
5
|
+
export class NbtByteArray extends NbtBase {
|
|
6
|
+
static fromBinaryData(bd, name) {
|
|
7
|
+
name ??= NbtByteArray.readName(bd);
|
|
8
|
+
const data = [];
|
|
9
|
+
const length = bd.getInt();
|
|
10
|
+
debugLogFromBinaryData(`BYTE_ARRAY, name ${name}, length ${length}`);
|
|
11
|
+
for (let i = 0; i < length; i++) {
|
|
12
|
+
data.push(bd.getByte());
|
|
13
|
+
}
|
|
14
|
+
debugLogFromBinaryData(`BYTE_ARRAY, data ${data}`);
|
|
15
|
+
return new NbtByteArray(data, name);
|
|
16
|
+
}
|
|
17
|
+
constructor(data, name) {
|
|
18
|
+
super(NbtTagType.BYTE_ARRAY, data, name);
|
|
19
|
+
}
|
|
20
|
+
toObject() {
|
|
21
|
+
return {
|
|
22
|
+
type: this.type,
|
|
23
|
+
byteArray: this.data,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
toSnbt() {
|
|
27
|
+
return `[B;${this.data.map((v) => `${v}b`).join(',')}]`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=nbt-byte-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-byte-array.js","sourceRoot":"","sources":["../../src/nbt/nbt-byte-array.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,iCAAiC,CAAC,CAAC;AAExE,MAAM,OAAO,YAAa,SAAQ,OAAiB;IAC/C,MAAM,CAAC,cAAc,CAAC,EAAc,EAAE,IAAa;QAC/C,IAAI,KAAK,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACnC,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;QAC3B,sBAAsB,CAAC,oBAAoB,IAAI,YAAY,MAAM,EAAE,CAAC,CAAC;QAErE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5B,CAAC;QAED,sBAAsB,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;QAEnD,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,YAAY,IAAc,EAAE,IAAa;QACrC,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,QAAQ;QACJ,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,IAAI;SACvB,CAAC;IACN,CAAC;IAED,MAAM;QACF,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC5D,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:byte-array:from-binary-data');\n\nexport class NbtByteArray extends NbtBase<number[]> {\n static fromBinaryData(bd: BinaryData, name?: string): NbtByteArray {\n name ??= NbtByteArray.readName(bd);\n const data: number[] = [];\n const length = bd.getInt();\n debugLogFromBinaryData(`BYTE_ARRAY, name ${name}, length ${length}`);\n\n for (let i = 0; i < length; i++) {\n data.push(bd.getByte());\n }\n\n debugLogFromBinaryData(`BYTE_ARRAY, data ${data}`);\n\n return new NbtByteArray(data, name);\n }\n\n constructor(data: number[], name?: string) {\n super(NbtTagType.BYTE_ARRAY, data, name);\n }\n\n toObject() {\n return {\n type: this.type,\n byteArray: this.data,\n };\n }\n\n toSnbt() {\n return `[B;${this.data.map((v) => `${v}b`).join(',')}]`;\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BinaryData } from '../lib/binary-data';
|
|
2
|
+
import { NbtBase } from './nbt-base';
|
|
3
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
4
|
+
export declare class NbtByte extends NbtBase<number> {
|
|
5
|
+
static fromBinaryData(bd: BinaryData, name?: string): NbtByte;
|
|
6
|
+
constructor(data: number, name?: string);
|
|
7
|
+
toObject(): {
|
|
8
|
+
type: NbtTagType;
|
|
9
|
+
byte: number;
|
|
10
|
+
};
|
|
11
|
+
toSnbt(): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=nbt-byte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-byte.d.ts","sourceRoot":"","sources":["../../src/nbt/nbt-byte.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,qBAAa,OAAQ,SAAQ,OAAO,CAAC,MAAM,CAAC;IACxC,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;gBAQjD,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAIvC,QAAQ;;;;IAOR,MAAM;CAGT"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { NbtBase } from './nbt-base';
|
|
3
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
4
|
+
const debugLogFromBinaryData = debug('nbt:byte:from-binary-data');
|
|
5
|
+
export class NbtByte extends NbtBase {
|
|
6
|
+
static fromBinaryData(bd, name) {
|
|
7
|
+
name ??= NbtByte.readName(bd);
|
|
8
|
+
const data = bd.getByte();
|
|
9
|
+
debugLogFromBinaryData(`BYTE, name ${name}, data ${data}`);
|
|
10
|
+
return new NbtByte(data, name);
|
|
11
|
+
}
|
|
12
|
+
constructor(data, name) {
|
|
13
|
+
super(NbtTagType.BYTE, data, name);
|
|
14
|
+
}
|
|
15
|
+
toObject() {
|
|
16
|
+
return {
|
|
17
|
+
type: this.type,
|
|
18
|
+
byte: this.data,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
toSnbt() {
|
|
22
|
+
return `${this.data}b`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=nbt-byte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-byte.js","sourceRoot":"","sources":["../../src/nbt/nbt-byte.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,2BAA2B,CAAC,CAAC;AAElE,MAAM,OAAO,OAAQ,SAAQ,OAAe;IACxC,MAAM,CAAC,cAAc,CAAC,EAAc,EAAE,IAAa;QAC/C,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QAC1B,sBAAsB,CAAC,cAAc,IAAI,UAAU,IAAI,EAAE,CAAC,CAAC;QAE3D,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,YAAY,IAAY,EAAE,IAAa;QACnC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,QAAQ;QACJ,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CAAC;IACN,CAAC;IAED,MAAM;QACF,OAAO,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC;IAC3B,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:byte:from-binary-data');\n\nexport class NbtByte extends NbtBase<number> {\n static fromBinaryData(bd: BinaryData, name?: string): NbtByte {\n name ??= NbtByte.readName(bd);\n const data = bd.getByte();\n debugLogFromBinaryData(`BYTE, name ${name}, data ${data}`);\n\n return new NbtByte(data, name);\n }\n\n constructor(data: number, name?: string) {\n super(NbtTagType.BYTE, data, name);\n }\n\n toObject() {\n return {\n type: this.type,\n byte: this.data,\n };\n }\n\n toSnbt() {\n return `${this.data}b`;\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BinaryData } from '../lib/binary-data';
|
|
2
|
+
import { NbtBase } from './nbt-base';
|
|
3
|
+
import { NbtTagType } from './nbt-tag-type';
|
|
4
|
+
export declare class NbtCompound extends NbtBase<NbtBase<any>[]> {
|
|
5
|
+
static fromBinaryData<T>(bd: BinaryData, name?: string): NbtCompound;
|
|
6
|
+
constructor(data: NbtBase<any>[], name?: string);
|
|
7
|
+
findChild<RESULT extends NbtBase<any>>(path: string): RESULT | undefined;
|
|
8
|
+
isCompound(name?: string): boolean;
|
|
9
|
+
toObject(): {
|
|
10
|
+
type: NbtTagType;
|
|
11
|
+
compound: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
toSnbt(): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=nbt-compound.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nbt-compound.d.ts","sourceRoot":"","sources":["../../src/nbt/nbt-compound.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAK5C,qBAAa,WAAY,SAAQ,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;IACpD,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW;gBAwBxD,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM;IAItC,SAAS,CAAC,MAAM,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM;IAmBnD,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IAQjC,QAAQ;;;;IAmBR,MAAM;CAUT"}
|