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,178 @@
|
|
|
1
|
+
import { NbtByteArray } from '../nbt/nbt-byte-array';
|
|
2
|
+
import { NbtByte } from '../nbt/nbt-byte';
|
|
3
|
+
import { NbtCompound } from '../nbt/nbt-compound';
|
|
4
|
+
import { NbtDouble } from '../nbt/nbt-double';
|
|
5
|
+
import { NbtFloat } from '../nbt/nbt-float';
|
|
6
|
+
import { NbtIntArray } from '../nbt/nbt-int-array';
|
|
7
|
+
import { NbtInt } from '../nbt/nbt-int';
|
|
8
|
+
import { NbtList } from '../nbt/nbt-list';
|
|
9
|
+
import { NbtLongArray } from '../nbt/nbt-long-array';
|
|
10
|
+
import { NbtLong } from '../nbt/nbt-long';
|
|
11
|
+
import { NbtShort } from '../nbt/nbt-short';
|
|
12
|
+
import { NbtString } from '../nbt/nbt-string';
|
|
13
|
+
export const fromSnbtData = {
|
|
14
|
+
BYTE: snbtToNbtByte,
|
|
15
|
+
BYTE_ARRAY_START: snbtToNbtByteArray,
|
|
16
|
+
COMPOUND_START: snbtToNbtCompound,
|
|
17
|
+
DOUBLE: snbtToNbtDouble,
|
|
18
|
+
FLOAT: snbtToNbtFloat,
|
|
19
|
+
INT: snbtToNbtInt,
|
|
20
|
+
INT_ARRAY_START: snbtToNbtIntArray,
|
|
21
|
+
LIST_START: snbtToNbtList,
|
|
22
|
+
LONG: snbtToNbtLong,
|
|
23
|
+
LONG_ARRAY_START: snbtToNbtLongArray,
|
|
24
|
+
SHORT: snbtToNbtShort,
|
|
25
|
+
STRING: snbtToNbtString,
|
|
26
|
+
};
|
|
27
|
+
export function snbtToNbt(snbtData) {
|
|
28
|
+
const token = snbtData.token();
|
|
29
|
+
const processor = fromSnbtData[token.type];
|
|
30
|
+
if (processor) {
|
|
31
|
+
return processor(token, snbtData);
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Invalid, non-matching token ${snbtData.showToken(token)}`);
|
|
34
|
+
}
|
|
35
|
+
function snbtToNbtByte(token) {
|
|
36
|
+
return new NbtByte(parseInt(token.content || ''));
|
|
37
|
+
}
|
|
38
|
+
function snbtToNbtByteArray(_token, snbtData) {
|
|
39
|
+
const bytes = [];
|
|
40
|
+
let token = snbtData.token();
|
|
41
|
+
while (token && token.type === 'BYTE') {
|
|
42
|
+
bytes.push(parseInt(token.content || ''));
|
|
43
|
+
try {
|
|
44
|
+
token = snbtData.token();
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
throw new Error(`${err} - Unexpected end of SNBT data while parsing byte array`);
|
|
48
|
+
}
|
|
49
|
+
if (token.type !== 'COMMA') {
|
|
50
|
+
throw new Error(`Expecting a comma but found ${snbtData.showToken(token)}`);
|
|
51
|
+
}
|
|
52
|
+
token = snbtData.token();
|
|
53
|
+
}
|
|
54
|
+
return new NbtByteArray(bytes);
|
|
55
|
+
}
|
|
56
|
+
function snbtToNbtCompound(_token, snbtData) {
|
|
57
|
+
const data = [];
|
|
58
|
+
let token = snbtData.token();
|
|
59
|
+
while (token && token.type !== 'COMPOUND_END') {
|
|
60
|
+
if (token.type !== 'STRING') {
|
|
61
|
+
throw new Error(`Expecting a string but found ${snbtData.showToken(token)}`);
|
|
62
|
+
}
|
|
63
|
+
const name = token.content;
|
|
64
|
+
let colon;
|
|
65
|
+
try {
|
|
66
|
+
colon = snbtData.token();
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
throw new Error(`${err} - Unexpected end of SNBT data while looking for colon`);
|
|
70
|
+
}
|
|
71
|
+
if (colon.type !== 'COLON') {
|
|
72
|
+
throw new Error(`Expecting a colon but found ${snbtData.showToken(colon)}`);
|
|
73
|
+
}
|
|
74
|
+
const nbt = snbtToNbt(snbtData);
|
|
75
|
+
nbt.name = name;
|
|
76
|
+
data.push(nbt);
|
|
77
|
+
token = snbtData.token();
|
|
78
|
+
}
|
|
79
|
+
return new NbtCompound(data);
|
|
80
|
+
}
|
|
81
|
+
function snbtToNbtDouble(token) {
|
|
82
|
+
return new NbtDouble(parseFloat(token.content.slice(0, -1) || ''));
|
|
83
|
+
}
|
|
84
|
+
function snbtToNbtFloat(token) {
|
|
85
|
+
return new NbtFloat(parseFloat(token.content || ''));
|
|
86
|
+
}
|
|
87
|
+
function snbtToNbtInt(token) {
|
|
88
|
+
return new NbtInt(parseInt(token.content || ''));
|
|
89
|
+
}
|
|
90
|
+
function snbtToNbtIntArray(_token, snbtData) {
|
|
91
|
+
const ints = [];
|
|
92
|
+
let token = snbtData.token();
|
|
93
|
+
while (token && token.type === 'INT') {
|
|
94
|
+
ints.push(parseInt(token.content || ''));
|
|
95
|
+
try {
|
|
96
|
+
token = snbtData.token();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
throw new Error(`${err} - Unexpected end of SNBT data while parsing int array`);
|
|
100
|
+
}
|
|
101
|
+
if (token.type !== 'COMMA') {
|
|
102
|
+
throw new Error(`Expecting a comma but found ${snbtData.showToken(token)}`);
|
|
103
|
+
}
|
|
104
|
+
token = snbtData.token();
|
|
105
|
+
}
|
|
106
|
+
return new NbtIntArray(ints);
|
|
107
|
+
}
|
|
108
|
+
function snbtToNbtList(_token, snbtData) {
|
|
109
|
+
const list = [];
|
|
110
|
+
let token;
|
|
111
|
+
try {
|
|
112
|
+
token = snbtData.token();
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
throw new Error(`${err} - Unexpected end of SNBT data while parsing list at beginning`);
|
|
116
|
+
}
|
|
117
|
+
while (token.type !== 'LIST_END') {
|
|
118
|
+
snbtData.step(-1);
|
|
119
|
+
let nbt;
|
|
120
|
+
try {
|
|
121
|
+
nbt = snbtToNbt(snbtData);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw new Error(`${err} - Error parsing list element`);
|
|
125
|
+
}
|
|
126
|
+
list.push(nbt);
|
|
127
|
+
token = snbtData.token();
|
|
128
|
+
if (token.type === 'COMMA') {
|
|
129
|
+
try {
|
|
130
|
+
token = snbtData.token();
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
throw new Error(`${err} - Unexpected end of SNBT data while looking for comma or end of list`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (token.type !== 'LIST_END') {
|
|
137
|
+
throw new Error(`Expecting a comma or list end but found ${snbtData.showToken(token)}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!list.length) {
|
|
141
|
+
throw new Error('Empty list not allowed in SNBT because the type cannot be inferred');
|
|
142
|
+
}
|
|
143
|
+
const firstType = list[0].type;
|
|
144
|
+
for (let i = 1; i < list.length; i++) {
|
|
145
|
+
if (list[i].type !== firstType) {
|
|
146
|
+
throw new Error(`List contains mixed types: ${firstType} and ${list[i].type}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return new NbtList(list, firstType);
|
|
150
|
+
}
|
|
151
|
+
function snbtToNbtLong(token) {
|
|
152
|
+
return new NbtLong(BigInt(token.content.slice(0, -1) || ''));
|
|
153
|
+
}
|
|
154
|
+
function snbtToNbtLongArray(_token, snbtData) {
|
|
155
|
+
const longs = [];
|
|
156
|
+
let token = snbtData.token();
|
|
157
|
+
while (token && token.type === 'LONG') {
|
|
158
|
+
longs.push(BigInt(token.content.slice(0, -1) || ''));
|
|
159
|
+
try {
|
|
160
|
+
token = snbtData.token();
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
throw new Error(`${err} - Unexpected end of SNBT data while parsing long array`);
|
|
164
|
+
}
|
|
165
|
+
if (token.type !== 'COMMA') {
|
|
166
|
+
throw new Error(`Expecting a comma but found ${snbtData.showToken(token)}`);
|
|
167
|
+
}
|
|
168
|
+
token = snbtData.token();
|
|
169
|
+
}
|
|
170
|
+
return new NbtLongArray(longs);
|
|
171
|
+
}
|
|
172
|
+
function snbtToNbtShort(token) {
|
|
173
|
+
return new NbtShort(parseInt(token.content || ''));
|
|
174
|
+
}
|
|
175
|
+
function snbtToNbtString(token) {
|
|
176
|
+
return new NbtString(token.content);
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=snbt-to-nbt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snbt-to-nbt.js","sourceRoot":"","sources":["../../src/nbt/snbt-to-nbt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM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IAAI,EAAE,CAAC,CAAC,CAAC;QAErD,IAAI,CAAC;YACD,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,yDAAyD,CAAC,CAAC;QACrF,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAChF,CAAC;QAED,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB;IACpC,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,eAAe,CAAC,KAAgB;IACrC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { NbtBase } from '../nbt/nbt-base';\nimport { NbtByteArray } from '../nbt/nbt-byte-array';\nimport { NbtByte } from '../nbt/nbt-byte';\nimport { NbtCompound } from '../nbt/nbt-compound';\nimport { NbtDouble } from '../nbt/nbt-double';\nimport { NbtFloat } from '../nbt/nbt-float';\nimport { NbtIntArray } from '../nbt/nbt-int-array';\nimport { NbtInt } from '../nbt/nbt-int';\nimport { NbtList } from '../nbt/nbt-list';\nimport { NbtLongArray } from '../nbt/nbt-long-array';\nimport { NbtLong } from '../nbt/nbt-long';\nimport { NbtShort } from '../nbt/nbt-short';\nimport { NbtString } from '../nbt/nbt-string';\nimport { SnbtData, SnbtToken } from './snbt-data';\n\nexport const fromSnbtData: {\n [key: string]: (token: SnbtToken, snbtData: SnbtData) => NbtBase<any>;\n} = {\n BYTE: snbtToNbtByte,\n BYTE_ARRAY_START: snbtToNbtByteArray,\n COMPOUND_START: snbtToNbtCompound,\n DOUBLE: snbtToNbtDouble,\n FLOAT: snbtToNbtFloat,\n INT: snbtToNbtInt,\n INT_ARRAY_START: snbtToNbtIntArray,\n LIST_START: snbtToNbtList,\n LONG: snbtToNbtLong,\n LONG_ARRAY_START: snbtToNbtLongArray,\n SHORT: snbtToNbtShort,\n STRING: snbtToNbtString,\n};\n\nexport function snbtToNbt(snbtData: SnbtData): NbtBase<any> {\n const token = snbtData.token();\n const processor = fromSnbtData[token.type];\n\n if (processor) {\n return processor(token, snbtData);\n }\n\n throw new Error(`Invalid, non-matching token ${snbtData.showToken(token)}`);\n}\n\nfunction snbtToNbtByte(token: SnbtToken): NbtByte {\n return new NbtByte(parseInt(token.content || ''));\n}\n\nfunction snbtToNbtByteArray(_token: SnbtToken, snbtData: SnbtData): NbtByteArray {\n const bytes: number[] = [];\n let token = snbtData.token();\n\n while (token && token.type === 'BYTE') {\n bytes.push(parseInt(token.content || ''));\n\n try {\n token = snbtData.token();\n } catch (err) {\n throw new Error(`${err} - Unexpected end of SNBT data while parsing byte array`);\n }\n\n if (token.type !== 'COMMA') {\n throw new Error(`Expecting a comma but found ${snbtData.showToken(token)}`);\n }\n\n token = snbtData.token();\n }\n\n return new NbtByteArray(bytes);\n}\n\nfunction snbtToNbtCompound(_token: SnbtToken, snbtData: SnbtData): NbtCompound {\n const data: NbtBase<any>[] = [];\n let token = snbtData.token();\n\n while (token && token.type !== 'COMPOUND_END') {\n if (token.type !== 'STRING') {\n throw new Error(`Expecting a string but found ${snbtData.showToken(token)}`);\n }\n\n const name = token.content;\n let colon;\n\n try {\n colon = snbtData.token();\n } catch (err) {\n throw new Error(`${err} - Unexpected end of SNBT data while looking for colon`);\n }\n\n if (colon.type !== 'COLON') {\n throw new Error(`Expecting a colon but found ${snbtData.showToken(colon)}`);\n }\n\n const nbt = snbtToNbt(snbtData);\n nbt.name = name;\n data.push(nbt);\n token = snbtData.token();\n }\n\n return new NbtCompound(data);\n}\n\nfunction snbtToNbtDouble(token: SnbtToken): NbtDouble {\n return new NbtDouble(parseFloat(token.content.slice(0, -1) || ''));\n}\n\nfunction snbtToNbtFloat(token: SnbtToken): NbtFloat {\n return new NbtFloat(parseFloat(token.content || ''));\n}\n\nfunction snbtToNbtInt(token: SnbtToken): NbtInt {\n return new NbtInt(parseInt(token.content || ''));\n}\n\nfunction snbtToNbtIntArray(_token: SnbtToken, snbtData: SnbtData): NbtIntArray {\n const ints: number[] = [];\n let token = snbtData.token();\n\n while (token && token.type === 'INT') {\n ints.push(parseInt(token.content || ''));\n\n try {\n token = snbtData.token();\n } catch (err) {\n throw new Error(`${err} - Unexpected end of SNBT data while parsing int array`);\n }\n\n if (token.type !== 'COMMA') {\n throw new Error(`Expecting a comma but found ${snbtData.showToken(token)}`);\n }\n\n token = snbtData.token();\n }\n\n return new NbtIntArray(ints);\n}\n\nfunction snbtToNbtList(_token: SnbtToken, snbtData: SnbtData): NbtList<any> {\n const list: NbtBase<any>[] = [];\n let token;\n\n try {\n token = snbtData.token();\n } catch (err) {\n throw new Error(`${err} - Unexpected end of SNBT data while parsing list at beginning`);\n }\n\n while (token.type !== 'LIST_END') {\n snbtData.step(-1);\n let nbt;\n\n try {\n nbt = snbtToNbt(snbtData);\n } catch (err) {\n throw new Error(`${err} - Error parsing list element`);\n }\n\n list.push(nbt);\n token = snbtData.token();\n\n if (token.type === 'COMMA') {\n try {\n token = snbtData.token();\n } catch (err) {\n throw new Error(`${err} - Unexpected end of SNBT data while looking for comma or end of list`);\n }\n } else if (token.type !== 'LIST_END') {\n throw new Error(`Expecting a comma or list end but found ${snbtData.showToken(token)}`);\n }\n }\n\n if (!list.length) {\n throw new Error('Empty list not allowed in SNBT because the type cannot be inferred');\n }\n\n const firstType = list[0].type;\n\n for (let i = 1; i < list.length; i++) {\n if (list[i].type !== firstType) {\n throw new Error(`List contains mixed types: ${firstType} and ${list[i].type}`);\n }\n }\n\n return new NbtList(list, firstType);\n}\n\nfunction snbtToNbtLong(token: SnbtToken): NbtLong {\n return new NbtLong(BigInt(token.content.slice(0, -1) || ''));\n}\n\nfunction snbtToNbtLongArray(_token: SnbtToken, snbtData: SnbtData): NbtLongArray {\n const longs: bigint[] = [];\n let token = snbtData.token();\n\n while (token && token.type === 'LONG') {\n longs.push(BigInt(token.content.slice(0, -1) || ''));\n\n try {\n token = snbtData.token();\n } catch (err) {\n throw new Error(`${err} - Unexpected end of SNBT data while parsing long array`);\n }\n\n if (token.type !== 'COMMA') {\n throw new Error(`Expecting a comma but found ${snbtData.showToken(token)}`);\n }\n\n token = snbtData.token();\n }\n\n return new NbtLongArray(longs);\n}\n\nfunction snbtToNbtShort(token: SnbtToken): NbtShort {\n return new NbtShort(parseInt(token.content || ''));\n}\n\nfunction snbtToNbtString(token: SnbtToken): NbtString {\n return new NbtString(token.content);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coords.d.ts","sourceRoot":"","sources":["../../src/types/coords.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACxC,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coords.js","sourceRoot":"","sources":["../../src/types/coords.ts"],"names":[],"mappings":"","sourcesContent":["export type Coords2d = [number, number]; // X and Z\nexport type Coords3d = [number, number, number]; // X, Y, and Z\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mca-json",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Convert Minecraft MCA (Anvil files) and NBT into JSON and back, or modify directly in memory. Works on region files and player data.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"mca-chunks": "dist/bin/mca-chunks.js",
|
|
7
|
+
"mca-json": "dist/bin/mca-json.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rm -rf dist && npm run build-index && tsc",
|
|
11
|
+
"build-index": "cd src; for F in $(grep '^export' -r . -l --include \\*.ts --exclude index.ts); do echo \"export * from '${F%.ts}';\"; done | LC_ALL=C sort > index.ts",
|
|
12
|
+
"reinstall": "rm -rf node_modules package-lock.json && npm install"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.mjs",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@types/node": "^25.2.3",
|
|
18
|
+
"debug": "^4.4.3",
|
|
19
|
+
"get-stdin": "^10.0.0",
|
|
20
|
+
"neodoc": "^2.0.2",
|
|
21
|
+
"pako": "^2.1.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/debug": "^4.1.12",
|
|
25
|
+
"@types/pako": "^2.0.4",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import getStdin from 'get-stdin';
|
|
4
|
+
import neodoc from 'neodoc';
|
|
5
|
+
import { Anvil } from '../lib/anvil';
|
|
6
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
7
|
+
|
|
8
|
+
async function readInput(filename: string | undefined) {
|
|
9
|
+
if (!filename || filename === '-') {
|
|
10
|
+
return await getStdin.buffer();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return readFile(filename);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const args: {
|
|
17
|
+
'<input>'?: string;
|
|
18
|
+
'<output>'?: string;
|
|
19
|
+
} = neodoc.run(
|
|
20
|
+
`Usage: mca-chunks [OPTIONS] [<input> [<output>]]
|
|
21
|
+
|
|
22
|
+
Lists the chunk coordinates in a Minecraft MCA file, one set of coordinates per
|
|
23
|
+
line. Each line will have "X,Z", such as "-23,14". Both input and output are
|
|
24
|
+
optional. If input is not provided, this reads from stdin. If output is not
|
|
25
|
+
provided, this writes to stdout.
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
-h, --help Show this message.
|
|
29
|
+
`,
|
|
30
|
+
{
|
|
31
|
+
argv: [...process.argv].slice(2),
|
|
32
|
+
laxPlacement: true,
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
readInput(args['<input>'])
|
|
37
|
+
.then((inputBuffer) => {
|
|
38
|
+
if (inputBuffer.length === 0) {
|
|
39
|
+
console.error('No input provided. Use --help for usage.');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const anvilParser = Anvil.fromBuffer(inputBuffer.buffer as ArrayBuffer);
|
|
44
|
+
let chunks = anvilParser.getAllChunks();
|
|
45
|
+
|
|
46
|
+
return chunks.map((chunk) => chunk.chunkKey()).join('\n');
|
|
47
|
+
})
|
|
48
|
+
.then((output: string) => {
|
|
49
|
+
if (args['<output>']) {
|
|
50
|
+
writeFile(args['<output>'], output);
|
|
51
|
+
} else {
|
|
52
|
+
console.log(output);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import debug from 'debug';
|
|
4
|
+
import neodoc from 'neodoc';
|
|
5
|
+
import { Anvil } from '../lib/anvil';
|
|
6
|
+
import { Chunk } from '../lib/chunk';
|
|
7
|
+
import { Sign } from '../block/sign';
|
|
8
|
+
import { readFile } from 'node:fs/promises';
|
|
9
|
+
|
|
10
|
+
const debugLog = debug('mca-find-chunks-with-signs');
|
|
11
|
+
const args: {
|
|
12
|
+
'--verbose'?: boolean;
|
|
13
|
+
MCA_FILE?: string[];
|
|
14
|
+
} = neodoc.run(
|
|
15
|
+
`Usage: mca-trim-chunks-without-signs [OPTIONS] MCA_FILE...
|
|
16
|
+
|
|
17
|
+
Displays chunk X and Z coordinates, separated by a tab, for all chunks in MCA
|
|
18
|
+
files that contain a sign block. Signs need to have at least one letter or
|
|
19
|
+
number on them to differentiate them from naturally generated signs.
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
-h, --help Show this message.
|
|
23
|
+
-v, --verbose Show more information during processing.
|
|
24
|
+
`,
|
|
25
|
+
{
|
|
26
|
+
argv: [...process.argv].slice(2),
|
|
27
|
+
laxPlacement: true,
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (!args.MCA_FILE?.length) {
|
|
32
|
+
console.error('No files specified.');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (const file of args.MCA_FILE) {
|
|
37
|
+
try {
|
|
38
|
+
await processFile(file);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(`Error processing file ${file}: ${e}`);
|
|
41
|
+
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function processFile(filename: string) {
|
|
47
|
+
debugLog(`Reading file: ${filename}`);
|
|
48
|
+
|
|
49
|
+
if (args['--verbose']) {
|
|
50
|
+
console.log(`Reading file: ${filename}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const contents = await readFile(filename);
|
|
54
|
+
const anvil = Anvil.fromBuffer(contents.buffer);
|
|
55
|
+
const chunks = anvil.getAllChunks();
|
|
56
|
+
|
|
57
|
+
for (const chunk of chunks) {
|
|
58
|
+
const chunkKey = chunk.chunkKey() || '';
|
|
59
|
+
|
|
60
|
+
if (processChunk(chunk)) {
|
|
61
|
+
const coords = chunk.chunkCoordinates();
|
|
62
|
+
|
|
63
|
+
if (!coords) {
|
|
64
|
+
throw new Error(`Chunk ${chunkKey} has no coordinates.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(`${coords[0]}\t${coords[1]}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function processChunk(chunk: Chunk): boolean {
|
|
73
|
+
const blockNames = chunk.uniqueBlockNames();
|
|
74
|
+
|
|
75
|
+
for (const blockName of blockNames) {
|
|
76
|
+
if (blockName.match(/^minecraft:.+_sign$/)) {
|
|
77
|
+
debugLog(`Found sign: ${blockName}`);
|
|
78
|
+
|
|
79
|
+
for (const coords of chunk.findBlocksByName(blockName)) {
|
|
80
|
+
const block = chunk.getBlock(coords);
|
|
81
|
+
|
|
82
|
+
if (!(block instanceof Sign)) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Block is supposed to be a sign: ${block.name}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const front = block.frontText();
|
|
89
|
+
const back = block.backText();
|
|
90
|
+
debugLog(`Front: ${JSON.stringify(front)}`);
|
|
91
|
+
debugLog(`Back: ${JSON.stringify(back)}`);
|
|
92
|
+
|
|
93
|
+
if ([...front, ...(back || [])].join('').match(/[a-z0-9]/i)) {
|
|
94
|
+
debugLog(`Found a user-created sign. Preserving chunk.`);
|
|
95
|
+
|
|
96
|
+
if (args['--verbose']) {
|
|
97
|
+
console.log(
|
|
98
|
+
`Found a user-created sign: ${JSON.stringify(front)} and ${JSON.stringify(back)}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import getStdin from 'get-stdin';
|
|
4
|
+
import neodoc from 'neodoc';
|
|
5
|
+
import { Anvil } from '../lib/anvil';
|
|
6
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
7
|
+
|
|
8
|
+
async function readInput(filename: string | undefined) {
|
|
9
|
+
if (!filename || filename === '-') {
|
|
10
|
+
return await getStdin.buffer();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return readFile(filename);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const args: {
|
|
17
|
+
'--chunk-coords'?: string | string[];
|
|
18
|
+
'--compact'?: boolean;
|
|
19
|
+
'--condense'?: boolean;
|
|
20
|
+
'<input>'?: string;
|
|
21
|
+
'<output>'?: string;
|
|
22
|
+
} = neodoc.run(
|
|
23
|
+
`Usage: mca-json [OPTIONS] [<input> [<output>]]
|
|
24
|
+
|
|
25
|
+
Converts a Minecraft MCA file to JSON. Both input and output are optional. If
|
|
26
|
+
input is not provided, this reads from stdin. If output is not provided, this
|
|
27
|
+
writes to stdout.
|
|
28
|
+
|
|
29
|
+
Because MCA files can contain a tremendous amount of information, the tool
|
|
30
|
+
might run out of memory. When that happens, you can dump specific chunks by
|
|
31
|
+
specifying the --chunk-coords option.
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
--chunk-coords=COORDS
|
|
35
|
+
Only write out the chunk at the specified chunk coordinates.
|
|
36
|
+
Chunk coordinates are absolute chunks from the world origin.
|
|
37
|
+
Can be specified multiple times. Coordinates are specified
|
|
38
|
+
as "x,z". Highly recommended to limit the size of the JSON
|
|
39
|
+
that's generated.
|
|
40
|
+
--compact Do not use pretty-printing in the JSON output.
|
|
41
|
+
--condense Condense arrays of bytes, ints, and longs to a single line.
|
|
42
|
+
This significantly cuts down on the size of the generated
|
|
43
|
+
JSON.
|
|
44
|
+
-h, --help Show this message.
|
|
45
|
+
`,
|
|
46
|
+
{
|
|
47
|
+
argv: [...process.argv].slice(2),
|
|
48
|
+
laxPlacement: true,
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
readInput(args['<input>'])
|
|
53
|
+
.then((inputBuffer) => {
|
|
54
|
+
if (inputBuffer.length === 0) {
|
|
55
|
+
console.error('No input provided. Use --help for usage.');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const anvilParser = Anvil.fromBuffer(inputBuffer.buffer as ArrayBuffer);
|
|
60
|
+
let chunks = anvilParser.getAllChunks();
|
|
61
|
+
|
|
62
|
+
if (args['--chunk-coords']) {
|
|
63
|
+
if (!Array.isArray(args['--chunk-coords'])) {
|
|
64
|
+
args['--chunk-coords'] = [args['--chunk-coords']];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const wanted = new Set<string | undefined>(args['--chunk-coords']);
|
|
68
|
+
chunks = chunks.filter((chunk) => wanted.has(chunk.chunkKey()));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let jsonObjects = chunks.map((chunk) => chunk.toObject());
|
|
72
|
+
|
|
73
|
+
if (args['--compact']) {
|
|
74
|
+
return JSON.stringify(jsonObjects);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let content = JSON.stringify(jsonObjects, null, 4);
|
|
78
|
+
|
|
79
|
+
if (args['--condense']) {
|
|
80
|
+
content = content.replace(
|
|
81
|
+
/: \[(\n\s*"?-?\d+"?,?)*\n\s*\]/g,
|
|
82
|
+
(match) => {
|
|
83
|
+
return match.replace(/\n\s*/g, ' ');
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return content;
|
|
89
|
+
})
|
|
90
|
+
.then((output: string) => {
|
|
91
|
+
if (args['<output>']) {
|
|
92
|
+
writeFile(args['<output>'], output);
|
|
93
|
+
} else {
|
|
94
|
+
console.log(output);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import debug from 'debug';
|
|
4
|
+
import neodoc from 'neodoc';
|
|
5
|
+
import { Anvil } from '../lib/anvil';
|
|
6
|
+
import { Chunk } from '../lib/chunk';
|
|
7
|
+
import { Sign } from '../block/sign';
|
|
8
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
9
|
+
|
|
10
|
+
const debugLog = debug('mca-trim-chunks-without-signs');
|
|
11
|
+
const args: {
|
|
12
|
+
'--dry-run'?: boolean;
|
|
13
|
+
'--preserve'?: string[];
|
|
14
|
+
'--verbose'?: boolean;
|
|
15
|
+
'MCA_FILE'?: string[];
|
|
16
|
+
} = neodoc.run(
|
|
17
|
+
`Usage: mca-trim-chunks-without-signs [OPTIONS] MCA_FILE...
|
|
18
|
+
|
|
19
|
+
Removes chunks from MCA files that do not contain a matching sign block. Signs
|
|
20
|
+
need to have at least one letter or number on them to differentiate them from
|
|
21
|
+
naturally generated signs.
|
|
22
|
+
|
|
23
|
+
This does not change the file size. Similar to deleting a file on a hard drive,
|
|
24
|
+
the space is marked as free but not overwritten.
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
-h, --help Show this message.
|
|
28
|
+
-n, --dry-run Do not write changes to the file.
|
|
29
|
+
--preserve CHUNK_COORDINATES...
|
|
30
|
+
Do not remove chunks with these coordinates. Coordinates
|
|
31
|
+
are in the format "x,z". May be specified multiple times.
|
|
32
|
+
-v, --verbose Show more information during processing.
|
|
33
|
+
`,
|
|
34
|
+
{
|
|
35
|
+
argv: [...process.argv].slice(2),
|
|
36
|
+
laxPlacement: true,
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (!args.MCA_FILE?.length) {
|
|
41
|
+
console.error('No files specified.');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!args['--preserve']) {
|
|
46
|
+
args['--preserve'] = [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (args['--preserve'].length) {
|
|
50
|
+
console.log(`Preserving coordinates: ${args['--preserve'].join(' ')}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const file of args.MCA_FILE) {
|
|
54
|
+
try {
|
|
55
|
+
await processFile(file);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error(`Error processing file ${file}: ${e}`);
|
|
58
|
+
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function processFile(filename: string) {
|
|
64
|
+
debugLog(`Reading file: ${filename}`);
|
|
65
|
+
|
|
66
|
+
if (args['--verbose']) {
|
|
67
|
+
console.log(`Reading file: ${filename}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const contents = await readFile(filename);
|
|
71
|
+
const anvil = Anvil.fromBuffer(contents.buffer);
|
|
72
|
+
const chunks = anvil.getAllChunks();
|
|
73
|
+
let changes = 0;
|
|
74
|
+
const preservedCoordinates = new Set(args['--preserve']);
|
|
75
|
+
|
|
76
|
+
for (const chunk of chunks) {
|
|
77
|
+
const chunkKey = chunk.chunkKey() || '';
|
|
78
|
+
|
|
79
|
+
if (preservedCoordinates.has(chunkKey)) {
|
|
80
|
+
debugLog(`Preserving chunk (via command-line): ${chunkKey}`);
|
|
81
|
+
|
|
82
|
+
if (args['--verbose']) {
|
|
83
|
+
console.log(`Preserving chunk (via command-line): ${chunkKey}`);
|
|
84
|
+
}
|
|
85
|
+
} else if (processChunk(chunk)) {
|
|
86
|
+
debugLog(`Preserving chunk (sign detected): ${chunkKey}`);
|
|
87
|
+
|
|
88
|
+
if (args['--verbose']) {
|
|
89
|
+
console.log(`Preserving chunk (sign detected): ${chunkKey}`);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
debugLog(`Removing chunk: ${chunkKey}`);
|
|
93
|
+
anvil.deleteChunk(chunk);
|
|
94
|
+
changes += 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (args['--verbose']) {
|
|
99
|
+
console.log(`Chunks removed: ${changes}/${chunks.length}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (changes) {
|
|
103
|
+
if (args['--dry-run']) {
|
|
104
|
+
console.log(`DRY RUN: Would write changes to file: ${filename}`);
|
|
105
|
+
} else {
|
|
106
|
+
console.log(`Writing changes to file: ${filename}`);
|
|
107
|
+
const modifiedBuffer = Buffer.from(anvil.buffer());
|
|
108
|
+
await writeFile(filename, modifiedBuffer);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function processChunk(chunk: Chunk): boolean {
|
|
114
|
+
const blockNames = chunk.uniqueBlockNames();
|
|
115
|
+
|
|
116
|
+
for (const blockName of blockNames) {
|
|
117
|
+
if (blockName.match(/^minecraft:.+_sign$/)) {
|
|
118
|
+
debugLog(`Found sign: ${blockName}`);
|
|
119
|
+
|
|
120
|
+
for (const coords of chunk.findBlocksByName(blockName)) {
|
|
121
|
+
const block = chunk.getBlock(coords);
|
|
122
|
+
|
|
123
|
+
if (!(block instanceof Sign)) {
|
|
124
|
+
throw new Error(`Block is supposed to be a sign: ${block.name}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const front = block.frontText();
|
|
128
|
+
const back = block.backText();
|
|
129
|
+
debugLog(`Front: ${JSON.stringify(front)}`);
|
|
130
|
+
debugLog(`Back: ${JSON.stringify(back)}`);
|
|
131
|
+
|
|
132
|
+
if ([...front, ...(back || [])].join('').match(/[a-z0-9]/i)) {
|
|
133
|
+
debugLog(`Found a user-created sign. Preserving chunk.`);
|
|
134
|
+
|
|
135
|
+
if (args['--verbose']) {
|
|
136
|
+
console.log(`Found a user-created sign: ${JSON.stringify(front)} and ${JSON.stringify(back)}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return false;
|
|
146
|
+
}
|