@serenityjs/nbt 0.5.0 → 0.5.1-beta-20240915201114
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/dist/index.js +261 -240
- package/package.json +31 -31
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -42,60 +43,63 @@ var import_binarystream9 = require("@serenityjs/binarystream");
|
|
|
42
43
|
|
|
43
44
|
// src/tags/tag.ts
|
|
44
45
|
var import_binarystream = require("@serenityjs/binarystream");
|
|
45
|
-
var NBTTag = class {
|
|
46
|
+
var NBTTag = class NBTTag2 {
|
|
47
|
+
static {
|
|
48
|
+
__name(this, "NBTTag");
|
|
49
|
+
}
|
|
46
50
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
* The type of the tag.
|
|
52
|
+
*/
|
|
49
53
|
static type;
|
|
50
54
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
* The name of the tag.
|
|
56
|
+
*/
|
|
53
57
|
name;
|
|
54
58
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
* The value of the tag.
|
|
60
|
+
*/
|
|
57
61
|
value;
|
|
58
62
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
* Creates a new NBTTag.
|
|
64
|
+
*
|
|
65
|
+
* @param name The name of the tag.
|
|
66
|
+
* @param value The value of the tag.
|
|
67
|
+
* @returns A new NBTTag.
|
|
68
|
+
*/
|
|
65
69
|
constructor(name, value) {
|
|
66
70
|
this.name = name;
|
|
67
71
|
this.value = value;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
* Sets the value of the tag.
|
|
75
|
+
* @param value The value to set.
|
|
76
|
+
*/
|
|
73
77
|
setValue(value) {
|
|
74
78
|
this.value = value;
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
* Returns the value of the tag.
|
|
82
|
+
*
|
|
83
|
+
* @returns The value of the tag.
|
|
84
|
+
*/
|
|
81
85
|
valueOf(_snbt) {
|
|
82
86
|
return this.value;
|
|
83
87
|
}
|
|
84
88
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
* Reads a tag from the stream.
|
|
90
|
+
*
|
|
91
|
+
* @param _stream The stream to read from.
|
|
92
|
+
* @param _type Whether or not to read the type of the tag.
|
|
93
|
+
* @returns The tag that was read.
|
|
94
|
+
*/
|
|
91
95
|
static read(_stream, _varint, _type) {
|
|
92
96
|
throw new Error("NBTTag.read() is not implemented.");
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
* Writes a tag to the stream.
|
|
100
|
+
*
|
|
101
|
+
* @param _stream The stream to write to.
|
|
102
|
+
*/
|
|
99
103
|
static write(_stream, _tag, _varint, _type) {
|
|
100
104
|
throw new Error("NBTTag.write() is not implemented.");
|
|
101
105
|
}
|
|
@@ -112,14 +116,17 @@ var NBTTag = class {
|
|
|
112
116
|
};
|
|
113
117
|
|
|
114
118
|
// src/tags/byte.ts
|
|
115
|
-
var ByteTag = class
|
|
116
|
-
static
|
|
119
|
+
var ByteTag = class ByteTag2 extends NBTTag {
|
|
120
|
+
static {
|
|
121
|
+
__name(this, "ByteTag");
|
|
122
|
+
}
|
|
123
|
+
static type = Tag.Byte;
|
|
117
124
|
valueOf(snbt) {
|
|
118
125
|
return snbt ? this.value + "b" : this.value;
|
|
119
126
|
}
|
|
120
127
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
* Reads a byte tag from the stream.
|
|
129
|
+
*/
|
|
123
130
|
static read(stream, varint = false, type = true) {
|
|
124
131
|
if (type) {
|
|
125
132
|
const type2 = stream.readByte();
|
|
@@ -129,11 +136,11 @@ var ByteTag = class _ByteTag extends NBTTag {
|
|
|
129
136
|
}
|
|
130
137
|
const name = this.readString(stream, varint);
|
|
131
138
|
const value = stream.readByte();
|
|
132
|
-
return new
|
|
139
|
+
return new ByteTag2(name, value);
|
|
133
140
|
}
|
|
134
141
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
* Writes a byte tag to the stream.
|
|
143
|
+
*/
|
|
137
144
|
static write(stream, tag, varint = false) {
|
|
138
145
|
stream.writeByte(this.type);
|
|
139
146
|
this.writeString(tag.name, stream, varint);
|
|
@@ -143,14 +150,17 @@ var ByteTag = class _ByteTag extends NBTTag {
|
|
|
143
150
|
|
|
144
151
|
// src/tags/short.ts
|
|
145
152
|
var import_binarystream2 = require("@serenityjs/binarystream");
|
|
146
|
-
var ShortTag = class
|
|
147
|
-
static
|
|
153
|
+
var ShortTag = class ShortTag2 extends NBTTag {
|
|
154
|
+
static {
|
|
155
|
+
__name(this, "ShortTag");
|
|
156
|
+
}
|
|
157
|
+
static type = Tag.Short;
|
|
148
158
|
valueOf(snbt) {
|
|
149
159
|
return snbt ? this.value + "s" : this.value;
|
|
150
160
|
}
|
|
151
161
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
* Reads a short tag from the stream.
|
|
163
|
+
*/
|
|
154
164
|
static read(stream, varint = false, type = true) {
|
|
155
165
|
if (type) {
|
|
156
166
|
const type2 = stream.readByte();
|
|
@@ -160,11 +170,11 @@ var ShortTag = class _ShortTag extends NBTTag {
|
|
|
160
170
|
}
|
|
161
171
|
const name = this.readString(stream, varint);
|
|
162
172
|
const value = stream.readShort(import_binarystream2.Endianness.Little);
|
|
163
|
-
return new
|
|
173
|
+
return new ShortTag2(name, value);
|
|
164
174
|
}
|
|
165
175
|
/**
|
|
166
|
-
|
|
167
|
-
|
|
176
|
+
* Writes a short tag to the stream.
|
|
177
|
+
*/
|
|
168
178
|
static write(stream, tag, varint = false) {
|
|
169
179
|
stream.writeByte(this.type);
|
|
170
180
|
this.writeString(tag.name, stream, varint);
|
|
@@ -174,14 +184,17 @@ var ShortTag = class _ShortTag extends NBTTag {
|
|
|
174
184
|
|
|
175
185
|
// src/tags/int.ts
|
|
176
186
|
var import_binarystream3 = require("@serenityjs/binarystream");
|
|
177
|
-
var IntTag = class
|
|
178
|
-
static
|
|
187
|
+
var IntTag = class IntTag2 extends NBTTag {
|
|
188
|
+
static {
|
|
189
|
+
__name(this, "IntTag");
|
|
190
|
+
}
|
|
191
|
+
static type = Tag.Int;
|
|
179
192
|
valueOf(snbt) {
|
|
180
193
|
return snbt ? this.value + "i" : this.value;
|
|
181
194
|
}
|
|
182
195
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
196
|
+
* Reads a int tag from the stream.
|
|
197
|
+
*/
|
|
185
198
|
static read(stream, varint = false, type = true) {
|
|
186
199
|
if (type) {
|
|
187
200
|
const type2 = stream.readByte();
|
|
@@ -191,11 +204,11 @@ var IntTag = class _IntTag extends NBTTag {
|
|
|
191
204
|
}
|
|
192
205
|
const name = this.readString(stream, varint);
|
|
193
206
|
const value = varint ? stream.readZigZag() : stream.readInt32(import_binarystream3.Endianness.Little);
|
|
194
|
-
return new
|
|
207
|
+
return new IntTag2(name, value);
|
|
195
208
|
}
|
|
196
209
|
/**
|
|
197
|
-
|
|
198
|
-
|
|
210
|
+
* Writes a int tag to the stream.
|
|
211
|
+
*/
|
|
199
212
|
static write(stream, tag, varint = false) {
|
|
200
213
|
stream.writeByte(this.type);
|
|
201
214
|
this.writeString(tag.name, stream, varint);
|
|
@@ -205,14 +218,17 @@ var IntTag = class _IntTag extends NBTTag {
|
|
|
205
218
|
|
|
206
219
|
// src/tags/long.ts
|
|
207
220
|
var import_binarystream4 = require("@serenityjs/binarystream");
|
|
208
|
-
var LongTag = class
|
|
209
|
-
static
|
|
221
|
+
var LongTag = class LongTag2 extends NBTTag {
|
|
222
|
+
static {
|
|
223
|
+
__name(this, "LongTag");
|
|
224
|
+
}
|
|
225
|
+
static type = Tag.Long;
|
|
210
226
|
valueOf(snbt) {
|
|
211
227
|
return snbt ? this.value + "l" : this.value;
|
|
212
228
|
}
|
|
213
229
|
/**
|
|
214
|
-
|
|
215
|
-
|
|
230
|
+
* Reads a long tag from the stream.
|
|
231
|
+
*/
|
|
216
232
|
static read(stream, varint = false, type = true) {
|
|
217
233
|
if (type) {
|
|
218
234
|
const type2 = stream.readByte();
|
|
@@ -222,11 +238,11 @@ var LongTag = class _LongTag extends NBTTag {
|
|
|
222
238
|
}
|
|
223
239
|
const name = this.readString(stream, varint);
|
|
224
240
|
const value = varint ? stream.readVarLong() : stream.readLong(import_binarystream4.Endianness.Little);
|
|
225
|
-
return new
|
|
241
|
+
return new LongTag2(name, value);
|
|
226
242
|
}
|
|
227
243
|
/**
|
|
228
|
-
|
|
229
|
-
|
|
244
|
+
* Writes a long tag to the stream.
|
|
245
|
+
*/
|
|
230
246
|
static write(stream, tag, varint = false) {
|
|
231
247
|
stream.writeByte(this.type);
|
|
232
248
|
this.writeString(tag.name, stream, varint);
|
|
@@ -236,14 +252,17 @@ var LongTag = class _LongTag extends NBTTag {
|
|
|
236
252
|
|
|
237
253
|
// src/tags/float.ts
|
|
238
254
|
var import_binarystream5 = require("@serenityjs/binarystream");
|
|
239
|
-
var FloatTag = class
|
|
240
|
-
static
|
|
255
|
+
var FloatTag = class FloatTag2 extends NBTTag {
|
|
256
|
+
static {
|
|
257
|
+
__name(this, "FloatTag");
|
|
258
|
+
}
|
|
259
|
+
static type = Tag.Float;
|
|
241
260
|
valueOf(snbt) {
|
|
242
261
|
return snbt ? this.value + "f" : this.value;
|
|
243
262
|
}
|
|
244
263
|
/**
|
|
245
|
-
|
|
246
|
-
|
|
264
|
+
* Reads a float tag from the stream.
|
|
265
|
+
*/
|
|
247
266
|
static read(stream, varint = false, type = true) {
|
|
248
267
|
if (type) {
|
|
249
268
|
const type2 = stream.readByte();
|
|
@@ -253,11 +272,11 @@ var FloatTag = class _FloatTag extends NBTTag {
|
|
|
253
272
|
}
|
|
254
273
|
const name = this.readString(stream, varint);
|
|
255
274
|
const value = stream.readFloat32(import_binarystream5.Endianness.Little);
|
|
256
|
-
return new
|
|
275
|
+
return new FloatTag2(name, value);
|
|
257
276
|
}
|
|
258
277
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
278
|
+
* Writes a float tag to the stream.
|
|
279
|
+
*/
|
|
261
280
|
static write(stream, tag, varint = false) {
|
|
262
281
|
stream.writeByte(this.type);
|
|
263
282
|
this.writeString(tag.name, stream, varint);
|
|
@@ -267,14 +286,17 @@ var FloatTag = class _FloatTag extends NBTTag {
|
|
|
267
286
|
|
|
268
287
|
// src/tags/double.ts
|
|
269
288
|
var import_binarystream6 = require("@serenityjs/binarystream");
|
|
270
|
-
var DoubleTag = class
|
|
271
|
-
static
|
|
289
|
+
var DoubleTag = class DoubleTag2 extends NBTTag {
|
|
290
|
+
static {
|
|
291
|
+
__name(this, "DoubleTag");
|
|
292
|
+
}
|
|
293
|
+
static type = Tag.Double;
|
|
272
294
|
valueOf(snbt) {
|
|
273
295
|
return snbt ? this.value + "d" : this.value;
|
|
274
296
|
}
|
|
275
297
|
/**
|
|
276
|
-
|
|
277
|
-
|
|
298
|
+
* Reads a double tag from the stream.
|
|
299
|
+
*/
|
|
278
300
|
static read(stream, varint = false, type = true) {
|
|
279
301
|
if (type) {
|
|
280
302
|
const type2 = stream.readByte();
|
|
@@ -284,11 +306,11 @@ var DoubleTag = class _DoubleTag extends NBTTag {
|
|
|
284
306
|
}
|
|
285
307
|
const name = this.readString(stream, varint);
|
|
286
308
|
const value = stream.readFloat64(import_binarystream6.Endianness.Little);
|
|
287
|
-
return new
|
|
309
|
+
return new DoubleTag2(name, value);
|
|
288
310
|
}
|
|
289
311
|
/**
|
|
290
|
-
|
|
291
|
-
|
|
312
|
+
* Writes a double tag to the stream.
|
|
313
|
+
*/
|
|
292
314
|
static write(stream, tag, varint = false) {
|
|
293
315
|
stream.writeByte(this.type);
|
|
294
316
|
this.writeString(tag.name, stream, varint);
|
|
@@ -298,11 +320,14 @@ var DoubleTag = class _DoubleTag extends NBTTag {
|
|
|
298
320
|
|
|
299
321
|
// src/tags/byte-list.ts
|
|
300
322
|
var import_binarystream7 = require("@serenityjs/binarystream");
|
|
301
|
-
var ByteListTag = class
|
|
302
|
-
static
|
|
323
|
+
var ByteListTag = class ByteListTag2 extends NBTTag {
|
|
324
|
+
static {
|
|
325
|
+
__name(this, "ByteListTag");
|
|
326
|
+
}
|
|
327
|
+
static type = Tag.ByteList;
|
|
303
328
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
329
|
+
* Reads a byte list tag from the stream.
|
|
330
|
+
*/
|
|
306
331
|
static read(stream, varint = false, type = true) {
|
|
307
332
|
if (type) {
|
|
308
333
|
const type2 = stream.readByte();
|
|
@@ -313,11 +338,11 @@ var ByteListTag = class _ByteListTag extends NBTTag {
|
|
|
313
338
|
const name = this.readString(stream, varint);
|
|
314
339
|
const length = varint ? stream.readVarInt() : stream.readInt32(import_binarystream7.Endianness.Little);
|
|
315
340
|
const value = stream.read(length);
|
|
316
|
-
return new
|
|
341
|
+
return new ByteListTag2(name, value);
|
|
317
342
|
}
|
|
318
343
|
/**
|
|
319
|
-
|
|
320
|
-
|
|
344
|
+
* Writes a byte list tag to the stream.
|
|
345
|
+
*/
|
|
321
346
|
static write(stream, tag, varint = false) {
|
|
322
347
|
stream.writeByte(this.type);
|
|
323
348
|
this.writeString(tag.name, stream, varint);
|
|
@@ -327,11 +352,14 @@ var ByteListTag = class _ByteListTag extends NBTTag {
|
|
|
327
352
|
};
|
|
328
353
|
|
|
329
354
|
// src/tags/string.ts
|
|
330
|
-
var StringTag = class
|
|
331
|
-
static
|
|
355
|
+
var StringTag = class StringTag2 extends NBTTag {
|
|
356
|
+
static {
|
|
357
|
+
__name(this, "StringTag");
|
|
358
|
+
}
|
|
359
|
+
static type = Tag.String;
|
|
332
360
|
/**
|
|
333
|
-
|
|
334
|
-
|
|
361
|
+
* Reads a string tag from the stream.
|
|
362
|
+
*/
|
|
335
363
|
static read(stream, varint = false, type = true) {
|
|
336
364
|
if (type) {
|
|
337
365
|
const type2 = stream.readByte();
|
|
@@ -341,11 +369,11 @@ var StringTag = class _StringTag extends NBTTag {
|
|
|
341
369
|
}
|
|
342
370
|
const name = this.readString(stream, varint);
|
|
343
371
|
const value = this.readString(stream, varint);
|
|
344
|
-
return new
|
|
372
|
+
return new StringTag2(name, value);
|
|
345
373
|
}
|
|
346
374
|
/**
|
|
347
|
-
|
|
348
|
-
|
|
375
|
+
* Writes a string tag to the stream.
|
|
376
|
+
*/
|
|
349
377
|
static write(stream, tag, varint = false) {
|
|
350
378
|
stream.writeByte(this.type);
|
|
351
379
|
this.writeString(tag.name, stream, varint);
|
|
@@ -355,8 +383,11 @@ var StringTag = class _StringTag extends NBTTag {
|
|
|
355
383
|
|
|
356
384
|
// src/tags/list.ts
|
|
357
385
|
var import_binarystream8 = require("@serenityjs/binarystream");
|
|
358
|
-
var ListTag = class
|
|
359
|
-
static
|
|
386
|
+
var ListTag = class ListTag2 extends NBTTag {
|
|
387
|
+
static {
|
|
388
|
+
__name(this, "ListTag");
|
|
389
|
+
}
|
|
390
|
+
static type = Tag.List;
|
|
360
391
|
type;
|
|
361
392
|
constructor(name, value, type) {
|
|
362
393
|
super(name, value);
|
|
@@ -378,20 +409,20 @@ var ListTag = class _ListTag extends NBTTag {
|
|
|
378
409
|
}
|
|
379
410
|
}
|
|
380
411
|
/**
|
|
381
|
-
|
|
382
|
-
|
|
412
|
+
* Pushes a value to the list.
|
|
413
|
+
*/
|
|
383
414
|
push(...value) {
|
|
384
415
|
this.value.push(...value);
|
|
385
416
|
}
|
|
386
417
|
/**
|
|
387
|
-
|
|
388
|
-
|
|
418
|
+
* Removes a value from the list.
|
|
419
|
+
*/
|
|
389
420
|
remove(index) {
|
|
390
421
|
this.value.splice(index, 1);
|
|
391
422
|
}
|
|
392
423
|
/**
|
|
393
|
-
|
|
394
|
-
|
|
424
|
+
* Reads a list tag from the stream.
|
|
425
|
+
*/
|
|
395
426
|
static read(stream, varint = false, type = true) {
|
|
396
427
|
if (type) {
|
|
397
428
|
const type2 = stream.readByte();
|
|
@@ -406,50 +437,42 @@ var ListTag = class _ListTag extends NBTTag {
|
|
|
406
437
|
for (let index = 0; index < length; index++) {
|
|
407
438
|
switch (tag) {
|
|
408
439
|
default: {
|
|
409
|
-
throw new Error(
|
|
410
|
-
`Tag type '${Tag[tag]}' has not been implemented for ListTag. ${stream.offset}`
|
|
411
|
-
);
|
|
440
|
+
throw new Error(`Tag type '${Tag[tag]}' has not been implemented for ListTag. ${stream.offset}`);
|
|
412
441
|
}
|
|
413
|
-
case
|
|
442
|
+
case Tag.Byte: {
|
|
414
443
|
values.push(new ByteTag("", stream.readByte()));
|
|
415
444
|
break;
|
|
416
445
|
}
|
|
417
|
-
case
|
|
446
|
+
case Tag.Short: {
|
|
418
447
|
values.push(new ShortTag("", stream.readInt16(import_binarystream8.Endianness.Little)));
|
|
419
448
|
break;
|
|
420
449
|
}
|
|
421
|
-
case
|
|
422
|
-
values.push(
|
|
423
|
-
varint ? new IntTag("", stream.readVarInt()) : new IntTag("", stream.readInt32(import_binarystream8.Endianness.Little))
|
|
424
|
-
);
|
|
450
|
+
case Tag.Int: {
|
|
451
|
+
values.push(varint ? new IntTag("", stream.readVarInt()) : new IntTag("", stream.readInt32(import_binarystream8.Endianness.Little)));
|
|
425
452
|
break;
|
|
426
453
|
}
|
|
427
|
-
case
|
|
428
|
-
values.push(
|
|
429
|
-
varint ? new LongTag("", stream.readVarLong()) : new LongTag("", stream.readLong(import_binarystream8.Endianness.Little))
|
|
430
|
-
);
|
|
454
|
+
case Tag.Long: {
|
|
455
|
+
values.push(varint ? new LongTag("", stream.readVarLong()) : new LongTag("", stream.readLong(import_binarystream8.Endianness.Little)));
|
|
431
456
|
break;
|
|
432
457
|
}
|
|
433
|
-
case
|
|
458
|
+
case Tag.Float: {
|
|
434
459
|
values.push(new FloatTag("", stream.readFloat32(import_binarystream8.Endianness.Little)));
|
|
435
460
|
break;
|
|
436
461
|
}
|
|
437
|
-
case
|
|
462
|
+
case Tag.Double: {
|
|
438
463
|
values.push(new DoubleTag("", stream.readFloat64(import_binarystream8.Endianness.Little)));
|
|
439
464
|
break;
|
|
440
465
|
}
|
|
441
|
-
case
|
|
466
|
+
case Tag.String: {
|
|
442
467
|
values.push(new StringTag("", this.readString(stream, varint)));
|
|
443
468
|
break;
|
|
444
469
|
}
|
|
445
|
-
case
|
|
470
|
+
case Tag.Compound: {
|
|
446
471
|
const value = {};
|
|
447
472
|
do {
|
|
448
473
|
const type2 = stream.readByte();
|
|
449
|
-
if (type2 ===
|
|
450
|
-
const reader = NBT_TAGS.find(
|
|
451
|
-
(tag2) => tag2.type === type2
|
|
452
|
-
);
|
|
474
|
+
if (type2 === Tag.End) break;
|
|
475
|
+
const reader = NBT_TAGS.find((tag2) => tag2.type === type2);
|
|
453
476
|
if (!reader) {
|
|
454
477
|
throw new Error(`Unknown tag type: ${type2} at ${stream.offset}`);
|
|
455
478
|
}
|
|
@@ -460,11 +483,11 @@ var ListTag = class _ListTag extends NBTTag {
|
|
|
460
483
|
}
|
|
461
484
|
}
|
|
462
485
|
}
|
|
463
|
-
return new
|
|
486
|
+
return new ListTag2(name, values, tag);
|
|
464
487
|
}
|
|
465
488
|
/**
|
|
466
|
-
|
|
467
|
-
|
|
489
|
+
* Writes a list tag to the stream.
|
|
490
|
+
*/
|
|
468
491
|
static write(stream, tag, varint = false) {
|
|
469
492
|
stream.writeByte(this.type);
|
|
470
493
|
this.writeString(tag.name, stream, varint);
|
|
@@ -473,50 +496,46 @@ var ListTag = class _ListTag extends NBTTag {
|
|
|
473
496
|
for (const value of tag.value) {
|
|
474
497
|
switch (tag.type) {
|
|
475
498
|
default: {
|
|
476
|
-
throw new Error(
|
|
477
|
-
`Tag type '${Tag[tag.type]}' has not been implemented for ListTag.`
|
|
478
|
-
);
|
|
499
|
+
throw new Error(`Tag type '${Tag[tag.type]}' has not been implemented for ListTag.`);
|
|
479
500
|
}
|
|
480
|
-
case
|
|
501
|
+
case Tag.Byte: {
|
|
481
502
|
stream.writeByte(value.value);
|
|
482
503
|
break;
|
|
483
504
|
}
|
|
484
|
-
case
|
|
505
|
+
case Tag.Short: {
|
|
485
506
|
stream.writeInt16(value.value, import_binarystream8.Endianness.Little);
|
|
486
507
|
break;
|
|
487
508
|
}
|
|
488
|
-
case
|
|
509
|
+
case Tag.Int: {
|
|
489
510
|
varint ? stream.writeVarInt(value.value) : stream.writeInt32(value.value, import_binarystream8.Endianness.Little);
|
|
490
511
|
break;
|
|
491
512
|
}
|
|
492
|
-
case
|
|
513
|
+
case Tag.Long: {
|
|
493
514
|
varint ? stream.writeVarLong(value.value) : stream.writeLong(value.value, import_binarystream8.Endianness.Little);
|
|
494
515
|
break;
|
|
495
516
|
}
|
|
496
|
-
case
|
|
517
|
+
case Tag.Float: {
|
|
497
518
|
stream.writeFloat32(value.value, import_binarystream8.Endianness.Little);
|
|
498
519
|
break;
|
|
499
520
|
}
|
|
500
|
-
case
|
|
521
|
+
case Tag.Double: {
|
|
501
522
|
stream.writeFloat64(value.value, import_binarystream8.Endianness.Little);
|
|
502
523
|
break;
|
|
503
524
|
}
|
|
504
|
-
case
|
|
525
|
+
case Tag.String: {
|
|
505
526
|
this.writeString(value.value, stream, varint);
|
|
506
527
|
break;
|
|
507
528
|
}
|
|
508
|
-
case
|
|
529
|
+
case Tag.Compound: {
|
|
509
530
|
const compound = value;
|
|
510
531
|
for (const tag2 of compound.getTags()) {
|
|
511
|
-
const writter = NBT_TAGS.find(
|
|
512
|
-
(x) => tag2 instanceof x
|
|
513
|
-
);
|
|
532
|
+
const writter = NBT_TAGS.find((x) => tag2 instanceof x);
|
|
514
533
|
if (!writter) {
|
|
515
534
|
throw new Error(`Unknown tag type for: ${tag2.name}`);
|
|
516
535
|
}
|
|
517
536
|
writter.write(stream, tag2, varint);
|
|
518
537
|
}
|
|
519
|
-
stream.writeByte(
|
|
538
|
+
stream.writeByte(Tag.End);
|
|
520
539
|
break;
|
|
521
540
|
}
|
|
522
541
|
}
|
|
@@ -525,23 +544,26 @@ var ListTag = class _ListTag extends NBTTag {
|
|
|
525
544
|
};
|
|
526
545
|
|
|
527
546
|
// src/tags/compound.ts
|
|
528
|
-
var CompoundTag = class
|
|
529
|
-
static
|
|
547
|
+
var CompoundTag = class CompoundTag2 extends NBTTag {
|
|
548
|
+
static {
|
|
549
|
+
__name(this, "CompoundTag");
|
|
550
|
+
}
|
|
551
|
+
static type = Tag.Compound;
|
|
530
552
|
/**
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
553
|
+
* Creates a new compound tag.
|
|
554
|
+
* @param name The name of the tag.
|
|
555
|
+
* @param value The value of the tag.
|
|
556
|
+
*/
|
|
535
557
|
constructor(name, value) {
|
|
536
558
|
super(name ?? String(), value ?? {});
|
|
537
559
|
}
|
|
538
560
|
/**
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
561
|
+
* Creates a new compound tag.
|
|
562
|
+
*
|
|
563
|
+
* @param name The name of the tag.
|
|
564
|
+
* @param value The value of the tag.
|
|
565
|
+
* @returns A new compound tag.
|
|
566
|
+
*/
|
|
545
567
|
addTag(...tags) {
|
|
546
568
|
for (const tag of tags) {
|
|
547
569
|
this.value[tag.name] = tag;
|
|
@@ -549,54 +571,54 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
549
571
|
return this;
|
|
550
572
|
}
|
|
551
573
|
/**
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
574
|
+
* Removes a tag from the compound tag.
|
|
575
|
+
*
|
|
576
|
+
* @param name The name of the tag to remove.
|
|
577
|
+
*/
|
|
556
578
|
removeTag(name) {
|
|
557
579
|
delete this.value[name];
|
|
558
580
|
return this;
|
|
559
581
|
}
|
|
560
582
|
/**
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
583
|
+
* Returns a tag from the compound tag.
|
|
584
|
+
*
|
|
585
|
+
* @param name The name of the tag to get.
|
|
586
|
+
* @returns The tag that was found.
|
|
587
|
+
*/
|
|
566
588
|
getTag(name) {
|
|
567
589
|
return this.value[name];
|
|
568
590
|
}
|
|
569
591
|
/**
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
592
|
+
* Returns a tag from the compound tag.
|
|
593
|
+
*
|
|
594
|
+
* @param name The name of the tag to get.
|
|
595
|
+
* @returns The tag that was found.
|
|
596
|
+
*/
|
|
575
597
|
hasTag(name) {
|
|
576
598
|
return name in this.value;
|
|
577
599
|
}
|
|
578
600
|
/**
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
601
|
+
* Sets a tag in the compound tag.
|
|
602
|
+
*
|
|
603
|
+
* @param name The name of the tag to set.
|
|
604
|
+
* @param tag The tag to set.
|
|
605
|
+
*/
|
|
584
606
|
setTag(name, tag) {
|
|
585
607
|
this.value[name] = tag;
|
|
586
608
|
return this;
|
|
587
609
|
}
|
|
588
610
|
/**
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
611
|
+
* Returns all the tags in the compound tag.
|
|
612
|
+
*
|
|
613
|
+
* @returns All the tags in the compound tag.
|
|
614
|
+
*/
|
|
593
615
|
getTags() {
|
|
594
616
|
return Object.values(this.value);
|
|
595
617
|
}
|
|
596
618
|
/**
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
619
|
+
* Returns all the names of the tags in the compound tag.
|
|
620
|
+
* @returns All the names of the tags in the compound tag.
|
|
621
|
+
*/
|
|
600
622
|
clear() {
|
|
601
623
|
for (const key in this.value) {
|
|
602
624
|
delete this.value[key];
|
|
@@ -604,90 +626,90 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
604
626
|
return this;
|
|
605
627
|
}
|
|
606
628
|
/**
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
629
|
+
* Creates a new byte tag on the compound.
|
|
630
|
+
* @param name The name of the tag.
|
|
631
|
+
* @param value The value of the tag.
|
|
632
|
+
* @returns The created tag.
|
|
633
|
+
*/
|
|
612
634
|
createByteTag(name, value) {
|
|
613
635
|
const tag = new ByteTag(name, value);
|
|
614
636
|
this.addTag(tag);
|
|
615
637
|
return tag;
|
|
616
638
|
}
|
|
617
639
|
/**
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
640
|
+
* Creates a new short tag on the compound.
|
|
641
|
+
* @param name The name of the tag.
|
|
642
|
+
* @param value The value of the tag.
|
|
643
|
+
* @returns The created tag.
|
|
644
|
+
*/
|
|
623
645
|
createShortTag(name, value) {
|
|
624
646
|
const tag = new ShortTag(name, value);
|
|
625
647
|
this.addTag(tag);
|
|
626
648
|
return tag;
|
|
627
649
|
}
|
|
628
650
|
/**
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
651
|
+
* Creates a new int tag on the compound.
|
|
652
|
+
* @param name The name of the tag.
|
|
653
|
+
* @param value The value of the tag.
|
|
654
|
+
* @returns The created tag.
|
|
655
|
+
*/
|
|
634
656
|
createIntTag(name, value) {
|
|
635
657
|
const tag = new IntTag(name, value);
|
|
636
658
|
this.addTag(tag);
|
|
637
659
|
return tag;
|
|
638
660
|
}
|
|
639
661
|
/**
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
662
|
+
* Creates a new long tag on the compound.
|
|
663
|
+
* @param name The name of the tag.
|
|
664
|
+
* @param value The value of the tag.
|
|
665
|
+
* @returns The created tag.
|
|
666
|
+
*/
|
|
645
667
|
createLongTag(name, value) {
|
|
646
668
|
const tag = new LongTag(name, value);
|
|
647
669
|
this.addTag(tag);
|
|
648
670
|
return tag;
|
|
649
671
|
}
|
|
650
672
|
/**
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
673
|
+
* Creates a new float tag on the compound.
|
|
674
|
+
* @param name The name of the tag.
|
|
675
|
+
* @param value The value of the tag.
|
|
676
|
+
* @returns The created tag.
|
|
677
|
+
*/
|
|
656
678
|
createFloatTag(name, value) {
|
|
657
679
|
const tag = new FloatTag(name, value);
|
|
658
680
|
this.addTag(tag);
|
|
659
681
|
return tag;
|
|
660
682
|
}
|
|
661
683
|
/**
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
684
|
+
* Creates a new double tag on the compound.
|
|
685
|
+
* @param name The name of the tag.
|
|
686
|
+
* @param value The value of the tag.
|
|
687
|
+
* @returns The created tag.
|
|
688
|
+
*/
|
|
667
689
|
createDoubleTag(name, value) {
|
|
668
690
|
const tag = new DoubleTag(name, value);
|
|
669
691
|
this.addTag(tag);
|
|
670
692
|
return tag;
|
|
671
693
|
}
|
|
672
694
|
/**
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
695
|
+
* Creates a new string tag on the compound.
|
|
696
|
+
* @param name The name of the tag.
|
|
697
|
+
* @param value The value of the tag.
|
|
698
|
+
* @returns The created tag.
|
|
699
|
+
*/
|
|
678
700
|
createStringTag(name, value) {
|
|
679
701
|
const tag = new StringTag(name, value);
|
|
680
702
|
this.addTag(tag);
|
|
681
703
|
return tag;
|
|
682
704
|
}
|
|
683
705
|
/**
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
706
|
+
* Creates a new compound tag on the compound.
|
|
707
|
+
* @param name The name of the tag.
|
|
708
|
+
* @param value The value of the tag.
|
|
709
|
+
* @returns The created tag.
|
|
710
|
+
*/
|
|
689
711
|
createCompoundTag(name, value) {
|
|
690
|
-
const tag = new
|
|
712
|
+
const tag = new CompoundTag2(name, value);
|
|
691
713
|
this.addTag(tag);
|
|
692
714
|
return tag;
|
|
693
715
|
}
|
|
@@ -700,11 +722,7 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
700
722
|
if (snbt) {
|
|
701
723
|
const value = {};
|
|
702
724
|
for (const key in this.value) {
|
|
703
|
-
value[key] = this.value[key] instanceof
|
|
704
|
-
this.value[key].valueOf(
|
|
705
|
-
true
|
|
706
|
-
)
|
|
707
|
-
) : this.value[key].valueOf(true);
|
|
725
|
+
value[key] = this.value[key] instanceof CompoundTag2 ? JSON.parse(this.value[key].valueOf(true)) : this.value[key].valueOf(true);
|
|
708
726
|
}
|
|
709
727
|
return JSON.stringify(value);
|
|
710
728
|
} else {
|
|
@@ -716,8 +734,8 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
716
734
|
}
|
|
717
735
|
}
|
|
718
736
|
/**
|
|
719
|
-
|
|
720
|
-
|
|
737
|
+
* Reads a compound tag from the stream.
|
|
738
|
+
*/
|
|
721
739
|
static read(stream, varint = false, type = true) {
|
|
722
740
|
if (type) {
|
|
723
741
|
const type2 = stream.readByte();
|
|
@@ -729,7 +747,7 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
729
747
|
const value = {};
|
|
730
748
|
do {
|
|
731
749
|
const type2 = stream.readByte();
|
|
732
|
-
if (type2 ===
|
|
750
|
+
if (type2 === Tag.End) break;
|
|
733
751
|
const reader = NBT_TAGS.find((tag) => tag.type === type2);
|
|
734
752
|
if (!reader) {
|
|
735
753
|
throw new Error(`Unknown tag type: ${type2} at ${stream.offset}`);
|
|
@@ -737,11 +755,11 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
737
755
|
const read = reader.read(stream, varint, false);
|
|
738
756
|
value[read.name] = read;
|
|
739
757
|
} while (!stream.cursorAtEnd());
|
|
740
|
-
return new
|
|
758
|
+
return new CompoundTag2(name, value);
|
|
741
759
|
}
|
|
742
760
|
/**
|
|
743
|
-
|
|
744
|
-
|
|
761
|
+
* Writes a compound tag to the stream.
|
|
762
|
+
*/
|
|
745
763
|
static write(stream, root, varint = false, type = true) {
|
|
746
764
|
if (type === true) {
|
|
747
765
|
stream.writeByte(this.type);
|
|
@@ -754,7 +772,7 @@ var CompoundTag = class _CompoundTag extends NBTTag {
|
|
|
754
772
|
}
|
|
755
773
|
writter.write(stream, tag, varint);
|
|
756
774
|
}
|
|
757
|
-
stream.writeByte(
|
|
775
|
+
stream.writeByte(Tag.End);
|
|
758
776
|
}
|
|
759
777
|
};
|
|
760
778
|
|
|
@@ -773,7 +791,8 @@ var NBT_TAGS = [
|
|
|
773
791
|
];
|
|
774
792
|
|
|
775
793
|
// src/named-binary-tag.ts
|
|
776
|
-
var Tag
|
|
794
|
+
var Tag;
|
|
795
|
+
(function(Tag2) {
|
|
777
796
|
Tag2[Tag2["End"] = 0] = "End";
|
|
778
797
|
Tag2[Tag2["Byte"] = 1] = "Byte";
|
|
779
798
|
Tag2[Tag2["Short"] = 2] = "Short";
|
|
@@ -787,9 +806,11 @@ var Tag = /* @__PURE__ */ ((Tag2) => {
|
|
|
787
806
|
Tag2[Tag2["Compound"] = 10] = "Compound";
|
|
788
807
|
Tag2[Tag2["IntList"] = 11] = "IntList";
|
|
789
808
|
Tag2[Tag2["LongList"] = 12] = "LongList";
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
809
|
+
})(Tag || (Tag = {}));
|
|
810
|
+
var NamedBinaryTag = class NamedBinaryTag2 extends import_binarystream9.BinaryStream {
|
|
811
|
+
static {
|
|
812
|
+
__name(this, "NamedBinaryTag");
|
|
813
|
+
}
|
|
793
814
|
varint;
|
|
794
815
|
length;
|
|
795
816
|
constructor(buffer, varint = false) {
|
|
@@ -814,30 +835,30 @@ var NamedBinaryTag = class extends import_binarystream9.BinaryStream {
|
|
|
814
835
|
this.writeBuffer(buffer);
|
|
815
836
|
}
|
|
816
837
|
/**
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
838
|
+
* Reads a tag from the stream.
|
|
839
|
+
* @returns The tag that was read.
|
|
840
|
+
*/
|
|
820
841
|
readByteTag() {
|
|
821
842
|
return ByteTag.read(this);
|
|
822
843
|
}
|
|
823
844
|
/**
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
845
|
+
* Writes a tag to the stream.
|
|
846
|
+
* @param tag The tag to write.
|
|
847
|
+
*/
|
|
827
848
|
writeByteTag(tag) {
|
|
828
849
|
ByteTag.write(this, tag);
|
|
829
850
|
}
|
|
830
851
|
/**
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
852
|
+
* Reads a tag from the stream.
|
|
853
|
+
* @returns The tag that was read.
|
|
854
|
+
*/
|
|
834
855
|
readShortTag() {
|
|
835
856
|
return ShortTag.read(this);
|
|
836
857
|
}
|
|
837
858
|
/**
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
859
|
+
* Writes a tag to the stream.
|
|
860
|
+
* @param tag The tag to write.
|
|
861
|
+
*/
|
|
841
862
|
writeShortTag(tag) {
|
|
842
863
|
ShortTag.write(this, tag);
|
|
843
864
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"name": "@serenityjs/nbt",
|
|
3
|
+
"version": "0.5.1-beta-20240915201114",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"repository": "https://github.com/SerenityJS/serenity",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"watch": "tsup --watch",
|
|
13
|
+
"lint": "eslint src/",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"test": "jest"
|
|
16
|
+
},
|
|
17
|
+
"jest": {
|
|
18
|
+
"preset": "@serenityjs/jest-presets/jest/node"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@serenityjs/eslint-config": "0.5.1-beta-20240915201114",
|
|
22
|
+
"@serenityjs/jest-presets": "0.5.1-beta-20240915201114",
|
|
23
|
+
"@serenityjs/typescript-config": "0.5.1-beta-20240915201114",
|
|
24
|
+
"@types/jest": "^29.5.12",
|
|
25
|
+
"@types/node": "^20.11.24",
|
|
26
|
+
"jest": "^29.7.0",
|
|
27
|
+
"tsup": "^8.0.2",
|
|
28
|
+
"typescript": "^5.4.2"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@serenityjs/binarystream": "^2.6.6"
|
|
32
|
+
}
|
|
33
33
|
}
|