@spyglassmc/java-edition 0.3.8 → 0.3.10

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.
Files changed (35) hide show
  1. package/lib/binder/index.d.ts +11 -9
  2. package/lib/binder/index.js +149 -150
  3. package/lib/common/index.js +6 -9
  4. package/lib/dependency/common.d.ts +5 -0
  5. package/lib/dependency/common.js +8 -0
  6. package/lib/dependency/index.js +7 -17
  7. package/lib/dependency/mcmeta.d.ts +6 -12
  8. package/lib/dependency/mcmeta.js +21 -38
  9. package/lib/index.d.ts +1 -0
  10. package/lib/index.js +74 -32
  11. package/lib/json/checker/index.d.ts +3 -10
  12. package/lib/json/checker/index.js +36 -244
  13. package/lib/json/index.d.ts +0 -1
  14. package/lib/json/index.js +0 -3
  15. package/lib/mcfunction/checker/index.d.ts +0 -2
  16. package/lib/mcfunction/checker/index.js +254 -183
  17. package/lib/mcfunction/common/index.d.ts +4 -2
  18. package/lib/mcfunction/common/index.js +56 -52
  19. package/lib/mcfunction/completer/argument.js +112 -57
  20. package/lib/mcfunction/index.d.ts +3 -2
  21. package/lib/mcfunction/index.js +18 -19
  22. package/lib/mcfunction/inlayHintProvider.js +2 -3
  23. package/lib/mcfunction/mcdocAttributes.d.ts +4 -0
  24. package/lib/mcfunction/mcdocAttributes.js +74 -0
  25. package/lib/mcfunction/node/argument.d.ts +115 -12
  26. package/lib/mcfunction/node/argument.js +131 -63
  27. package/lib/mcfunction/parser/argument.d.ts +14 -4
  28. package/lib/mcfunction/parser/argument.js +380 -212
  29. package/lib/mcfunction/signatureHelpProvider.d.ts +2 -1
  30. package/lib/mcfunction/signatureHelpProvider.js +10 -18
  31. package/lib/mcfunction/tree/argument.d.ts +68 -1
  32. package/lib/mcfunction/tree/patch.js +279 -77
  33. package/lib/mcfunction/tree/patchValidator.d.ts +7 -0
  34. package/lib/mcfunction/tree/patchValidator.js +25 -0
  35. package/package.json +8 -9
@@ -116,44 +116,38 @@ export function getPatch(release) {
116
116
  },
