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,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import debug from 'debug';
|
|
4
|
+
import getStdin from 'get-stdin';
|
|
5
|
+
import neodoc from 'neodoc';
|
|
6
|
+
import { inflate } from 'pako';
|
|
7
|
+
import { Nbt } from '../nbt/nbt';
|
|
8
|
+
import { readFile } from 'node:fs/promises';
|
|
9
|
+
|
|
10
|
+
const debugLog = debug('mca-trim-chunks-without-signs');
|
|
11
|
+
main();
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
const args: {
|
|
15
|
+
'NBT_FILE'?: string[];
|
|
16
|
+
} = neodoc.run(
|
|
17
|
+
`Usage: nbt-get-player-locations NBT_FILE...
|
|
18
|
+
|
|
19
|
+
Scans a player NBT data file for the player location and prints it to stdout.
|
|
20
|
+
NBT files can be compressed or uncompressed and this tool can handle both. If the filename is "-" or not provided, this will read from stdin.
|
|
21
|
+
|
|
22
|
+
The output shows the following tab delimited fields:
|
|
23
|
+
|
|
24
|
+
* Dimension: "minecraft:overworld", "minecraft:the_nether", or "minecraft:the_end"
|
|
25
|
+
* X: The player's X coordinate, rounded
|
|
26
|
+
* Y: The player's Y coordinate, rounded
|
|
27
|
+
* Z: The player's Z coordinate, rounded
|
|
28
|
+
* chunkX: The player's chunk X coordinate
|
|
29
|
+
* chunkZ: The player's chunk Z coordinate
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
-h, --help Show this message.
|
|
33
|
+
`,
|
|
34
|
+
{
|
|
35
|
+
argv: [...process.argv].slice(2),
|
|
36
|
+
laxPlacement: true,
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (!args.NBT_FILE?.length) {
|
|
41
|
+
args.NBT_FILE = ['-'];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const file of args.NBT_FILE) {
|
|
45
|
+
try {
|
|
46
|
+
await processFile(file);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(`Error processing file ${file}: ${e}`);
|
|
49
|
+
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function readInput(filename: string | undefined) {
|
|
56
|
+
if (!filename || filename === '-') {
|
|
57
|
+
debugLog(`Reading from stdin`);
|
|
58
|
+
return await getStdin.buffer();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
debugLog(`Reading file: ${filename}`);
|
|
62
|
+
|
|
63
|
+
return readFile(filename);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function processFile(filename: string) {
|
|
67
|
+
const inputBuffer = await readInput(filename);
|
|
68
|
+
|
|
69
|
+
if (inputBuffer.length === 0) {
|
|
70
|
+
if (filename === '-') {
|
|
71
|
+
console.error('Input (stdin) is empty.');
|
|
72
|
+
} else {
|
|
73
|
+
console.error(`Input file is empty: ${filename}`);
|
|
74
|
+
}
|
|
75
|
+
console.error('Aborting. Use --help for usage.');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let buffer = inputBuffer.buffer as ArrayBufferLike;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
buffer = inflate(inputBuffer).buffer;
|
|
83
|
+
} catch (_ignore) {}
|
|
84
|
+
|
|
85
|
+
const nbt = Nbt.fromBuffer(buffer);
|
|
86
|
+
|
|
87
|
+
const dimension = nbt.findChild('Dimension')?.data;
|
|
88
|
+
const x = nbt.findChild('Pos/0')?.data;
|
|
89
|
+
const y = nbt.findChild('Pos/1')?.data;
|
|
90
|
+
const z = nbt.findChild('Pos/2')?.data;
|
|
91
|
+
|
|
92
|
+
if (typeof dimension !== 'string' || typeof x !== 'number' || typeof y !== 'number' || typeof z !== 'number') {
|
|
93
|
+
console.error(`NBT file ${filename} does not contain valid player location data.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const chunkX = Math.floor(x / 16);
|
|
98
|
+
const chunkZ = Math.floor(z / 16);
|
|
99
|
+
|
|
100
|
+
const output = [dimension, Math.round(x), Math.round(y), Math.round(z), chunkX, chunkZ];
|
|
101
|
+
console.log(output.join('\t'));
|
|
102
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import getStdin from 'get-stdin';
|
|
4
|
+
import neodoc from 'neodoc';
|
|
5
|
+
import { inflate } from 'pako';
|
|
6
|
+
import { Nbt } from '../nbt/nbt';
|
|
7
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
8
|
+
|
|
9
|
+
async function readInput(filename: string | undefined) {
|
|
10
|
+
if (!filename || filename === '-') {
|
|
11
|
+
return await getStdin.buffer();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return readFile(filename);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const args: {
|
|
18
|
+
'--compact'?: boolean;
|
|
19
|
+
'--condense'?: boolean;
|
|
20
|
+
'<input>'?: string;
|
|
21
|
+
'<output>'?: string;
|
|
22
|
+
} = neodoc.run(
|
|
23
|
+
`Usage: nbt-json [OPTIONS] [<input> [<output>]]
|
|
24
|
+
|
|
25
|
+
Shows NBT data in a JSON format. Both input and output are optional. If input
|
|
26
|
+
is not provided, this reads from stdin. If output is not provided, this writes
|
|
27
|
+
to stdout.
|
|
28
|
+
|
|
29
|
+
NBT files can be compressed or uncompressed. This tool can handle both. One
|
|
30
|
+
example NBT file is the player.dat file.
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--compact Do not use pretty-printing in the JSON output.
|
|
34
|
+
--condense Condense arrays of bytes, ints, and longs to a single line.
|
|
35
|
+
This significantly cuts down on the size of the generated
|
|
36
|
+
JSON.
|
|
37
|
+
-h, --help Show this message.
|
|
38
|
+
`,
|
|
39
|
+
{
|
|
40
|
+
argv: [...process.argv].slice(2),
|
|
41
|
+
laxPlacement: true,
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
readInput(args['<input>'])
|
|
46
|
+
.then((inputBuffer) => {
|
|
47
|
+
if (inputBuffer.length === 0) {
|
|
48
|
+
console.error('No input provided. Use --help for usage.');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let buffer = inputBuffer.buffer as ArrayBufferLike;
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
buffer = inflate(inputBuffer).buffer;
|
|
56
|
+
} catch (_ignore) {}
|
|
57
|
+
|
|
58
|
+
const nbt = Nbt.fromBuffer(buffer);
|
|
59
|
+
|
|
60
|
+
let jsonObject = nbt.toObject();
|
|
61
|
+
|
|
62
|
+
if (args['--compact']) {
|
|
63
|
+
return JSON.stringify(jsonObject);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let content = JSON.stringify(jsonObject, null, 4);
|
|
67
|
+
|
|
68
|
+
if (args['--condense']) {
|
|
69
|
+
content = content.replace(
|
|
70
|
+
/: \[(\n\s*"?-?\d+"?,?)*\n\s*\]/g,
|
|
71
|
+
(match) => {
|
|
72
|
+
return match.replace(/\n\s*/g, ' ');
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return content;
|
|
78
|
+
})
|
|
79
|
+
.then((output: string) => {
|
|
80
|
+
if (args['<output>']) {
|
|
81
|
+
writeFile(args['<output>'], output);
|
|
82
|
+
} else {
|
|
83
|
+
console.log(output);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { HasEntityData } from './has-entity-data';
|
|
2
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
3
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
4
|
+
import { NbtString } from '../nbt/nbt-string';
|
|
5
|
+
|
|
6
|
+
export interface BannerPatternDefinition {
|
|
7
|
+
asset_id: string;
|
|
8
|
+
translation_key: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BannerPattern {
|
|
12
|
+
color: string;
|
|
13
|
+
pattern: string | BannerPatternDefinition;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Banner extends HasEntityData {
|
|
17
|
+
patterns(): BannerPattern[] {
|
|
18
|
+
const patterns =
|
|
19
|
+
this.entityData.findChild<NbtList<NbtCompound>>('Patterns');
|
|
20
|
+
|
|
21
|
+
if (!patterns) {
|
|
22
|
+
throw new Error('Unable to find patterns in banner');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return patterns.data.map((compound) => {
|
|
26
|
+
const color = compound.findChild<NbtString>('Color');
|
|
27
|
+
const pattern = compound.findChild<NbtString | NbtCompound>(
|
|
28
|
+
'Pattern'
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (!color || !pattern) {
|
|
32
|
+
throw new Error('Color or pattern not found in banner pattern');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (pattern instanceof NbtString) {
|
|
36
|
+
return { color: color.data, pattern: pattern.data };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
color: color.data,
|
|
41
|
+
pattern: {
|
|
42
|
+
asset_id:
|
|
43
|
+
pattern.findChild<NbtString>('Pattern')?.data ?? '',
|
|
44
|
+
translation_key:
|
|
45
|
+
pattern.findChild<NbtString>('Pattern')?.data ?? '',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { HasEntityData } from './has-entity-data';
|
|
2
|
+
import { CustomName } from './mixins/custom-name';
|
|
3
|
+
import { Lock } from './mixins/lock';
|
|
4
|
+
import { Mixin } from './mixins/mixin';
|
|
5
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
6
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
7
|
+
import { NbtLong } from '../nbt/nbt-long';
|
|
8
|
+
import { NbtString } from '../nbt/nbt-string';
|
|
9
|
+
|
|
10
|
+
export class Barrel extends Mixin(
|
|
11
|
+
HasEntityData,
|
|
12
|
+
CustomName,
|
|
13
|
+
Lock,
|
|
14
|
+
class extends HasEntityData {
|
|
15
|
+
items(): NbtList<NbtCompound> {
|
|
16
|
+
const items =
|
|
17
|
+
this.entityData.findChild<NbtList<NbtCompound>>('Items');
|
|
18
|
+
|
|
19
|
+
if (!items) {
|
|
20
|
+
throw new Error('Barrel is missing items tag');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return items;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
lootTable(): string | undefined {
|
|
27
|
+
return this.entityData.findChild<NbtString>('LootTable')?.data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
lootTableSeed(): bigint | undefined {
|
|
31
|
+
return this.entityData.findChild<NbtLong>('LootTableSeed')?.data;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
) {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CustomName } from './mixins/custom-name';
|
|
2
|
+
import { HasEntityData } from './has-entity-data';
|
|
3
|
+
import { Lock } from './mixins/lock';
|
|
4
|
+
import { Mixin } from './mixins/mixin';
|
|
5
|
+
import { NbtString } from '../nbt/nbt-string';
|
|
6
|
+
|
|
7
|
+
export class Beacon extends Mixin(
|
|
8
|
+
HasEntityData,
|
|
9
|
+
CustomName,
|
|
10
|
+
Lock,
|
|
11
|
+
class extends HasEntityData {
|
|
12
|
+
primaryEffect(): string | undefined {
|
|
13
|
+
return this.entityData.findChild<NbtString>('LootTable')?.data;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
secondaryEffect(): string | undefined {
|
|
17
|
+
return this.entityData.findChild<NbtString>('LootTableSeed')?.data;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
) {}
|
package/src/block/bed.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Coords3d } from '../types/coords';
|
|
2
|
+
import { HasEntityData } from './has-entity-data';
|
|
3
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
4
|
+
import { NbtIntArray } from '../nbt/nbt-int-array';
|
|
5
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
6
|
+
|
|
7
|
+
export class Beehive extends HasEntityData {
|
|
8
|
+
bees(): NbtList<NbtCompound> | undefined {
|
|
9
|
+
return this.entityData.findChild<NbtList<NbtCompound>>('bees');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
flowerPos(): Coords3d | undefined {
|
|
13
|
+
return this.entityData.findChild<NbtIntArray>('flower_pos')?.data as
|
|
14
|
+
| Coords3d
|
|
15
|
+
| undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Banner } from './banner';
|
|
2
|
+
import { Barrel } from './barrel';
|
|
3
|
+
import { Beacon } from './beacon';
|
|
4
|
+
import { Bed } from './bed';
|
|
5
|
+
import { Beehive } from './beehive';
|
|
6
|
+
import { Bell } from './bell';
|
|
7
|
+
import { Coords3d } from '../types/coords';
|
|
8
|
+
import { Generic } from './generic';
|
|
9
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
10
|
+
import { Sign } from './sign';
|
|
11
|
+
|
|
12
|
+
export type BlockInstance = Banner | Barrel | Beacon | Bed | Beehive | Bell | Generic | Sign;
|
|
13
|
+
|
|
14
|
+
export class Block {
|
|
15
|
+
static blockConstructor = new Map<(name: string) => boolean, typeof Generic>([
|
|
16
|
+
[Block.isBanner, Banner],
|
|
17
|
+
[Block.isBarrel, Barrel],
|
|
18
|
+
[Block.isBeacon, Beacon],
|
|
19
|
+
[Block.isBed, Bed],
|
|
20
|
+
[Block.isBeehive, Beehive],
|
|
21
|
+
[Block.isBell, Bell],
|
|
22
|
+
[Block.isSign, Sign]
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
static create(name: string, coords: Coords3d, entityData?: NbtCompound): Generic {
|
|
26
|
+
for (const [isBlock, blockConstructor] of Block.blockConstructor) {
|
|
27
|
+
if (isBlock(name)) {
|
|
28
|
+
return new blockConstructor(name, coords, entityData);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return new Generic(name, coords, entityData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static isBanner(name: string): boolean {
|
|
36
|
+
return !!name.match(/^minecraft:.+_banner$/);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static isBarrel(name: string): boolean {
|
|
40
|
+
return name === 'minecraft:barrel';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static isBeacon(name: string): boolean {
|
|
44
|
+
return name === 'minecraft:beacon';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static isBed(name: string): boolean {
|
|
48
|
+
return !!name.match(/^minecraft:.+_bed$/);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static isBeehive(name: string): boolean {
|
|
52
|
+
return name === 'minecraft:beehive' || name === 'minecraft:bee_nest';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static isBell(name: string): boolean {
|
|
56
|
+
return name === 'minecraft:bell';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static isSign(name: string): boolean {
|
|
60
|
+
return !!name.match(/^minecraft:.+_sign$/);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Coords3d } from '../types/coords';
|
|
2
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
3
|
+
|
|
4
|
+
export class Generic {
|
|
5
|
+
constructor(
|
|
6
|
+
public name: string,
|
|
7
|
+
public coords: Coords3d,
|
|
8
|
+
public entityData?: NbtCompound
|
|
9
|
+
) {}
|
|
10
|
+
|
|
11
|
+
components(): NbtCompound | undefined {
|
|
12
|
+
return this.entityData?.findChild<NbtCompound>('components');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Generic } from './generic';
|
|
2
|
+
import { Coords3d } from '../types/coords';
|
|
3
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
4
|
+
|
|
5
|
+
export class HasEntityData extends Generic {
|
|
6
|
+
override entityData: NbtCompound;
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
name: string,
|
|
10
|
+
coords: Coords3d,
|
|
11
|
+
entityData?: NbtCompound
|
|
12
|
+
) {
|
|
13
|
+
if (!entityData) {
|
|
14
|
+
throw new Error('Block is supposed to have entity data');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
super(name, coords, entityData);
|
|
18
|
+
this.entityData = entityData;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HasEntityData } from '../has-entity-data';
|
|
2
|
+
import { NbtString } from '../../nbt/nbt-string';
|
|
3
|
+
|
|
4
|
+
export class CustomName extends HasEntityData {
|
|
5
|
+
customName(): string | undefined {
|
|
6
|
+
return this.entityData.findChild<NbtString>('CustomName')?.data;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
24
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
25
|
+
k: infer I
|
|
26
|
+
) => void
|
|
27
|
+
? I
|
|
28
|
+
: never;
|
|
29
|
+
|
|
30
|
+
type ClassType = new (...args: any[]) => any;
|
|
31
|
+
|
|
32
|
+
export function Mixin<T extends ClassType, R extends T[]>(
|
|
33
|
+
BaseType: T,
|
|
34
|
+
...classRefs: [...R]
|
|
35
|
+
): new (
|
|
36
|
+
...args: ConstructorParameters<T>
|
|
37
|
+
) => UnionToIntersection<InstanceType<[...R][number]>> {
|
|
38
|
+
const derived = class extends BaseType {};
|
|
39
|
+
classRefs.forEach((classRef) => {
|
|
40
|
+
Object.getOwnPropertyNames(classRef.prototype).forEach((name) => {
|
|
41
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
42
|
+
classRef.prototype,
|
|
43
|
+
name
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (name !== 'constructor' && descriptor) {
|
|
47
|
+
Object.defineProperty(derived.prototype, name, descriptor);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return derived;
|
|
53
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { HasEntityData } from './has-entity-data';
|
|
2
|
+
import { Nbt } from '../nbt/nbt';
|
|
3
|
+
import { NbtByte } from '../nbt/nbt-byte';
|
|
4
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
5
|
+
import { NbtString } from '../nbt/nbt-string';
|
|
6
|
+
import { NbtTagType } from '../nbt/nbt-tag-type';
|
|
7
|
+
|
|
8
|
+
type SignText = [string, string, string, string];
|
|
9
|
+
|
|
10
|
+
export class Sign extends HasEntityData {
|
|
11
|
+
backColor(): string | undefined {
|
|
12
|
+
// 1.20+
|
|
13
|
+
return this.entityData.findChild<NbtString>('back_text/color')?.data;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
backGlowingText(): boolean | undefined {
|
|
17
|
+
// 1.20+
|
|
18
|
+
const byte = this.entityData.findChild<NbtByte>(
|
|
19
|
+
'back_text/has_glowing_text'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (byte) {
|
|
23
|
+
return byte.data !== 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Up to 1.19
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
backText(): SignText | undefined {
|
|
31
|
+
// 1.20+
|
|
32
|
+
const backSnbt = this.entityData
|
|
33
|
+
.findChild<NbtList<NbtString>>('back_text/messages')
|
|
34
|
+
?.data.map((tag) => tag.data);
|
|
35
|
+
|
|
36
|
+
if (this.isSignText(backSnbt)) {
|
|
37
|
+
return this.snbtToText(backSnbt);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Up to 1.19
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
frontColor(): string | undefined {
|
|
45
|
+
return (
|
|
46
|
+
// 1.20+
|
|
47
|
+
this.entityData.findChild<NbtString>('front_text/color')?.data ||
|
|
48
|
+
// Up to 1.19
|
|
49
|
+
this.entityData.findChild<NbtString>('Color')?.data
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
frontGlowingText(): boolean | undefined {
|
|
54
|
+
const byte =
|
|
55
|
+
// 1.20+
|
|
56
|
+
this.entityData.findChild<NbtByte>('front_text/has_glowing_text') ||
|
|
57
|
+
// Up to 1.19
|
|
58
|
+
this.entityData.findChild<NbtByte>('GlowingText');
|
|
59
|
+
|
|
60
|
+
if (byte) {
|
|
61
|
+
return byte.data !== 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
frontText(): SignText {
|
|
68
|
+
// 1.20+
|
|
69
|
+
const frontSnbt = this.entityData
|
|
70
|
+
.findChild<NbtList<NbtString>>('front_text/messages')
|
|
71
|
+
?.data.map((tag) => tag.data);
|
|
72
|
+
|
|
73
|
+
if (this.isSignText(frontSnbt)) {
|
|
74
|
+
return this.snbtToText(frontSnbt);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Up to 1.19
|
|
78
|
+
const frontOldSnbt = [
|
|
79
|
+
this.entityData.findChild<NbtString>('Text1')?.data,
|
|
80
|
+
this.entityData.findChild<NbtString>('Text2')?.data,
|
|
81
|
+
this.entityData.findChild<NbtString>('Text3')?.data,
|
|
82
|
+
this.entityData.findChild<NbtString>('Text4')?.data,
|
|
83
|
+
].filter((tag): tag is string => !!tag);
|
|
84
|
+
|
|
85
|
+
if (this.isSignText(frontOldSnbt)) {
|
|
86
|
+
return this.snbtToText(frontOldSnbt);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throw new Error('Unknown format for sign text');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
isWaxed(): boolean | undefined {
|
|
93
|
+
const tag = this.entityData.findChild<NbtByte>('waxed');
|
|
94
|
+
|
|
95
|
+
if (!tag) {
|
|
96
|
+
// Up to 1.19
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 1.20+
|
|
101
|
+
return tag.data !== 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private isSignText(value?: string[]): value is SignText {
|
|
105
|
+
return value?.length === 4;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private snbtToText(snbtList: SignText): SignText {
|
|
109
|
+
return snbtList.map((snbt) => {
|
|
110
|
+
const tag = Nbt.fromSnbt(snbt);
|
|
111
|
+
|
|
112
|
+
// 1.20 and newer
|
|
113
|
+
if (tag.type === NbtTagType.STRING) {
|
|
114
|
+
return tag.data;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Up to 1.19
|
|
118
|
+
return tag.findChild<NbtString>('text')?.data ?? '';
|
|
119
|
+
}) as SignText;
|
|
120
|
+
}
|
|
121
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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';
|