Skip to content

Commit e668a03

Browse files
committed
SNBT changes
1 parent cce054e commit e668a03

File tree

2 files changed

+53743
-53665
lines changed

2 files changed

+53743
-53665
lines changed

src/util/SNBT.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ export class SNBTTag {
359359
const TYPE_BYTE = getFormatter('type_byte')
360360
const TYPE_SHORT = getFormatter('type_short')
361361
const TYPE_INT = getFormatter('type_int_list')
362+
const SNYTAX = getFormatter('syntax')
363+
const COMPOUND_NAME_FORMATTER = getFormatter('compound_name')
362364
switch (this.type) {
363365
case SNBTTagType.END:
364366
throw new Error('Cannot convert END tag to string')
@@ -394,26 +396,28 @@ export class SNBTTag {
394396
'\n' +
395397
entries
396398
.map(([key, value]) =>
397-
`${key}:${value.toHighlightString(highlighters)}`
399+
`${COMPOUND_NAME_FORMATTER(key)}${SNYTAX(
400+
':'
401+
)}${value.toHighlightString(highlighters)}`
398402
.split('\n')
399403
.map((_) => ` ${_}`)
400404
.join('\n')
401405
)
402-
.join(',\n') +
406+
.join(SNYTAX(',') + '\n') +
403407
'\n' +
404408
BRACKET_FORMATTER('}')
405409
)
406410
case SNBTTagType.INT_ARRAY: {
407411
let items = this.value.map((item) =>
408412
item.toHighlightString(highlighters)
409413
)
410-
let combined = items.join(',')
414+
let combined = items.join(SNYTAX(','))
411415
let isIndented = items.indexOf('\n') > -1
412-
if (combined.length > 16) isIndented = true
416+
if (this.value.join(',').length > 16) isIndented = true
413417
if (isIndented) {
414418
return `${ARRAY_FORMATTER('[')}${TYPE_INT('I')};\n${items
415419
.map((_) => ` ${_}`)
416-
.join(',\n')}\n${ARRAY_FORMATTER(']')}`
420+
.join(SNYTAX(',') + '\n')}\n${ARRAY_FORMATTER(']')}`
417421
}
418422
return (
419423
`${ARRAY_FORMATTER('[')}${TYPE_INT('I')};` +
@@ -437,7 +441,7 @@ export class SNBTTag {
437441
.map((i) => ` ${i}`)
438442
.join('\n')
439443
)
440-
.join(',\n')}\n${ARRAY_FORMATTER(']')}`
444+
.join(SNYTAX(',') + '\n')}\n${ARRAY_FORMATTER(']')}`
441445
}
442446
return ARRAY_FORMATTER('[') + combined + ARRAY_FORMATTER(']')
443447
}

tests/SNBT.nnb

Lines changed: 53733 additions & 53659 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)