117
117
  data: {
118
118
  children: {
119
- get: DataSource,
120
- merge: DataTarget,
121
- modify: {
122
- children: {
123
- block: {
124
- children: {
125
- targetPos: {
126
- children: {
127
- targetPath: DataModifyOperation,
128
- },
129
- },
130
- },
131
- },
132
- entity: {
119
+ get: getDataPatch('target', 'path'),
120
+ merge: getDataPatch('target', 'nbt', {
121
+ isMerge: true,
122
+ vaultAccessType: 1 /* SymbolAccessType.Write */,
123
+ }),
124
+ modify: getDataPatch('target', 'targetPath', {
125
+ nbtAccessType: 1 /* SymbolAccessType.Write */,
126
+ vaultAccessType: 1 /* SymbolAccessType.Write */,
127
+ children: (type) => ({
128
+ append: getDataModifySource(type, {
129
+ isListIndex: true,
130
+ }),
131
+ insert: {
133
132
  children: {
134
- target: {
135
- children: {
136
- targetPath: DataModifyOperation,
137
- },
138
- },
139
- },
140
- },
141
- storage: {
142
- children: {
143
- target: {
144
- properties: {
145
- category: 'storage',
146
- accessType: 1 /* SymbolAccessType.Write */,
147
- },
148
- children: {
149
- targetPath: DataModifyOperation,
150
- },
151
- },
133
+ index: getDataModifySource(type, {
134
+ isListIndex: true,
135
+ }),
152
136
  },
153
137
  },
154
- },
155
- },
156
- remove: DataSource,
138
+ merge: getDataModifySource(type, {
139
+ isMerge: true,
140
+ }),
141
+ prepend: getDataModifySource(type, {
142
+ isListIndex: true,
143
+ }),
144
+ set: getDataModifySource(type),
145
+ }),
146
+ }),
147
+ remove: getDataPatch('target', 'path', {
148
+ nbtAccessType: 1 /* SymbolAccessType.Write */,
149
+ vaultAccessType: 1 /* SymbolAccessType.Write */,
150
+ }),
157
151
  },
158
152
  },
159
153
  debug: {
@@ -174,8 +168,29 @@ export function getPatch(release) {
174
168
  unless: ExecuteCondition,
175
169
  },
176
170
  },
171
+ function: {
172
+ children: {
173
+ name: {
174
+ ...(ReleaseVersion.cmp(release, '1.20.2') >= 0
175
+ ? {
176
+ children: {
177
+ // Added in 23w31a (1.20.2, pack format 16)
178
+ arguments: {
179
+ properties: {
180
+ dispatcher: 'minecraft:macro_function',
181
+ dispatchedBy: 'name',
182
+ },
183
+ },
184
+ with: getDataPatch('source', 'path'),
185
+ },
186
+ }
187
+ : {}),
188
+ },
189
+ },
190
+ },
177
191
  ...(ReleaseVersion.cmp(release, '1.17') >= 0
178
192
  ? {
193
+ // Added in 20w46a (1.17, pack format 7)
179
194
  item: {
180
195
  children: {
181
196
  replace: {
@@ -329,6 +344,7 @@ export function getPatch(release) {
329
344
  },
330
345
  ...(ReleaseVersion.cmp(release, '1.18') >= 0
331
346
  ? {
347
+ // Added in 21w37a (1.18, pack format 8)
332
348
  jfr: {
333
349
  permission: 4,
334
350
  },
@@ -340,13 +356,17 @@ export function getPatch(release) {
340
356
  list: {
341
357
  permission: 0,
342
358
  },
343
- ...(ReleaseVersion.cmp(release, '1.16') >= 0
359
+ ...(ReleaseVersion.isBetween(release, '1.16', '1.19')
344
360
  ? {
361
+ // Added in 20w06a (1.16, pack format 5)
362
+ // Removed in 22w19a (1.19, pack format 10)
345
363
  locatebiome: {
346
364
  children: {
347
365
  biome: {
348
366
  properties: {
349
367
  category: 'worldgen/biome',
368
+ // Allowed in 1.18.2-pre1 (1.18.2, pack format 9)
369
+ allowTag: ReleaseVersion.cmp(release, '1.18.2') >= 0,
350
370
  },
351
371
  },
352
372
  },
@@ -421,6 +441,7 @@ export function getPatch(release) {
421
441
  },
422
442
  ...(ReleaseVersion.cmp(release, '1.17') >= 0
423
443
  ? {
444
+ // Added in 1.17 Pre-release 1 (1.17, pack format 7)
424
445
  perf: {
425
446
  permission: 4,
426
447
  },
@@ -428,18 +449,33 @@ export function getPatch(release) {
428
449
  : {}),
429
450
  ...(ReleaseVersion.cmp(release, '1.19') >= 0
430
451
  ? {
452
+ // Added in 22w18a (1.19, pack format 10)
431
453
  place: {
432
454
  children: {
455
+ jigsaw: {
456
+ children: {
457
+ pool: {
458
+ children: {
459
+ target: {
460
+ properties: {
461
+ category: 'jigsaw_block_name',
462
+ allowUnknown: true,
463
+ },
464
+ },
465
+ },
466
+ },
467
+ },
468
+ },
433
469
  template: {
434
470
  children: {
435
471
  template: {
436
472
  properties: {
437
- category: 'structure'
438
- }
439
- }
440
- }
441
- }
442
- }
473
+ category: 'structure',
474
+ },
475
+ },
476
+ },
477
+ },
478
+ },
443
479
  },
444
480
  }
445
481
  : {}),
@@ -447,6 +483,53 @@ export function getPatch(release) {
447
483
  publish: {
448
484
  permission: 4,
449
485
  },
486
+ ...(ReleaseVersion.cmp(release, '1.20.2') >= 0
487
+ ? {
488
+ // Added in 23w31a (1.20.2, pack format 16)
489
+ random: {
490
+ children: {
491
+ reset: {
492
+ children: {
493
+ sequence: {
494
+ properties: {
495
+ category: 'random_sequence',
496
+ allowUnknown: true,
497
+ },
498
+ },
499
+ },
500
+ },
501
+ roll: {
502
+ children: {
503
+ range: {
504
+ children: {
505
+ sequence: {
506
+ properties: {
507
+ category: 'random_sequence',
508
+ allowUnknown: true,
509
+ },
510
+ },
511
+ },
512
+ },
513
+ },
514
+ },
515
+ value: {
516
+ children: {
517
+ range: {
518
+ children: {
519
+ sequence: {
520
+ properties: {
521
+ category: 'random_sequence',
522
+ allowUnknown: true,
523
+ },
524
+ },
525
+ },
526
+ },
527
+ },
528
+ },
529
+ },
530
+ },
531
+ }
532
+ : {}),
450
533
  recipe: {
451
534
  children: {
452
535
  give: RecipeTargets,
@@ -462,6 +545,18 @@ export function getPatch(release) {
462
545
  'save-on': {
463
546
  permission: 4,
464
547
  },
548
+ schedule: {
549
+ children: {
550
+ clear: {
551
+ children: {
552
+ function: {
553
+ parser: 'minecraft:function',
554
+ properties: undefined,
555
+ },
556
+ },
557
+ },
558
+ },
559
+ },
465
560
  scoreboard: {
466
561
  children: {
467
562
  objectives: {
@@ -514,6 +609,24 @@ export function getPatch(release) {
514
609
  },
515
610
  },
516
611
  },
612
+ summon: {
613
+ children: {
614
+ entity: {
615
+ children: {
616
+ pos: {
617
+ children: {
618
+ nbt: {
619
+ properties: {
620
+ dispatcher: 'minecraft:entity',
621
+ dispatchedBy: 'entity',
622
+ },
623
+ },
624
+ },
625
+ },
626
+ },
627
+ },
628
+ },
629
+ },
517
630
  tag: {
518
631
  children: {
519
632
  targets: {
@@ -522,6 +635,9 @@ export function getPatch(release) {
522
635
  children: {
523
636
  name: {
524
637
  parser: 'spyglassmc:tag',
638
+ properties: {
639
+ usageType: 'definition',
640
+ },
525
641
  },
526
642
  },
527
643
  },
@@ -584,8 +700,9 @@ export function getPatch(release) {
584
700
  tell: {
585
701
  permission: 0,
586
702
  },
587
- ...(ReleaseVersion.cmp(release, '1.20.2') >= 0
703
+ ...(ReleaseVersion.cmp(release, '1.20.3') >= 0
588
704
  ? {
705
+ // Added in 23w43a (1.20.3, pack format 22)
589
706
  tick: {
590
707
  permission: 3,
591
708
  },
@@ -594,6 +711,14 @@ export function getPatch(release) {
594
711
  tm: {
595
712
  permission: 0,
596
713
  },
714
+ ...(ReleaseVersion.cmp(release, '1.20.5') >= 0
715
+ ? {
716
+ // Added in 24w04a (1.20.5, pack format 29)
717
+ transfer: {
718
+ permission: 3,
719
+ },
720
+ }
721
+ : {}),
597
722
  trigger: {
598
723
  permission: 0,
599
724
  children: {
@@ -658,54 +783,124 @@ const AdvancementTargets = Object.freeze({
658
783
  },
659
784
  },
660
785
  });
661
- const DataSource = Object.freeze({
662
- children: {
663
- storage: {
664
- children: {
665
- source: {
666
- properties: {
667
- category: 'storage',
786
+ /**
787
+ * Return the command tree patch for anything related to data sources as used in
788
+ * `data`, `execute if` and `execute store` commands.
789
+ *
790
+ * A **vault** refers to a block, an entity, or a storage that contains NBT data.
791
+ *
792
+ * e.g., in a syntax like
793
+ * `block <targetPos>|entity <target>|storage <target>) <targetPath>`, the
794
+ * `<targetPos>` and `<target>` arguments identify a vault, and the
795
+ * `<targetPath>` argument is an NBT path that points to data in the vault.
796
+ *
797
+ * @param vaultKey Key of the argument identifying a vault. This argument should
798
+ * be a vec3, an entity, or a storage resource location.
799
+ * @param nbtKey Key of the argument containing an NBT tag or an NBT path.
800
+ * @param nbtAccessType Access type for the NBT argument. This is only
801
+ * meaningful for NBT paths and should be enforced by the
802
+ * NBT path checker.
803
+ * Note this usually match `vaultAccessType`. The only case
804
+ * where they don't match is in `data merge`, where the
805
+ * vault is being written to while the NBT argument is
806
+ * being read from.
807
+ * @default {@link SymbolAccessType.Read}
808
+ * @param vaultAccessType Access type for the vault. This is only meaningful for
809
+ * storage vaults and should be enforced by the resource
810
+ * location checker.
811
+ * @see {@link nbtAccessType}
812
+ * @default {@link SymbolAccessType.Read}
813
+ * @param children Optional patch for children after the NBT argument.
814
+ */
815
+ function getDataPatch(vaultKey, nbtKey, { children, isPredicate = false, isMerge = false, nbtAccessType = 0 /* SymbolAccessType.Read */, vaultAccessType = 0 /* SymbolAccessType.Read */, } = {}) {
816
+ return Object.freeze({
817
+ children: {
818
+ block: {
819
+ children: {
820
+ [`${vaultKey}Pos`]: {
821
+ children: {
822
+ [nbtKey]: {
823
+ properties: {
824
+ dispatcher: 'minecraft:block',
825
+ dispatchedBy: `${vaultKey}Pos`,
826
+ accessType: nbtAccessType,
827
+ isPredicate,
828
+ isMerge,
829
+ },
830
+ ...children ? { children: children('block') } : {},
831
+ },
832
+ },
668
833
  },
669
834
  },
670
835
  },
671
- },
672
- },
673
- });
674
- const DataTarget = Object.freeze({
675
- children: {
676
- storage: {
677
- children: {
678
- target: {
679
- properties: {
680
- category: 'storage',
681
- accessType: 1 /* SymbolAccessType.Write */,
836
+ entity: {
837
+ children: {
838
+ [vaultKey]: {
839
+ children: {
840
+ [nbtKey]: {
841
+ properties: {
842
+ dispatcher: 'minecraft:entity',
843
+ dispatchedBy: vaultKey,
844
+ accessType: nbtAccessType,
845
+ isPredicate,
846
+ isMerge,
847
+ },
848
+ ...children ? { children: children('entity') } : {},
849
+ },
850
+ },
851
+ },
852
+ },
853
+ },
854
+ storage: {
855
+ children: {
856
+ [vaultKey]: {
857
+ properties: {
858
+ category: 'storage',
859
+ accessType: vaultAccessType,
860
+ usageType: 'definition',
861
+ },
862
+ children: {
863
+ [nbtKey]: {
864
+ properties: {
865
+ dispatcher: 'minecraft:storage',
866
+ dispatchedBy: vaultKey,
867
+ accessType: nbtAccessType,
868
+ isPredicate,
869
+ isMerge,
870
+ },
871
+ ...children ? { children: children('storage') } : {},
872
+ },
873
+ },
682
874
  },
683
875
  },
684
876
  },
685
877
  },
686
- },
687
- });
688
- const DataModifySource = Object.freeze({
689
- children: {
690
- from: DataSource,
691
- },
692
- });
693
- const DataModifyOperation = Object.freeze({
878
+ });
879
+ }
880
+ const getDataModifySource = (type, { isMerge = false, isListIndex = false, } = {}) => Object.freeze({
694
881
  children: {
695
- append: DataModifySource,
696
- insert: {
882
+ from: getDataPatch('source', 'sourcePath'),
883
+ string: getDataPatch('source', 'sourcePath'),
884
+ value: {
697
885
  children: {
698
- index: DataModifySource,
886
+ value: {
887
+ properties: {
888
+ dispatcher: `minecraft:${type}`,
889
+ dispatchedBy: type === 'block' ? 'targetPos' : 'target',
890
+ indexedBy: 'targetPath',
891
+ isMerge,
892
+ isListIndex,
893
+ },
894
+ },
699
895
  },
700
896
  },
701
- merge: DataModifySource,
702
- prepend: DataModifySource,
703
- set: DataModifySource,
704
897
  },
705
898
  });
706
899
  const ExecuteCondition = Object.freeze({
707
900
  children: {
708
- data: DataSource,
901
+ data: getDataPatch('source', 'path', {
902
+ isPredicate: true,
903
+ }),
709
904
  predicate: {
710
905
  children: {
711
906
  predicate: {
@@ -719,7 +914,11 @@ const ExecuteCondition = Object.freeze({
719
914
  });
720
915
  const ExecuteStoreTarget = Object.freeze({
721
916
  children: {
722
- ...DataTarget.children,
917
+ ...getDataPatch('target', 'path', {
918
+ nbtAccessType: 1 /* SymbolAccessType.Write */,
919
+ vaultAccessType: 1 /* SymbolAccessType.Write */,
920
+ })
921
+ .children,
723
922
  bossbar: {
724
923
  children: {
725
924
  id: {
@@ -757,6 +956,9 @@ const LootSource = Object.freeze({
757
956
  const ObjectiveWriteTargets = Object.freeze({
758
957
  children: {
759
958
  targets: {
959
+ properties: {
960
+ usageType: 'definition',
961
+ },
760
962
  children: {
761
963
  objective: {
762
964
  properties: {
@@ -0,0 +1,7 @@
1
+ import type * as core from '@spyglassmc/core';
2
+ import type { RootTreeNode } from '@spyglassmc/mcfunction';
3
+ /**
4
+ * Validate that parsers requiring patches have been patched in the tree.
5
+ */
6
+ export declare function validatePatchedTree(tree: RootTreeNode, logger: core.Logger): void;
7
+ //# sourceMappingURL=patchValidator.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * A set of parsers that must be patched with a `properties` field.
3
+ */
4
+ const PatchRequiredParsers = new Set([
5
+ 'minecraft:nbt_compound_tag',
6
+ 'minecraft:nbt_path',
7
+ 'minecraft:nbt_tag',
8
+ 'minecraft:resource_location',
9
+ 'minecraft:uuid',
10
+ ]);
11
+ /**
12
+ * Validate that parsers requiring patches have been patched in the tree.
13
+ */
14
+ export function validatePatchedTree(tree, logger) {
15
+ walk(tree, []);
16
+ function walk(node, path) {
17
+ if (node.type === 'argument' && PatchRequiredParsers.has(node.parser) && !node.properties) {
18
+ logger.warn(`[validatePatchedTree] Patch required: ${node.parser} at ${path.join('.')}`);
19
+ }
20
+ for (const [key, value] of Object.entries(node.children ?? {})) {
21
+ walk(value, [...path, key]);
22
+ }
23
+ }
24
+ }
25
+ //# sourceMappingURL=patchValidator.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/java-edition",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -17,16 +17,15 @@
17
17
  "release:dry": "npm publish --dry-run"
18
18
  },
19
19
  "dependencies": {
20
- "@spyglassmc/core": "0.4.5",
21
- "@spyglassmc/json": "0.3.7",
22
- "@spyglassmc/locales": "0.3.5",
23
- "@spyglassmc/mcfunction": "0.2.7",
24
- "@spyglassmc/mcdoc": "0.3.8",
25
- "@spyglassmc/nbt": "0.3.8"
20
+ "@spyglassmc/core": "0.4.7",
21
+ "@spyglassmc/json": "0.3.9",
22
+ "@spyglassmc/locales": "0.3.7",
23
+ "@spyglassmc/mcfunction": "0.2.9",
24
+ "@spyglassmc/mcdoc": "0.3.10",
25
+ "@spyglassmc/nbt": "0.3.10"
26
26
  },
27
27
  "devDependencies": {
28
- "fast-glob": "^3.2.5",
29
- "vanilla-datapack-data": "SPGoding/vanilla-datapack#634cc1bf99c37bdb99cde101713f55abbbbe5e95"
28
+ "fast-glob": "^3.2.5"
30
29
  },
31
30
  "publishConfig": {
32
31
  "access": "public"