@spyglassmc/nbt 0.3.31 → 0.3.33
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/lib/parser/collection.js +5 -9
- package/lib/parser/primitive.d.ts +2 -4
- package/lib/parser/primitive.js +10 -2
- package/lib/util.d.ts +2 -0
- package/lib/util.js +5 -0
- package/package.json +4 -4
package/lib/parser/collection.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import { localize } from '@spyglassmc/locales';
|
|
3
|
-
import { localizeTag } from '../util.js';
|
|
3
|
+
import { localizeTag, newSyntax } from '../util.js';
|
|
4
4
|
import { entry } from './entry.js';
|
|
5
5
|
import { primitive } from './primitive.js';
|
|
6
6
|
export const list = (src, ctx) => {
|
|
@@ -15,14 +15,10 @@ export const list = (src, ctx) => {
|
|
|
15
15
|
ans.type = 'nbt:list';
|
|
16
16
|
ans.valueType = ans.children[0]?.value?.type;
|
|
17
17
|
// Check if every element is of the same type.
|
|
18
|
-
if (ans.valueType) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (const { value } of ans.children) {
|
|
23
|
-
if (value && value.type !== ans.valueType) {
|
|
24
|
-
ctx.err.report(localize('expected-got', localizeTag(ans.valueType), localizeTag(value.type)), value);
|
|
25
|
-
}
|
|
18
|
+
if (ans.valueType && !newSyntax(ctx)) {
|
|
19
|
+
for (const { value } of ans.children) {
|
|
20
|
+
if (value && value.type !== ans.valueType) {
|
|
21
|
+
ctx.err.report(localize('expected-got', localizeTag(ans.valueType), localizeTag(value.type)), value);
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
|
-
import type { NbtPrimitiveNode } from '../node/index.js';
|
|
3
|
-
export declare const string: core.InfallibleParser<
|
|
4
|
-
type: "nbt:string";
|
|
5
|
-
}>;
|
|
2
|
+
import type { NbtPrimitiveNode, NbtStringNode } from '../node/index.js';
|
|
3
|
+
export declare const string: core.InfallibleParser<NbtStringNode>;
|
|
6
4
|
export declare const primitive: core.InfallibleParser<NbtPrimitiveNode>;
|
|
7
5
|
//# sourceMappingURL=primitive.d.ts.map
|
package/lib/parser/primitive.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import { localize } from '@spyglassmc/locales';
|
|
3
|
-
import { localizeTag } from '../util.js';
|
|
3
|
+
import { localizeTag, newSyntax } from '../util.js';
|
|
4
4
|
const FloatMaximum = (2 - 2 ** -23) * 2 ** 127;
|
|
5
5
|
const NumeralPatterns = [
|
|
6
6
|
{
|
|
@@ -62,7 +62,15 @@ const NumeralPatterns = [
|
|
|
62
62
|
{ pattern: /^true$/i, type: 'nbt:byte', value: 1, group: 0 /* Group.Boolean */ },
|
|
63
63
|
{ pattern: /^false$/i, type: 'nbt:byte', value: 0, group: 0 /* Group.Boolean */ },
|
|
64
64
|
];
|
|
65
|
-
|
|
65
|
+
const NbtStringOptions = {
|
|
66
|
+
escapable: { characters: ['b', 'f', 'n', 'r', 's', 't'], unicode: true },
|
|
67
|
+
quotes: ['"', "'"],
|
|
68
|
+
unquotable: core.BrigadierUnquotableOption,
|
|
69
|
+
};
|
|
70
|
+
export const string = (src, ctx) => {
|
|
71
|
+
const options = newSyntax(ctx) ? NbtStringOptions : core.BrigadierStringOptions;
|
|
72
|
+
return core.setType('nbt:string', core.string(options))(src, ctx);
|
|
73
|
+
};
|
|
66
74
|
export const primitive = (src, ctx) => {
|
|
67
75
|
if (core.Source.isBrigadierQuote(src.peek())) {
|
|
68
76
|
return string(src, ctx);
|
package/lib/util.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ParserContext } from '@spyglassmc/core';
|
|
1
2
|
import type { NbtNode } from './node/index.js';
|
|
2
3
|
export declare function localizeTag(type: NbtNode['type']): string;
|
|
4
|
+
export declare function newSyntax(ctx: ParserContext): boolean;
|
|
3
5
|
//# sourceMappingURL=util.d.ts.map
|
package/lib/util.js
CHANGED
|
@@ -2,4 +2,9 @@ import { localize } from '@spyglassmc/locales';
|
|
|
2
2
|
export function localizeTag(type) {
|
|
3
3
|
return localize(`nbt.node.${type.replace(/^nbt:/, '')}`);
|
|
4
4
|
}
|
|
5
|
+
export function newSyntax(ctx) {
|
|
6
|
+
// TODO: don't have this inline java-edition version check
|
|
7
|
+
const release = ctx.project['loadedVersion'];
|
|
8
|
+
return !release || Number(release.slice(2)) >= Number('1.21.5'.slice(2));
|
|
9
|
+
}
|
|
5
10
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/nbt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@spyglassmc/core": "0.4.
|
|
29
|
-
"@spyglassmc/locales": "0.3.
|
|
30
|
-
"@spyglassmc/mcdoc": "0.3.
|
|
28
|
+
"@spyglassmc/core": "0.4.28",
|
|
29
|
+
"@spyglassmc/locales": "0.3.14",
|
|
30
|
+
"@spyglassmc/mcdoc": "0.3.32"
|
|
31
31
|
}
|
|
32
32
|
}
|