sandstone 1.0.0-beta.2 → 1.0.0-beta.3

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 (121) hide show
  1. package/CLAUDE.md +315 -16
  2. package/bun.lock +18 -22
  3. package/dist/arguments/index.js +1093 -367
  4. package/dist/arguments/selector.d.ts +6 -6
  5. package/dist/commands/implementations/block/setblock.d.ts +6 -9
  6. package/dist/commands/implementations/entity/execute.d.ts +36 -21
  7. package/dist/commands/implementations/server/return.d.ts +14 -7
  8. package/dist/commands/implementations/world/data.d.ts +29 -32
  9. package/dist/commands/index.js +1102 -364
  10. package/dist/core/index.js +2207 -1481
  11. package/dist/core/resources/datapack/mcfunction.d.ts +1 -1
  12. package/dist/core/resources/datapack/variant.d.ts +1 -1
  13. package/dist/core/resources/resource.d.ts +4 -4
  14. package/dist/flow/Flow.d.ts +21 -22
  15. package/dist/flow/if_else.d.ts +8 -3
  16. package/dist/flow/index.d.ts +1 -0
  17. package/dist/flow/index.js +2196 -1451
  18. package/dist/flow/loop.d.ts +5 -4
  19. package/dist/flow/loops/for_i.d.ts +1 -1
  20. package/dist/flow/loops/for_of.d.ts +4 -3
  21. package/dist/flow/loops/staticAnalysis.d.ts +26 -0
  22. package/dist/flow/loops/while.d.ts +1 -1
  23. package/dist/flow/switch_case.d.ts +94 -12
  24. package/dist/index.d.ts +6 -6
  25. package/dist/index.js +1093 -367
  26. package/dist/pack/index.js +1103 -364
  27. package/dist/pack/pack.d.ts +12 -12
  28. package/dist/pack/visitors/index.d.ts +1 -0
  29. package/dist/pack/visitors/loopTransformationVisitor.d.ts +13 -6
  30. package/dist/pack/visitors/simplifyExecuteFunction.d.ts +3 -2
  31. package/dist/pack/visitors/simplifyReturnRunFunction.d.ts +2 -1
  32. package/dist/pack/visitors/switchTransformationVisitor.d.ts +31 -0
  33. package/dist/pack/visitors/unifyChainedExecutes.d.ts +3 -2
  34. package/dist/pack/visitors/visitor.d.ts +5 -1
  35. package/dist/utils.d.ts +34 -3
  36. package/dist/variables/Data.d.ts +7 -5
  37. package/dist/variables/DataSets.d.ts +17 -14
  38. package/dist/variables/Label.d.ts +1 -0
  39. package/dist/variables/Loop.d.ts +10 -2
  40. package/dist/variables/ResolveNBT.d.ts +4 -3
  41. package/dist/variables/Score.d.ts +49 -3
  42. package/dist/variables/index.js +1066 -328
  43. package/package.json +1 -1
  44. package/src/arguments/selector.ts +12 -0
  45. package/src/commands/implementations/block/setblock.ts +8 -12
  46. package/src/commands/implementations/entity/damage.ts +2 -2
  47. package/src/commands/implementations/entity/execute.ts +103 -34
  48. package/src/commands/implementations/server/return.ts +15 -7
  49. package/src/commands/implementations/world/data.ts +96 -48
  50. package/src/core/Macro.ts +18 -1
  51. package/src/core/resources/datapack/advancement.ts +1 -1
  52. package/src/core/resources/datapack/bannerPattern.ts +1 -1
  53. package/src/core/resources/datapack/chatType.ts +1 -1
  54. package/src/core/resources/datapack/damageType.ts +1 -1
  55. package/src/core/resources/datapack/dialog.ts +1 -1
  56. package/src/core/resources/datapack/enchantment.ts +2 -2
  57. package/src/core/resources/datapack/gametest.ts +2 -2
  58. package/src/core/resources/datapack/instrument.ts +1 -1
  59. package/src/core/resources/datapack/itemModifier.ts +1 -1
  60. package/src/core/resources/datapack/jukeboxSong.ts +1 -1
  61. package/src/core/resources/datapack/lootTable.ts +1 -1
  62. package/src/core/resources/datapack/mcfunction.ts +36 -17
  63. package/src/core/resources/datapack/predicate.ts +1 -1
  64. package/src/core/resources/datapack/recipe.ts +1 -1
  65. package/src/core/resources/datapack/structure.ts +1 -1
  66. package/src/core/resources/datapack/tag.ts +4 -4
  67. package/src/core/resources/datapack/timeline.ts +2 -2
  68. package/src/core/resources/datapack/trialSpawner.ts +1 -1
  69. package/src/core/resources/datapack/trimMaterial.ts +1 -1
  70. package/src/core/resources/datapack/trimPattern.ts +1 -1
  71. package/src/core/resources/datapack/variant.ts +2 -2
  72. package/src/core/resources/datapack/villagerTrade.ts +2 -2
  73. package/src/core/resources/resource.ts +22 -11
  74. package/src/core/resources/resourcepack/atlas.ts +1 -1
  75. package/src/core/resources/resourcepack/blockstate.ts +1 -1
  76. package/src/core/resources/resourcepack/equipment.ts +1 -1
  77. package/src/core/resources/resourcepack/font.ts +1 -1
  78. package/src/core/resources/resourcepack/itemDefinition.ts +1 -1
  79. package/src/core/resources/resourcepack/language.ts +1 -1
  80. package/src/core/resources/resourcepack/model.ts +1 -1
  81. package/src/core/resources/resourcepack/particle.ts +1 -1
  82. package/src/core/resources/resourcepack/postEffect.ts +1 -1
  83. package/src/core/resources/resourcepack/shader.ts +1 -1
  84. package/src/core/resources/resourcepack/sound.ts +1 -1
  85. package/src/core/resources/resourcepack/waypointStyle.ts +1 -1
  86. package/src/core/sandstoneCore.ts +9 -1
  87. package/src/flow/Flow.ts +58 -94
  88. package/src/flow/conditions/command.ts +1 -1
  89. package/src/flow/conditions/variables/dataPoint.ts +2 -2
  90. package/src/flow/if_else.ts +14 -3
  91. package/src/flow/index.ts +1 -0
  92. package/src/flow/loop.ts +10 -6
  93. package/src/flow/loops/for_i.ts +21 -17
  94. package/src/flow/loops/for_of.ts +43 -36
  95. package/src/flow/loops/staticAnalysis.ts +114 -0
  96. package/src/flow/loops/while.ts +8 -5
  97. package/src/flow/switch_case.ts +214 -13
  98. package/src/index.ts +6 -1
  99. package/src/pack/pack.ts +24 -19
  100. package/src/pack/visitors/containerCommandsToMCFunction.ts +12 -5
  101. package/src/pack/visitors/ifElseTransformationVisitor.ts +44 -16
  102. package/src/pack/visitors/index.ts +1 -0
  103. package/src/pack/visitors/initConstantsVisitor.ts +13 -11
  104. package/src/pack/visitors/loopTransformationVisitor.ts +30 -7
  105. package/src/pack/visitors/simplifyExecuteFunction.ts +43 -6
  106. package/src/pack/visitors/simplifyReturnRunFunction.ts +40 -17
  107. package/src/pack/visitors/switchTransformationVisitor.ts +452 -0
  108. package/src/pack/visitors/unifyChainedExecutes.ts +9 -1
  109. package/src/pack/visitors/visitor.ts +9 -1
  110. package/src/utils.ts +53 -12
  111. package/src/variables/Data.ts +20 -4
  112. package/src/variables/DataSets.ts +57 -23
  113. package/src/variables/JSONTextComponentClass.ts +6 -1
  114. package/src/variables/Label.ts +0 -3
  115. package/src/variables/Loop.ts +30 -1
  116. package/src/variables/Objective.ts +0 -1
  117. package/src/variables/ResolveNBT.ts +5 -3
  118. package/src/variables/Score.ts +238 -8
  119. package/src/variables/Sleep.ts +2 -2
  120. package/src/variables/UUID.ts +8 -6
  121. package/src/variables/nbt/NBTs.ts +14 -0
@@ -42,7 +42,17 @@ class MacroArgument {
42
42
  try {
43
43
  currentMCFunctionName = sandstoneCore.getCurrentMCFunctionOrThrow().resource.name;
44
44
  } catch {}
45
- return `$(${this.local.get(this.sandstoneCore.currentNode) || this.local.get(currentMCFunctionName)})`;
45
+ let result = this.local.get(this.sandstoneCore.currentNode) || this.local.get(currentMCFunctionName);
46
+ if (!result) {
47
+ let path = this.sandstoneCore.currentNode;
48
+ while (path.includes("/")) {
49
+ path = path.substring(0, path.lastIndexOf("/"));
50
+ result = this.local.get(path);
51
+ if (result)
52
+ break;
53
+ }
54
+ }
55
+ return `$(${result})`;
46
56
  };
47
57
  }
48
58
  }
@@ -82,6 +92,9 @@ var init_Macro = __esm(() => {
82
92
  result += `${macro}`;
83
93
  } else {
84
94
  result += macro.toMacro();
95
+ if (result.endsWith("}")) {
96
+ console.warn("what", macro);
97
+ }
85
98
  }
86
99
  }
87
100
  }
@@ -165,17 +178,15 @@ function randomUUID() {
165
178
  }
166
179
  return array;
167
180
  }
168
- function add(object) {
169
- if (object === undefined) {
170
- return {};
171
- }
172
- const output = {};
173
- for (const [key, value] of object.entries()) {
181
+ function add(obj) {
182
+ const filtered = {};
183
+ for (const key of Object.keys(obj)) {
184
+ const value = obj[key];
174
185
  if (value !== undefined) {
175
- output[key] = value;
186
+ filtered[key] = value;
176
187
  }
177
188
  }
178
- return output;
189
+ return filtered;
179
190
  }
180
191
  async function safeWrite(...args) {
181
192
  if (typeof args[0] !== "string")
@@ -193,6 +204,14 @@ function formatDebugString(className, args, body, currentIndent) {
193
204
  argsString = args;
194
205
  } else if (Array.isArray(args)) {
195
206
  argsString = args.map((arg) => util.inspect(arg, options)).join(", ");
207
+ if (argsString.includes(`
208
+ `)) {
209
+ argsString = `
210
+ ${nextIndent}${args.map((arg) => util.inspect(arg, options).replaceAll(`
211
+ `, `
212
+ ${nextIndent}`)).join(`,
213
+ ${nextIndent}`)}`;
214
+ }
196
215
  } else if (args && typeof args === "object") {
197
216
  argsString = Object.entries(args).map(([key, value]) => `${key}: ${util.inspect(value, options)}`).join(", ");
198
217
  } else {
@@ -443,1214 +462,1215 @@ function hasContext() {
443
462
  }
444
463
  var _context;
445
464
 
446
- // src/variables/nbt/grammar.ts
447
- function id(d) {
448
- return d[0];
465
+ // src/arguments/basics.ts
466
+ var init_basics = __esm(() => {
467
+ init_arguments();
468
+ });
469
+ // src/pack/packType.ts
470
+ var PACK_TYPE_BRAND, PackType;
471
+ var init_packType = __esm(() => {
472
+ PACK_TYPE_BRAND = Symbol.for("sandstone.PackType");
473
+ PackType = class PackType {
474
+ [PACK_TYPE_BRAND] = true;
475
+ type;
476
+ clientPath;
477
+ serverPath;
478
+ rootPath;
479
+ networkSides;
480
+ resourceSubFolder;
481
+ namespaced;
482
+ archiveOutput;
483
+ handleOutput;
484
+ constructor(type, clientPath, serverPath, rootPath, networkSides, archiveOutput = false, resourceSubFolder, namespaced = false) {
485
+ this.type = type;
486
+ this.clientPath = clientPath;
487
+ this.serverPath = serverPath;
488
+ this.rootPath = rootPath;
489
+ this.networkSides = networkSides;
490
+ this.archiveOutput = archiveOutput;
491
+ this.resourceSubFolder = resourceSubFolder;
492
+ this.namespaced = namespaced;
493
+ }
494
+ static [Symbol.hasInstance](instance) {
495
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[PACK_TYPE_BRAND] === true;
496
+ }
497
+ };
498
+ });
499
+
500
+ // src/pack/dependencies.ts
501
+ var DataPackDependencies, ResourcePackDependencies;
502
+ var init_dependencies = __esm(() => {
503
+ init_packType();
504
+ DataPackDependencies = class DataPackDependencies extends PackType {
505
+ constructor() {
506
+ super("datapack_dependencies", "saves/$worldName$/datapacks", "world/datapacks", "datapacks", "server", false, undefined, false);
507
+ }
508
+ handleOutput = async (type) => {
509
+ if (type === "output") {}
510
+ };
511
+ };
512
+ ResourcePackDependencies = class ResourcePackDependencies extends PackType {
513
+ constructor() {
514
+ super("resourcepack_dependencies", "resourcepacks", "dependency_resources", "resourcepacks", "client", false, undefined, false);
515
+ }
516
+ handleOutput = async (type) => {
517
+ if (type === "output") {}
518
+ };
519
+ };
520
+ });
521
+
522
+ // src/variables/Coordinates.ts
523
+ import { inspect as inspect3 } from "util";
524
+ function relative(...coordinates) {
525
+ if (coordinates.length === 0) {
526
+ return new VectorClass(["~", "~", "~"]);
527
+ }
528
+ if (coordinates.length === 1) {
529
+ return `~${coordinates[0] || ""}`;
530
+ }
531
+ return new VectorClass(coordinates.map((coord) => `~${coord || ""}`));
449
532
  }
450
- var isCompoundSymbol, grammar, grammar_default;
451
- var init_grammar = __esm(() => {
452
- isCompoundSymbol = Symbol("isCompound");
453
- grammar = {
454
- Lexer: undefined,
455
- ParserRules: [
456
- { name: "_$ebnf$1", symbols: [] },
457
- { name: "_$ebnf$1", symbols: ["_$ebnf$1", "wschar"], postprocess: (d) => d[0].concat([d[1]]) },
458
- {
459
- name: "_",
460
- symbols: ["_$ebnf$1"],
461
- postprocess(d) {
462
- return null;
463
- }
464
- },
465
- { name: "__$ebnf$1", symbols: ["wschar"] },
466
- { name: "__$ebnf$1", symbols: ["__$ebnf$1", "wschar"], postprocess: (d) => d[0].concat([d[1]]) },
467
- {
468
- name: "__",
469
- symbols: ["__$ebnf$1"],
470
- postprocess(d) {
471
- return null;
533
+ var VECTOR_CLASS_BRAND, VectorClass;
534
+ var init_Coordinates = __esm(() => {
535
+ VECTOR_CLASS_BRAND = Symbol.for("sandstone.VectorClass");
536
+ VectorClass = class VectorClass {
537
+ [VECTOR_CLASS_BRAND] = true;
538
+ values;
539
+ constructor(values) {
540
+ if (!Array.isArray(values) || !values.every((i) => typeof i === "string")) {
541
+ throw new Error(`Expected array of string for Vector values, got ${inspect3(values)}`);
542
+ }
543
+ this.values = values;
544
+ }
545
+ toString() {
546
+ return this.values.join(" ");
547
+ }
548
+ toJSON() {
549
+ return this.toString();
550
+ }
551
+ toNBT() {
552
+ return this.toString();
553
+ }
554
+ [Symbol.iterator]() {
555
+ return this.values[Symbol.iterator]();
556
+ }
557
+ static [Symbol.hasInstance](instance) {
558
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[VECTOR_CLASS_BRAND] === true;
559
+ }
560
+ };
561
+ });
562
+
563
+ // src/variables/parsers.ts
564
+ function coordinatesParser(coordinates) {
565
+ if (Array.isArray(coordinates)) {
566
+ if (coordinates.length === 3 || coordinates.length === 2) {
567
+ return new VectorClass(coordinates.map((coord) => {
568
+ if (typeof coord === "string") {
569
+ return coord;
472
570
  }
473
- },
474
- { name: "wschar", symbols: [/[ \t\n\v\f]/], postprocess: id },
475
- { name: "unsigned_int$ebnf$1", symbols: [/[0-9]/] },
476
- { name: "unsigned_int$ebnf$1", symbols: ["unsigned_int$ebnf$1", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
477
- {
478
- name: "unsigned_int",
479
- symbols: ["unsigned_int$ebnf$1"],
480
- postprocess(d) {
481
- return Number.parseInt(d[0].join(""));
571
+ if (typeof coord === "number") {
572
+ return `${coord}`;
482
573
  }
483
- },
484
- { name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "-" }] },
485
- { name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "+" }] },
486
- { name: "int$ebnf$1", symbols: ["int$ebnf$1$subexpression$1"], postprocess: id },
487
- { name: "int$ebnf$1", symbols: [], postprocess: () => null },
488
- { name: "int$ebnf$2", symbols: [/[0-9]/] },
489
- { name: "int$ebnf$2", symbols: ["int$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
490
- {
491
- name: "int",
492
- symbols: ["int$ebnf$1", "int$ebnf$2"],
493
- postprocess(d) {
494
- if (d[0]) {
495
- return Number.parseInt(d[0][0] + d[1].join(""));
496
- }
497
- return Number.parseInt(d[1].join(""));
574
+ if ("toMacro" in coord) {
575
+ return coord.toMacro();
498
576
  }
499
- },
500
- { name: "unsigned_decimal$ebnf$1", symbols: [/[0-9]/] },
501
- {
502
- name: "unsigned_decimal$ebnf$1",
503
- symbols: ["unsigned_decimal$ebnf$1", /[0-9]/],
504
- postprocess: (d) => d[0].concat([d[1]])
505
- },
506
- { name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
507
- {
508
- name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1",
509
- symbols: ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/],
510
- postprocess: (d) => d[0].concat([d[1]])
511
- },
512
- {
513
- name: "unsigned_decimal$ebnf$2$subexpression$1",
514
- symbols: [{ literal: "." }, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]
515
- },
516
- { name: "unsigned_decimal$ebnf$2", symbols: ["unsigned_decimal$ebnf$2$subexpression$1"], postprocess: id },
517
- { name: "unsigned_decimal$ebnf$2", symbols: [], postprocess: () => null },
518
- {
519
- name: "unsigned_decimal",
520
- symbols: ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"],
521
- postprocess(d) {
522
- return Number.parseFloat(d[0].join("") + (d[1] ? `.${d[1][1].join("")}` : ""));
577
+ throw new Error(`[coordinatesParser] Unsupported vector component ${coord}`);
578
+ }));
579
+ }
580
+ throw new Error(`[coordinatesParser] Unsupported vector size ${coordinates.length}`);
581
+ } else {
582
+ return coordinates;
583
+ }
584
+ }
585
+ function rotationParser(rotation) {
586
+ if (Array.isArray(rotation)) {
587
+ if (rotation.length === 2) {
588
+ return new VectorClass(rotation.map((coord) => {
589
+ if (typeof coord === "string") {
590
+ return coord;
523
591
  }
524
- },
525
- { name: "decimal$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
526
- { name: "decimal$ebnf$1", symbols: [], postprocess: () => null },
527
- { name: "decimal$ebnf$2", symbols: [/[0-9]/] },
528
- { name: "decimal$ebnf$2", symbols: ["decimal$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
529
- { name: "decimal$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
530
- {
531
- name: "decimal$ebnf$3$subexpression$1$ebnf$1",
532
- symbols: ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
533
- postprocess: (d) => d[0].concat([d[1]])
534
- },
535
- { name: "decimal$ebnf$3$subexpression$1", symbols: [{ literal: "." }, "decimal$ebnf$3$subexpression$1$ebnf$1"] },
536
- { name: "decimal$ebnf$3", symbols: ["decimal$ebnf$3$subexpression$1"], postprocess: id },
537
- { name: "decimal$ebnf$3", symbols: [], postprocess: () => null },
538
- {
539
- name: "decimal",
540
- symbols: ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"],
541
- postprocess(d) {
542
- return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : ""));
592
+ if (typeof coord === "number") {
593
+ return `${coord}`;
543
594
  }
544
- },
545
- {
546
- name: "percentage",
547
- symbols: ["decimal", { literal: "%" }],
548
- postprocess(d) {
549
- return d[0] / 100;
595
+ if ("toMacro" in coord) {
596
+ return coord.toMacro();
550
597
  }
551
- },
552
- { name: "jsonfloat$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
553
- { name: "jsonfloat$ebnf$1", symbols: [], postprocess: () => null },
554
- { name: "jsonfloat$ebnf$2", symbols: [/[0-9]/] },
555
- { name: "jsonfloat$ebnf$2", symbols: ["jsonfloat$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
556
- { name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
557
- {
558
- name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1",
559
- symbols: ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
560
- postprocess: (d) => d[0].concat([d[1]])
561
- },
562
- {
563
- name: "jsonfloat$ebnf$3$subexpression$1",
564
- symbols: [{ literal: "." }, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]
565
- },
566
- { name: "jsonfloat$ebnf$3", symbols: ["jsonfloat$ebnf$3$subexpression$1"], postprocess: id },
567
- { name: "jsonfloat$ebnf$3", symbols: [], postprocess: () => null },
568
- { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [/[+-]/], postprocess: id },
569
- { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [], postprocess: () => null },
570
- { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2", symbols: [/[0-9]/] },
571
- {
572
- name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2",
573
- symbols: ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/],
574
- postprocess: (d) => d[0].concat([d[1]])
575
- },
576
- {
577
- name: "jsonfloat$ebnf$4$subexpression$1",
578
- symbols: [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"]
579
- },
580
- { name: "jsonfloat$ebnf$4", symbols: ["jsonfloat$ebnf$4$subexpression$1"], postprocess: id },
581
- { name: "jsonfloat$ebnf$4", symbols: [], postprocess: () => null },
582
- {
583
- name: "jsonfloat",
584
- symbols: ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"],
585
- postprocess(d) {
586
- return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : "") + (d[3] ? `e${d[3][1] || "+"}${d[3][2].join("")}` : ""));
587
- }
588
- },
589
- { name: "dqstring$ebnf$1", symbols: [] },
590
- { name: "dqstring$ebnf$1", symbols: ["dqstring$ebnf$1", "dstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
591
- {
592
- name: "dqstring",
593
- symbols: [{ literal: '"' }, "dqstring$ebnf$1", { literal: '"' }],
594
- postprocess(d) {
595
- return d[1].join("");
596
- }
597
- },
598
- { name: "sqstring$ebnf$1", symbols: [] },
599
- { name: "sqstring$ebnf$1", symbols: ["sqstring$ebnf$1", "sstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
600
- {
601
- name: "sqstring",
602
- symbols: [{ literal: "'" }, "sqstring$ebnf$1", { literal: "'" }],
603
- postprocess(d) {
604
- return d[1].join("");
605
- }
606
- },
607
- { name: "btstring$ebnf$1", symbols: [] },
608
- { name: "btstring$ebnf$1", symbols: ["btstring$ebnf$1", /[^`]/], postprocess: (d) => d[0].concat([d[1]]) },
609
- {
610
- name: "btstring",
611
- symbols: [{ literal: "`" }, "btstring$ebnf$1", { literal: "`" }],
612
- postprocess(d) {
613
- return d[1].join("");
614
- }
615
- },
616
- { name: "dstrchar", symbols: [/[^\\"\n]/], postprocess: id },
617
- {
618
- name: "dstrchar",
619
- symbols: [{ literal: "\\" }, "strescape"],
620
- postprocess(d) {
621
- return JSON.parse(`"${d.join("")}"`);
622
- }
623
- },
624
- { name: "sstrchar", symbols: [/[^\\'\n]/], postprocess: id },
625
- {
626
- name: "sstrchar",
627
- symbols: [{ literal: "\\" }, "strescape"],
628
- postprocess(d) {
629
- return JSON.parse(`"${d.join("")}"`);
630
- }
631
- },
632
- { name: "sstrchar$string$1", symbols: [{ literal: "\\" }, { literal: "'" }], postprocess: (d) => d.join("") },
633
- {
634
- name: "sstrchar",
635
- symbols: ["sstrchar$string$1"],
636
- postprocess(d) {
637
- return "'";
638
- }
639
- },
640
- { name: "strescape", symbols: [/["\\/bfnrt]/], postprocess: id },
641
- {
642
- name: "strescape",
643
- symbols: [{ literal: "u" }, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/],
644
- postprocess(d) {
645
- return d.join("");
646
- }
647
- },
648
- { name: "expression$subexpression$1", symbols: ["string"] },
649
- { name: "expression$subexpression$1", symbols: ["typedNum"] },
650
- { name: "expression$subexpression$1", symbols: ["number"] },
651
- { name: "expression$subexpression$1", symbols: ["boolean"] },
652
- { name: "expression$subexpression$1", symbols: ["byteArray"] },
653
- { name: "expression$subexpression$1", symbols: ["intArray"] },
654
- { name: "expression$subexpression$1", symbols: ["longArray"] },
655
- { name: "expression$subexpression$1", symbols: ["array"] },
656
- { name: "expression$subexpression$1", symbols: ["object"] },
657
- {
658
- name: "expression",
659
- symbols: ["expression$subexpression$1"],
660
- postprocess: (data) => data[0][0]
661
- },
662
- {
663
- name: "object",
664
- symbols: [{ literal: "{" }, "objectInner", { literal: "}" }],
665
- postprocess: (data) => Object.fromEntries([
666
- ...data[1].map(({ key, value }) => [key, value]),
667
- [isCompoundSymbol, true]
668
- ])
669
- },
670
- { name: "objectInner", symbols: ["_"], postprocess: (data) => [] },
671
- { name: "objectInner$ebnf$1", symbols: [] },
672
- { name: "objectInner$ebnf$1$subexpression$1", symbols: ["objectKeyValue", "_", { literal: "," }, "_"] },
673
- {
674
- name: "objectInner$ebnf$1",
675
- symbols: ["objectInner$ebnf$1", "objectInner$ebnf$1$subexpression$1"],
676
- postprocess: (d) => d[0].concat([d[1]])
677
- },
678
- { name: "objectInner$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
679
- { name: "objectInner$ebnf$2", symbols: ["objectInner$ebnf$2$subexpression$1"], postprocess: id },
680
- { name: "objectInner$ebnf$2", symbols: [], postprocess: () => null },
681
- {
682
- name: "objectInner",
683
- symbols: ["_", "objectInner$ebnf$1", "objectKeyValue", "objectInner$ebnf$2", "_"],
684
- postprocess: (data) => {
685
- const firstKeyValues = data[1].map(([keyValue]) => keyValue);
686
- const keyValues = [...firstKeyValues, data[2]];
687
- return keyValues;
688
- }
689
- },
690
- { name: "objectKeyValue$ebnf$1", symbols: [/[a-zA-Z]/] },
691
- {
692
- name: "objectKeyValue$ebnf$1",
693
- symbols: ["objectKeyValue$ebnf$1", /[a-zA-Z]/],
694
- postprocess: (d) => d[0].concat([d[1]])
695
- },
696
- {
697
- name: "objectKeyValue",
698
- symbols: ["objectKeyValue$ebnf$1", "_", { literal: ":" }, "_", "expression"],
699
- postprocess: (data) => ({ key: data[0].join(""), value: data[4] })
700
- },
701
- {
702
- name: "objectKeyValue",
703
- symbols: ["string", "_", { literal: ":" }, "_", "expression"],
704
- postprocess: (data) => ({ key: data[0].value, value: data[4] })
705
- },
706
- { name: "array$macrocall$2", symbols: ["expression"] },
707
- { name: "array$macrocall$1", symbols: ["_"], postprocess: () => [] },
708
- { name: "array$macrocall$1$ebnf$1", symbols: [] },
709
- { name: "array$macrocall$1$ebnf$1$subexpression$1", symbols: ["array$macrocall$2", "_", { literal: "," }, "_"] },
710
- {
711
- name: "array$macrocall$1$ebnf$1",
712
- symbols: ["array$macrocall$1$ebnf$1", "array$macrocall$1$ebnf$1$subexpression$1"],
713
- postprocess: (d) => d[0].concat([d[1]])
714
- },
715
- { name: "array$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
716
- { name: "array$macrocall$1$ebnf$2", symbols: ["array$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
717
- { name: "array$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
718
- {
719
- name: "array$macrocall$1",
720
- symbols: ["_", "array$macrocall$1$ebnf$1", "array$macrocall$2", "array$macrocall$1$ebnf$2", "_"],
721
- postprocess: (data) => {
722
- const firstArray = data[1].map(([expression]) => expression[0]);
723
- return [...firstArray, data[2][0]];
724
- }
725
- },
726
- {
727
- name: "array",
728
- symbols: [{ literal: "[" }, "array$macrocall$1", { literal: "]" }],
729
- postprocess: (data) => data[1]
730
- },
731
- { name: "byteArray$macrocall$2", symbols: ["typedByte"] },
732
- { name: "byteArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
733
- { name: "byteArray$macrocall$1$ebnf$1", symbols: [] },
734
- {
735
- name: "byteArray$macrocall$1$ebnf$1$subexpression$1",
736
- symbols: ["byteArray$macrocall$2", "_", { literal: "," }, "_"]
737
- },
738
- {
739
- name: "byteArray$macrocall$1$ebnf$1",
740
- symbols: ["byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$1$ebnf$1$subexpression$1"],
741
- postprocess: (d) => d[0].concat([d[1]])
742
- },
743
- { name: "byteArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
744
- {
745
- name: "byteArray$macrocall$1$ebnf$2",
746
- symbols: ["byteArray$macrocall$1$ebnf$2$subexpression$1"],
747
- postprocess: id
748
- },
749
- { name: "byteArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
750
- {
751
- name: "byteArray$macrocall$1",
752
- symbols: ["_", "byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$2", "byteArray$macrocall$1$ebnf$2", "_"],
753
- postprocess: (data) => {
754
- const firstArray = data[1].map(([expression]) => expression[0]);
755
- return [...firstArray, data[2][0]];
598
+ throw new Error(`[rotationParser] Unsupported vector component ${coord}`);
599
+ }));
600
+ }
601
+ throw new Error(`[rotationParser] Unsupported vector size ${rotation.length}`);
602
+ } else {
603
+ return rotation;
604
+ }
605
+ }
606
+ function targetParser(target) {
607
+ if (target === undefined) {
608
+ throw new Error("Target cannot be undefined.");
609
+ }
610
+ if (typeof target === "string") {
611
+ return target;
612
+ }
613
+ if (target._toSelector) {
614
+ return target._toSelector();
615
+ }
616
+ if (target.toMacro) {
617
+ return target;
618
+ }
619
+ return target.toString();
620
+ }
621
+ var sanitizeValue = (core, value) => {
622
+ if (value === undefined || value === null) {
623
+ return "";
624
+ }
625
+ if (typeof value === "string") {
626
+ return value;
627
+ }
628
+ if (isMacroArgument(core, value)) {
629
+ return value.toMacro();
630
+ }
631
+ if (Number.isFinite(value)) {
632
+ return value.toString();
633
+ }
634
+ return "";
635
+ }, rangeParser = (core, range) => {
636
+ if (Array.isArray(range)) {
637
+ return `${sanitizeValue(core, range[0])}..${sanitizeValue(core, range[1])}`;
638
+ }
639
+ return range.toString();
640
+ }, structureRotationParser = (rotation) => {
641
+ if (!rotation) {
642
+ return "none";
643
+ }
644
+ if (typeof rotation === "object") {
645
+ return rotation;
646
+ }
647
+ const numToLiteral = (angle) => {
648
+ switch (angle) {
649
+ case 0:
650
+ return "none";
651
+ case 90:
652
+ return "clockwise_90";
653
+ case 180:
654
+ return "180";
655
+ case 270:
656
+ return "counterclockwise_90";
657
+ case -90:
658
+ return "counterclockwise_90";
659
+ case -180:
660
+ return "180";
661
+ case -270:
662
+ return "clockwise_90";
663
+ default: {
664
+ if (!Number.isInteger(angle / 90)) {
665
+ throw new Error("Structure rotation must be in increments of 90!");
756
666
  }
757
- },
758
- {
759
- name: "byteArray",
760
- symbols: [
761
- { literal: "[" },
762
- "_",
763
- { literal: "B" },
764
- "_",
765
- { literal: ";" },
766
- "byteArray$macrocall$1",
767
- { literal: "]" }
768
- ],
769
- postprocess: (data) => ({ dataType: "byteArray", value: data[5] })
770
- },
771
- { name: "intArray$macrocall$2", symbols: ["number"] },
772
- { name: "intArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
773
- { name: "intArray$macrocall$1$ebnf$1", symbols: [] },
774
- {
775
- name: "intArray$macrocall$1$ebnf$1$subexpression$1",
776
- symbols: ["intArray$macrocall$2", "_", { literal: "," }, "_"]
777
- },
778
- {
779
- name: "intArray$macrocall$1$ebnf$1",
780
- symbols: ["intArray$macrocall$1$ebnf$1", "intArray$macrocall$1$ebnf$1$subexpression$1"],
781
- postprocess: (d) => d[0].concat([d[1]])
782
- },
783
- { name: "intArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
784
- { name: "intArray$macrocall$1$ebnf$2", symbols: ["intArray$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
785
- { name: "intArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
786
- {
787
- name: "intArray$macrocall$1",
788
- symbols: ["_", "intArray$macrocall$1$ebnf$1", "intArray$macrocall$2", "intArray$macrocall$1$ebnf$2", "_"],
789
- postprocess: (data) => {
790
- const firstArray = data[1].map(([expression]) => expression[0]);
791
- return [...firstArray, data[2][0]];
792
- }
793
- },
794
- {
795
- name: "intArray",
796
- symbols: [
797
- { literal: "[" },
798
- "_",
799
- { literal: "I" },
800
- "_",
801
- { literal: ";" },
802
- "intArray$macrocall$1",
803
- { literal: "]" }
804
- ],
805
- postprocess: (data) => ({ dataType: "intArray", value: data[5] })
806
- },
807
- { name: "longArray$macrocall$2", symbols: ["typedLong"] },
808
- { name: "longArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
809
- { name: "longArray$macrocall$1$ebnf$1", symbols: [] },
810
- {
811
- name: "longArray$macrocall$1$ebnf$1$subexpression$1",
812
- symbols: ["longArray$macrocall$2", "_", { literal: "," }, "_"]
813
- },
814
- {
815
- name: "longArray$macrocall$1$ebnf$1",
816
- symbols: ["longArray$macrocall$1$ebnf$1", "longArray$macrocall$1$ebnf$1$subexpression$1"],
817
- postprocess: (d) => d[0].concat([d[1]])
818
- },
819
- { name: "longArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
820
- {
821
- name: "longArray$macrocall$1$ebnf$2",
822
- symbols: ["longArray$macrocall$1$ebnf$2$subexpression$1"],
823
- postprocess: id
824
- },
825
- { name: "longArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
826
- {
827
- name: "longArray$macrocall$1",
828
- symbols: ["_", "longArray$macrocall$1$ebnf$1", "longArray$macrocall$2", "longArray$macrocall$1$ebnf$2", "_"],
829
- postprocess: (data) => {
830
- const firstArray = data[1].map(([expression]) => expression[0]);
831
- return [...firstArray, data[2][0]];
832
- }
833
- },
834
- {
835
- name: "longArray",
836
- symbols: [
837
- { literal: "[" },
838
- "_",
839
- { literal: "L" },
840
- "_",
841
- { literal: ";" },
842
- "longArray$macrocall$1",
843
- { literal: "]" }
844
- ],
845
- postprocess: (data) => ({ dataType: "longArray", value: data[5] })
846
- },
847
- { name: "string$subexpression$1", symbols: ["dqstring"] },
848
- { name: "string$subexpression$1", symbols: ["sqstring"] },
849
- {
850
- name: "string",
851
- symbols: ["string$subexpression$1"],
852
- postprocess: (data) => ({ dataType: "string", value: data[0][0] })
853
- },
854
- { name: "typedNum$subexpression$1", symbols: ["typedByte"] },
855
- { name: "typedNum$subexpression$1", symbols: ["typedShort"] },
856
- { name: "typedNum$subexpression$1", symbols: ["typedLong"] },
857
- { name: "typedNum$subexpression$1", symbols: ["typedFloat"] },
858
- { name: "typedNum", symbols: ["typedNum$subexpression$1"], postprocess: (data) => data[0][0] },
859
- {
860
- name: "typedByte$subexpression$1",
861
- symbols: [/[bB]/],
862
- postprocess(d) {
863
- return d.join("");
864
- }
865
- },
866
- {
867
- name: "typedByte",
868
- symbols: ["int", "typedByte$subexpression$1"],
869
- postprocess: (data) => ({ dataType: "byte", value: data[0] })
870
- },
871
- {
872
- name: "typedShort$subexpression$1",
873
- symbols: [/[sS]/],
874
- postprocess(d) {
875
- return d.join("");
876
- }
877
- },
878
- {
879
- name: "typedShort",
880
- symbols: ["int", "typedShort$subexpression$1"],
881
- postprocess: (data) => ({ dataType: "short", value: data[0] })
882
- },
883
- {
884
- name: "typedLong$subexpression$1",
885
- symbols: [/[lL]/],
886
- postprocess(d) {
887
- return d.join("");
888
- }
889
- },
890
- {
891
- name: "typedLong",
892
- symbols: ["int", "typedLong$subexpression$1"],
893
- postprocess: (data) => ({ dataType: "long", value: data[0] })
894
- },
895
- {
896
- name: "typedFloat$subexpression$1",
897
- symbols: [/[dD]/],
898
- postprocess(d) {
899
- return d.join("");
900
- }
901
- },
902
- {
903
- name: "typedFloat",
904
- symbols: ["decimal", "typedFloat$subexpression$1"],
905
- postprocess: (data) => ({ dataType: "double", value: data[0] })
906
- },
907
- {
908
- name: "typedFloat$subexpression$2",
909
- symbols: [/[fF]/],
910
- postprocess(d) {
911
- return d.join("");
912
- }
913
- },
914
- {
915
- name: "typedFloat",
916
- symbols: ["decimal", "typedFloat$subexpression$2"],
917
- postprocess: (data) => ({ dataType: "float", value: data[0] })
918
- },
919
- { name: "number$subexpression$1", symbols: ["decimal"] },
920
- {
921
- name: "number",
922
- symbols: ["number$subexpression$1"],
923
- postprocess: (data) => ({ dataType: "number", value: data[0][0] })
924
- },
925
- {
926
- name: "boolean$subexpression$1$string$1",
927
- symbols: [{ literal: "t" }, { literal: "r" }, { literal: "u" }, { literal: "e" }],
928
- postprocess: (d) => d.join("")
929
- },
930
- { name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$1"] },
931
- {
932
- name: "boolean$subexpression$1$string$2",
933
- symbols: [{ literal: "f" }, { literal: "a" }, { literal: "l" }, { literal: "s" }, { literal: "e" }],
934
- postprocess: (d) => d.join("")
935
- },
936
- { name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$2"] },
937
- {
938
- name: "boolean",
939
- symbols: ["boolean$subexpression$1"],
940
- postprocess: (data) => ({ dataType: "boolean", value: data[0].join("") === "true" })
667
+ angle %= 360;
668
+ angle = (angle + 360) % 360;
669
+ if (angle > 180)
670
+ angle -= 360;
671
+ return numToLiteral(angle);
941
672
  }
942
- ],
943
- ParserStart: "expression"
673
+ }
944
674
  };
945
- grammar_default = grammar;
675
+ if (typeof rotation === "number") {
676
+ return numToLiteral(rotation);
677
+ }
678
+ if (rotation === "clockwise_90" || rotation === "counterclockwise_90") {
679
+ return rotation;
680
+ }
681
+ return numToLiteral(Number(rotation));
682
+ }, structureMirrorParser = (mirror) => {
683
+ if (typeof mirror === "object") {
684
+ return mirror.toMacro();
685
+ }
686
+ if (typeof mirror === "string") {
687
+ const lastCharacter = mirror.slice(0, -1);
688
+ if (lastCharacter === "x") {
689
+ return "left_right";
690
+ }
691
+ if (lastCharacter === "z") {
692
+ return "front_back";
693
+ }
694
+ return mirror;
695
+ }
696
+ if (mirror) {
697
+ return "left_right";
698
+ }
699
+ return "none";
700
+ };
701
+ var init_parsers = __esm(() => {
702
+ init_Macro();
703
+ init_Coordinates();
946
704
  });
947
705
 
948
- // src/variables/nbt/parser.ts
949
- import nearley from "nearley";
950
- function isCompoundNbt(nbt) {
951
- return !!nbt[isCompoundSymbol];
952
- }
953
- function parseRaw(nbt) {
954
- const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar_default));
955
- parser.feed(nbt);
956
- parser.finish();
957
- return parser.results[0];
706
+ // src/commands/helpers.ts
707
+ class FinalCommandOutput {
708
+ node;
709
+ constructor(node) {
710
+ this.node = node;
711
+ }
958
712
  }
959
- function parseExpression(NBT, nbt) {
960
- if (Array.isArray(nbt)) {
961
- return nbt.map((x) => parseExpression(NBT, x));
713
+
714
+ class CommandArguments {
715
+ sandstonePack;
716
+ previousNode;
717
+ autoCommit;
718
+ NodeType;
719
+ sandstoneCore;
720
+ sandstoneCommands;
721
+ constructor(sandstonePack, previousNode, autoCommit = true) {
722
+ this.sandstonePack = sandstonePack;
723
+ this.previousNode = previousNode;
724
+ this.autoCommit = autoCommit;
725
+ this.sandstoneCore = sandstonePack.core;
726
+ this.sandstoneCommands = sandstonePack.commands;
962
727
  }
963
- if (typeof nbt === "object") {
964
- if (isCompoundNbt(nbt)) {
965
- return Object.keys(nbt).reduce((acc, key) => {
966
- acc[key] = parseExpression(NBT, nbt[key]);
967
- return acc;
968
- }, {});
728
+ getNode = () => {
729
+ if (this.previousNode) {
730
+ return this.previousNode;
969
731
  }
970
- switch (nbt.dataType) {
971
- case "byte":
972
- return NBT.byte(nbt.value);
973
- case "short":
974
- return NBT.short(nbt.value);
975
- case "long":
976
- return NBT.long(nbt.value);
977
- case "float":
978
- return NBT.float(nbt.value);
979
- case "double":
980
- return NBT.double(nbt.value);
981
- case "number":
982
- return nbt.value;
983
- case "string":
984
- return nbt.value;
985
- case "byteArray":
986
- return NBT.byteArray(nbt.value.map((x) => x.value));
987
- case "intArray":
988
- return NBT.intArray(nbt.value.map((x) => x.value));
989
- case "longArray":
990
- return NBT.longArray(nbt.value.map((x) => x.value));
991
- }
992
- }
993
- throw new Error(`Unrecognized data type: ${nbt.dataType}`);
994
- }
995
- function parseNBT(NBT, nbt) {
996
- const rawResult = parseRaw(nbt);
997
- return parseExpression(NBT, rawResult);
998
- }
999
- var init_parser = __esm(() => {
1000
- init_grammar();
1001
- });
1002
-
1003
- // src/variables/nbt/NBTs.ts
1004
- import * as util3 from "util";
1005
- function customNumber(num, _class) {
1006
- if (Array.isArray(num)) {
1007
- return num.map((n) => new _class(n));
1008
- }
1009
- return new _class(num);
1010
- }
1011
- function dynamicNBT(template, ...args) {
1012
- const mixedArgs = template.flatMap((s, i) => [s, args[i]]).slice(0, -1);
1013
- const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtStringifier(element) : element.toString()).join("");
1014
- return parseNBT(NBT, result);
1015
- }
1016
- var N_B_T_CLASS_BRAND, NBTClass, N_B_T_PRIMITIVE_BRAND, NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, N_B_T_TYPED_ARRAY_BRAND, NBTTypedArray, NBTLongArray, NBTByteArray, NBTIntArray, NotNBT, NBTAnyValue, NBT, nbtStringifier = (nbt) => {
1017
- if (nbt === null || nbt === undefined) {
1018
- throw new Error("Nullish nbt values are not allowed");
1019
- }
1020
- if (typeof nbt === "number") {
1021
- return `${nbt}d`;
1022
- }
1023
- if (typeof nbt === "boolean") {
1024
- return nbt.toString();
1025
- }
1026
- if (typeof nbt === "string") {
1027
- const inspectedStr = util3.inspect(nbt, {
1028
- breakLength: Number.POSITIVE_INFINITY,
1029
- compact: true,
1030
- maxStringLength: Number.POSITIVE_INFINITY,
1031
- depth: Number.POSITIVE_INFINITY
1032
- });
1033
- if (inspectedStr[0] === "`") {
1034
- return JSON.stringify(nbt);
1035
- }
1036
- return inspectedStr;
1037
- }
1038
- if (Array.isArray(nbt)) {
1039
- const itemsStr = nbt.map(nbtStringifier).join(",");
1040
- return `[${itemsStr}]`;
1041
- }
1042
- if (nbt instanceof NBTClass) {
1043
- return nbt[util3.inspect.custom]();
1044
- }
1045
- if (typeof nbt === "object" || typeof nbt === "function") {
1046
- let failedMacro = false;
1047
- if ("toMacro" in nbt) {
1048
- const macro = nbt.toMacro();
1049
- if (macro === "$()") {
1050
- failedMacro = true;
1051
- } else {
1052
- return macro;
1053
- }
1054
- }
1055
- if ("toNBT" in nbt) {
1056
- return nbt.toNBT();
1057
- } else if (failedMacro) {
1058
- throw new Error("[nbtStringifier] A macro variable NBT insertion was attempted in an mcfunction without macros defined.");
1059
- }
1060
- if (typeof nbt === "function") {
1061
- throw new Error(`[nbtStringifier] This should never happen. A function or callable instance (${nbt.constructor?.name}) without toNBT was passed in as an NBT value.`);
1062
- }
1063
- if (nbt.constructor.name !== "Object") {
1064
- if ("toString" in nbt) {
1065
- return `${toString}`;
1066
- } else {
1067
- throw new Error(`[nbtStringifier] A ${nbt.constructor?.name} was passed in as an NBT value. Hint: define toNBT or toString if this was intentional`);
1068
- }
1069
- }
1070
- }
1071
- const objectStr = Object.entries(nbt).map(([key, value]) => `${key}:${nbtStringifier(value)}`).join(",");
1072
- return `{${objectStr}}`;
1073
- };
1074
- var init_NBTs = __esm(() => {
1075
- init_utils();
1076
- init_parser();
1077
- N_B_T_CLASS_BRAND = Symbol.for("sandstone.NBTClass");
1078
- NBTClass = class NBTClass {
1079
- [N_B_T_CLASS_BRAND] = true;
1080
- static [Symbol.hasInstance](instance) {
1081
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_CLASS_BRAND] === true;
732
+ if (this.NodeType) {
733
+ return new this.NodeType(this.sandstonePack);
1082
734
  }
735
+ throw new Error("No node type specified & no previous node for a non-root-level command");
1083
736
  };
1084
- N_B_T_PRIMITIVE_BRAND = Symbol.for("sandstone.NBTPrimitive");
1085
- NBTPrimitive = class NBTPrimitive extends NBTClass {
1086
- [N_B_T_PRIMITIVE_BRAND] = true;
1087
- value;
1088
- unit;
1089
- constructor(value, unit) {
1090
- super();
1091
- this.value = value;
1092
- this.unit = unit;
737
+ finalCommand = (args, currentNode) => {
738
+ const node = currentNode ?? this.getNode();
739
+ if (args) {
740
+ node.args.push(...args);
1093
741
  }
1094
- [util3.inspect.custom] = () => `${this.value}${this.unit}`;
1095
- static [Symbol.hasInstance](instance) {
1096
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_PRIMITIVE_BRAND] === true;
742
+ if (this.autoCommit) {
743
+ node.commit();
1097
744
  }
745
+ return new FinalCommandOutput(node);
1098
746
  };
1099
- NBTLong = class NBTLong extends NBTPrimitive {
1100
- constructor(value) {
1101
- super(value, "l");
747
+ subCommand = (args, NextArgumentType, executable = false, additionalNextArgs = [], currentNode) => {
748
+ const node = currentNode ?? this.getNode();
749
+ if (args) {
750
+ node.args.push(...args);
1102
751
  }
1103
- };
1104
- NBTByte = class NBTByte extends NBTPrimitive {
1105
- constructor(value) {
1106
- super(value, "b");
752
+ if (executable && this.autoCommit) {
753
+ node.commit();
1107
754
  }
755
+ return new NextArgumentType(this.sandstonePack, node, this.autoCommit, ...additionalNextArgs);
1108
756
  };
1109
- NBTShort = class NBTShort extends NBTPrimitive {
1110
- constructor(value) {
1111
- super(value, "s");
1112
- }
757
+ }
758
+
759
+ // src/commands/validators.ts
760
+ function validateIntegerRange(integer, name, minimum = 0, maximum = 2147483647) {
761
+ if (typeof integer !== "number") {
762
+ return integer;
763
+ }
764
+ if (integer && integer <= minimum) {
765
+ throw new Error(`\`${name}\` must be greater than or equal to ${minimum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
766
+ }
767
+ if (integer && integer >= maximum) {
768
+ throw new Error(`\`${name}\` must be lower than or equal to ${maximum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
769
+ }
770
+ return integer;
771
+ }
772
+
773
+ // src/commands/implementations/block/place.ts
774
+ var PlaceCommandNode, PlaceCommand;
775
+ var init_place = __esm(() => {
776
+ init_nodes();
777
+ init_parsers();
778
+ PlaceCommandNode = class PlaceCommandNode extends CommandNode {
779
+ command = "place";
1113
780
  };
1114
- NBTFloat = class NBTFloat extends NBTPrimitive {
1115
- constructor(value) {
1116
- super(value, "f");
1117
- }
781
+ PlaceCommand = class PlaceCommand extends CommandArguments {
782
+ NodeType = PlaceCommandNode;
783
+ feature = (feature, pos = "~ ~ ~") => this.finalCommand(["feature", feature, coordinatesParser(pos)]);
784
+ jigsaw = (pool, target, maxDepth, pos = "~ ~ ~") => this.finalCommand([
785
+ "jigsaw",
786
+ pool,
787
+ target,
788
+ `${validateIntegerRange(maxDepth, "Jigsaw max depth", 0, 7)}`,
789
+ coordinatesParser(pos)
790
+ ]);
791
+ structure = (configuredStructure, pos = "~ ~ ~") => this.finalCommand(["structure", configuredStructure, coordinatesParser(pos)]);
792
+ template = (structure, pos = "~ ~ ~", rotation, mirror, integrity = 1, seed = 0, mode) => {
793
+ this.finalCommand([
794
+ "template",
795
+ `${structure}`,
796
+ coordinatesParser(pos),
797
+ structureRotationParser(rotation),
798
+ structureMirrorParser(mirror),
799
+ `${integrity}`,
800
+ `${seed}`,
801
+ ...mode === undefined ? [] : [mode]
802
+ ]);
803
+ };
1118
804
  };
1119
- NBTInt = class NBTInt extends NBTPrimitive {
1120
- constructor(value) {
1121
- super(value, "i");
1122
- }
805
+ });
806
+
807
+ // src/commands/implementations/entity/damage.ts
808
+ var DamageCommandNode, DamageCauseCommand, DamageSourceCommand, DamageCommand;
809
+ var init_damage = __esm(() => {
810
+ init_nodes();
811
+ init_parsers();
812
+ DamageCommandNode = class DamageCommandNode extends CommandNode {
813
+ command = "damage";
1123
814
  };
1124
- NBTDouble = class NBTDouble extends NBTPrimitive {
1125
- constructor(value) {
1126
- super(value, "d");
1127
- }
815
+ DamageCauseCommand = class DamageCauseCommand extends CommandArguments {
816
+ from = (cause) => this.finalCommand(["from", targetParser(cause)]);
1128
817
  };
1129
- N_B_T_TYPED_ARRAY_BRAND = Symbol.for("sandstone.NBTTypedArray");
1130
- NBTTypedArray = class NBTTypedArray extends NBTClass {
1131
- [N_B_T_TYPED_ARRAY_BRAND] = true;
1132
- values;
1133
- unit;
1134
- constructor(values, unit) {
1135
- super();
1136
- this.values = values;
1137
- this.unit = unit;
1138
- }
1139
- [util3.inspect.custom] = () => `[${this.unit};${this.values.length === 0 ? "" : this.values.join(",")}]`;
1140
- static [Symbol.hasInstance](instance) {
1141
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_TYPED_ARRAY_BRAND] === true;
1142
- }
818
+ DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
819
+ by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand, true);
820
+ at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
1143
821
  };
1144
- NBTLongArray = class NBTLongArray extends NBTTypedArray {
1145
- constructor(values) {
1146
- super(values, "L");
1147
- }
822
+ DamageCommand = class DamageCommand extends CommandArguments {
823
+ NodeType = DamageCommandNode;
824
+ damage = (target, amount, damageType) => {
825
+ validateIntegerRange(amount, "amount", 0, 1e6);
826
+ return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand, true);
827
+ };
1148
828
  };
1149
- NBTByteArray = class NBTByteArray extends NBTTypedArray {
1150
- constructor(values) {
1151
- super(values, "B");
829
+ });
830
+
831
+ // src/commands/implementations/_fake/comment.ts
832
+ var CommentCommandNode, CommentCommand;
833
+ var init_comment = __esm(() => {
834
+ init_nodes();
835
+ CommentCommandNode = class CommentCommandNode extends CommandNode {
836
+ command = "#";
837
+ getValue() {
838
+ return this.args[0].join(" ").split(`
839
+ `).map((line) => `# ${line}`).join(`
840
+ `);
1152
841
  }
1153
842
  };
1154
- NBTIntArray = class NBTIntArray extends NBTTypedArray {
1155
- constructor(values) {
1156
- super(values, "I");
1157
- }
843
+ CommentCommand = class CommentCommand extends CommandArguments {
844
+ NodeType = CommentCommandNode;
845
+ comment = (...comments) => this.finalCommand([comments]);
1158
846
  };
1159
- NotNBT = class NotNBT extends NBTClass {
1160
- nbt;
1161
- constructor(nbt) {
1162
- super();
1163
- this.nbt = nbt;
1164
- }
1165
- [util3.inspect.custom] = () => `!${nbtStringifier(this.nbt)}`;
847
+ });
848
+
849
+ // src/commands/implementations/_fake/raw.ts
850
+ var RawCommandNode, RawCommand;
851
+ var init_raw = __esm(() => {
852
+ init_nodes();
853
+ RawCommandNode = class RawCommandNode extends CommandNode {
854
+ command = "";
1166
855
  };
1167
- NBTAnyValue = class NBTAnyValue extends NBTPrimitive {
856
+ RawCommand = class RawCommand extends CommandArguments {
857
+ NodeType = RawCommandNode;
858
+ raw = (...args) => this.finalCommand([...args]);
1168
859
  };
1169
- NBT = makeCallable({
1170
- int: (num) => customNumber(num, NBTInt),
1171
- float: (num) => customNumber(num, NBTFloat),
1172
- double: (num) => customNumber(num, NBTDouble),
1173
- byte: (num) => customNumber(num, NBTByte),
1174
- short: (num) => customNumber(num, NBTShort),
1175
- long: (num) => customNumber(num, NBTLong),
1176
- intArray: (numbers) => new NBTIntArray(numbers),
1177
- longArray: (numbers) => new NBTLongArray(numbers),
1178
- byteArray: (numbers) => new NBTByteArray(numbers),
1179
- not: (nbt) => new NotNBT(nbt),
1180
- stringify: (nbt) => nbtStringifier(nbt),
1181
- parse: (nbt) => parseNBT(NBT, nbt)
1182
- }, dynamicNBT);
1183
860
  });
1184
861
 
1185
- // src/arguments/basics.ts
1186
- var init_basics = __esm(() => {
1187
- init_arguments();
1188
- });
1189
- // src/pack/packType.ts
1190
- var PACK_TYPE_BRAND, PackType;
1191
- var init_packType = __esm(() => {
1192
- PACK_TYPE_BRAND = Symbol.for("sandstone.PackType");
1193
- PackType = class PackType {
1194
- [PACK_TYPE_BRAND] = true;
1195
- type;
1196
- clientPath;
1197
- serverPath;
1198
- rootPath;
1199
- networkSides;
1200
- resourceSubFolder;
1201
- namespaced;
1202
- archiveOutput;
1203
- handleOutput;
1204
- constructor(type, clientPath, serverPath, rootPath, networkSides, archiveOutput = false, resourceSubFolder, namespaced = false) {
1205
- this.type = type;
1206
- this.clientPath = clientPath;
1207
- this.serverPath = serverPath;
1208
- this.rootPath = rootPath;
1209
- this.networkSides = networkSides;
1210
- this.archiveOutput = archiveOutput;
1211
- this.resourceSubFolder = resourceSubFolder;
1212
- this.namespaced = namespaced;
862
+ // src/commands/implementations/block/clone.ts
863
+ var CloneCommandNode, CloneCommand, CloneFromDimensionCommand, CloneToDimensionCommand, CloneOptionsCommand, CloneStrictOptionsCommand, CloneModeCommand;
864
+ var init_clone = __esm(() => {
865
+ init_nodes();
866
+ init_parsers();
867
+ CloneCommandNode = class CloneCommandNode extends CommandNode {
868
+ command = "clone";
869
+ };
870
+ CloneCommand = class CloneCommand extends CommandArguments {
871
+ NodeType = CloneCommandNode;
872
+ clone(begin, end, destination) {
873
+ if (begin === undefined) {
874
+ return this.subCommand([], CloneFromDimensionCommand, false);
875
+ }
876
+ return this.subCommand([begin, end, destination].map(coordinatesParser), CloneOptionsCommand, true);
1213
877
  }
1214
- static [Symbol.hasInstance](instance) {
1215
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[PACK_TYPE_BRAND] === true;
878
+ };
879
+ CloneFromDimensionCommand = class CloneFromDimensionCommand extends CommandArguments {
880
+ from(dimension, begin, end, destination) {
881
+ if (destination === undefined) {
882
+ return this.subCommand(["from", dimension, coordinatesParser(begin), coordinatesParser(end)], CloneToDimensionCommand, false);
883
+ }
884
+ return this.subCommand(["from", ...[begin, end, destination].map(coordinatesParser)], CloneOptionsCommand, true);
1216
885
  }
1217
886
  };
887
+ CloneToDimensionCommand = class CloneToDimensionCommand extends CommandArguments {
888
+ to = (dimension, destination) => this.subCommand(["to", dimension, coordinatesParser(destination)], CloneOptionsCommand, true);
889
+ };
890
+ CloneOptionsCommand = class CloneOptionsCommand extends CommandArguments {
891
+ replace = () => this.subCommand(["replace"], CloneModeCommand, true);
892
+ strict = () => this.subCommand(["strict"], CloneStrictOptionsCommand, true);
893
+ masked = () => this.subCommand(["masked"], CloneModeCommand, true);
894
+ filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
895
+ };
896
+ CloneStrictOptionsCommand = class CloneStrictOptionsCommand extends CommandArguments {
897
+ replace = () => this.subCommand(["replace"], CloneModeCommand, true);
898
+ masked = () => this.subCommand(["masked"], CloneModeCommand, true);
899
+ filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
900
+ };
901
+ CloneModeCommand = class CloneModeCommand extends CommandArguments {
902
+ force = () => this.finalCommand(["force"]);
903
+ move = () => this.finalCommand(["move"]);
904
+ normal = () => this.finalCommand(["normal"]);
905
+ };
1218
906
  });
1219
907
 
1220
- // src/pack/dependencies.ts
1221
- var DataPackDependencies, ResourcePackDependencies;
1222
- var init_dependencies = __esm(() => {
1223
- init_packType();
1224
- DataPackDependencies = class DataPackDependencies extends PackType {
1225
- constructor() {
1226
- super("datapack_dependencies", "saves/$worldName$/datapacks", "world/datapacks", "datapacks", "server", false, undefined, false);
908
+ // src/variables/abstractClasses.ts
909
+ var CONDITION_CLASS_BRAND, ConditionClass, SELECTOR_PICK_CLASS_BRAND, SelectorPickClass;
910
+ var init_abstractClasses = __esm(() => {
911
+ CONDITION_CLASS_BRAND = Symbol.for("sandstone.ConditionClass");
912
+ ConditionClass = class ConditionClass {
913
+ [CONDITION_CLASS_BRAND] = true;
914
+ _toMinecraftCondition() {
915
+ throw new Error("Not implemented");
916
+ }
917
+ static [Symbol.hasInstance](instance) {
918
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[CONDITION_CLASS_BRAND] === true;
1227
919
  }
1228
- handleOutput = async (type) => {
1229
- if (type === "output") {}
1230
- };
1231
920
  };
1232
- ResourcePackDependencies = class ResourcePackDependencies extends PackType {
1233
- constructor() {
1234
- super("resourcepack_dependencies", "resourcepacks", "dependency_resources", "resourcepacks", "client", false, undefined, false);
921
+ SELECTOR_PICK_CLASS_BRAND = Symbol.for("sandstone.SelectorPickClass");
922
+ SelectorPickClass = class SelectorPickClass {
923
+ [SELECTOR_PICK_CLASS_BRAND] = true;
924
+ _toSelector() {
925
+ throw new Error("Not implemented");
1235
926
  }
1236
- handleOutput = async (type) => {
1237
- if (type === "output") {}
1238
- };
927
+ toNBT() {
928
+ throw new Error("Not implemented");
929
+ }
930
+ static [Symbol.hasInstance](instance) {
931
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SELECTOR_PICK_CLASS_BRAND] === true;
932
+ }
933
+ };
934
+ });
935
+
936
+ // src/variables/nbt/grammar.ts
937
+ function id(d) {
938
+ return d[0];
939
+ }
940
+ var isCompoundSymbol, grammar, grammar_default;
941
+ var init_grammar = __esm(() => {
942
+ isCompoundSymbol = Symbol("isCompound");
943
+ grammar = {
944
+ Lexer: undefined,
945
+ ParserRules: [
946
+ { name: "_$ebnf$1", symbols: [] },
947
+ { name: "_$ebnf$1", symbols: ["_$ebnf$1", "wschar"], postprocess: (d) => d[0].concat([d[1]]) },
948
+ {
949
+ name: "_",
950
+ symbols: ["_$ebnf$1"],
951
+ postprocess(d) {
952
+ return null;
953
+ }
954
+ },
955
+ { name: "__$ebnf$1", symbols: ["wschar"] },
956
+ { name: "__$ebnf$1", symbols: ["__$ebnf$1", "wschar"], postprocess: (d) => d[0].concat([d[1]]) },
957
+ {
958
+ name: "__",
959
+ symbols: ["__$ebnf$1"],
960
+ postprocess(d) {
961
+ return null;
962
+ }
963
+ },
964
+ { name: "wschar", symbols: [/[ \t\n\v\f]/], postprocess: id },
965
+ { name: "unsigned_int$ebnf$1", symbols: [/[0-9]/] },
966
+ { name: "unsigned_int$ebnf$1", symbols: ["unsigned_int$ebnf$1", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
967
+ {
968
+ name: "unsigned_int",
969
+ symbols: ["unsigned_int$ebnf$1"],
970
+ postprocess(d) {
971
+ return Number.parseInt(d[0].join(""));
972
+ }
973
+ },
974
+ { name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "-" }] },
975
+ { name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "+" }] },
976
+ { name: "int$ebnf$1", symbols: ["int$ebnf$1$subexpression$1"], postprocess: id },
977
+ { name: "int$ebnf$1", symbols: [], postprocess: () => null },
978
+ { name: "int$ebnf$2", symbols: [/[0-9]/] },
979
+ { name: "int$ebnf$2", symbols: ["int$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
980
+ {
981
+ name: "int",
982
+ symbols: ["int$ebnf$1", "int$ebnf$2"],
983
+ postprocess(d) {
984
+ if (d[0]) {
985
+ return Number.parseInt(d[0][0] + d[1].join(""));
986
+ }
987
+ return Number.parseInt(d[1].join(""));
988
+ }
989
+ },
990
+ { name: "unsigned_decimal$ebnf$1", symbols: [/[0-9]/] },
991
+ {
992
+ name: "unsigned_decimal$ebnf$1",
993
+ symbols: ["unsigned_decimal$ebnf$1", /[0-9]/],
994
+ postprocess: (d) => d[0].concat([d[1]])
995
+ },
996
+ { name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
997
+ {
998
+ name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1",
999
+ symbols: ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/],
1000
+ postprocess: (d) => d[0].concat([d[1]])
1001
+ },
1002
+ {
1003
+ name: "unsigned_decimal$ebnf$2$subexpression$1",
1004
+ symbols: [{ literal: "." }, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]
1005
+ },
1006
+ { name: "unsigned_decimal$ebnf$2", symbols: ["unsigned_decimal$ebnf$2$subexpression$1"], postprocess: id },
1007
+ { name: "unsigned_decimal$ebnf$2", symbols: [], postprocess: () => null },
1008
+ {
1009
+ name: "unsigned_decimal",
1010
+ symbols: ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"],
1011
+ postprocess(d) {
1012
+ return Number.parseFloat(d[0].join("") + (d[1] ? `.${d[1][1].join("")}` : ""));
1013
+ }
1014
+ },
1015
+ { name: "decimal$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
1016
+ { name: "decimal$ebnf$1", symbols: [], postprocess: () => null },
1017
+ { name: "decimal$ebnf$2", symbols: [/[0-9]/] },
1018
+ { name: "decimal$ebnf$2", symbols: ["decimal$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
1019
+ { name: "decimal$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
1020
+ {
1021
+ name: "decimal$ebnf$3$subexpression$1$ebnf$1",
1022
+ symbols: ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
1023
+ postprocess: (d) => d[0].concat([d[1]])
1024
+ },
1025
+ { name: "decimal$ebnf$3$subexpression$1", symbols: [{ literal: "." }, "decimal$ebnf$3$subexpression$1$ebnf$1"] },
1026
+ { name: "decimal$ebnf$3", symbols: ["decimal$ebnf$3$subexpression$1"], postprocess: id },
1027
+ { name: "decimal$ebnf$3", symbols: [], postprocess: () => null },
1028
+ {
1029
+ name: "decimal",
1030
+ symbols: ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"],
1031
+ postprocess(d) {
1032
+ return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : ""));
1033
+ }
1034
+ },
1035
+ {
1036
+ name: "percentage",
1037
+ symbols: ["decimal", { literal: "%" }],
1038
+ postprocess(d) {
1039
+ return d[0] / 100;
1040
+ }
1041
+ },
1042
+ { name: "jsonfloat$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
1043
+ { name: "jsonfloat$ebnf$1", symbols: [], postprocess: () => null },
1044
+ { name: "jsonfloat$ebnf$2", symbols: [/[0-9]/] },
1045
+ { name: "jsonfloat$ebnf$2", symbols: ["jsonfloat$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
1046
+ { name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
1047
+ {
1048
+ name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1",
1049
+ symbols: ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
1050
+ postprocess: (d) => d[0].concat([d[1]])
1051
+ },
1052
+ {
1053
+ name: "jsonfloat$ebnf$3$subexpression$1",
1054
+ symbols: [{ literal: "." }, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]
1055
+ },
1056
+ { name: "jsonfloat$ebnf$3", symbols: ["jsonfloat$ebnf$3$subexpression$1"], postprocess: id },
1057
+ { name: "jsonfloat$ebnf$3", symbols: [], postprocess: () => null },
1058
+ { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [/[+-]/], postprocess: id },
1059
+ { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [], postprocess: () => null },
1060
+ { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2", symbols: [/[0-9]/] },
1061
+ {
1062
+ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2",
1063
+ symbols: ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/],
1064
+ postprocess: (d) => d[0].concat([d[1]])
1065
+ },
1066
+ {
1067
+ name: "jsonfloat$ebnf$4$subexpression$1",
1068
+ symbols: [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"]
1069
+ },
1070
+ { name: "jsonfloat$ebnf$4", symbols: ["jsonfloat$ebnf$4$subexpression$1"], postprocess: id },
1071
+ { name: "jsonfloat$ebnf$4", symbols: [], postprocess: () => null },
1072
+ {
1073
+ name: "jsonfloat",
1074
+ symbols: ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"],
1075
+ postprocess(d) {
1076
+ return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : "") + (d[3] ? `e${d[3][1] || "+"}${d[3][2].join("")}` : ""));
1077
+ }
1078
+ },
1079
+ { name: "dqstring$ebnf$1", symbols: [] },
1080
+ { name: "dqstring$ebnf$1", symbols: ["dqstring$ebnf$1", "dstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
1081
+ {
1082
+ name: "dqstring",
1083
+ symbols: [{ literal: '"' }, "dqstring$ebnf$1", { literal: '"' }],
1084
+ postprocess(d) {
1085
+ return d[1].join("");
1086
+ }
1087
+ },
1088
+ { name: "sqstring$ebnf$1", symbols: [] },
1089
+ { name: "sqstring$ebnf$1", symbols: ["sqstring$ebnf$1", "sstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
1090
+ {
1091
+ name: "sqstring",
1092
+ symbols: [{ literal: "'" }, "sqstring$ebnf$1", { literal: "'" }],
1093
+ postprocess(d) {
1094
+ return d[1].join("");
1095
+ }
1096
+ },
1097
+ { name: "btstring$ebnf$1", symbols: [] },
1098
+ { name: "btstring$ebnf$1", symbols: ["btstring$ebnf$1", /[^`]/], postprocess: (d) => d[0].concat([d[1]]) },
1099
+ {
1100
+ name: "btstring",
1101
+ symbols: [{ literal: "`" }, "btstring$ebnf$1", { literal: "`" }],
1102
+ postprocess(d) {
1103
+ return d[1].join("");
1104
+ }
1105
+ },
1106
+ { name: "dstrchar", symbols: [/[^\\"\n]/], postprocess: id },
1107
+ {
1108
+ name: "dstrchar",
1109
+ symbols: [{ literal: "\\" }, "strescape"],
1110
+ postprocess(d) {
1111
+ return JSON.parse(`"${d.join("")}"`);
1112
+ }
1113
+ },
1114
+ { name: "sstrchar", symbols: [/[^\\'\n]/], postprocess: id },
1115
+ {
1116
+ name: "sstrchar",
1117
+ symbols: [{ literal: "\\" }, "strescape"],
1118
+ postprocess(d) {
1119
+ return JSON.parse(`"${d.join("")}"`);
1120
+ }
1121
+ },
1122
+ { name: "sstrchar$string$1", symbols: [{ literal: "\\" }, { literal: "'" }], postprocess: (d) => d.join("") },
1123
+ {
1124
+ name: "sstrchar",
1125
+ symbols: ["sstrchar$string$1"],
1126
+ postprocess(d) {
1127
+ return "'";
1128
+ }
1129
+ },
1130
+ { name: "strescape", symbols: [/["\\/bfnrt]/], postprocess: id },
1131
+ {
1132
+ name: "strescape",
1133
+ symbols: [{ literal: "u" }, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/],
1134
+ postprocess(d) {
1135
+ return d.join("");
1136
+ }
1137
+ },
1138
+ { name: "expression$subexpression$1", symbols: ["string"] },
1139
+ { name: "expression$subexpression$1", symbols: ["typedNum"] },
1140
+ { name: "expression$subexpression$1", symbols: ["number"] },
1141
+ { name: "expression$subexpression$1", symbols: ["boolean"] },
1142
+ { name: "expression$subexpression$1", symbols: ["byteArray"] },
1143
+ { name: "expression$subexpression$1", symbols: ["intArray"] },
1144
+ { name: "expression$subexpression$1", symbols: ["longArray"] },
1145
+ { name: "expression$subexpression$1", symbols: ["array"] },
1146
+ { name: "expression$subexpression$1", symbols: ["object"] },
1147
+ {
1148
+ name: "expression",
1149
+ symbols: ["expression$subexpression$1"],
1150
+ postprocess: (data) => data[0][0]
1151
+ },
1152
+ {
1153
+ name: "object",
1154
+ symbols: [{ literal: "{" }, "objectInner", { literal: "}" }],
1155
+ postprocess: (data) => Object.fromEntries([
1156
+ ...data[1].map(({ key, value }) => [key, value]),
1157
+ [isCompoundSymbol, true]
1158
+ ])
1159
+ },
1160
+ { name: "objectInner", symbols: ["_"], postprocess: (data) => [] },
1161
+ { name: "objectInner$ebnf$1", symbols: [] },
1162
+ { name: "objectInner$ebnf$1$subexpression$1", symbols: ["objectKeyValue", "_", { literal: "," }, "_"] },
1163
+ {
1164
+ name: "objectInner$ebnf$1",
1165
+ symbols: ["objectInner$ebnf$1", "objectInner$ebnf$1$subexpression$1"],
1166
+ postprocess: (d) => d[0].concat([d[1]])
1167
+ },
1168
+ { name: "objectInner$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
1169
+ { name: "objectInner$ebnf$2", symbols: ["objectInner$ebnf$2$subexpression$1"], postprocess: id },
1170
+ { name: "objectInner$ebnf$2", symbols: [], postprocess: () => null },
1171
+ {
1172
+ name: "objectInner",
1173
+ symbols: ["_", "objectInner$ebnf$1", "objectKeyValue", "objectInner$ebnf$2", "_"],
1174
+ postprocess: (data) => {
1175
+ const firstKeyValues = data[1].map(([keyValue]) => keyValue);
1176
+ const keyValues = [...firstKeyValues, data[2]];
1177
+ return keyValues;
1178
+ }
1179
+ },
1180
+ { name: "objectKeyValue$ebnf$1", symbols: [/[a-zA-Z]/] },
1181
+ {
1182
+ name: "objectKeyValue$ebnf$1",
1183
+ symbols: ["objectKeyValue$ebnf$1", /[a-zA-Z]/],
1184
+ postprocess: (d) => d[0].concat([d[1]])
1185
+ },
1186
+ {
1187
+ name: "objectKeyValue",
1188
+ symbols: ["objectKeyValue$ebnf$1", "_", { literal: ":" }, "_", "expression"],
1189
+ postprocess: (data) => ({ key: data[0].join(""), value: data[4] })
1190
+ },
1191
+ {
1192
+ name: "objectKeyValue",
1193
+ symbols: ["string", "_", { literal: ":" }, "_", "expression"],
1194
+ postprocess: (data) => ({ key: data[0].value, value: data[4] })
1195
+ },
1196
+ { name: "array$macrocall$2", symbols: ["expression"] },
1197
+ { name: "array$macrocall$1", symbols: ["_"], postprocess: () => [] },
1198
+ { name: "array$macrocall$1$ebnf$1", symbols: [] },
1199
+ { name: "array$macrocall$1$ebnf$1$subexpression$1", symbols: ["array$macrocall$2", "_", { literal: "," }, "_"] },
1200
+ {
1201
+ name: "array$macrocall$1$ebnf$1",
1202
+ symbols: ["array$macrocall$1$ebnf$1", "array$macrocall$1$ebnf$1$subexpression$1"],
1203
+ postprocess: (d) => d[0].concat([d[1]])
1204
+ },
1205
+ { name: "array$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
1206
+ { name: "array$macrocall$1$ebnf$2", symbols: ["array$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
1207
+ { name: "array$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
1208
+ {
1209
+ name: "array$macrocall$1",
1210
+ symbols: ["_", "array$macrocall$1$ebnf$1", "array$macrocall$2", "array$macrocall$1$ebnf$2", "_"],
1211
+ postprocess: (data) => {
1212
+ const firstArray = data[1].map(([expression]) => expression[0]);
1213
+ return [...firstArray, data[2][0]];
1214
+ }
1215
+ },
1216
+ {
1217
+ name: "array",
1218
+ symbols: [{ literal: "[" }, "array$macrocall$1", { literal: "]" }],
1219
+ postprocess: (data) => data[1]
1220
+ },
1221
+ { name: "byteArray$macrocall$2", symbols: ["typedByte"] },
1222
+ { name: "byteArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
1223
+ { name: "byteArray$macrocall$1$ebnf$1", symbols: [] },
1224
+ {
1225
+ name: "byteArray$macrocall$1$ebnf$1$subexpression$1",
1226
+ symbols: ["byteArray$macrocall$2", "_", { literal: "," }, "_"]
1227
+ },
1228
+ {
1229
+ name: "byteArray$macrocall$1$ebnf$1",
1230
+ symbols: ["byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$1$ebnf$1$subexpression$1"],
1231
+ postprocess: (d) => d[0].concat([d[1]])
1232
+ },
1233
+ { name: "byteArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
1234
+ {
1235
+ name: "byteArray$macrocall$1$ebnf$2",
1236
+ symbols: ["byteArray$macrocall$1$ebnf$2$subexpression$1"],
1237
+ postprocess: id
1238
+ },
1239
+ { name: "byteArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
1240
+ {
1241
+ name: "byteArray$macrocall$1",
1242
+ symbols: ["_", "byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$2", "byteArray$macrocall$1$ebnf$2", "_"],
1243
+ postprocess: (data) => {
1244
+ const firstArray = data[1].map(([expression]) => expression[0]);
1245
+ return [...firstArray, data[2][0]];
1246
+ }
1247
+ },
1248
+ {
1249
+ name: "byteArray",
1250
+ symbols: [
1251
+ { literal: "[" },
1252
+ "_",
1253
+ { literal: "B" },
1254
+ "_",
1255
+ { literal: ";" },
1256
+ "byteArray$macrocall$1",
1257
+ { literal: "]" }
1258
+ ],
1259
+ postprocess: (data) => ({ dataType: "byteArray", value: data[5] })
1260
+ },
1261
+ { name: "intArray$macrocall$2", symbols: ["number"] },
1262
+ { name: "intArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
1263
+ { name: "intArray$macrocall$1$ebnf$1", symbols: [] },
1264
+ {
1265
+ name: "intArray$macrocall$1$ebnf$1$subexpression$1",
1266
+ symbols: ["intArray$macrocall$2", "_", { literal: "," }, "_"]
1267
+ },
1268
+ {
1269
+ name: "intArray$macrocall$1$ebnf$1",
1270
+ symbols: ["intArray$macrocall$1$ebnf$1", "intArray$macrocall$1$ebnf$1$subexpression$1"],
1271
+ postprocess: (d) => d[0].concat([d[1]])
1272
+ },
1273
+ { name: "intArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
1274
+ { name: "intArray$macrocall$1$ebnf$2", symbols: ["intArray$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
1275
+ { name: "intArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
1276
+ {
1277
+ name: "intArray$macrocall$1",
1278
+ symbols: ["_", "intArray$macrocall$1$ebnf$1", "intArray$macrocall$2", "intArray$macrocall$1$ebnf$2", "_"],
1279
+ postprocess: (data) => {
1280
+ const firstArray = data[1].map(([expression]) => expression[0]);
1281
+ return [...firstArray, data[2][0]];
1282
+ }
1283
+ },
1284
+ {
1285
+ name: "intArray",
1286
+ symbols: [
1287
+ { literal: "[" },
1288
+ "_",
1289
+ { literal: "I" },
1290
+ "_",
1291
+ { literal: ";" },
1292
+ "intArray$macrocall$1",
1293
+ { literal: "]" }
1294
+ ],
1295
+ postprocess: (data) => ({ dataType: "intArray", value: data[5] })
1296
+ },
1297
+ { name: "longArray$macrocall$2", symbols: ["typedLong"] },
1298
+ { name: "longArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
1299
+ { name: "longArray$macrocall$1$ebnf$1", symbols: [] },
1300
+ {
1301
+ name: "longArray$macrocall$1$ebnf$1$subexpression$1",
1302
+ symbols: ["longArray$macrocall$2", "_", { literal: "," }, "_"]
1303
+ },
1304
+ {
1305
+ name: "longArray$macrocall$1$ebnf$1",
1306
+ symbols: ["longArray$macrocall$1$ebnf$1", "longArray$macrocall$1$ebnf$1$subexpression$1"],
1307
+ postprocess: (d) => d[0].concat([d[1]])
1308
+ },
1309
+ { name: "longArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
1310
+ {
1311
+ name: "longArray$macrocall$1$ebnf$2",
1312
+ symbols: ["longArray$macrocall$1$ebnf$2$subexpression$1"],
1313
+ postprocess: id
1314
+ },
1315
+ { name: "longArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
1316
+ {
1317
+ name: "longArray$macrocall$1",
1318
+ symbols: ["_", "longArray$macrocall$1$ebnf$1", "longArray$macrocall$2", "longArray$macrocall$1$ebnf$2", "_"],
1319
+ postprocess: (data) => {
1320
+ const firstArray = data[1].map(([expression]) => expression[0]);
1321
+ return [...firstArray, data[2][0]];
1322
+ }
1323
+ },
1324
+ {
1325
+ name: "longArray",
1326
+ symbols: [
1327
+ { literal: "[" },
1328
+ "_",
1329
+ { literal: "L" },
1330
+ "_",
1331
+ { literal: ";" },
1332
+ "longArray$macrocall$1",
1333
+ { literal: "]" }
1334
+ ],
1335
+ postprocess: (data) => ({ dataType: "longArray", value: data[5] })
1336
+ },
1337
+ { name: "string$subexpression$1", symbols: ["dqstring"] },
1338
+ { name: "string$subexpression$1", symbols: ["sqstring"] },
1339
+ {
1340
+ name: "string",
1341
+ symbols: ["string$subexpression$1"],
1342
+ postprocess: (data) => ({ dataType: "string", value: data[0][0] })
1343
+ },
1344
+ { name: "typedNum$subexpression$1", symbols: ["typedByte"] },
1345
+ { name: "typedNum$subexpression$1", symbols: ["typedShort"] },
1346
+ { name: "typedNum$subexpression$1", symbols: ["typedLong"] },
1347
+ { name: "typedNum$subexpression$1", symbols: ["typedFloat"] },
1348
+ { name: "typedNum", symbols: ["typedNum$subexpression$1"], postprocess: (data) => data[0][0] },
1349
+ {
1350
+ name: "typedByte$subexpression$1",
1351
+ symbols: [/[bB]/],
1352
+ postprocess(d) {
1353
+ return d.join("");
1354
+ }
1355
+ },
1356
+ {
1357
+ name: "typedByte",
1358
+ symbols: ["int", "typedByte$subexpression$1"],
1359
+ postprocess: (data) => ({ dataType: "byte", value: data[0] })
1360
+ },
1361
+ {
1362
+ name: "typedShort$subexpression$1",
1363
+ symbols: [/[sS]/],
1364
+ postprocess(d) {
1365
+ return d.join("");
1366
+ }
1367
+ },
1368
+ {
1369
+ name: "typedShort",
1370
+ symbols: ["int", "typedShort$subexpression$1"],
1371
+ postprocess: (data) => ({ dataType: "short", value: data[0] })
1372
+ },
1373
+ {
1374
+ name: "typedLong$subexpression$1",
1375
+ symbols: [/[lL]/],
1376
+ postprocess(d) {
1377
+ return d.join("");
1378
+ }
1379
+ },
1380
+ {
1381
+ name: "typedLong",
1382
+ symbols: ["int", "typedLong$subexpression$1"],
1383
+ postprocess: (data) => ({ dataType: "long", value: data[0] })
1384
+ },
1385
+ {
1386
+ name: "typedFloat$subexpression$1",
1387
+ symbols: [/[dD]/],
1388
+ postprocess(d) {
1389
+ return d.join("");
1390
+ }
1391
+ },
1392
+ {
1393
+ name: "typedFloat",
1394
+ symbols: ["decimal", "typedFloat$subexpression$1"],
1395
+ postprocess: (data) => ({ dataType: "double", value: data[0] })
1396
+ },
1397
+ {
1398
+ name: "typedFloat$subexpression$2",
1399
+ symbols: [/[fF]/],
1400
+ postprocess(d) {
1401
+ return d.join("");
1402
+ }
1403
+ },
1404
+ {
1405
+ name: "typedFloat",
1406
+ symbols: ["decimal", "typedFloat$subexpression$2"],
1407
+ postprocess: (data) => ({ dataType: "float", value: data[0] })
1408
+ },
1409
+ { name: "number$subexpression$1", symbols: ["decimal"] },
1410
+ {
1411
+ name: "number",
1412
+ symbols: ["number$subexpression$1"],
1413
+ postprocess: (data) => ({ dataType: "number", value: data[0][0] })
1414
+ },
1415
+ {
1416
+ name: "boolean$subexpression$1$string$1",
1417
+ symbols: [{ literal: "t" }, { literal: "r" }, { literal: "u" }, { literal: "e" }],
1418
+ postprocess: (d) => d.join("")
1419
+ },
1420
+ { name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$1"] },
1421
+ {
1422
+ name: "boolean$subexpression$1$string$2",
1423
+ symbols: [{ literal: "f" }, { literal: "a" }, { literal: "l" }, { literal: "s" }, { literal: "e" }],
1424
+ postprocess: (d) => d.join("")
1425
+ },
1426
+ { name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$2"] },
1427
+ {
1428
+ name: "boolean",
1429
+ symbols: ["boolean$subexpression$1"],
1430
+ postprocess: (data) => ({ dataType: "boolean", value: data[0].join("") === "true" })
1431
+ }
1432
+ ],
1433
+ ParserStart: "expression"
1239
1434
  };
1435
+ grammar_default = grammar;
1240
1436
  });
1241
1437
 
1242
- // src/variables/Coordinates.ts
1243
- import { inspect as inspect4 } from "util";
1244
- function relative(...coordinates) {
1245
- if (coordinates.length === 0) {
1246
- return new VectorClass(["~", "~", "~"]);
1247
- }
1248
- if (coordinates.length === 1) {
1249
- return `~${coordinates[0] || ""}`;
1250
- }
1251
- return new VectorClass(coordinates.map((coord) => `~${coord || ""}`));
1438
+ // src/variables/nbt/parser.ts
1439
+ import nearley from "nearley";
1440
+ function isCompoundNbt(nbt) {
1441
+ return !!nbt[isCompoundSymbol];
1252
1442
  }
1253
- var VECTOR_CLASS_BRAND, VectorClass;
1254
- var init_Coordinates = __esm(() => {
1255
- VECTOR_CLASS_BRAND = Symbol.for("sandstone.VectorClass");
1256
- VectorClass = class VectorClass {
1257
- [VECTOR_CLASS_BRAND] = true;
1258
- values;
1259
- constructor(values) {
1260
- if (!Array.isArray(values) || !values.every((i) => typeof i === "string")) {
1261
- throw new Error(`Expected array of string for Vector values, got ${inspect4(values)}`);
1262
- }
1263
- this.values = values;
1264
- }
1265
- toString() {
1266
- return this.values.join(" ");
1267
- }
1268
- toJSON() {
1269
- return this.toString();
1270
- }
1271
- toNBT() {
1272
- return this.toString();
1273
- }
1274
- [Symbol.iterator]() {
1275
- return this.values[Symbol.iterator]();
1276
- }
1277
- static [Symbol.hasInstance](instance) {
1278
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[VECTOR_CLASS_BRAND] === true;
1443
+ function parseRaw(nbt) {
1444
+ const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar_default));
1445
+ parser.feed(nbt);
1446
+ parser.finish();
1447
+ return parser.results[0];
1448
+ }
1449
+ function parseExpression(NBT, nbt) {
1450
+ if (Array.isArray(nbt)) {
1451
+ return nbt.map((x) => parseExpression(NBT, x));
1452
+ }
1453
+ if (typeof nbt === "object") {
1454
+ if (isCompoundNbt(nbt)) {
1455
+ return Object.keys(nbt).reduce((acc, key) => {
1456
+ acc[key] = parseExpression(NBT, nbt[key]);
1457
+ return acc;
1458
+ }, {});
1279
1459
  }
1280
- };
1281
- });
1282
-
1283
- // src/variables/parsers.ts
1284
- function coordinatesParser(coordinates) {
1285
- if (Array.isArray(coordinates)) {
1286
- if (coordinates.length === 3 || coordinates.length === 2) {
1287
- return new VectorClass(coordinates.map((coord) => {
1288
- if (typeof coord === "string") {
1289
- return coord;
1290
- }
1291
- if (typeof coord === "number") {
1292
- return `${coord}`;
1293
- }
1294
- if ("toMacro" in coord) {
1295
- return coord.toMacro();
1296
- }
1297
- throw new Error(`[coordinatesParser] Unsupported vector component ${coord}`);
1298
- }));
1460
+ switch (nbt.dataType) {
1461
+ case "byte":
1462
+ return NBT.byte(nbt.value);
1463
+ case "short":
1464
+ return NBT.short(nbt.value);
1465
+ case "long":
1466
+ return NBT.long(nbt.value);
1467
+ case "float":
1468
+ return NBT.float(nbt.value);
1469
+ case "double":
1470
+ return NBT.double(nbt.value);
1471
+ case "number":
1472
+ return nbt.value;
1473
+ case "string":
1474
+ return nbt.value;
1475
+ case "byteArray":
1476
+ return NBT.byteArray(nbt.value.map((x) => x.value));
1477
+ case "intArray":
1478
+ return NBT.intArray(nbt.value.map((x) => x.value));
1479
+ case "longArray":
1480
+ return NBT.longArray(nbt.value.map((x) => x.value));
1299
1481
  }
1300
- throw new Error(`[coordinatesParser] Unsupported vector size ${coordinates.length}`);
1301
- } else {
1302
- return coordinates;
1303
1482
  }
1483
+ throw new Error(`Unrecognized data type: ${nbt.dataType}`);
1304
1484
  }
1305
- function rotationParser(rotation) {
1306
- if (Array.isArray(rotation)) {
1307
- if (rotation.length === 2) {
1308
- return new VectorClass(rotation.map((coord) => {
1309
- if (typeof coord === "string") {
1310
- return coord;
1311
- }
1312
- if (typeof coord === "number") {
1313
- return `${coord}`;
1314
- }
1315
- if ("toMacro" in coord) {
1316
- return coord.toMacro();
1317
- }
1318
- throw new Error(`[rotationParser] Unsupported vector component ${coord}`);
1319
- }));
1320
- }
1321
- throw new Error(`[rotationParser] Unsupported vector size ${rotation.length}`);
1322
- } else {
1323
- return rotation;
1324
- }
1485
+ function parseNBT(NBT, nbt) {
1486
+ const rawResult = parseRaw(nbt);
1487
+ return parseExpression(NBT, rawResult);
1325
1488
  }
1326
- function targetParser(target) {
1327
- if (target === undefined) {
1328
- throw new Error("Target cannot be undefined.");
1329
- }
1330
- if (typeof target === "string") {
1331
- return target;
1332
- }
1333
- if (target._toSelector) {
1334
- return target._toSelector();
1335
- }
1336
- if (target.toMacro) {
1337
- return target;
1489
+ var init_parser = __esm(() => {
1490
+ init_grammar();
1491
+ });
1492
+
1493
+ // src/variables/nbt/NBTs.ts
1494
+ import * as util3 from "util";
1495
+ function customNumber(num, _class) {
1496
+ if (Array.isArray(num)) {
1497
+ return num.map((n) => new _class(n));
1338
1498
  }
1339
- return target.toString();
1499
+ return new _class(num);
1340
1500
  }
1341
- var sanitizeValue = (core, value) => {
1342
- if (value === undefined || value === null) {
1343
- return "";
1344
- }
1345
- if (typeof value === "string") {
1346
- return value;
1347
- }
1348
- if (isMacroArgument(core, value)) {
1349
- return value.toMacro();
1350
- }
1351
- if (Number.isFinite(value)) {
1352
- return value.toString();
1353
- }
1354
- return "";
1355
- }, rangeParser = (core, range) => {
1356
- if (Array.isArray(range)) {
1357
- return `${sanitizeValue(core, range[0])}..${sanitizeValue(core, range[1])}`;
1358
- }
1359
- return range.toString();
1360
- }, structureRotationParser = (rotation) => {
1361
- if (!rotation) {
1362
- return "none";
1363
- }
1364
- if (typeof rotation === "object") {
1365
- return rotation;
1366
- }
1367
- const numToLiteral = (angle) => {
1368
- switch (angle) {
1369
- case 0:
1370
- return "none";
1371
- case 90:
1372
- return "clockwise_90";
1373
- case 180:
1374
- return "180";
1375
- case 270:
1376
- return "counterclockwise_90";
1377
- case -90:
1378
- return "counterclockwise_90";
1379
- case -180:
1380
- return "180";
1381
- case -270:
1382
- return "clockwise_90";
1383
- default: {
1384
- if (!Number.isInteger(angle / 90)) {
1385
- throw new Error("Structure rotation must be in increments of 90!");
1386
- }
1387
- angle %= 360;
1388
- angle = (angle + 360) % 360;
1389
- if (angle > 180)
1390
- angle -= 360;
1391
- return numToLiteral(angle);
1392
- }
1393
- }
1394
- };
1395
- if (typeof rotation === "number") {
1396
- return numToLiteral(rotation);
1501
+ function dynamicNBT(template, ...args) {
1502
+ const mixedArgs = template.flatMap((s, i) => [s, args[i]]).slice(0, -1);
1503
+ const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtStringifier(element) : element.toString()).join("");
1504
+ return parseNBT(NBT, result);
1505
+ }
1506
+ var N_B_T_CLASS_BRAND, NBTClass, N_B_T_PRIMITIVE_BRAND, NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, NBTTypedArray, NBTLongArray, NBTByteArray, NBTIntArray, NotNBT, NBTAnyValue, NBT, nbtStringifier = (nbt) => {
1507
+ if (nbt === null || nbt === undefined) {
1508
+ throw new Error("Nullish nbt values are not allowed");
1397
1509
  }
1398
- if (rotation === "clockwise_90" || rotation === "counterclockwise_90") {
1399
- return rotation;
1510
+ if (typeof nbt === "number") {
1511
+ return `${nbt}d`;
1400
1512
  }
1401
- return numToLiteral(Number(rotation));
1402
- }, structureMirrorParser = (mirror) => {
1403
- if (typeof mirror === "object") {
1404
- return mirror.toMacro();
1513
+ if (typeof nbt === "boolean") {
1514
+ return nbt.toString();
1405
1515
  }
1406
- if (typeof mirror === "string") {
1407
- const lastCharacter = mirror.slice(0, -1);
1408
- if (lastCharacter === "x") {
1409
- return "left_right";
1410
- }
1411
- if (lastCharacter === "z") {
1412
- return "front_back";
1516
+ if (typeof nbt === "string") {
1517
+ const inspectedStr = util3.inspect(nbt, {
1518
+ breakLength: Number.POSITIVE_INFINITY,
1519
+ compact: true,
1520
+ maxStringLength: Number.POSITIVE_INFINITY,
1521
+ depth: Number.POSITIVE_INFINITY
1522
+ });
1523
+ if (inspectedStr[0] === "`") {
1524
+ return JSON.stringify(nbt);
1413
1525
  }
1414
- return mirror;
1415
- }
1416
- if (mirror) {
1417
- return "left_right";
1526
+ return inspectedStr;
1418
1527
  }
1419
- return "none";
1420
- };
1421
- var init_parsers = __esm(() => {
1422
- init_Macro();
1423
- init_Coordinates();
1424
- });
1425
-
1426
- // src/commands/helpers.ts
1427
- class FinalCommandOutput {
1428
- node;
1429
- constructor(node) {
1430
- this.node = node;
1528
+ if (Array.isArray(nbt)) {
1529
+ const itemsStr = nbt.map(nbtStringifier).join(",");
1530
+ return `[${itemsStr}]`;
1431
1531
  }
1432
- }
1433
-
1434
- class CommandArguments {
1435
- sandstonePack;
1436
- previousNode;
1437
- autoCommit;
1438
- NodeType;
1439
- sandstoneCore;
1440
- sandstoneCommands;
1441
- constructor(sandstonePack, previousNode, autoCommit = true) {
1442
- this.sandstonePack = sandstonePack;
1443
- this.previousNode = previousNode;
1444
- this.autoCommit = autoCommit;
1445
- this.sandstoneCore = sandstonePack.core;
1446
- this.sandstoneCommands = sandstonePack.commands;
1532
+ if (nbt instanceof NBTClass) {
1533
+ return nbt[util3.inspect.custom]();
1447
1534
  }
1448
- getNode = () => {
1449
- if (this.previousNode) {
1450
- return this.previousNode;
1535
+ if (typeof nbt === "object" || typeof nbt === "function") {
1536
+ let failedMacro = false;
1537
+ if ("toMacro" in nbt) {
1538
+ const macro = nbt.toMacro();
1539
+ if (macro === "$()") {
1540
+ failedMacro = true;
1541
+ } else {
1542
+ return macro;
1543
+ }
1451
1544
  }
1452
- if (this.NodeType) {
1453
- return new this.NodeType(this.sandstonePack);
1545
+ if ("toNBT" in nbt) {
1546
+ return nbt.toNBT();
1547
+ } else if (failedMacro) {
1548
+ throw new Error("[nbtStringifier] A macro variable NBT insertion was attempted in an mcfunction without macros defined.");
1454
1549
  }
1455
- throw new Error("No node type specified & no previous node for a non-root-level command");
1456
- };
1457
- finalCommand = (args, currentNode) => {
1458
- const node = currentNode ?? this.getNode();
1459
- if (args) {
1460
- node.args.push(...args);
1550
+ if (typeof nbt === "function") {
1551
+ throw new Error(`[nbtStringifier] This should never happen. A function or callable instance (${nbt.constructor?.name}) without toNBT was passed in as an NBT value.`);
1461
1552
  }
1462
- if (this.autoCommit) {
1463
- node.commit();
1553
+ if (nbt.constructor.name !== "Object") {
1554
+ if ("toString" in nbt) {
1555
+ return `${toString}`;
1556
+ } else {
1557
+ throw new Error(`[nbtStringifier] A ${nbt.constructor?.name} was passed in as an NBT value. Hint: define toNBT or toString if this was intentional`);
1558
+ }
1559
+ }
1560
+ }
1561
+ const objectStr = Object.entries(nbt).map(([key, value]) => `${key}:${nbtStringifier(value)}`).join(",");
1562
+ return `{${objectStr}}`;
1563
+ };
1564
+ var init_NBTs = __esm(() => {
1565
+ init_utils();
1566
+ init_parser();
1567
+ N_B_T_CLASS_BRAND = Symbol.for("sandstone.NBTClass");
1568
+ NBTClass = class NBTClass {
1569
+ [N_B_T_CLASS_BRAND] = true;
1570
+ static [Symbol.hasInstance](instance) {
1571
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_CLASS_BRAND] === true;
1464
1572
  }
1465
- return new FinalCommandOutput(node);
1466
1573
  };
1467
- subCommand = (args, NextArgumentType, executable = false, additionalNextArgs = [], currentNode) => {
1468
- const node = currentNode ?? this.getNode();
1469
- if (args) {
1470
- node.args.push(...args);
1574
+ N_B_T_PRIMITIVE_BRAND = Symbol.for("sandstone.NBTPrimitive");
1575
+ NBTPrimitive = class NBTPrimitive extends NBTClass {
1576
+ [N_B_T_PRIMITIVE_BRAND] = true;
1577
+ value;
1578
+ unit;
1579
+ constructor(value, unit) {
1580
+ super();
1581
+ this.value = value;
1582
+ this.unit = unit;
1471
1583
  }
1472
- if (executable && this.autoCommit) {
1473
- node.commit();
1584
+ toJSON() {
1585
+ return this.value;
1474
1586
  }
1475
- return new NextArgumentType(this.sandstonePack, node, this.autoCommit, ...additionalNextArgs);
1476
- };
1477
- }
1478
-
1479
- // src/commands/validators.ts
1480
- function validateIntegerRange(integer, name, minimum = 0, maximum = 2147483647) {
1481
- if (typeof integer !== "number") {
1482
- return integer;
1483
- }
1484
- if (integer && integer <= minimum) {
1485
- throw new Error(`\`${name}\` must be greater than or equal to ${minimum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
1486
- }
1487
- if (integer && integer >= maximum) {
1488
- throw new Error(`\`${name}\` must be lower than or equal to ${maximum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
1489
- }
1490
- return integer;
1491
- }
1492
-
1493
- // src/commands/implementations/block/place.ts
1494
- var PlaceCommandNode, PlaceCommand;
1495
- var init_place = __esm(() => {
1496
- init_nodes();
1497
- init_parsers();
1498
- PlaceCommandNode = class PlaceCommandNode extends CommandNode {
1499
- command = "place";
1500
- };
1501
- PlaceCommand = class PlaceCommand extends CommandArguments {
1502
- NodeType = PlaceCommandNode;
1503
- feature = (feature, pos = "~ ~ ~") => this.finalCommand(["feature", feature, coordinatesParser(pos)]);
1504
- jigsaw = (pool, target, maxDepth, pos = "~ ~ ~") => this.finalCommand([
1505
- "jigsaw",
1506
- pool,
1507
- target,
1508
- `${validateIntegerRange(maxDepth, "Jigsaw max depth", 0, 7)}`,
1509
- coordinatesParser(pos)
1510
- ]);
1511
- structure = (configuredStructure, pos = "~ ~ ~") => this.finalCommand(["structure", configuredStructure, coordinatesParser(pos)]);
1512
- template = (structure, pos = "~ ~ ~", rotation, mirror, integrity = 1, seed = 0, mode) => {
1513
- this.finalCommand([
1514
- "template",
1515
- `${structure}`,
1516
- coordinatesParser(pos),
1517
- structureRotationParser(rotation),
1518
- structureMirrorParser(mirror),
1519
- `${integrity}`,
1520
- `${seed}`,
1521
- ...mode === undefined ? [] : [mode]
1522
- ]);
1523
- };
1524
- };
1525
- });
1526
-
1527
- // src/commands/implementations/entity/damage.ts
1528
- var DamageCommandNode, DamageCauseCommand, DamageSourceCommand, DamageCommand;
1529
- var init_damage = __esm(() => {
1530
- init_nodes();
1531
- init_parsers();
1532
- DamageCommandNode = class DamageCommandNode extends CommandNode {
1533
- command = "damage";
1534
- };
1535
- DamageCauseCommand = class DamageCauseCommand extends CommandArguments {
1536
- from = (cause) => this.finalCommand(["from", targetParser(cause)]);
1537
- };
1538
- DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
1539
- by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand);
1540
- at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
1541
- };
1542
- DamageCommand = class DamageCommand extends CommandArguments {
1543
- NodeType = DamageCommandNode;
1544
- damage = (target, amount, damageType) => {
1545
- validateIntegerRange(amount, "amount", 0, 1e6);
1546
- return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand);
1547
- };
1548
- };
1549
- });
1550
-
1551
- // src/commands/implementations/_fake/comment.ts
1552
- var CommentCommandNode, CommentCommand;
1553
- var init_comment = __esm(() => {
1554
- init_nodes();
1555
- CommentCommandNode = class CommentCommandNode extends CommandNode {
1556
- command = "#";
1557
- getValue() {
1558
- return this.args[0].join(" ").split(`
1559
- `).map((line) => `# ${line}`).join(`
1560
- `);
1587
+ [util3.inspect.custom] = () => `${this.value}${this.unit}`;
1588
+ static [Symbol.hasInstance](instance) {
1589
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_PRIMITIVE_BRAND] === true;
1561
1590
  }
1562
1591
  };
1563
- CommentCommand = class CommentCommand extends CommandArguments {
1564
- NodeType = CommentCommandNode;
1565
- comment = (...comments) => this.finalCommand([comments]);
1566
- };
1567
- });
1568
-
1569
- // src/commands/implementations/_fake/raw.ts
1570
- var RawCommandNode, RawCommand;
1571
- var init_raw = __esm(() => {
1572
- init_nodes();
1573
- RawCommandNode = class RawCommandNode extends CommandNode {
1574
- command = "";
1575
- };
1576
- RawCommand = class RawCommand extends CommandArguments {
1577
- NodeType = RawCommandNode;
1578
- raw = (...args) => this.finalCommand([...args]);
1579
- };
1580
- });
1581
-
1582
- // src/commands/implementations/block/clone.ts
1583
- var CloneCommandNode, CloneCommand, CloneFromDimensionCommand, CloneToDimensionCommand, CloneOptionsCommand, CloneStrictOptionsCommand, CloneModeCommand;
1584
- var init_clone = __esm(() => {
1585
- init_nodes();
1586
- init_parsers();
1587
- CloneCommandNode = class CloneCommandNode extends CommandNode {
1588
- command = "clone";
1589
- };
1590
- CloneCommand = class CloneCommand extends CommandArguments {
1591
- NodeType = CloneCommandNode;
1592
- clone(begin, end, destination) {
1593
- if (begin === undefined) {
1594
- return this.subCommand([], CloneFromDimensionCommand, false);
1595
- }
1596
- return this.subCommand([begin, end, destination].map(coordinatesParser), CloneOptionsCommand, true);
1592
+ NBTLong = class NBTLong extends NBTPrimitive {
1593
+ constructor(value) {
1594
+ super(value, "l");
1597
1595
  }
1598
1596
  };
1599
- CloneFromDimensionCommand = class CloneFromDimensionCommand extends CommandArguments {
1600
- from(dimension, begin, end, destination) {
1601
- if (destination === undefined) {
1602
- return this.subCommand(["from", dimension, coordinatesParser(begin), coordinatesParser(end)], CloneToDimensionCommand, false);
1603
- }
1604
- return this.subCommand(["from", ...[begin, end, destination].map(coordinatesParser)], CloneOptionsCommand, true);
1597
+ NBTByte = class NBTByte extends NBTPrimitive {
1598
+ constructor(value) {
1599
+ super(value, "b");
1605
1600
  }
1606
1601
  };
1607
- CloneToDimensionCommand = class CloneToDimensionCommand extends CommandArguments {
1608
- to = (dimension, destination) => this.subCommand(["to", dimension, coordinatesParser(destination)], CloneOptionsCommand, true);
1602
+ NBTShort = class NBTShort extends NBTPrimitive {
1603
+ constructor(value) {
1604
+ super(value, "s");
1605
+ }
1609
1606
  };
1610
- CloneOptionsCommand = class CloneOptionsCommand extends CommandArguments {
1611
- replace = () => this.subCommand(["replace"], CloneModeCommand, true);
1612
- strict = () => this.subCommand(["strict"], CloneStrictOptionsCommand, true);
1613
- masked = () => this.subCommand(["masked"], CloneModeCommand, true);
1614
- filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
1607
+ NBTFloat = class NBTFloat extends NBTPrimitive {
1608
+ constructor(value) {
1609
+ super(value, "f");
1610
+ }
1615
1611
  };
1616
- CloneStrictOptionsCommand = class CloneStrictOptionsCommand extends CommandArguments {
1617
- replace = () => this.subCommand(["replace"], CloneModeCommand, true);
1618
- masked = () => this.subCommand(["masked"], CloneModeCommand, true);
1619
- filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
1612
+ NBTInt = class NBTInt extends NBTPrimitive {
1613
+ constructor(value) {
1614
+ super(value, "i");
1615
+ }
1620
1616
  };
1621
- CloneModeCommand = class CloneModeCommand extends CommandArguments {
1622
- force = () => this.finalCommand(["force"]);
1623
- move = () => this.finalCommand(["move"]);
1624
- normal = () => this.finalCommand(["normal"]);
1617
+ NBTDouble = class NBTDouble extends NBTPrimitive {
1618
+ constructor(value) {
1619
+ super(value, "d");
1620
+ }
1625
1621
  };
1626
- });
1627
-
1628
- // src/variables/abstractClasses.ts
1629
- var CONDITION_CLASS_BRAND, ConditionClass, SELECTOR_PICK_CLASS_BRAND, SelectorPickClass;
1630
- var init_abstractClasses = __esm(() => {
1631
- CONDITION_CLASS_BRAND = Symbol.for("sandstone.ConditionClass");
1632
- ConditionClass = class ConditionClass {
1633
- [CONDITION_CLASS_BRAND] = true;
1634
- _toMinecraftCondition() {
1635
- throw new Error("Not implemented");
1622
+ NBTTypedArray = class NBTTypedArray extends NBTClass {
1623
+ values;
1624
+ unit;
1625
+ constructor(values, unit) {
1626
+ super();
1627
+ this.values = values;
1628
+ this.unit = unit;
1636
1629
  }
1637
- static [Symbol.hasInstance](instance) {
1638
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[CONDITION_CLASS_BRAND] === true;
1630
+ toJSON() {
1631
+ return this.values;
1639
1632
  }
1633
+ [util3.inspect.custom] = () => `[${this.unit};${this.values.length === 0 ? "" : this.values.join(",")}]`;
1640
1634
  };
1641
- SELECTOR_PICK_CLASS_BRAND = Symbol.for("sandstone.SelectorPickClass");
1642
- SelectorPickClass = class SelectorPickClass {
1643
- [SELECTOR_PICK_CLASS_BRAND] = true;
1644
- _toSelector() {
1645
- throw new Error("Not implemented");
1635
+ NBTLongArray = class NBTLongArray extends NBTTypedArray {
1636
+ constructor(values) {
1637
+ super(values, "L");
1646
1638
  }
1647
- toNBT() {
1648
- throw new Error("Not implemented");
1639
+ };
1640
+ NBTByteArray = class NBTByteArray extends NBTTypedArray {
1641
+ constructor(values) {
1642
+ super(values, "B");
1649
1643
  }
1650
- static [Symbol.hasInstance](instance) {
1651
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SELECTOR_PICK_CLASS_BRAND] === true;
1644
+ };
1645
+ NBTIntArray = class NBTIntArray extends NBTTypedArray {
1646
+ constructor(values) {
1647
+ super(values, "I");
1648
+ }
1649
+ };
1650
+ NotNBT = class NotNBT extends NBTClass {
1651
+ nbt;
1652
+ constructor(nbt) {
1653
+ super();
1654
+ this.nbt = nbt;
1652
1655
  }
1656
+ [util3.inspect.custom] = () => `!${nbtStringifier(this.nbt)}`;
1657
+ };
1658
+ NBTAnyValue = class NBTAnyValue extends NBTPrimitive {
1653
1659
  };
1660
+ NBT = makeCallable({
1661
+ int: (num) => customNumber(num, NBTInt),
1662
+ float: (num) => customNumber(num, NBTFloat),
1663
+ double: (num) => customNumber(num, NBTDouble),
1664
+ byte: (num) => customNumber(num, NBTByte),
1665
+ short: (num) => customNumber(num, NBTShort),
1666
+ long: (num) => customNumber(num, NBTLong),
1667
+ intArray: (numbers) => new NBTIntArray(numbers),
1668
+ longArray: (numbers) => new NBTLongArray(numbers),
1669
+ byteArray: (numbers) => new NBTByteArray(numbers),
1670
+ not: (nbt) => new NotNBT(nbt),
1671
+ stringify: (nbt) => nbtStringifier(nbt),
1672
+ parse: (nbt) => parseNBT(NBT, nbt)
1673
+ }, dynamicNBT);
1654
1674
  });
1655
1675
 
1656
1676
  // src/variables/Score.ts
@@ -1714,6 +1734,9 @@ var init_Score = __esm(() => {
1714
1734
  ]));
1715
1735
  unaryOperation(operation, operator, ...args) {
1716
1736
  if (typeof args[0] === "number") {
1737
+ if (args[0] < 0 && operation !== "set") {
1738
+ return this.binaryOperation(operator, args[0]);
1739
+ }
1717
1740
  this.commands.scoreboard.players[operation](this, args[0]);
1718
1741
  } else if (args[0] instanceof Score) {
1719
1742
  this.commands.scoreboard.players.operation(this, operator, args[0].target, args[0].objective);
@@ -1730,7 +1753,7 @@ var init_Score = __esm(() => {
1730
1753
  let objective = args[1] ?? this.objective;
1731
1754
  if (typeof args[0] === "number") {
1732
1755
  this.sandstonePack.registerNewConstant(args[0]);
1733
- objective = "sandstone_const";
1756
+ objective = "__sandstone";
1734
1757
  }
1735
1758
  this.commands.scoreboard.players.operation(this, operator, args[0], objective);
1736
1759
  return this;
@@ -1886,7 +1909,99 @@ Warning: Score.match() will have to create ${maximum - minimum} mcfunction files
1886
1909
  }
1887
1910
  return MCFunction(`__sandstone:score_match/${matcher}`, [score], () => Macro.returnCmd.run.functionCmd(Macro`__sandstone:score_match/${matcher}/${score}`));
1888
1911
  };
1889
- [util4.inspect.custom](depth, options) {
1912
+ getDecomposer(size, splitsOrCount, componentCount = 31, includeSign = true) {
1913
+ if (typeof this.target !== "string" || this.target.search(/-|@/) !== -1) {
1914
+ throw new Error("[Score#getDecomposer] Must use a fake-player Score for decomposition.");
1915
+ }
1916
+ const { MCFunction, _, commands } = this.sandstonePack;
1917
+ const { execute, returnCmd } = commands;
1918
+ const newScore = this.objective.ScoreHolder;
1919
+ const components = [];
1920
+ const sign = includeSign ? newScore(`${this.target}._32`) : undefined;
1921
+ let decompose;
1922
+ if (size === "bit" || size === undefined) {
1923
+ for (let i = 1;i <= componentCount; i++) {
1924
+ components.push(newScore(`${this.target}._${i}`));
1925
+ }
1926
+ decompose = MCFunction(`__sandstone:score/decompose_bits/${componentCount}_${splitsOrCount === undefined ? 0 : splitsOrCount.size}/${this.target.replaceAll(".", "/").toLowerCase()}`, () => {
1927
+ const resetBits = execute.store.result(components[0]);
1928
+ for (const component of components.slice(1, -1)) {
1929
+ resetBits.store.result(component);
1930
+ resetBits.nestedExecute(["\\\n "], false);
1931
+ }
1932
+ if (includeSign) {
1933
+ resetBits.store.result(components.at(-1));
1934
+ resetBits.nestedExecute(["\\\n "], false);
1935
+ resetBits.run(() => sign["="](0));
1936
+ } else {
1937
+ resetBits.run(() => components.at(-1)["="](0));
1938
+ }
1939
+ const input = newScore(`${this.target}._bf_iterator`);
1940
+ const splits = splitsOrCount ?? new Set;
1941
+ const bitExecute = (bit) => execute.store.success(components[bit - 1]);
1942
+ input["="](this);
1943
+ _.if(this["=="](0), () => {
1944
+ returnCmd(1);
1945
+ });
1946
+ if (includeSign) {
1947
+ execute.store.success(sign).if.score(input, "matches", [null, -1]).run(() => {
1948
+ input["*="](-1);
1949
+ });
1950
+ }
1951
+ input.decomposeBits(splits, componentCount, bitExecute);
1952
+ }, {
1953
+ creator: "sandstone",
1954
+ onConflict: "rename",
1955
+ addToSandstoneCore: true
1956
+ });
1957
+ } else {
1958
+ throw new Error("[Score#getDecomposer(byte)] Byte decomposition is not yet supported");
1959
+ }
1960
+ const result = {
1961
+ components,
1962
+ ...add({ sign })
1963
+ };
1964
+ return {
1965
+ ...result,
1966
+ decompose: () => {
1967
+ decompose();
1968
+ return result;
1969
+ }
1970
+ };
1971
+ }
1972
+ decomposeBits(splits, componentCount, bitExecute, extra) {
1973
+ const { _ } = this.sandstonePack;
1974
+ const sortedSplits = [...splits].filter((s) => s > 0 && s < componentCount).sort((a, b) => b - a);
1975
+ const boundaries = [componentCount, ...sortedSplits, 0];
1976
+ const processRange = (high, low) => {
1977
+ let halvedAgain = 2 ** high;
1978
+ for (let bit = high;bit >= low; bit--) {
1979
+ halvedAgain /= 2;
1980
+ bitExecute(bit, halvedAgain).if.score(this, "matches", [halvedAgain, null]).run(() => {
1981
+ this["-="](halvedAgain);
1982
+ extra?.(bit, halvedAgain);
1983
+ });
1984
+ }
1985
+ };
1986
+ const buildNested = (rangeIndex) => {
1987
+ const high = boundaries[rangeIndex];
1988
+ const low = boundaries[rangeIndex + 1] + 1;
1989
+ if (rangeIndex > 0) {
1990
+ const higherMinValue = 2 ** boundaries[rangeIndex];
1991
+ _.if(this.matches([higherMinValue, null]), () => {
1992
+ buildNested(rangeIndex - 1);
1993
+ });
1994
+ }
1995
+ processRange(high, low);
1996
+ };
1997
+ if (splits.size === 0) {
1998
+ processRange(componentCount, 1);
1999
+ } else {
2000
+ const lowestRangeIndex = boundaries.length - 2;
2001
+ buildNested(lowestRangeIndex);
2002
+ }
2003
+ }
2004
+ [util4.inspect.custom](_depth, options) {
1890
2005
  return formatDebugString(this.constructor.name, {
1891
2006
  target: this.target,
1892
2007
  display: this.display,
@@ -1946,7 +2061,9 @@ class TargetlessDataClass {
1946
2061
  this.sandstonePack = sandstonePack;
1947
2062
  this.type = type;
1948
2063
  }
1949
- target = (target) => new DataClass(this.sandstonePack, this.type, target);
2064
+ target = (target) => {
2065
+ return new DataClass(this.sandstonePack, this.type, target);
2066
+ };
1950
2067
  select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, path);
1951
2068
  }
1952
2069
 
@@ -1959,7 +2076,9 @@ class TargetlessDataPointClass {
1959
2076
  this.type = type;
1960
2077
  this.path = NBTpathToString(sandstonePack, path);
1961
2078
  }
1962
- target = (target) => new DataPointClass(this.sandstonePack, this.type, target, [this.path]);
2079
+ target = (target) => {
2080
+ return new DataPointClass(this.sandstonePack, this.type, target, [this.path]);
2081
+ };
1963
2082
  select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, [this.path, ...path]);
1964
2083
  }
1965
2084
 
@@ -2047,7 +2166,9 @@ var init_Data = __esm(() => {
2047
2166
  append = (value) => this.modify((data) => data.append, value);
2048
2167
  prepend = (value) => this.modify((data) => data.prepend, value);
2049
2168
  insert = (value, index) => this.modify((data) => data.insert(index), value);
2050
- remove = () => this.sandstonePack.commands.data.remove[this.type](this.currentTarget, this.path);
2169
+ remove = () => {
2170
+ return this.sandstonePack.commands.data.remove[this.type](this.currentTarget, this.path);
2171
+ };
2051
2172
  slice = (start, end) => new StringDataPointClass(this.sandstonePack, this.type, this.currentTarget, this.path, start, end);
2052
2173
  _toMinecraftCondition = () => new this.sandstonePack.conditions.DataPointExists(this.sandstonePack.core, this);
2053
2174
  equals = (value) => new this.sandstonePack.conditions.DataPointEquals(this.sandstonePack.core, this, value);
@@ -2092,7 +2213,7 @@ function isTagClass(v) {
2092
2213
  }
2093
2214
  function objectToString(value) {
2094
2215
  if (isMCFunctionClass(value)) {
2095
- if (value.node.resource.env) {
2216
+ if (value.env && value.callback.length < 2) {
2096
2217
  return value.node.sandstoneCore.pack.MCFunction(`${value.name}/_env`, () => value(), {
2097
2218
  creator: "sandstone",
2098
2219
  onConflict: "rename"
@@ -2108,7 +2229,7 @@ function objectToString(value) {
2108
2229
  }
2109
2230
  if (typeof value === "object") {
2110
2231
  if (isMCFunctionClass(value.id)) {
2111
- if (value.id.node.resource.env) {
2232
+ if (value.id.env && value.id.callback.length < 2) {
2112
2233
  return {
2113
2234
  id: value.id.node.sandstoneCore.pack.MCFunction(`${value.id.name}/_env`, () => value.id(), { creator: "sandstone", onConflict: "rename" }).name,
2114
2235
  required: value.required
@@ -2142,7 +2263,7 @@ var init_tag = __esm(() => {
2142
2263
  super(sandstoneCore);
2143
2264
  this.resource = resource;
2144
2265
  }
2145
- getValue = () => jsonStringify(this.resource.tagJSON);
2266
+ getValue = () => jsonStringify(this.resource.tagJSON, this.resource._resourceType);
2146
2267
  };
2147
2268
  TAG_CLASS_BRAND = Symbol.for("sandstone.TagClass");
2148
2269
  TagClass = class TagClass extends ResourceClass {
@@ -2235,7 +2356,7 @@ var init_model = __esm(() => {
2235
2356
  super(sandstoneCore);
2236
2357
  this.resource = resource;
2237
2358
  }
2238
- getValue = () => jsonStringify(this.resource.modelJSON);
2359
+ getValue = () => jsonStringify(this.resource.modelJSON, this.resource._resourceType);
2239
2360
  };
2240
2361
  MODEL_CLASS_BRAND = Symbol.for("sandstone.ModelClass");
2241
2362
  ModelClass = class ModelClass extends ResourceClass {
@@ -2439,7 +2560,7 @@ var init_itemDefinition = __esm(() => {
2439
2560
  super(sandstoneCore);
2440
2561
  this.resource = resource;
2441
2562
  }
2442
- getValue = () => jsonStringify(this.resource.itemDefinitionJSON);
2563
+ getValue = () => jsonStringify(this.resource.itemDefinitionJSON, this.resource._resourceType);
2443
2564
  };
2444
2565
  ItemModelDefinitionClass = class ItemModelDefinitionClass extends ResourceClass {
2445
2566
  static resourceType = "item_definition";
@@ -2607,7 +2728,12 @@ var init_DataSets = __esm(() => {
2607
2728
  init_Data();
2608
2729
  init_Score();
2609
2730
  IterableDataClass = class IterableDataClass extends ConditionalDataPointPickClass {
2610
- iterator(_callback) {
2731
+ iteratorType;
2732
+ constructor(sandstoneCore, iteratorType) {
2733
+ super(sandstoneCore);
2734
+ this.iteratorType = iteratorType;
2735
+ }
2736
+ iterator(_callback, _direction = "normal") {
2611
2737
  throw new Error("Not implemented");
2612
2738
  }
2613
2739
  size() {
@@ -2616,24 +2742,30 @@ var init_DataSets = __esm(() => {
2616
2742
  last() {
2617
2743
  throw new Error("Not implemented");
2618
2744
  }
2619
- get continue() {
2745
+ continue(direction = "normal") {
2620
2746
  throw new Error("Not implemented");
2621
2747
  }
2622
2748
  };
2623
2749
  DataIndexMapClass = class DataIndexMapClass extends IterableDataClass {
2624
2750
  pack;
2625
- initialize;
2626
2751
  entries = {};
2627
2752
  dataPoint;
2628
2753
  constructor(pack, initialize, dataPoint) {
2629
- super(pack.core);
2754
+ super(pack.core, "map");
2630
2755
  this.pack = pack;
2631
- this.initialize = initialize;
2632
2756
  if (dataPoint) {
2633
2757
  this.dataPoint = dataPoint;
2634
2758
  } else {
2635
2759
  this.dataPoint = this.pack.DataVariable(undefined, "IndexMap");
2636
2760
  }
2761
+ if (pack.core.currentMCFunction) {
2762
+ this.init(initialize);
2763
+ } else {
2764
+ const init = this.init;
2765
+ pack.initMCFunction.push(() => init(initialize));
2766
+ }
2767
+ }
2768
+ init(initialize) {
2637
2769
  for (const [i, [key, value]] of Object.entries(initialize).entries()) {
2638
2770
  this.dataPoint.select("Index").select(key).set(i);
2639
2771
  this.dataPoint.select("Entries").append([]);
@@ -2644,21 +2776,22 @@ var init_DataSets = __esm(() => {
2644
2776
  }
2645
2777
  }
2646
2778
  __entryIterator;
2647
- get entryIterator() {
2779
+ entryIterator(direction) {
2648
2780
  if (!this.__entryIterator) {
2649
- this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select("[-1]");
2781
+ this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select(`[${direction === "normal" ? 0 : -1}]`);
2650
2782
  }
2651
2783
  return this.__entryIterator;
2652
2784
  }
2653
- iterator(callback) {
2785
+ iterator(callback, direction = "normal") {
2654
2786
  this.__entryIterator = undefined;
2787
+ const entryIterator = this.entryIterator(direction);
2655
2788
  return () => {
2656
- callback([this.entryIterator.select("[0]").slice(0), this.entryIterator.select("[1]")]);
2657
- this.entryIterator.remove();
2789
+ callback([entryIterator.select("[0]").slice(0), entryIterator.select("[1]")]);
2790
+ entryIterator.remove();
2658
2791
  };
2659
2792
  }
2660
- get continue() {
2661
- return this.entryIterator._toMinecraftCondition();
2793
+ continue(direction = "normal") {
2794
+ return this.entryIterator(direction)._toMinecraftCondition();
2662
2795
  }
2663
2796
  size = () => this.dataPoint.select("Entries");
2664
2797
  last = () => [this.dataPoint.select("Entries[-1][0]").slice(0), this.dataPoint.select("Entries[-1][1]")];
@@ -2767,33 +2900,42 @@ var init_DataSets = __esm(() => {
2767
2900
  pack;
2768
2901
  dataPoint;
2769
2902
  constructor(pack, initialize, dataPoint) {
2770
- super(pack.core);
2903
+ super(pack.core, "list");
2771
2904
  this.pack = pack;
2772
2905
  if (dataPoint) {
2773
2906
  this.dataPoint = dataPoint;
2774
2907
  } else {
2775
2908
  this.dataPoint = this.pack.DataVariable([], "Array");
2776
2909
  }
2910
+ if (pack.core.currentMCFunction) {
2911
+ this.init(initialize);
2912
+ } else {
2913
+ const init = this.init;
2914
+ pack.initMCFunction.push(() => init(initialize));
2915
+ }
2916
+ }
2917
+ init(initialize) {
2777
2918
  for (const entry of initialize) {
2778
2919
  this.dataPoint.append(entry);
2779
2920
  }
2780
2921
  }
2781
2922
  __entryIterator;
2782
- get entryIterator() {
2923
+ entryIterator(direction) {
2783
2924
  if (!this.__entryIterator) {
2784
- this.__entryIterator = this.pack.DataVariable(this.dataPoint).select("[-1]");
2925
+ this.__entryIterator = this.pack.DataVariable(this.dataPoint).select(`[${direction === "normal" ? 0 : -1}]`);
2785
2926
  }
2786
2927
  return this.__entryIterator;
2787
2928
  }
2788
- iterator(callback) {
2929
+ iterator(callback, direction = "normal") {
2789
2930
  this.__entryIterator = undefined;
2931
+ const entryIterator = this.entryIterator(direction);
2790
2932
  return () => {
2791
- callback([this.entryIterator]);
2792
- this.entryIterator.remove();
2933
+ callback([entryIterator]);
2934
+ entryIterator.remove();
2793
2935
  };
2794
2936
  }
2795
- get continue() {
2796
- return this.entryIterator._toMinecraftCondition();
2937
+ continue(direction = "normal") {
2938
+ return this.entryIterator(direction)._toMinecraftCondition();
2797
2939
  }
2798
2940
  size = () => this.dataPoint;
2799
2941
  last = () => this.dataPoint.select("[-1]");
@@ -2875,7 +3017,11 @@ var init_JSONTextComponentClass = __esm(() => {
2875
3017
  this.jsonTextComponent = jsonTextComponent;
2876
3018
  }
2877
3019
  toString() {
2878
- return JSON.stringify(toComponent(this.jsonTextComponent), function(key, value) {
3020
+ const component = toComponent(this.jsonTextComponent);
3021
+ if (typeof component === "string") {
3022
+ return `"${component}"`;
3023
+ }
3024
+ return JSON.stringify(component, function(key, value) {
2879
3025
  if (Array.isArray(this)) {
2880
3026
  const realValue = this[Number.parseInt(key, 10)];
2881
3027
  return toComponent(realValue);
@@ -3090,14 +3236,52 @@ var init_Label = __esm(() => {
3090
3236
  LabelClass = makeClassCallable(_RawLabelClass);
3091
3237
  });
3092
3238
 
3239
+ // src/commands/implementations/server/function.ts
3240
+ var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
3241
+ var init_function = __esm(() => {
3242
+ init_nodes();
3243
+ init_tag();
3244
+ init_NBTs();
3245
+ FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
3246
+ FunctionCommandNode = class FunctionCommandNode extends CommandNode {
3247
+ [FUNCTION_COMMAND_NODE_BRAND] = true;
3248
+ command = "function";
3249
+ static [Symbol.hasInstance](instance) {
3250
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
3251
+ }
3252
+ };
3253
+ FunctionCommand = class FunctionCommand extends CommandArguments {
3254
+ NodeType = FunctionCommandNode;
3255
+ function(mcFunction, params, pointOrType, target, path) {
3256
+ const args = [];
3257
+ if (params) {
3258
+ if (params === "with" && pointOrType) {
3259
+ args.push("with");
3260
+ if (typeof pointOrType === "string") {
3261
+ args.push(pointOrType, target, path ?? "{}");
3262
+ } else {
3263
+ const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
3264
+ args.push(point.type, point.currentTarget, point.path);
3265
+ }
3266
+ } else {
3267
+ args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
3268
+ }
3269
+ }
3270
+ return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
3271
+ }
3272
+ };
3273
+ });
3274
+
3093
3275
  // src/variables/Loop.ts
3094
3276
  var LOOP_ARGUMENT_BRAND, LoopArgument;
3095
3277
  var init_Loop = __esm(() => {
3278
+ init_function();
3096
3279
  init_nodes();
3097
3280
  LOOP_ARGUMENT_BRAND = Symbol.for("sandstone.LoopArgument");
3098
3281
  LoopArgument = class LoopArgument extends Node {
3099
3282
  pack;
3100
3283
  [LOOP_ARGUMENT_BRAND] = true;
3284
+ loopIfNode = null;
3101
3285
  constructor(pack) {
3102
3286
  super(pack.core);
3103
3287
  this.pack = pack;
@@ -3107,7 +3291,15 @@ var init_Loop = __esm(() => {
3107
3291
  return this.toLoop();
3108
3292
  }
3109
3293
  toLoop() {
3110
- return `function ${this.pack.core.currentNode}`;
3294
+ const loopExecute = this.loopIfNode?.resultingExecuteNode;
3295
+ if (loopExecute?.createdMCFunction) {
3296
+ const funcNode = new FunctionCommandNode(this.pack, loopExecute.createdMCFunction.name);
3297
+ if (loopExecute.macroStorage) {
3298
+ funcNode.args.push("with", "storage", loopExecute.macroStorage.currentTarget, loopExecute.macroStorage.path);
3299
+ }
3300
+ return funcNode.getValue();
3301
+ }
3302
+ return new FunctionCommandNode(this.pack, this.pack.core.currentNode);
3111
3303
  }
3112
3304
  static [Symbol.hasInstance](instance) {
3113
3305
  return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[LOOP_ARGUMENT_BRAND] === true;
@@ -3147,7 +3339,6 @@ var init_Objective = __esm(() => {
3147
3339
  return formatDebugString(this.constructor.name, {
3148
3340
  name: this.name,
3149
3341
  criteria: this.criteria,
3150
- display: this.display,
3151
3342
  creator: this.creator
3152
3343
  }, undefined, options.indent);
3153
3344
  }
@@ -3344,13 +3535,13 @@ var init_Sleep = __esm(() => {
3344
3535
  const { execute } = commands;
3345
3536
  const name = `__sandstone:asyncTimer.${currentFunction.resource.name.replace(/[:/]/g, ".")}`;
3346
3537
  const timer = new ObjectiveClass(core.pack, name.replace(":", "."), "dummy", undefined, { creator: "sandstone" });
3347
- execute.store.result.score(timer("@s")).run.time.query("gametime");
3538
+ execute.store.result(timer("@s")).run.time.query("gametime");
3348
3539
  timer("@s").add(Duration);
3349
3540
  const label = Label(name);
3350
3541
  label("@s").add();
3351
3542
  this.mcfunction.unshift(() => label("@s").remove());
3352
3543
  schedule = MCFunction(`${this.mcfunction.name}/_context`, () => {
3353
- execute.store.result.score(timer("#current")).run.time.query("gametime");
3544
+ execute.store.result(timer("#current")).run.time.query("gametime");
3354
3545
  execute.as(Selector("@e", { tag: label.fullName })).if.score(timer("@s"), "=", timer("#current")).at("@s").run.functionCmd(this.mcfunction);
3355
3546
  }, {
3356
3547
  packType: currentFunction.resource.packType
@@ -3435,7 +3626,7 @@ var init_mcfunction = __esm(() => {
3435
3626
  return this.body.filter((node) => node.getValue() !== null).map((node) => node.getValue()).join(`
3436
3627
  `);
3437
3628
  };
3438
- [util10.inspect.custom](depth, options) {
3629
+ [util10.inspect.custom](_depth, options) {
3439
3630
  return formatDebugString(this.constructor.name, {
3440
3631
  name: this.resource.name
3441
3632
  }, this.body, options.indent);
@@ -3451,6 +3642,7 @@ var init_mcfunction = __esm(() => {
3451
3642
  tags;
3452
3643
  lazy;
3453
3644
  env;
3645
+ macroPoint;
3454
3646
  constructor(core, name, args, env) {
3455
3647
  if (name.startsWith("./")) {
3456
3648
  const currentMCFunctionName = core.currentMCFunction?.resource.name;
@@ -3473,11 +3665,16 @@ var init_mcfunction = __esm(() => {
3473
3665
  this.lazy = !!args.lazy;
3474
3666
  this.addToSandstoneCore = !!args.addToSandstoneCore;
3475
3667
  this.tags = args.tags;
3476
- if (env) {
3668
+ if (env && env.length !== 0) {
3477
3669
  this.env = env;
3478
3670
  }
3671
+ if (this.env || this.callback.length > 1) {
3672
+ this.macroPoint = core.pack.DataVariable();
3673
+ } else {
3674
+ this.macroPoint = undefined;
3675
+ }
3479
3676
  if (args.runOnLoad) {
3480
- if (env) {
3677
+ if (this.env) {
3481
3678
  core.pack.loadTags.load.push(core.pack.MCFunction(`load_${this.name.split(":")[1]}`, () => {
3482
3679
  this.__call__();
3483
3680
  }));
@@ -3531,21 +3728,25 @@ var init_mcfunction = __esm(() => {
3531
3728
  __call__ = (..._params) => {
3532
3729
  if (this.env || _params.length !== 0) {
3533
3730
  const args = {};
3731
+ if (this.env) {
3732
+ for (const [i, env] of this.env.entries()) {
3733
+ args[`env_${i}`] = ResolveNBTPart(env);
3734
+ env.local.set(this.name, `env_${i}`);
3735
+ }
3736
+ }
3534
3737
  if (_params.length !== 0) {
3535
3738
  for (const [i, param] of _params.entries()) {
3536
3739
  args[`param_${i}`] = ResolveNBTPart(param);
3537
3740
  param.local.set(this.name, `param_${i}`);
3538
3741
  }
3539
3742
  this.node.body = [];
3743
+ this.core.enterMCFunction(this);
3540
3744
  this.core.insideContext(this.node, () => this.callback(makeCallable(this, this.__call__.bind(undefined, ..._params)), ..._params), false);
3745
+ this.core.exitMCFunction();
3746
+ } else if (this.callback.length > 1) {
3747
+ throw new Error(`[MCFunctionClass] Function ${this.name} expects ${this.callback.length - 1} params at the call-site`);
3541
3748
  }
3542
- if (this.env) {
3543
- for (const [i, env] of this.env.entries()) {
3544
- args[`env_${i}`] = ResolveNBTPart(env);
3545
- env.local.set(this.name, `env_${i}`);
3546
- }
3547
- }
3548
- return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args).dataPoint);
3749
+ return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args, this.macroPoint).dataPoint);
3549
3750
  }
3550
3751
  return this.commands.functionCmd(this.name);
3551
3752
  };
@@ -3575,12 +3776,14 @@ var init_mcfunction = __esm(() => {
3575
3776
  });
3576
3777
  if (contents[0] instanceof _RawMCFunctionClass) {
3577
3778
  for (const mcfunction of contents) {
3779
+ mcfunction.generate();
3578
3780
  this.node.body.unshift(...mcfunction.node.body);
3579
3781
  }
3580
3782
  } else {
3581
3783
  this.core.enterMCFunction(fake);
3582
3784
  this.core.insideContext(fake.node, contents[0], false);
3583
3785
  this.core.exitMCFunction();
3786
+ fake.generate();
3584
3787
  this.node.body.unshift(...fake.node.body);
3585
3788
  }
3586
3789
  }
@@ -3593,12 +3796,14 @@ var init_mcfunction = __esm(() => {
3593
3796
  const fullBody = [];
3594
3797
  if (contents[0] instanceof _RawMCFunctionClass) {
3595
3798
  for (const mcfunction of contents) {
3799
+ mcfunction.generate();
3596
3800
  fullBody.push(...mcfunction.node.body);
3597
3801
  }
3598
3802
  } else {
3599
3803
  this.core.enterMCFunction(fake);
3600
3804
  this.core.insideContext(fake.node, contents[0], false);
3601
3805
  this.core.exitMCFunction();
3806
+ fake.generate();
3602
3807
  fullBody.push(...fake.node.body);
3603
3808
  }
3604
3809
  this.node.body.splice(start, removeItems === "auto" ? fullBody.length : removeItems, ...fullBody);
@@ -3686,42 +3891,6 @@ var init_setblock = __esm(() => {
3686
3891
  };
3687
3892
  });
3688
3893
 
3689
- // src/commands/implementations/server/function.ts
3690
- var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
3691
- var init_function = __esm(() => {
3692
- init_nodes();
3693
- init_tag();
3694
- init_NBTs();
3695
- FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
3696
- FunctionCommandNode = class FunctionCommandNode extends CommandNode {
3697
- [FUNCTION_COMMAND_NODE_BRAND] = true;
3698
- command = "function";
3699
- static [Symbol.hasInstance](instance) {
3700
- return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
3701
- }
3702
- };
3703
- FunctionCommand = class FunctionCommand extends CommandArguments {
3704
- NodeType = FunctionCommandNode;
3705
- function(mcFunction, params, pointOrType, target, path) {
3706
- const args = [];
3707
- if (params) {
3708
- if (params === "with" && pointOrType) {
3709
- args.push("with");
3710
- if (typeof pointOrType === "string") {
3711
- args.push(pointOrType, target, path ?? "{}");
3712
- } else {
3713
- const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
3714
- args.push(point.type, point.currentTarget, point.path);
3715
- }
3716
- } else {
3717
- args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
3718
- }
3719
- }
3720
- return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
3721
- }
3722
- };
3723
- });
3724
-
3725
3894
  // src/commands/implementations/entity/execute.ts
3726
3895
  function createDeferredMacroExecute(pack, executeChain, options) {
3727
3896
  const { childFunctionName, prependArgs } = options;
@@ -3744,7 +3913,7 @@ function createDeferredMacroExecute(pack, executeChain, options) {
3744
3913
  childFunctionNode = childFunction.node;
3745
3914
  } else {
3746
3915
  const childFunction = pack.MCFunction(`${currentFunction.resource.name}/${childFunctionName}`, () => {}, { creator: "sandstone", onConflict: "rename" });
3747
- pack.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage);
3916
+ pack.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage.currentTarget, options.macroStorage.path);
3748
3917
  childFunctionNode = childFunction.node;
3749
3918
  }
3750
3919
  childFunctionNode.body.push(macroNode);
@@ -3828,15 +3997,15 @@ var init_execute = __esm(() => {
3828
3997
  isSingleExecute;
3829
3998
  givenCallbackName;
3830
3999
  macroStorage;
3831
- constructor(sandstonePack, args = [], { isFake = false, isSingleExecute = true, givenCallbackName = undefined, body = [], macroStorage = undefined } = {}) {
4000
+ pendingCommit;
4001
+ createdMCFunction = null;
4002
+ constructor(sandstonePack, args = [], { isFake = false, isSingleExecute = true, givenCallbackName = undefined, body = [], macroStorage = undefined, pendingCommit = false } = {}) {
3832
4003
  super(sandstonePack, ...args);
3833
4004
  this.givenCallbackName = givenCallbackName;
3834
4005
  this.isSingleExecute = isSingleExecute;
3835
4006
  this.isFake = isFake;
3836
4007
  this.macroStorage = macroStorage;
3837
- if (macroStorage) {
3838
- this.isMacro = true;
3839
- }
4008
+ this.pendingCommit = pendingCommit;
3840
4009
  this.append(...body);
3841
4010
  }
3842
4011
  get callbackName() {
@@ -3847,6 +4016,9 @@ var init_execute = __esm(() => {
3847
4016
  this.body.push(node);
3848
4017
  if (this.isSingleExecute) {
3849
4018
  this.sandstoneCore.getCurrentMCFunctionOrThrow().exitContext();
4019
+ if (this.pendingCommit && !this.commited) {
4020
+ this.commit();
4021
+ }
3850
4022
  }
3851
4023
  }
3852
4024
  return nodes.length === 1 ? nodes[0] : nodes;
@@ -3895,9 +4067,10 @@ var init_execute = __esm(() => {
3895
4067
  });
3896
4068
  const mcFunctionNode = mcFunction.node;
3897
4069
  mcFunctionNode.body = this.body;
4070
+ this.createdMCFunction = mcFunction;
3898
4071
  const mcFunctionCall = new FunctionCommandNode(this.sandstonePack, mcFunction);
3899
4072
  if (this.macroStorage) {
3900
- mcFunctionCall.args.push("with", "storage", this.macroStorage, "");
4073
+ mcFunctionCall.args.push("with", "storage", this.macroStorage.currentTarget, this.macroStorage.path);
3901
4074
  }
3902
4075
  this.body = [mcFunctionCall];
3903
4076
  return { node: this, mcFunction: mcFunctionNode };
@@ -3910,20 +4083,30 @@ var init_execute = __esm(() => {
3910
4083
  block = (targetPos, path, type, scale) => this.nestedExecute(["block", coordinatesParser(targetPos), path, type, scale]);
3911
4084
  bossbar = (id2, type) => this.nestedExecute(["bossbar", id2, type]);
3912
4085
  entity = (target, path, type, scale) => this.nestedExecute(["entity", targetParser(target), path, type, scale]);
3913
- score(...args) {
3914
- if (isScore(args[0])) {
3915
- return this.nestedExecute(["score", args[0]]);
3916
- }
3917
- return this.nestedExecute(["score", targetParser(args[0]), args[1]]);
3918
- }
4086
+ score = (targets, objective) => this.nestedExecute(["score", targetParser(targets), objective]);
3919
4087
  storage = (target, path, type, scale = 1) => this.nestedExecute(["storage", target, path, type, scale]);
3920
4088
  };
3921
4089
  ExecuteStoreCommand = class ExecuteStoreCommand extends ExecuteCommandPart {
4090
+ _storeCallable(cmd, target, type, scale) {
4091
+ if (isScore(target)) {
4092
+ return cmd.score(target.target, target.objective);
4093
+ }
4094
+ const resolvedType = type ?? "int";
4095
+ if (target.type === "block") {
4096
+ return cmd.block(coordinatesParser(target.currentTarget), target.path, resolvedType, scale);
4097
+ }
4098
+ if (target.type === "entity") {
4099
+ return cmd.entity(target.currentTarget, target.path, resolvedType, scale);
4100
+ }
4101
+ return cmd.storage(target.currentTarget, target.path, resolvedType, scale);
4102
+ }
3922
4103
  get result() {
3923
- return this.subCommand([["result"]], ExecuteStoreArgsCommand, false);
4104
+ const cmd = this.subCommand([["result"]], ExecuteStoreArgsCommand, false);
4105
+ return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
3924
4106
  }
3925
4107
  get success() {
3926
- return this.subCommand([["success"]], ExecuteStoreArgsCommand, false);
4108
+ const cmd = this.subCommand([["success"]], ExecuteStoreArgsCommand, false);
4109
+ return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
3927
4110
  }
3928
4111
  };
3929
4112
  ExecuteDataArgsCommand = class ExecuteDataArgsCommand extends ExecuteCommandPart {
@@ -4048,6 +4231,9 @@ var init_execute = __esm(() => {
4048
4231
  const node = this.getNode();
4049
4232
  const commands = new Proxy(this.sandstonePack.commands, {
4050
4233
  get: (_t, p, _r) => {
4234
+ if (!node.commited) {
4235
+ node.pendingCommit = true;
4236
+ }
4051
4237
  this.sandstoneCore.getCurrentMCFunctionOrThrow().enterContext(node, false);
4052
4238
  return this.sandstonePack.commands[p];
4053
4239
  }
@@ -4058,7 +4244,7 @@ var init_execute = __esm(() => {
4058
4244
  node.givenCallbackName = args[0];
4059
4245
  }
4060
4246
  node.isSingleExecute = false;
4061
- this.sandstoneCore.insideContext(node, callback, false);
4247
+ this.sandstoneCore.insideContext(node, callback, !node.commited);
4062
4248
  return new FinalCommandOutput(node);
4063
4249
  }, true);
4064
4250
  }
@@ -4278,7 +4464,7 @@ class UUIDClass {
4278
4464
  }
4279
4465
  if (this.data || this.scores) {
4280
4466
  const pack = this.core.pack;
4281
- const { MCFunction, getTempStorage, commands: commands2 } = pack;
4467
+ const { MCFunction, getTempStorage, commands: commands2, Macro, Data } = pack;
4282
4468
  const { data } = commands2;
4283
4469
  let sourceData = this.data;
4284
4470
  if (!sourceData && this.scores) {
@@ -4292,15 +4478,15 @@ class UUIDClass {
4292
4478
  tempUUID.set(sourceData);
4293
4479
  const cacheKeyVar = this.primarySource === "scores" && this.scores ? this.scores[0] : tempUUID;
4294
4480
  const currentFunction = this.core.getCurrentMCFunctionOrThrow();
4295
- const lookupFunction = MCFunction(`${currentFunction.resource.name}/__uuid_lookup`, [cacheKeyVar], () => {
4296
- data.modify.storage("__sandstone:temp", "uuid_string").set.from.storage(UUID_CACHE.STORAGE, '"$(env_0)"');
4297
- }, { creator: "sandstone", onConflict: "rename" });
4298
- lookupFunction();
4481
+ const uuidLookup = Data("storage", "__sandstone:temp", "uuid_lookup");
4482
+ MCFunction(`${currentFunction.resource.name}/__uuid_lookup`, [cacheKeyVar], () => {
4483
+ Macro.data.modify(uuidLookup.select("uuid_string")).set.from.storage(UUID_CACHE.STORAGE, Macro`"${cacheKeyVar}"`);
4484
+ }, { creator: "sandstone", onConflict: "rename" })();
4299
4485
  const deferredExecute = new ExecuteCommand(pack, undefined, false);
4300
4486
  return createDeferredMacroExecute(pack, deferredExecute, {
4301
4487
  childFunctionName: "__uuid_execute",
4302
4488
  prependArgs: () => [["as", "$(uuid_string)"]],
4303
- macroStorage: "__sandstone:temp"
4489
+ macroStorage: uuidLookup
4304
4490
  });
4305
4491
  }
4306
4492
  throw new Error("Cannot use execute on a UUID with no available source. " + "The UUID must have at least one of: known value, selector, data, or scores.");
@@ -5325,7 +5511,7 @@ var init_reload = __esm(() => {
5325
5511
  });
5326
5512
 
5327
5513
  // src/commands/implementations/server/return.ts
5328
- var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, ReturnCommandNode, ReturnCommand;
5514
+ var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, RETURN_COMMAND_NODE_BRAND, ReturnCommandNode, ReturnCommand;
5329
5515
  var init_return = __esm(() => {
5330
5516
  init_nodes();
5331
5517
  init_utils();
@@ -5335,9 +5521,11 @@ var init_return = __esm(() => {
5335
5521
  [RETURN_RUN_COMMAND_NODE_BRAND] = true;
5336
5522
  command = "return";
5337
5523
  isSingleExecute;
5338
- constructor(sandstonePack, args = [], { isSingleExecute = true, body = [] } = {}) {
5524
+ isFlowControl;
5525
+ constructor(sandstonePack, args = [], { isSingleExecute = true, body = [], isFlowControl = false } = {}) {
5339
5526
  super(sandstonePack, ...args);
5340
5527
  this.isSingleExecute = isSingleExecute;
5528
+ this.isFlowControl = isFlowControl;
5341
5529
  this.append(...body);
5342
5530
  }
5343
5531
  getValue = () => {
@@ -5397,8 +5585,13 @@ var init_return = __esm(() => {
5397
5585
  }, true);
5398
5586
  }
5399
5587
  };
5588
+ RETURN_COMMAND_NODE_BRAND = Symbol.for("sandstone.ReturnCommandNode");
5400
5589
  ReturnCommandNode = class ReturnCommandNode extends CommandNode {
5590
+ [RETURN_COMMAND_NODE_BRAND] = true;
5401
5591
  command = "return";
5592
+ static [Symbol.hasInstance](instance) {
5593
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RETURN_COMMAND_NODE_BRAND] === true;
5594
+ }
5402
5595
  };
5403
5596
  ReturnCommand = class ReturnCommand extends CommandArguments {
5404
5597
  NodeType = ReturnCommandNode;
@@ -5580,8 +5773,8 @@ var init_version = __esm(() => {
5580
5773
  // src/commands/implementations/world/data.ts
5581
5774
  var DataCommandNode, DataCommand, DataGetCommand, DataMergeCommand, DataModifyFromCommand, DataModifyValuesCommand, DataModifyTypeCommand, DataModifyCommand, DataRemoveCommand;
5582
5775
  var init_data = __esm(() => {
5583
- init_core();
5584
5776
  init_nodes();
5777
+ init_utils();
5585
5778
  init_NBTs();
5586
5779
  init_parsers();
5587
5780
  DataCommandNode = class DataCommandNode extends CommandNode {
@@ -5590,22 +5783,55 @@ var init_data = __esm(() => {
5590
5783
  DataCommand = class DataCommand extends CommandArguments {
5591
5784
  NodeType = DataCommandNode;
5592
5785
  get get() {
5593
- return this.subCommand(["get"], DataGetCommand, false);
5786
+ const cmd = this.subCommand(["get"], DataGetCommand, false);
5787
+ return makeCallable(cmd, (dataPoint, scale) => {
5788
+ if (dataPoint.type === "block") {
5789
+ return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path, scale);
5790
+ }
5791
+ if (dataPoint.type === "entity") {
5792
+ return cmd.entity(dataPoint.currentTarget, dataPoint.path, scale);
5793
+ }
5794
+ return cmd.storage(dataPoint.currentTarget, dataPoint.path, scale);
5795
+ });
5594
5796
  }
5595
5797
  get merge() {
5596
5798
  return this.subCommand(["merge"], DataMergeCommand, false);
5597
5799
  }
5598
5800
  get modify() {
5599
- return this.subCommand(["modify"], DataModifyCommand, false);
5801
+ const cmd = this.subCommand(["modify"], DataModifyCommand, false);
5802
+ return makeCallable(cmd, (dataPoint) => {
5803
+ if (dataPoint.type === "block") {
5804
+ return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
5805
+ }
5806
+ if (dataPoint.type === "entity") {
5807
+ return cmd.entity(dataPoint.currentTarget, dataPoint.path);
5808
+ }
5809
+ return cmd.storage(dataPoint.currentTarget, dataPoint.path);
5810
+ });
5600
5811
  }
5601
5812
  get remove() {
5602
- return this.subCommand(["remove"], DataRemoveCommand, false);
5813
+ const cmd = this.subCommand(["remove"], DataRemoveCommand, false);
5814
+ return makeCallable(cmd, (dataPoint) => {
5815
+ if (dataPoint.type === "block") {
5816
+ return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
5817
+ }
5818
+ if (dataPoint.type === "entity") {
5819
+ return cmd.entity(dataPoint.currentTarget, dataPoint.path);
5820
+ }
5821
+ return cmd.storage(dataPoint.currentTarget, dataPoint.path);
5822
+ });
5603
5823
  }
5604
5824
  };
5605
5825
  DataGetCommand = class DataGetCommand extends CommandArguments {
5606
- block = (targetPos, path, scale) => this.finalCommand(["block", coordinatesParser(targetPos), path, scale]);
5607
- entity = (target, path, scale) => this.finalCommand(["entity", targetParser(target), path, scale]);
5608
- storage = (target, path, scale) => this.finalCommand(["storage", target, path, scale]);
5826
+ block = (targetPos, path, scale) => {
5827
+ return this.finalCommand(["block", coordinatesParser(targetPos), path, scale]);
5828
+ };
5829
+ entity = (target, path, scale) => {
5830
+ return this.finalCommand(["entity", targetParser(target), path, scale]);
5831
+ };
5832
+ storage = (target, path, scale) => {
5833
+ return this.finalCommand(["storage", target, path, scale]);
5834
+ };
5609
5835
  };
5610
5836
  DataMergeCommand = class DataMergeCommand extends CommandArguments {
5611
5837
  block = (targetPos, nbt2) => this.finalCommand(["block", coordinatesParser(targetPos), nbtStringifier(nbt2)]);
@@ -5615,20 +5841,22 @@ var init_data = __esm(() => {
5615
5841
  DataModifyFromCommand = class DataModifyFromCommand extends CommandArguments {
5616
5842
  block = (sourcePosition, sourcePath) => this.finalCommand(["block", coordinatesParser(sourcePosition), sourcePath]);
5617
5843
  entity = (source, sourcePath) => this.finalCommand(["entity", targetParser(source), sourcePath]);
5618
- storage(source, sourcePath) {
5619
- let storageArg;
5620
- if (isMacroArgument(this.sandstoneCore, source) || typeof source === "string") {
5621
- storageArg = source;
5622
- } else {
5623
- const dataPoint = source;
5624
- storageArg = `${dataPoint.currentTarget} ${dataPoint.path}`;
5625
- }
5626
- return this.finalCommand(["storage", storageArg, sourcePath]);
5627
- }
5844
+ storage = (source, sourcePath) => {
5845
+ return this.finalCommand(["storage", source, sourcePath]);
5846
+ };
5628
5847
  };
5629
5848
  DataModifyValuesCommand = class DataModifyValuesCommand extends CommandArguments {
5630
5849
  get from() {
5631
- return this.subCommand(["from"], DataModifyFromCommand, false);
5850
+ const cmd = this.subCommand(["from"], DataModifyFromCommand, false);
5851
+ return makeCallable(cmd, (dataPoint) => {
5852
+ if (dataPoint.type === "block") {
5853
+ return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
5854
+ }
5855
+ if (dataPoint.type === "entity") {
5856
+ return cmd.entity(dataPoint.currentTarget, dataPoint.path);
5857
+ }
5858
+ return cmd.storage(dataPoint.currentTarget, dataPoint.path);
5859
+ });
5632
5860
  }
5633
5861
  string = {
5634
5862
  block: (sourcePosition, sourcePath, start, end) => {
@@ -5687,14 +5915,26 @@ var init_data = __esm(() => {
5687
5915
  }
5688
5916
  };
5689
5917
  DataModifyCommand = class DataModifyCommand extends CommandArguments {
5690
- block = (targetPos, targetPath) => this.subCommand(["block", coordinatesParser(targetPos), targetPath], DataModifyTypeCommand, false);
5691
- entity = (target, targetPath) => this.subCommand(["entity", targetParser(target), targetPath], DataModifyTypeCommand, false);
5692
- storage = (target, targetPath) => this.subCommand(["storage", target, targetPath], DataModifyTypeCommand, false);
5918
+ block = (targetPos, targetPath) => {
5919
+ return this.subCommand(["block", coordinatesParser(targetPos), targetPath], DataModifyTypeCommand, false);
5920
+ };
5921
+ entity = (target, targetPath) => {
5922
+ return this.subCommand(["entity", targetParser(target), targetPath], DataModifyTypeCommand, false);
5923
+ };
5924
+ storage = (target, targetPath) => {
5925
+ return this.subCommand(["storage", target, targetPath], DataModifyTypeCommand, false);
5926
+ };
5693
5927
  };
5694
5928
  DataRemoveCommand = class DataRemoveCommand extends CommandArguments {
5695
- block = (targetPos, targetPath) => this.finalCommand(["block", coordinatesParser(targetPos), targetPath]);
5696
- entity = (target, targetPath) => this.finalCommand(["entity", targetParser(target), targetPath]);
5697
- storage = (target, targetPath) => this.finalCommand(["storage", target, targetPath]);
5929
+ block = (targetPos, targetPath) => {
5930
+ return this.finalCommand(["block", coordinatesParser(targetPos), targetPath]);
5931
+ };
5932
+ entity = (target, targetPath) => {
5933
+ return this.finalCommand(["entity", targetParser(target), targetPath]);
5934
+ };
5935
+ storage = (target, targetPath) => {
5936
+ return this.finalCommand(["storage", target, targetPath]);
5937
+ };
5698
5938
  };
5699
5939
  });
5700
5940
 
@@ -6580,11 +6820,11 @@ var init_dataPoint = __esm(() => {
6580
6820
  const { execute: execute2 } = commands2;
6581
6821
  const anon = DataVariable(this.dataPoint);
6582
6822
  this.conditional = Variable();
6583
- execute2.store.result.score(this.conditional).run(() => anon.set(this.value));
6823
+ execute2.store.result(this.conditional).run(() => anon.set(this.value));
6584
6824
  }
6585
6825
  getValue = (negated) => (negated ? ["if", ...this.getCondition()] : ["unless", ...this.getCondition()]).join(" ");
6586
6826
  getCondition() {
6587
- return ["score", "matches", "0.."];
6827
+ return ["score", this.conditional, "matches", "0.."];
6588
6828
  }
6589
6829
  };
6590
6830
  });
@@ -6671,7 +6911,7 @@ var init_command = __esm(() => {
6671
6911
  this.result = result;
6672
6912
  const store = sandstoneCore.pack.commands.execute.store[type];
6673
6913
  this.variable = sandstoneCore.pack.Variable(undefined, "condition");
6674
- command(store.score(this.variable));
6914
+ command(store(this.variable));
6675
6915
  }
6676
6916
  getCondition() {
6677
6917
  if (this.type === "success") {
@@ -6723,11 +6963,13 @@ var init_loaded = __esm(() => {
6723
6963
  });
6724
6964
 
6725
6965
  // src/flow/conditions/variables/score.ts
6726
- var ScoreConditionNode;
6966
+ var SCORE_CONDITION_NODE_BRAND, ScoreConditionNode;
6727
6967
  var init_score = __esm(() => {
6728
6968
  init_condition();
6969
+ SCORE_CONDITION_NODE_BRAND = Symbol.for("sandstone.ScoreConditionNode");
6729
6970
  ScoreConditionNode = class ScoreConditionNode extends SingleConditionNode {
6730
6971
  args;
6972
+ [SCORE_CONDITION_NODE_BRAND] = true;
6731
6973
  constructor(sandstoneCore, args) {
6732
6974
  super(sandstoneCore);
6733
6975
  this.args = args;
@@ -6735,6 +6977,9 @@ var init_score = __esm(() => {
6735
6977
  getCondition() {
6736
6978
  return ["score", ...this.args];
6737
6979
  }
6980
+ static [Symbol.hasInstance](instance) {
6981
+ return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SCORE_CONDITION_NODE_BRAND] === true;
6982
+ }
6738
6983
  };
6739
6984
  });
6740
6985
 
@@ -6837,7 +7082,7 @@ class IfStatement {
6837
7082
  this.node = new IfNode(sandstoneCore, condition2, callback);
6838
7083
  }
6839
7084
  elseIf = (condition2, callback) => {
6840
- const statement = new IfStatement(this.sandstoneCore, this.sandstoneCore.pack.flow.conditionToNode(condition2), callback);
7085
+ const statement = new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
6841
7086
  this.node.nextFlowNode = statement.getNode();
6842
7087
  statement.node._isElseIf = true;
6843
7088
  return statement;
@@ -6865,6 +7110,7 @@ var IF_NODE_BRAND, IfNode, ELSE_NODE_BRAND, ElseNode;
6865
7110
  var init_if_else = __esm(() => {
6866
7111
  init_core();
6867
7112
  init_utils();
7113
+ init_Flow();
6868
7114
  IF_NODE_BRAND = Symbol.for("sandstone.IfNode");
6869
7115
  IfNode = class IfNode extends ContainerNode {
6870
7116
  condition;
@@ -6872,10 +7118,14 @@ var init_if_else = __esm(() => {
6872
7118
  [IF_NODE_BRAND] = true;
6873
7119
  nextFlowNode;
6874
7120
  _isElseIf = false;
6875
- constructor(sandstoneCore, condition2, callback) {
7121
+ parentMCFunction;
7122
+ givenCallbackName;
7123
+ resultingExecuteNode;
7124
+ constructor(sandstoneCore, condition2, callback, parentMCFunction) {
6876
7125
  super(sandstoneCore);
6877
7126
  this.condition = condition2;
6878
7127
  this.callback = callback;
7128
+ this.parentMCFunction = parentMCFunction ?? sandstoneCore.getCurrentMCFunctionOrThrow();
6879
7129
  if (callback && callback.toString() !== "() => {}") {
6880
7130
  this.sandstoneCore.insideContext(this, callback, true);
6881
7131
  }
@@ -6917,26 +7167,6 @@ ${indent}${nextFormatting}`;
6917
7167
  });
6918
7168
 
6919
7169
  // src/flow/loops/binary_for.ts
6920
- function binaryFor(flow, from, to, callback, maximum = 128) {
6921
- if (typeof from === "number" && typeof to === "number") {
6922
- callback(to - from);
6923
- }
6924
- const { Variable } = flow.sandstoneCore.pack;
6925
- const realStart = from instanceof Score ? from : Variable(from);
6926
- const realEnd = to instanceof Score ? to : Variable(to);
6927
- const iterations = realEnd.minus(realStart);
6928
- const _ = flow;
6929
- _.while(iterations.lessThan(maximum), () => {
6930
- callback(maximum);
6931
- iterations.remove(maximum);
6932
- });
6933
- for (let i = 1;i < maximum; i *= 2) {
6934
- _.if(iterations.moduloBy(2).equalTo(1), () => {
6935
- callback(i);
6936
- });
6937
- iterations.dividedBy(2);
6938
- }
6939
- }
6940
7170
  var init_binary_for = __esm(() => {
6941
7171
  init_variables();
6942
7172
  });
@@ -6946,16 +7176,18 @@ var LoopNode;
6946
7176
  var init_loop = __esm(() => {
6947
7177
  init_core();
6948
7178
  LoopNode = class LoopNode extends ContainerNode {
6949
- executeArgs;
7179
+ condition;
6950
7180
  callback;
6951
7181
  loopback;
6952
- constructor(sandstoneCore, executeArgs, callback, loopback) {
7182
+ parentMCFunction;
7183
+ constructor(sandstoneCore, condition2, callback, loopback) {
6953
7184
  super(sandstoneCore);
6954
- this.executeArgs = executeArgs;
7185
+ this.condition = condition2;
6955
7186
  this.callback = callback;
6956
7187
  this.loopback = loopback;
7188
+ const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
7189
+ this.parentMCFunction = currentNode;
6957
7190
  if (callback.toString() !== "() => {}") {
6958
- const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
6959
7191
  currentNode.enterContext(this);
6960
7192
  this.callback();
6961
7193
  this.loopback();
@@ -6968,6 +7200,75 @@ var init_loop = __esm(() => {
6968
7200
  };
6969
7201
  });
6970
7202
 
7203
+ // src/flow/loops/staticAnalysis.ts
7204
+ function valueMatchesRange(value, rangeStr) {
7205
+ if (rangeStr.includes("..")) {
7206
+ const [minStr, maxStr] = rangeStr.split("..");
7207
+ const min = minStr !== "" ? parseInt(minStr, 10) : Number.NEGATIVE_INFINITY;
7208
+ const max = maxStr !== "" ? parseInt(maxStr, 10) : Number.POSITIVE_INFINITY;
7209
+ return value >= min && value <= max;
7210
+ }
7211
+ return value === parseInt(rangeStr, 10);
7212
+ }
7213
+ function analyzeCondition(condition2, targetScore, value, negated = false) {
7214
+ if (condition2 instanceof ScoreConditionNode) {
7215
+ const args = condition2.args;
7216
+ if (args.length >= 4 && args[2] === "matches") {
7217
+ const [target, objective, , rangeStr] = args;
7218
+ if (target !== `${targetScore.target}` || objective !== `${targetScore.objective}`) {
7219
+ return { canAnalyze: false };
7220
+ }
7221
+ let result = valueMatchesRange(value, rangeStr);
7222
+ if (negated)
7223
+ result = !result;
7224
+ return { canAnalyze: true, result };
7225
+ }
7226
+ return { canAnalyze: false };
7227
+ }
7228
+ if (condition2 instanceof AndNode) {
7229
+ for (const subCondition of condition2.conditions) {
7230
+ const subResult = analyzeCondition(subCondition, targetScore, value, negated);
7231
+ if (!subResult.canAnalyze)
7232
+ return { canAnalyze: false };
7233
+ if (!subResult.result)
7234
+ return { canAnalyze: true, result: false };
7235
+ }
7236
+ return { canAnalyze: true, result: true };
7237
+ }
7238
+ if (condition2 instanceof OrNode) {
7239
+ let anyTrue = false;
7240
+ for (const subCondition of condition2.conditions) {
7241
+ const subResult = analyzeCondition(subCondition, targetScore, value, negated);
7242
+ if (!subResult.canAnalyze)
7243
+ return { canAnalyze: false };
7244
+ if (subResult.result)
7245
+ anyTrue = true;
7246
+ }
7247
+ return { canAnalyze: true, result: anyTrue };
7248
+ }
7249
+ if (condition2 instanceof NotNode) {
7250
+ return analyzeCondition(condition2.condition, targetScore, value, !negated);
7251
+ }
7252
+ return { canAnalyze: false };
7253
+ }
7254
+ function getDeclarationLocation() {
7255
+ const stack = new Error().stack;
7256
+ const locationMatch = stack?.split(`
7257
+ `).find((line) => line.includes(".ts:") && !line.includes("/loops/") && !line.includes("node_modules"));
7258
+ return locationMatch?.trim() || "unknown location";
7259
+ }
7260
+ function warnStaticallyFalseCondition(loopType, details) {
7261
+ const location = getDeclarationLocation();
7262
+ console.warn(`[Sandstone] Warning: ${loopType} loop condition is statically false (${details}). ` + `The loop body will never execute. If this is intentional, you can ignore this warning.
7263
+ ` + ` at ${location}`);
7264
+ }
7265
+ var init_staticAnalysis = __esm(() => {
7266
+ init_score();
7267
+ init_and();
7268
+ init_or();
7269
+ init_not();
7270
+ });
7271
+
6971
7272
  // src/flow/loops/for_i.ts
6972
7273
  class ForIStatement {
6973
7274
  sandstoneCore;
@@ -6988,43 +7289,64 @@ class ForIStatement {
6988
7289
  }
6989
7290
  var ForINode;
6990
7291
  var init_for_i = __esm(() => {
6991
- init_commands2();
6992
7292
  init_variables();
7293
+ init_flow();
7294
+ init_if_else();
6993
7295
  init_loop();
7296
+ init_staticAnalysis();
6994
7297
  ForINode = class ForINode extends LoopNode {
6995
7298
  constructor(sandstoneCore, initialValue, endCondition, iterate, callback) {
6996
7299
  const iterator = sandstoneCore.pack.Variable(initialValue, "loop_iterator");
6997
- const condition2 = sandstoneCore.pack._.conditionToNode(endCondition(iterator));
6998
- const value = condition2.getValue().split(" ");
6999
- const conditionValue = [value[0], value.slice(1).join(" ")];
7000
- const _continue = () => sandstoneCore.pack.commands.returnCmd.run(() => new ExecuteCommandNode(sandstoneCore.pack, [conditionValue], {
7001
- body: [new LoopArgument(sandstoneCore.pack)]
7002
- }));
7003
- callback(iterator, _continue);
7004
- iterate(iterator);
7005
- super(sandstoneCore, [conditionValue], () => callback(iterator, _continue), () => {
7300
+ const condition2 = conditionToNode(endCondition(iterator));
7301
+ const _continue = () => sandstoneCore.pack.commands.returnCmd.run(() => new IfStatement(sandstoneCore, condition2, () => new LoopArgument(sandstoneCore.pack)));
7302
+ const analysisResult = typeof initialValue === "number" ? analyzeCondition(condition2, iterator, initialValue) : { canAnalyze: false };
7303
+ if (analysisResult.canAnalyze) {
7304
+ if (analysisResult.result) {
7305
+ callback(iterator, _continue);
7306
+ iterate(iterator);
7307
+ } else {
7308
+ warnStaticallyFalseCondition("for", `initial value ${initialValue} does not satisfy condition`);
7309
+ }
7310
+ }
7311
+ super(sandstoneCore, condition2, () => callback(iterator, _continue), () => {
7006
7312
  iterate(iterator);
7007
- return new ExecuteCommandNode(sandstoneCore.pack, [conditionValue], {
7008
- body: [new LoopArgument(sandstoneCore.pack)]
7009
- });
7313
+ new IfStatement(sandstoneCore, condition2, () => new LoopArgument(sandstoneCore.pack));
7010
7314
  });
7011
7315
  }
7012
7316
  };
7013
7317
  });
7014
7318
 
7015
7319
  // src/flow/loops/for_of.ts
7320
+ function isMultipleVariable(iteratorType) {
7321
+ if (Array.isArray(iteratorType)) {
7322
+ return true;
7323
+ }
7324
+ return false;
7325
+ }
7326
+ function isMapIterator(iteratorType, iterable) {
7327
+ if (isMultipleVariable(iteratorType) && iteratorType[0] === "key") {
7328
+ if (iterable.iteratorType === "map") {
7329
+ return true;
7330
+ }
7331
+ throw new Error('Attempt to use "for key value" loop with a List iterable; this is not supported. (Hint: use "for entry" or "for i entry" instead)');
7332
+ }
7333
+ return false;
7334
+ }
7335
+
7016
7336
  class ForOfStatement {
7017
7337
  sandstoneCore;
7018
7338
  iteratorType;
7339
+ direction;
7019
7340
  iterable;
7020
7341
  callback;
7021
7342
  node;
7022
- constructor(sandstoneCore, iteratorType, iterable, callback) {
7343
+ constructor(sandstoneCore, iteratorType, direction, iterable, callback) {
7023
7344
  this.sandstoneCore = sandstoneCore;
7024
7345
  this.iteratorType = iteratorType;
7346
+ this.direction = direction;
7025
7347
  this.iterable = iterable;
7026
7348
  this.callback = callback;
7027
- this.node = new ForOfNode(sandstoneCore, iteratorType, iterable, callback);
7349
+ this.node = new ForOfNode(sandstoneCore, iteratorType, direction, iterable, callback);
7028
7350
  }
7029
7351
  getNode = () => this.node;
7030
7352
  }
@@ -7034,35 +7356,31 @@ var init_for_of = __esm(() => {
7034
7356
  init_if_else();
7035
7357
  init_loop();
7036
7358
  ForOfNode = class ForOfNode extends LoopNode {
7037
- constructor(sandstoneCore, iteratorType, iterable, callback) {
7038
- const _iterable = iterable._toDataPoint();
7039
- let startCondition;
7359
+ constructor(sandstoneCore, iteratorType, direction, iterable, callback) {
7040
7360
  let iterate;
7041
- let continueCondition;
7042
- if (Array.isArray(iteratorType)) {
7043
- if (iteratorType[0] === "key") {
7044
- startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
7361
+ if (isMultipleVariable(iteratorType)) {
7362
+ if (isMapIterator(iteratorType, iterable)) {
7045
7363
  iterate = iterable.iterator((dataPoints) => {
7046
- if (dataPoints.length === 1) {
7047
- throw new Error('Error: Attempt to use "for key value" loop with an Array dataset; this is not supported. (Hint: use "for entry" or "for i entry" instead)');
7048
- }
7049
7364
  callback(...[dataPoints[0], dataPoints[1]]);
7050
- });
7365
+ }, direction);
7051
7366
  } else {
7052
- startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
7053
- const _iterator = sandstoneCore.pack.Variable();
7054
- _iterator.set(iterable.size());
7055
- continueCondition = _iterator["!="](-1);
7367
+ const _iterator = sandstoneCore.pack.Variable(direction === "normal" ? -1 : undefined);
7368
+ if (direction === "reverse") {
7369
+ _iterator.set(iterable.size());
7370
+ }
7056
7371
  iterate = iterable.iterator((dataPoints) => {
7057
- _iterator.decrease();
7372
+ if (direction === "normal") {
7373
+ _iterator.increase();
7374
+ } else {
7375
+ _iterator.decrease();
7376
+ }
7058
7377
  if (dataPoints.length === 1) {
7059
7378
  return callback(...[_iterator, dataPoints[0]]);
7060
7379
  }
7061
7380
  return callback(...[_iterator, dataPoints[1]]);
7062
- });
7381
+ }, direction);
7063
7382
  }
7064
7383
  } else {
7065
- startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
7066
7384
  iterate = iterable.iterator((dataPoints) => {
7067
7385
  if (dataPoints.length === 1) {
7068
7386
  return callback(...[dataPoints[0]]);
@@ -7070,8 +7388,8 @@ var init_for_of = __esm(() => {
7070
7388
  return callback(...[dataPoints[1]]);
7071
7389
  });
7072
7390
  }
7073
- iterate();
7074
- super(sandstoneCore, [startCondition], () => iterate, () => new IfStatement(sandstoneCore, continueCondition || iterable.continue, () => new LoopArgument(sandstoneCore.pack)));
7391
+ const continueCondition = iterable.continue(direction);
7392
+ super(sandstoneCore, continueCondition, () => iterate, () => new IfStatement(sandstoneCore, continueCondition, () => new LoopArgument(sandstoneCore.pack)));
7075
7393
  }
7076
7394
  };
7077
7395
  });
@@ -7093,11 +7411,12 @@ var WhileNode;
7093
7411
  var init_while = __esm(() => {
7094
7412
  init_variables();
7095
7413
  init_if_else();
7414
+ init_flow();
7096
7415
  init_loop();
7097
7416
  WhileNode = class WhileNode extends LoopNode {
7098
7417
  constructor(sandstoneCore, condition2, callback) {
7099
- const _condition = sandstoneCore.pack._.conditionToNode(condition2);
7100
- super(sandstoneCore, [_condition.getValue().split(" ")], callback, () => new IfStatement(sandstoneCore, _condition, () => new LoopArgument(sandstoneCore.pack)));
7418
+ const _condition = conditionToNode(condition2);
7419
+ super(sandstoneCore, _condition, callback, () => new IfStatement(sandstoneCore, _condition, () => new LoopArgument(sandstoneCore.pack)));
7101
7420
  }
7102
7421
  };
7103
7422
  });
@@ -7111,29 +7430,77 @@ var init_loops = __esm(() => {
7111
7430
  });
7112
7431
 
7113
7432
  // src/flow/switch_case.ts
7114
- var CASE_STATEMENT_BRAND, CaseStatement;
7433
+ function isConditionCase(c) {
7434
+ return typeof c === "function";
7435
+ }
7436
+ function executeSwitch(sandstoneCore, value, _cases) {
7437
+ let staticCaseEntries = [];
7438
+ let conditionCaseEntries = [];
7439
+ let _default;
7440
+ if (_cases instanceof CaseStatement) {
7441
+ staticCaseEntries = _cases.getStaticCases();
7442
+ conditionCaseEntries = _cases.getConditionCases();
7443
+ } else if (Array.isArray(_cases)) {
7444
+ for (const _case of _cases) {
7445
+ if (_case[0] === "default") {
7446
+ _default = _case;
7447
+ continue;
7448
+ }
7449
+ const [, condition2, callback] = _case;
7450
+ if (isConditionCase(condition2)) {
7451
+ conditionCaseEntries.push({ type: "condition", condition: condition2, callback });
7452
+ } else {
7453
+ staticCaseEntries.push({ type: "static", value: condition2, callback });
7454
+ }
7455
+ }
7456
+ } else {
7457
+ for (const _case of _cases.entries) {
7458
+ if (_case.type === "condition") {
7459
+ conditionCaseEntries.push(_case);
7460
+ } else {
7461
+ staticCaseEntries.push(_case);
7462
+ }
7463
+ }
7464
+ if (_cases.default) {
7465
+ _default = ["default", _cases.default];
7466
+ }
7467
+ }
7468
+ const staticCaseNodes = staticCaseEntries.map((c) => new StaticCaseNode(sandstoneCore, c.value, c.callback));
7469
+ const conditionCaseNodes = conditionCaseEntries.map((c) => new ConditionCaseNode(sandstoneCore, c.condition, c.callback));
7470
+ const defaultCaseNode = _default ? new DefaultCaseNode(sandstoneCore, _default[1]) : undefined;
7471
+ new SwitchNode(sandstoneCore, value, staticCaseNodes, conditionCaseNodes, defaultCaseNode);
7472
+ }
7473
+ var CASE_STATEMENT_BRAND, CaseStatement, SwitchNode, StaticCaseNode, ConditionCaseNode, DefaultCaseNode;
7115
7474
  var init_switch_case = __esm(() => {
7475
+ init_core();
7116
7476
  CASE_STATEMENT_BRAND = Symbol.for("sandstone.CaseStatement");
7117
7477
  CaseStatement = class CaseStatement {
7118
- value;
7119
- callback;
7120
- previous;
7478
+ entries;
7121
7479
  [CASE_STATEMENT_BRAND] = true;
7122
- constructor(value, callback, previous) {
7123
- this.value = value;
7124
- this.callback = callback;
7125
- this.previous = previous;
7480
+ constructor(entries = []) {
7481
+ this.entries = entries;
7126
7482
  }
7127
- getCases = () => this.previous ? [...this.previous, this] : [this];
7128
- getValue() {
7129
- return ["case", this.value, this.callback];
7483
+ getStaticCases() {
7484
+ return this.entries.filter((e) => e.type === "static");
7130
7485
  }
7131
- case(value, callback) {
7132
- return new CaseStatement(value, callback, this.getCases());
7486
+ getConditionCases() {
7487
+ return this.entries.filter((e) => e.type === "condition");
7488
+ }
7489
+ case(valueOrCondition, callback) {
7490
+ if (typeof valueOrCondition === "function") {
7491
+ return new CaseStatement([
7492
+ ...this.entries,
7493
+ { type: "condition", condition: valueOrCondition, callback }
7494
+ ]);
7495
+ }
7496
+ return new CaseStatement([
7497
+ ...this.entries,
7498
+ { type: "static", value: valueOrCondition, callback }
7499
+ ]);
7133
7500
  }
7134
7501
  default(callback) {
7135
7502
  return {
7136
- cases: this.getCases(),
7503
+ entries: this.entries,
7137
7504
  default: callback
7138
7505
  };
7139
7506
  }
@@ -7141,24 +7508,83 @@ var init_switch_case = __esm(() => {
7141
7508
  return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[CASE_STATEMENT_BRAND] === true;
7142
7509
  }
7143
7510
  };
7511
+ SwitchNode = class SwitchNode extends ContainerNode {
7512
+ value;
7513
+ staticCases;
7514
+ conditionCases;
7515
+ defaultCase;
7516
+ parentMCFunction;
7517
+ constructor(sandstoneCore, value, staticCases, conditionCases, defaultCase) {
7518
+ super(sandstoneCore);
7519
+ this.value = value;
7520
+ this.staticCases = staticCases;
7521
+ this.conditionCases = conditionCases;
7522
+ this.defaultCase = defaultCase;
7523
+ this.parentMCFunction = sandstoneCore.getCurrentMCFunctionOrThrow();
7524
+ this.parentMCFunction.enterContext(this);
7525
+ for (const caseNode of [...staticCases, ...conditionCases]) {
7526
+ this.parentMCFunction.enterContext(caseNode);
7527
+ caseNode.callback();
7528
+ this.parentMCFunction.exitContext();
7529
+ }
7530
+ if (defaultCase) {
7531
+ this.parentMCFunction.enterContext(defaultCase);
7532
+ defaultCase.callback();
7533
+ this.parentMCFunction.exitContext();
7534
+ }
7535
+ this.parentMCFunction.exitContext();
7536
+ }
7537
+ getValue = () => {
7538
+ throw new Error("SwitchNode must be transformed by SwitchTransformationVisitor");
7539
+ };
7540
+ };
7541
+ StaticCaseNode = class StaticCaseNode extends ContainerNode {
7542
+ value;
7543
+ callback;
7544
+ constructor(sandstoneCore, value, callback) {
7545
+ super(sandstoneCore);
7546
+ this.value = value;
7547
+ this.callback = callback;
7548
+ }
7549
+ getValue = () => null;
7550
+ };
7551
+ ConditionCaseNode = class ConditionCaseNode extends ContainerNode {
7552
+ condition;
7553
+ callback;
7554
+ constructor(sandstoneCore, condition2, callback) {
7555
+ super(sandstoneCore);
7556
+ this.condition = condition2;
7557
+ this.callback = callback;
7558
+ }
7559
+ getValue = () => null;
7560
+ };
7561
+ DefaultCaseNode = class DefaultCaseNode extends ContainerNode {
7562
+ callback;
7563
+ constructor(sandstoneCore, callback) {
7564
+ super(sandstoneCore);
7565
+ this.callback = callback;
7566
+ }
7567
+ getValue = () => null;
7568
+ };
7144
7569
  });
7145
7570
 
7146
7571
  // src/flow/Flow.ts
7572
+ function conditionToNode(condition2) {
7573
+ if (!(condition2 instanceof ConditionNode)) {
7574
+ return condition2._toMinecraftCondition();
7575
+ }
7576
+ return condition2;
7577
+ }
7578
+
7147
7579
  class Flow {
7148
7580
  sandstoneCore;
7149
7581
  constructor(sandstoneCore) {
7150
7582
  this.sandstoneCore = sandstoneCore;
7151
7583
  }
7152
- conditionToNode(condition2) {
7153
- if (!(condition2 instanceof ConditionNode)) {
7154
- return condition2._toMinecraftCondition();
7155
- }
7156
- return condition2;
7157
- }
7158
- if = (condition2, callback) => new IfStatement(this.sandstoneCore, this.conditionToNode(condition2), callback);
7159
- and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
7160
- or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
7161
- not = (condition2) => new NotNode(this.sandstoneCore, this.conditionToNode(condition2));
7584
+ if = (condition2, callback) => new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
7585
+ and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
7586
+ or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
7587
+ not = (condition2) => new NotNode(this.sandstoneCore, conditionToNode(condition2));
7162
7588
  get return() {
7163
7589
  return this.sandstoneCore.pack.commands.returnCmd;
7164
7590
  }
@@ -7181,77 +7607,56 @@ Sandstone Pack Error:
7181
7607
  if (broadcast !== false) {
7182
7608
  tellraw2(broadcast || "@a", fullError);
7183
7609
  }
7184
- const errorString = parseJSONText(this.sandstoneCore, fullError);
7610
+ const errorSerializable = parseJSONText(this.sandstoneCore, fullError);
7185
7611
  if (dataPoint2 !== false) {
7186
7612
  let point;
7187
7613
  if (dataPoint2 === undefined) {
7188
- point = DataVariable(parseJSONText(this.sandstoneCore, fullError));
7614
+ point = DataVariable(errorSerializable.toJSON());
7189
7615
  } else {
7190
- point = dataPoint2.set(errorString);
7616
+ point = dataPoint2.set(errorSerializable.toJSON());
7191
7617
  }
7192
7618
  returnCmd.fail();
7193
7619
  return point;
7194
7620
  }
7195
7621
  returnCmd.fail();
7196
- return errorString;
7622
+ return errorSerializable;
7197
7623
  }
7198
7624
  while(condition2, callback) {
7199
- return new WhileStatement(this.sandstoneCore, this.conditionToNode(condition2), callback);
7625
+ return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
7200
7626
  }
7201
7627
  doWhile(condition2, callback) {
7202
7628
  callback();
7203
- return new WhileStatement(this.sandstoneCore, this.conditionToNode(condition2), callback);
7629
+ return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
7204
7630
  }
7205
7631
  for(arg1, arg2, arg3, arg4) {
7206
7632
  if (typeof arg1 === "number" || arg1 instanceof Score) {
7207
7633
  return new ForIStatement(this.sandstoneCore, arg1, arg2, arg3, arg4);
7208
7634
  }
7209
7635
  if (arg1 === "entry") {
7210
- return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
7636
+ return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
7211
7637
  }
7212
7638
  if (arg1[0] === "key") {
7213
- return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
7639
+ return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
7214
7640
  }
7215
7641
  if (typeof arg1[0] === "number" || arg1[0] instanceof Score) {
7216
7642
  if (arg2 === "iterate") {
7217
7643
  return new ForIStatement(this.sandstoneCore, arg1[0], (i) => i["<="](arg1[1]), (i) => i["++"], arg3);
7218
7644
  }
7219
- return binaryFor(this, arg1[0], arg1[1], arg3, arg1[2]);
7220
7645
  }
7221
- return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
7646
+ return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
7222
7647
  }
7223
- switch(value, _cases, _default) {
7224
- let cases;
7225
- if (_cases instanceof CaseStatement) {
7226
- cases = _cases.getCases().map((c) => c.getValue());
7227
- } else if (Array.isArray(_cases)) {
7228
- cases = _cases;
7229
- } else {
7230
- cases = _cases.cases.map((c) => c.getValue());
7231
- _default = ["default", _cases.default];
7232
- }
7233
- const { Data: Data2, initMCFunction, MCFunction, Macro } = this.sandstoneCore.pack;
7234
- const id2 = switches++;
7235
- const values = Data2("storage", `__sandstone:switch_${id2}`, "Values");
7236
- initMCFunction.push(() => values.set(cases.map(([_, v, callback], i) => {
7237
- MCFunction(`__sandstone:switch_${id2}_case_${i}`, [], () => callback());
7238
- return { Value: v, Index: i };
7239
- })));
7240
- const flow = this;
7241
- MCFunction(`__sandstone:switch_${id2}`, [value], () => {
7242
- const index = Data2("storage", `__sandstone:switch_${id2}`, "Index");
7243
- Macro.data.modify.storage(index.currentTarget, "Index").set.from.storage(values.currentTarget, Macro`Values[{Value:${value}}}].Index`);
7244
- const _if = flow.if(index, () => {
7245
- MCFunction(`__sandstone:switch_${id2}_inner`, [index], () => {
7246
- Macro.functionCmd(Macro`__sandstone:switch_${id2}_case_${index}`);
7247
- })();
7248
- });
7249
- if (_default)
7250
- _if.else(() => _default?.[1]());
7251
- })();
7648
+ switch(value, cases) {
7649
+ executeSwitch(this.sandstoneCore, value, cases);
7252
7650
  }
7253
7651
  case(value, callback) {
7254
- return new CaseStatement(value, callback);
7652
+ if (typeof value === "function") {
7653
+ return new CaseStatement([
7654
+ { type: "condition", condition: value, callback }
7655
+ ]);
7656
+ }
7657
+ return new CaseStatement([
7658
+ { type: "static", value, callback }
7659
+ ]);
7255
7660
  }
7256
7661
  biome = (coordinates, biome2) => {
7257
7662
  return new SandstoneConditions.Biome(this.sandstoneCore, coordinates, biome2);
@@ -7293,7 +7698,6 @@ Sandstone Pack Error:
7293
7698
  return new SandstoneConditions.Predicate(this.sandstoneCore, predicate2.name);
7294
7699
  };
7295
7700
  }
7296
- var switches = 0;
7297
7701
  var init_Flow = __esm(() => {
7298
7702
  init_variables();
7299
7703
  init_conditions();
@@ -7308,6 +7712,7 @@ var init_flow = __esm(() => {
7308
7712
  init_Flow();
7309
7713
  init_if_else();
7310
7714
  init_loop();
7715
+ init_switch_case();
7311
7716
  });
7312
7717
 
7313
7718
  // src/core/visitors.ts
@@ -7390,6 +7795,10 @@ var init_visitor = __esm(() => {
7390
7795
  visitIfNode;
7391
7796
  visitElseNode;
7392
7797
  visitLoopNode;
7798
+ visitSwitchNode;
7799
+ visitStaticCaseNode;
7800
+ visitConditionCaseNode;
7801
+ visitDefaultCaseNode;
7393
7802
  visitLoopArgumentNode;
7394
7803
  visitAdvancementCommandNode;
7395
7804
  visitAttributeCommandNode;
@@ -7419,6 +7828,7 @@ var init_addAwaitBodyToMCFunctions = __esm(() => {
7419
7828
  // src/pack/visitors/containerCommandsToMCFunction.ts
7420
7829
  var ContainerCommandsToMCFunctionVisitor;
7421
7830
  var init_containerCommandsToMCFunction = __esm(() => {
7831
+ init_commands2();
7422
7832
  init_core();
7423
7833
  init_visitor();
7424
7834
  ContainerCommandsToMCFunctionVisitor = class ContainerCommandsToMCFunctionVisitor extends GenericSandstoneVisitor {
@@ -7438,6 +7848,14 @@ var init_containerCommandsToMCFunction = __esm(() => {
7438
7848
  this.currentMCFunction = node;
7439
7849
  this.core.currentNode = node.resource.name;
7440
7850
  const result = this.genericVisit(node);
7851
+ if (node.resource.creator === "sandstone" && node.body.length > 0) {
7852
+ const lastNode = node.body.at(-1);
7853
+ if (lastNode instanceof FunctionCommandNode) {
7854
+ const returnRunNode = new ReturnRunCommandNode(this.pack, ["run"]);
7855
+ returnRunNode.body = [lastNode];
7856
+ node.body[node.body.length - 1] = returnRunNode;
7857
+ }
7858
+ }
7441
7859
  this.core.currentNode = prev?.resource.name ?? "";
7442
7860
  this.currentMCFunction = prev;
7443
7861
  return result;
@@ -7480,7 +7898,7 @@ function* flattenIfNode(node) {
7480
7898
  yield next;
7481
7899
  }
7482
7900
  }
7483
- function handleMultipleNodes(visitor, nodes) {
7901
+ function handleMultipleNodes(visitor, nodes, macroStorage) {
7484
7902
  return nodes.flatMap((node, i) => {
7485
7903
  const { body } = node;
7486
7904
  if (node instanceof IfNode) {
@@ -7491,25 +7909,32 @@ function handleMultipleNodes(visitor, nodes) {
7491
7909
  if (Array.isArray(child)) {
7492
7910
  actualBody = child;
7493
7911
  } else {
7494
- return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
7912
+ return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
7495
7913
  isSingleExecute: false,
7496
7914
  givenCallbackName: callbackName,
7497
- body: [i === nodes.length - 1 ? child : new ReturnCommandNode(visitor.pack, [`run ${child.getValue()}`])]
7498
- });
7915
+ body: [i === nodes.length - 1 ? child : new ReturnRunCommandNode(visitor.pack, ["run"], {
7916
+ isSingleExecute: false,
7917
+ isFlowControl: true,
7918
+ body: [child]
7919
+ })],
7920
+ macroStorage
7921
+ }));
7499
7922
  }
7500
7923
  }
7501
- return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
7924
+ return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
7502
7925
  isSingleExecute: false,
7503
7926
  givenCallbackName: `${i}_${callbackName}`,
7504
7927
  body: [
7505
7928
  new ReturnRunCommandNode(visitor.pack, ["run"], {
7506
7929
  isSingleExecute: false,
7930
+ isFlowControl: true,
7507
7931
  body: actualBody
7508
7932
  })
7509
- ]
7510
- });
7933
+ ],
7934
+ macroStorage
7935
+ }));
7511
7936
  }
7512
- return body;
7937
+ return body.flatMap((n) => visitor.visit(n));
7513
7938
  });
7514
7939
  }
7515
7940
  var IfElseTransformationVisitor;
@@ -7523,19 +7948,30 @@ var init_ifElseTransformationVisitor = __esm(() => {
7523
7948
  return [];
7524
7949
  }
7525
7950
  const nodes = Array.from(flattenIfNode(node_));
7951
+ const { parentMCFunction, condition: condition2, givenCallbackName, body } = node_;
7952
+ const callbackName = givenCallbackName ?? "if";
7953
+ const macroStorage = parentMCFunction.resource.macroPoint;
7526
7954
  if (nodes.length === 1) {
7527
- return this.visit(new ExecuteCommandNode(this.pack, [[node_.condition.getValue()]], {
7955
+ const executeNode = new ExecuteCommandNode(this.pack, [[condition2.getValue()]], {
7528
7956
  isSingleExecute: false,
7529
- givenCallbackName: "if",
7530
- body: node_.body
7531
- }));
7957
+ givenCallbackName: callbackName,
7958
+ body,
7959
+ macroStorage
7960
+ });
7961
+ node_.resultingExecuteNode = executeNode;
7962
+ return this.visit(executeNode);
7963
+ }
7964
+ if (nodes.at(-1) === parentMCFunction.body.at(-1)) {
7965
+ return handleMultipleNodes(this, nodes, macroStorage);
7532
7966
  }
7533
7967
  const wrapper = new ExecuteCommandNode(this.pack, [], {
7534
7968
  isFake: true,
7535
7969
  isSingleExecute: false,
7536
- givenCallbackName: "if",
7537
- body: handleMultipleNodes(this, nodes)
7970
+ givenCallbackName: callbackName,
7971
+ body: handleMultipleNodes(this, nodes, macroStorage),
7972
+ macroStorage
7538
7973
  });
7974
+ node_.resultingExecuteNode = wrapper;
7539
7975
  return this.visit(wrapper);
7540
7976
  };
7541
7977
  };
@@ -7544,19 +7980,15 @@ var init_ifElseTransformationVisitor = __esm(() => {
7544
7980
  // src/pack/visitors/initConstantsVisitor.ts
7545
7981
  var InitConstantsVisitor;
7546
7982
  var init_initConstantsVisitor = __esm(() => {
7983
+ init_commands2();
7547
7984
  init_visitor();
7548
7985
  InitConstantsVisitor = class InitConstantsVisitor extends GenericSandstoneVisitor {
7549
7986
  onStart = () => {
7550
7987
  const { pack } = this;
7551
- const { scoreboard: scoreboard2 } = pack.commands;
7552
- let constants = [...pack.constants.values()];
7553
- constants = constants.filter((item2, index) => constants.indexOf(item2) === index);
7554
- if (constants.length !== 0) {
7555
- pack.initMCFunction.unshift(() => {
7556
- for (const constant of constants) {
7557
- scoreboard2.players.set(constant, pack.rootObjective, constant);
7558
- }
7559
- });
7988
+ if (pack.constants.size !== 0) {
7989
+ for (const constant of pack.constants) {
7990
+ pack.initMCFunction.node.body.push(new ScoreboardCommandNode(pack, "players", "set", constant, pack.rootObjective, constant));
7991
+ }
7560
7992
  }
7561
7993
  };
7562
7994
  };
@@ -7632,15 +8064,24 @@ var init_inlineFunctionCallVisitor = __esm(() => {
7632
8064
  // src/pack/visitors/loopTransformationVisitor.ts
7633
8065
  var LoopTransformationVisitor;
7634
8066
  var init_loopTransformationVisitor = __esm(() => {
7635
- init_commands2();
8067
+ init_flow();
7636
8068
  init_visitor();
7637
8069
  LoopTransformationVisitor = class LoopTransformationVisitor extends GenericSandstoneVisitor {
8070
+ currentLoopIfNode = null;
7638
8071
  visitLoopNode = (node_) => {
7639
- return new ExecuteCommandNode(this.pack, node_.executeArgs, {
7640
- isSingleExecute: false,
7641
- givenCallbackName: "loop",
7642
- body: node_.body.map((node) => this.genericVisit(node))
7643
- });
8072
+ const ifNode = new IfNode(this.core, node_.condition, undefined, node_.parentMCFunction);
8073
+ ifNode.givenCallbackName = "loop";
8074
+ const previousLoopIfNode = this.currentLoopIfNode;
8075
+ this.currentLoopIfNode = ifNode;
8076
+ ifNode.body = node_.body.flatMap((node) => this.visit(node));
8077
+ this.currentLoopIfNode = previousLoopIfNode;
8078
+ return ifNode;
8079
+ };
8080
+ visitLoopArgument = (node_) => {
8081
+ if (this.currentLoopIfNode) {
8082
+ node_.loopIfNode = this.currentLoopIfNode;
8083
+ }
8084
+ return node_;
7644
8085
  };
7645
8086
  visitWhileNode = this.visitLoopNode;
7646
8087
  visitForINode = this.visitLoopNode;
@@ -7739,7 +8180,7 @@ var init_simplifyExecuteFunction = __esm(() => {
7739
8180
  return this.genericVisit(node);
7740
8181
  }
7741
8182
  const mcFunction = functionNode.args[0];
7742
- if (typeof mcFunction === "string") {
8183
+ if (typeof mcFunction === "string" || !mcFunction?.node) {
7743
8184
  return this.genericVisit(node);
7744
8185
  }
7745
8186
  const mcFunctionNode = mcFunction.node;
@@ -7751,11 +8192,33 @@ var init_simplifyExecuteFunction = __esm(() => {
7751
8192
  return this.genericVisit(node);
7752
8193
  }
7753
8194
  }
8195
+ if (command instanceof LoopArgument) {
8196
+ const loopExecute = command.loopIfNode?.resultingExecuteNode;
8197
+ const loopFunctionName = loopExecute?.createdMCFunction?.name;
8198
+ if (loopFunctionName) {
8199
+ node.body = [new FunctionCommandNode(this.pack, loopFunctionName)];
8200
+ if (mcFunction.creator === "sandstone") {
8201
+ this.core.resourceNodes.delete(mcFunctionNode);
8202
+ }
8203
+ return this.genericVisit(node);
8204
+ }
8205
+ return this.genericVisit(node);
8206
+ }
7754
8207
  if (!(command instanceof CommandNode)) {
7755
8208
  return this.genericVisit(node);
7756
8209
  }
7757
- if (command instanceof LoopArgument) {
7758
- return new FunctionCommandNode(this.pack, mcFunctionNode.resource.name);
8210
+ if (command instanceof ReturnRunCommandNode) {
8211
+ if (mcFunction.creator === "sandstone") {
8212
+ this.core.resourceNodes.delete(mcFunctionNode);
8213
+ }
8214
+ if (command.isFlowControl) {
8215
+ node.body = [this.genericVisit(command)];
8216
+ } else {
8217
+ const returnCmd = this.visit(command);
8218
+ node.body = returnCmd.body;
8219
+ return this.visitExecuteCommandNode(node);
8220
+ }
8221
+ return this.genericVisit(node);
7759
8222
  }
7760
8223
  if (command instanceof FunctionCommandNode) {
7761
8224
  const innerMCFunction = command.args[0];
@@ -7798,17 +8261,24 @@ var init_simplifyReturnRunFunction = __esm(() => {
7798
8261
  init_nodes();
7799
8262
  init_flow();
7800
8263
  init_visitor();
8264
+ init_Macro();
7801
8265
  SimplifyReturnRunFunctionVisitor = class SimplifyReturnRunFunctionVisitor extends GenericSandstoneVisitor {
7802
8266
  visitReturnRunCommandNode = (node) => {
7803
8267
  if (node.body.length === 0 || node.body.length > 1) {
7804
8268
  return this.genericVisit(node);
7805
8269
  }
7806
- const functionNode = node.body[0];
7807
- if (!(functionNode instanceof FunctionCommandNode)) {
8270
+ const childNode = node.body[0];
8271
+ if (!(childNode instanceof FunctionCommandNode)) {
8272
+ if (childNode instanceof ReturnRunCommandNode) {
8273
+ return this.visitReturnRunCommandNode(childNode);
8274
+ }
8275
+ if (childNode instanceof ReturnCommandNode) {
8276
+ return this.genericVisit(childNode);
8277
+ }
7808
8278
  return this.genericVisit(node);
7809
8279
  }
7810
- const mcFunction = functionNode.args[0];
7811
- if (typeof mcFunction === "string") {
8280
+ const mcFunction = childNode.args[0];
8281
+ if (typeof mcFunction === "string" || isMacroArgument(this.core, mcFunction)) {
7812
8282
  return this.genericVisit(node);
7813
8283
  }
7814
8284
  const mcFunctionNode = mcFunction.node;
@@ -7824,10 +8294,6 @@ var init_simplifyReturnRunFunction = __esm(() => {
7824
8294
  return this.genericVisit(node);
7825
8295
  }
7826
8296
  if (command instanceof FunctionCommandNode) {
7827
- const innerMCFunction = command.args[0];
7828
- if (typeof innerMCFunction === "string") {
7829
- return this.genericVisit(node);
7830
- }
7831
8297
  node.body = [command];
7832
8298
  if (mcFunction.creator === "sandstone") {
7833
8299
  this.core.resourceNodes.delete(mcFunctionNode);
@@ -7835,7 +8301,18 @@ var init_simplifyReturnRunFunction = __esm(() => {
7835
8301
  return this.genericVisit(node);
7836
8302
  }
7837
8303
  if (command instanceof ReturnRunCommandNode) {
7838
- return this.genericVisit(node);
8304
+ node.body = command.body;
8305
+ node.isFlowControl = node.isFlowControl || command.isFlowControl;
8306
+ if (mcFunction.creator === "sandstone") {
8307
+ this.core.resourceNodes.delete(mcFunctionNode);
8308
+ }
8309
+ return this.visitReturnRunCommandNode(node);
8310
+ }
8311
+ if (command instanceof ReturnCommandNode) {
8312
+ if (mcFunction.creator === "sandstone") {
8313
+ this.core.resourceNodes.delete(mcFunctionNode);
8314
+ }
8315
+ return this.genericVisit(command);
7839
8316
  }
7840
8317
  node.body = [this.genericVisit(command)];
7841
8318
  if (mcFunction.creator === "sandstone") {
@@ -7846,6 +8323,233 @@ var init_simplifyReturnRunFunction = __esm(() => {
7846
8323
  };
7847
8324
  });
7848
8325
 
8326
+ // src/pack/visitors/switchTransformationVisitor.ts
8327
+ var SwitchTransformationVisitor;
8328
+ var init_switchTransformationVisitor = __esm(() => {
8329
+ init_commands2();
8330
+ init_core();
8331
+ init_flow();
8332
+ init_variables();
8333
+ init_visitor();
8334
+ SwitchTransformationVisitor = class SwitchTransformationVisitor extends GenericSandstoneVisitor {
8335
+ visitSwitchNode = (node) => {
8336
+ const { value, staticCases, conditionCases, defaultCase, parentMCFunction } = node;
8337
+ const { Data: Data2, initMCFunction, Macro, commands: commands2 } = this.pack;
8338
+ const { functionCmd } = commands2;
8339
+ const parentName = parentMCFunction?.resource.name ?? "__sandstone:switch";
8340
+ const hasStaticCases = staticCases.length > 0;
8341
+ const switchMCFunction = new MCFunctionClass(this.core, `${parentName}/switch`, {
8342
+ addToSandstoneCore: true,
8343
+ creator: "sandstone",
8344
+ onConflict: "rename"
8345
+ }, hasStaticCases ? [value] : undefined);
8346
+ const storageKey = `__sandstone:${switchMCFunction.name.replace(/[:/]/g, "_")}`;
8347
+ const values = Data2("storage", storageKey, "Values");
8348
+ if (hasStaticCases) {
8349
+ const isScoreSwitch = value instanceof Score;
8350
+ if (typeof value.local?.set === "function") {
8351
+ value.local.set(switchMCFunction.name, "env_0");
8352
+ }
8353
+ this.core.enterMCFunction(switchMCFunction);
8354
+ if (isScoreSwitch) {
8355
+ for (const caseNode of staticCases) {
8356
+ const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${caseNode.value}`, {
8357
+ addToSandstoneCore: true,
8358
+ creator: "sandstone",
8359
+ onConflict: "rename"
8360
+ });
8361
+ caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
8362
+ }
8363
+ const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
8364
+ if (hasFallback) {
8365
+ const tryCaseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/try_case`, {
8366
+ addToSandstoneCore: true,
8367
+ creator: "sandstone",
8368
+ onConflict: "rename"
8369
+ });
8370
+ this.core.enterMCFunction(tryCaseMCFunction);
8371
+ Macro.returnCmd.run.functionCmd(Macro`${switchMCFunction.name}/case_${value}`);
8372
+ this.core.exitMCFunction();
8373
+ const successScore = this.pack.rootObjective("$switch_success");
8374
+ const resultScore = this.pack.rootObjective("$switch_result");
8375
+ commands2.execute.store.success(successScore).store.result(resultScore).run.functionCmd(tryCaseMCFunction.name, "with", switchMCFunction.macroPoint);
8376
+ commands2.execute.if.score(successScore, "matches", 1).run.returnCmd.run.scoreboard.players.get(resultScore);
8377
+ this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
8378
+ } else {
8379
+ const dispatchMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/dispatch`, {
8380
+ addToSandstoneCore: true,
8381
+ creator: "sandstone",
8382
+ onConflict: "rename"
8383
+ });
8384
+ this.core.enterMCFunction(dispatchMCFunction);
8385
+ Macro.returnCmd.run.functionCmd(Macro`${switchMCFunction.name}/case_${value}`);
8386
+ this.core.exitMCFunction();
8387
+ commands2.returnCmd.run.functionCmd(dispatchMCFunction.name, "with", switchMCFunction.macroPoint);
8388
+ }
8389
+ const macroPoint = switchMCFunction.macroPoint;
8390
+ const env0Point = macroPoint.select("env_0");
8391
+ commands2.execute.store.result.storage(env0Point.currentTarget, env0Point.path, "int").run.scoreboard.players.get(value);
8392
+ const copyNode = switchMCFunction.node.body.pop();
8393
+ switchMCFunction.node.body.unshift(copyNode);
8394
+ const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
8395
+ if (canInline) {
8396
+ this.core.exitMCFunction();
8397
+ this.core.resourceNodes.delete(switchMCFunction.node);
8398
+ return switchMCFunction.node.body;
8399
+ }
8400
+ } else {
8401
+ const index = switchMCFunction.macroPoint.select("Index");
8402
+ index.local.set(switchMCFunction.name, "Index");
8403
+ index.remove();
8404
+ Macro.data.modify.storage(index.currentTarget, index.path).set.from.storage(values.currentTarget, Macro`Values[{Value:${value}}].Index`);
8405
+ const caseData = [];
8406
+ for (let i = 0;i < staticCases.length; i++) {
8407
+ const caseNode = staticCases[i];
8408
+ const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${i}`, {
8409
+ addToSandstoneCore: true,
8410
+ creator: "sandstone",
8411
+ onConflict: "rename"
8412
+ });
8413
+ caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
8414
+ caseData.push({
8415
+ Value: caseNode.value,
8416
+ Index: NBT.int(i)
8417
+ });
8418
+ }
8419
+ initMCFunction.push(() => values.set(caseData));
8420
+ const innerMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/inner`, {
8421
+ addToSandstoneCore: true,
8422
+ creator: "sandstone",
8423
+ onConflict: "rename"
8424
+ });
8425
+ this.core.enterMCFunction(innerMCFunction);
8426
+ Macro.returnCmd.run.functionCmd(Macro`${switchMCFunction.name}/case_${index}`);
8427
+ this.core.exitMCFunction();
8428
+ const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
8429
+ if (hasFallback) {
8430
+ const ifNode = new IfNode(this.core, index._toMinecraftCondition(), undefined, switchMCFunction.node);
8431
+ switchMCFunction.node.enterContext(ifNode, false);
8432
+ functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
8433
+ switchMCFunction.node.exitContext();
8434
+ switchMCFunction.node.body.push(ifNode);
8435
+ this.buildFallback(ifNode, value, conditionCases, defaultCase, switchMCFunction);
8436
+ } else {
8437
+ this.pack.commands.execute.if.data.storage(index.currentTarget, index.path).run.returnCmd.run.functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
8438
+ }
8439
+ }
8440
+ this.core.exitMCFunction();
8441
+ } else {
8442
+ this.core.enterMCFunction(switchMCFunction);
8443
+ this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
8444
+ this.core.exitMCFunction();
8445
+ const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
8446
+ if (canInline) {
8447
+ this.core.resourceNodes.delete(switchMCFunction.node);
8448
+ for (const bodyNode of switchMCFunction.node.body) {
8449
+ if (bodyNode instanceof IfNode) {
8450
+ bodyNode.parentMCFunction = parentMCFunction;
8451
+ let lastIfNode = bodyNode;
8452
+ while (lastIfNode.nextFlowNode instanceof IfNode) {
8453
+ lastIfNode.nextFlowNode.parentMCFunction = parentMCFunction;
8454
+ lastIfNode = lastIfNode.nextFlowNode;
8455
+ }
8456
+ if (lastIfNode !== bodyNode) {
8457
+ switchMCFunction.node.body.push(lastIfNode);
8458
+ }
8459
+ }
8460
+ }
8461
+ return switchMCFunction.node.body;
8462
+ }
8463
+ }
8464
+ const isLastNode = parentMCFunction && node === parentMCFunction.body.at(-1);
8465
+ if (hasStaticCases && !(value instanceof Score)) {
8466
+ const macroPoint = switchMCFunction.macroPoint;
8467
+ const resolvedValue = value instanceof DataPointPickClass ? value._toDataPoint() : value;
8468
+ const env0Point = macroPoint.select("env_0");
8469
+ const copyNode = new DataCommandNode(this.pack);
8470
+ copyNode.args = [
8471
+ "modify",
8472
+ "storage",
8473
+ env0Point.currentTarget,
8474
+ env0Point.path,
8475
+ "set",
8476
+ "from",
8477
+ resolvedValue.type,
8478
+ resolvedValue.currentTarget,
8479
+ resolvedValue.path
8480
+ ];
8481
+ const funcNode2 = new FunctionCommandNode(this.pack, switchMCFunction.name);
8482
+ funcNode2.args.push("with", macroPoint.type, macroPoint.currentTarget, macroPoint.path);
8483
+ if (isLastNode) {
8484
+ const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
8485
+ callNode.body = [funcNode2];
8486
+ return [copyNode, callNode].flatMap((n) => this.visit(n));
8487
+ }
8488
+ return [copyNode, funcNode2].flatMap((n) => this.visit(n));
8489
+ }
8490
+ const funcNode = new FunctionCommandNode(this.pack, switchMCFunction.name);
8491
+ if (isLastNode) {
8492
+ const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
8493
+ callNode.body = [funcNode];
8494
+ return this.visit(callNode);
8495
+ }
8496
+ return this.visit(funcNode);
8497
+ };
8498
+ buildFallback(_if, value, conditionCases, defaultCase, switchMCFunction, targetBody) {
8499
+ if (conditionCases.length === 0 && !defaultCase)
8500
+ return;
8501
+ const body = targetBody ?? switchMCFunction.node.body;
8502
+ if (conditionCases.length > 0) {
8503
+ const firstCondition = conditionCases[0].condition(value);
8504
+ const firstConditionNode = conditionToNode(firstCondition);
8505
+ let currentIfNode;
8506
+ if (_if === undefined) {
8507
+ currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
8508
+ currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
8509
+ body.push(currentIfNode);
8510
+ } else {
8511
+ currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
8512
+ currentIfNode._isElseIf = true;
8513
+ _if.nextFlowNode = currentIfNode;
8514
+ currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
8515
+ }
8516
+ for (let i = 1;i < conditionCases.length; i++) {
8517
+ const condition2 = conditionCases[i].condition(value);
8518
+ const conditionNode = conditionToNode(condition2);
8519
+ const nextIfNode = new IfNode(this.core, conditionNode, undefined, switchMCFunction.node);
8520
+ nextIfNode._isElseIf = true;
8521
+ currentIfNode.nextFlowNode = nextIfNode;
8522
+ nextIfNode.body = conditionCases[i].body.flatMap((n) => this.visit(n));
8523
+ currentIfNode = nextIfNode;
8524
+ }
8525
+ if (defaultCase) {
8526
+ const elseNode = new ElseNode(this.core, () => {});
8527
+ elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
8528
+ currentIfNode.nextFlowNode = elseNode;
8529
+ }
8530
+ } else if (defaultCase) {
8531
+ if (_if === undefined) {
8532
+ const visitedNodes = defaultCase.body.flatMap((n) => this.visit(n));
8533
+ body.push(...visitedNodes);
8534
+ } else {
8535
+ const elseNode = new ElseNode(this.core, () => {});
8536
+ elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
8537
+ _if.nextFlowNode = elseNode;
8538
+ }
8539
+ }
8540
+ }
8541
+ visitStaticCaseNode = (_node) => {
8542
+ return [];
8543
+ };
8544
+ visitConditionCaseNode = (_node) => {
8545
+ return [];
8546
+ };
8547
+ visitDefaultCaseNode = (_node) => {
8548
+ return [];
8549
+ };
8550
+ };
8551
+ });
8552
+
7849
8553
  // src/pack/visitors/unifyChainedExecutes.ts
7850
8554
  var UnifyChainedExecutesVisitor;
7851
8555
  var init_unifyChainedExecutes = __esm(() => {
@@ -7861,6 +8565,10 @@ var init_unifyChainedExecutes = __esm(() => {
7861
8565
  node.body = chainedCommand.body;
7862
8566
  node.args.push(...chainedCommand.args);
7863
8567
  }
8568
+ const flattenedArgs = node.args.flat(1).filter((a) => a !== undefined && a !== null);
8569
+ if (flattenedArgs.length === 0 && node.body.length === 1) {
8570
+ return this.genericVisit(node.body[0]);
8571
+ }
7864
8572
  return this.genericVisit(node);
7865
8573
  };
7866
8574
  };
@@ -7878,6 +8586,7 @@ var init_visitors2 = __esm(() => {
7878
8586
  init_orTransformationVisitor();
7879
8587
  init_simplifyExecuteFunction();
7880
8588
  init_simplifyReturnRunFunction();
8589
+ init_switchTransformationVisitor();
7881
8590
  init_unifyChainedExecutes();
7882
8591
  });
7883
8592
 
@@ -7947,6 +8656,8 @@ class SandstonePack {
7947
8656
  this.__rootObjective = undefined;
7948
8657
  this.__initMCFunction = undefined;
7949
8658
  this.objectives.clear();
8659
+ this.anonymousDataId = 0;
8660
+ this.anonymousScoreId = 0;
7950
8661
  this.constants.clear();
7951
8662
  this.tickedLoops = {};
7952
8663
  this.dependencies.clear();
@@ -8009,7 +8720,7 @@ class SandstonePack {
8009
8720
  return [namespace, ...resourceFolders, ...fullPath];
8010
8721
  };
8011
8722
  get _() {
8012
- return new Flow(this.core);
8723
+ return this.flow;
8013
8724
  }
8014
8725
  registerNewObjective = (objective) => {
8015
8726
  this.objectives.add(objective);
@@ -8048,7 +8759,7 @@ class SandstonePack {
8048
8759
  return this.Variable(undefined, name2).set(nbt2, scale);
8049
8760
  }
8050
8761
  const [initialValue, name] = args;
8051
- const anonymousScore = score2(`${name ?? "anon"}_${this.packUid}_${this.anonymousScoreId++}`);
8762
+ const anonymousScore = score2(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousScoreId++}` : ""}`);
8052
8763
  if (initialValue === undefined) {
8053
8764
  return anonymousScore;
8054
8765
  }
@@ -8092,7 +8803,7 @@ class SandstonePack {
8092
8803
  return this.DataVariable(undefined, name2).set(score2, storeType || "int", scale || 1);
8093
8804
  }
8094
8805
  const [initialValue, name] = args;
8095
- const anonymousData = data2.select(`${name ?? "anon"}_${this.packUid}_${this.anonymousDataId++}`);
8806
+ const anonymousData = data2.select(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousDataId++}` : ""}`);
8096
8807
  if (initialValue === undefined) {
8097
8808
  return anonymousData;
8098
8809
  }
@@ -8495,6 +9206,7 @@ class SandstonePack {
8495
9206
  new InitConstantsVisitor(this),
8496
9207
  new GenerateLazyMCFunction(this),
8497
9208
  new LoopTransformationVisitor(this),
9209
+ new SwitchTransformationVisitor(this),
8498
9210
  new OrTransformationVisitor(this),
8499
9211
  new IfElseTransformationVisitor(this),
8500
9212
  new ContainerCommandsToMCFunctionVisitor(this),
@@ -8545,7 +9257,7 @@ var init_pack = __esm(() => {
8545
9257
  }
8546
9258
  handleOutput = async (type, readFile, writeFile) => {
8547
9259
  if (type === "output") {
8548
- await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
9260
+ await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
8549
9261
  }
8550
9262
  };
8551
9263
  };
@@ -8566,7 +9278,7 @@ var init_pack = __esm(() => {
8566
9278
  }
8567
9279
  handleOutput = async (type, readFile, writeFile) => {
8568
9280
  if (type === "output") {
8569
- await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
9281
+ await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
8570
9282
  }
8571
9283
  };
8572
9284
  };
@@ -8641,7 +9353,11 @@ var init_src = __esm(() => {
8641
9353
  return new Proxy(fn, {
8642
9354
  get(_target, subProp) {
8643
9355
  const method = sandstonePack[prop];
8644
- return method[subProp];
9356
+ const value = method[subProp];
9357
+ if (typeof value === "function") {
9358
+ return value.bind(method);
9359
+ }
9360
+ return value;
8645
9361
  },
8646
9362
  apply(_target, _thisArg, args) {
8647
9363
  const method = sandstonePack[prop];
@@ -8901,20 +9617,16 @@ class ListResource {
8901
9617
  push(..._args) {}
8902
9618
  unshift(..._args) {}
8903
9619
  }
8904
- function jsonStringify(json) {
8905
- return JSON.stringify(json, (_key, value) => {
8906
- if (value instanceof NBTPrimitive) {
8907
- return value.value;
8908
- }
8909
- if (value instanceof NBTTypedArray) {
8910
- return value.values;
9620
+ function jsonStringify(json, resourceType) {
9621
+ return JSON.stringify(json, function(key, value) {
9622
+ if ((typeof value === "object" || typeof value === "function") && value.constructor.name !== "Object" && "toResourceJSON" in value) {
9623
+ return value.toResourceJSON(key, this, resourceType, json);
8911
9624
  }
8912
9625
  return value;
8913
9626
  }, 2);
8914
9627
  }
8915
9628
  var RESOURCE_CLASS_BRAND, ResourceClass, CallableResourceClass, ResourceNodesMap;
8916
9629
  var init_resource = __esm(() => {
8917
- init_NBTs();
8918
9630
  init_arguments();
8919
9631
  RESOURCE_CLASS_BRAND = Symbol.for("sandstone.ResourceClass");
8920
9632
  ResourceClass = class ResourceClass {
@@ -9018,6 +9730,9 @@ var init_resource = __esm(() => {
9018
9730
  toNBT() {
9019
9731
  return this.name;
9020
9732
  }
9733
+ toJSON() {
9734
+ return this.name;
9735
+ }
9021
9736
  static [Symbol.hasInstance](instance) {
9022
9737
  return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RESOURCE_CLASS_BRAND] === true;
9023
9738
  }
@@ -9117,7 +9832,7 @@ var init_advancement3 = __esm(() => {
9117
9832
  super(sandstoneCore);
9118
9833
  this.resource = resource;
9119
9834
  }
9120
- getValue = () => jsonStringify(this.resource.advancementJSON);
9835
+ getValue = () => jsonStringify(this.resource.advancementJSON, this.resource._resourceType);
9121
9836
  };
9122
9837
  ADVANCEMENT_CLASS_BRAND = Symbol.for("sandstone.AdvancementClass");
9123
9838
  AdvancementClass = class AdvancementClass extends ResourceClass {
@@ -9175,7 +9890,7 @@ var init_bannerPattern = __esm(() => {
9175
9890
  super(sandstoneCore);
9176
9891
  this.resource = resource;
9177
9892
  }
9178
- getValue = () => jsonStringify(this.resource.bannerPatternJSON);
9893
+ getValue = () => jsonStringify(this.resource.bannerPatternJSON, this.resource._resourceType);
9179
9894
  };
9180
9895
  BannerPatternClass = class BannerPatternClass extends ResourceClass {
9181
9896
  static resourceType = "banner_pattern";
@@ -9200,7 +9915,7 @@ var init_chatType = __esm(() => {
9200
9915
  super(sandstoneCore);
9201
9916
  this.resource = resource;
9202
9917
  }
9203
- getValue = () => jsonStringify(this.resource.chatTypeJSON);
9918
+ getValue = () => jsonStringify(this.resource.chatTypeJSON, this.resource._resourceType);
9204
9919
  };
9205
9920
  ChatTypeClass = class ChatTypeClass extends ResourceClass {
9206
9921
  static resourceType = "chat_type";
@@ -9226,7 +9941,7 @@ var init_damageType = __esm(() => {
9226
9941
  super(sandstoneCore);
9227
9942
  this.resource = resource;
9228
9943
  }
9229
- getValue = () => jsonStringify(this.resource.damageTypeJSON);
9944
+ getValue = () => jsonStringify(this.resource.damageTypeJSON, this.resource._resourceType);
9230
9945
  };
9231
9946
  DamageTypeClass = class DamageTypeClass extends ResourceClass {
9232
9947
  static resourceType = "damage_type";
@@ -9288,7 +10003,7 @@ var init_dialog2 = __esm(() => {
9288
10003
  super(sandstoneCore);
9289
10004
  this.resource = resource;
9290
10005
  }
9291
- getValue = () => jsonStringify(this.resource.dialogJSON);
10006
+ getValue = () => jsonStringify(this.resource.dialogJSON, this.resource._resourceType);
9292
10007
  };
9293
10008
  DialogClass = class DialogClass extends ResourceClass {
9294
10009
  static resourceType = "dialog";
@@ -9313,7 +10028,7 @@ var init_enchantment = __esm(() => {
9313
10028
  super(sandstoneCore);
9314
10029
  this.resource = resource;
9315
10030
  }
9316
- getValue = () => jsonStringify(this.resource.enchantmentJSON);
10031
+ getValue = () => jsonStringify(this.resource.enchantmentJSON, this.resource._resourceType);
9317
10032
  };
9318
10033
  EnchantmentClass = class EnchantmentClass extends ResourceClass {
9319
10034
  static resourceType = "enchantment";
@@ -9330,7 +10045,7 @@ var init_enchantment = __esm(() => {
9330
10045
  super(sandstoneCore);
9331
10046
  this.resource = resource;
9332
10047
  }
9333
- getValue = () => jsonStringify(this.resource.enchantmentProviderJSON);
10048
+ getValue = () => jsonStringify(this.resource.enchantmentProviderJSON, this.resource._resourceType);
9334
10049
  };
9335
10050
  EnchantmentProviderClass = class EnchantmentProviderClass extends ResourceClass {
9336
10051
  static resourceType = "enchantment_provider";
@@ -9355,7 +10070,7 @@ var init_gametest = __esm(() => {
9355
10070
  super(sandstoneCore);
9356
10071
  this.resource = resource;
9357
10072
  }
9358
- getValue = () => jsonStringify(this.resource.testEnvironmentJSON);
10073
+ getValue = () => jsonStringify(this.resource.testEnvironmentJSON, this.resource._resourceType);
9359
10074
  };
9360
10075
  TestEnvironmentClass = class TestEnvironmentClass extends ResourceClass {
9361
10076
  static resourceType = "test_environment";
@@ -9372,7 +10087,7 @@ var init_gametest = __esm(() => {
9372
10087
  super(sandstoneCore);
9373
10088
  this.resource = resource;
9374
10089
  }
9375
- getValue = () => jsonStringify(this.resource.testInstanceJSON);
10090
+ getValue = () => jsonStringify(this.resource.testInstanceJSON, this.resource._resourceType);
9376
10091
  };
9377
10092
  TestInstanceClass = class TestInstanceClass extends ResourceClass {
9378
10093
  static resourceType = "test_instance";
@@ -9397,7 +10112,7 @@ var init_instrument = __esm(() => {
9397
10112
  super(sandstoneCore);
9398
10113
  this.resource = resource;
9399
10114
  }
9400
- getValue = () => jsonStringify(this.resource.instrumentJSON);
10115
+ getValue = () => jsonStringify(this.resource.instrumentJSON, this.resource._resourceType);
9401
10116
  };
9402
10117
  InstrumentClass = class InstrumentClass extends ResourceClass {
9403
10118
  static resourceType = "instrument";
@@ -9423,7 +10138,7 @@ var init_itemModifier = __esm(() => {
9423
10138
  super(sandstoneCore);
9424
10139
  this.resource = resource;
9425
10140
  }
9426
- getValue = () => jsonStringify(this.resource.itemModifierJSON);
10141
+ getValue = () => jsonStringify(this.resource.itemModifierJSON, this.resource._resourceType);
9427
10142
  };
9428
10143
  ITEM_MODIFIER_CLASS_BRAND = Symbol.for("sandstone.ItemModifierClass");
9429
10144
  ItemModifierClass = class ItemModifierClass extends ResourceClass {
@@ -9499,7 +10214,7 @@ var init_jukeboxSong = __esm(() => {
9499
10214
  super(sandstoneCore);
9500
10215
  this.resource = resource;
9501
10216
  }
9502
- getValue = () => jsonStringify(this.resource.jukeboxSongJSON);
10217
+ getValue = () => jsonStringify(this.resource.jukeboxSongJSON, this.resource._resourceType);
9503
10218
  };
9504
10219
  JukeboxSongClass = class JukeboxSongClass extends ResourceClass {
9505
10220
  static resourceType = "jukebox_song";
@@ -9524,7 +10239,7 @@ var init_lootTable = __esm(() => {
9524
10239
  super(sandstoneCore);
9525
10240
  this.resource = resource;
9526
10241
  }
9527
- getValue = () => jsonStringify(this.resource.lootTableJSON);
10242
+ getValue = () => jsonStringify(this.resource.lootTableJSON, this.resource._resourceType);
9528
10243
  };
9529
10244
  LootTableClass = class LootTableClass extends ResourceClass {
9530
10245
  static resourceType = "loot_table";
@@ -9557,7 +10272,7 @@ var init_predicate2 = __esm(() => {
9557
10272
  super(sandstoneCore);
9558
10273
  this.resource = resource;
9559
10274
  }
9560
- getValue = () => jsonStringify(this.resource.predicateJSON);
10275
+ getValue = () => jsonStringify(this.resource.predicateJSON, this.resource._resourceType);
9561
10276
  };
9562
10277
  PREDICATE_CLASS_BRAND = Symbol.for("sandstone.PredicateClass");
9563
10278
  PredicateClass = class PredicateClass extends ResourceClass {
@@ -9627,7 +10342,7 @@ var init_recipe2 = __esm(() => {
9627
10342
  super(sandstoneCore);
9628
10343
  this.resource = resource;
9629
10344
  }
9630
- getValue = () => jsonStringify(this.resource.recipeJSON);
10345
+ getValue = () => jsonStringify(this.resource.recipeJSON, this.resource._resourceType);
9631
10346
  };
9632
10347
  RecipeClass = class RecipeClass extends ResourceClass {
9633
10348
  static resourceType = "recipe";
@@ -9865,7 +10580,7 @@ var init_structure = __esm(() => {
9865
10580
  blockPos: [layer[0], row[0], entry[0]],
9866
10581
  nbt: {
9867
10582
  id: entity.id,
9868
- ...add(entity.nbt)
10583
+ ...add({ ...entity.nbt })
9869
10584
  }
9870
10585
  });
9871
10586
  }
@@ -9945,7 +10660,7 @@ var init_timeline = __esm(() => {
9945
10660
  super(sandstoneCore);
9946
10661
  this.resource = resource;
9947
10662
  }
9948
- getValue = () => jsonStringify(this.resource.timelineJSON);
10663
+ getValue = () => jsonStringify(this.resource.timelineJSON, this.resource._resourceType);
9949
10664
  };
9950
10665
  TimelineClass = class TimelineClass extends ResourceClass {
9951
10666
  static resourceType = "timeline";
@@ -9962,7 +10677,7 @@ var init_timeline = __esm(() => {
9962
10677
  super(sandstoneCore);
9963
10678
  this.resource = resource;
9964
10679
  }
9965
- getValue = () => jsonStringify(this.resource.worldClockJSON);
10680
+ getValue = () => jsonStringify(this.resource.worldClockJSON, this.resource._resourceType);
9966
10681
  };
9967
10682
  WorldClockClass = class WorldClockClass extends ResourceClass {
9968
10683
  static resourceType = "world_clock";
@@ -9990,7 +10705,7 @@ var init_trialSpawner = __esm(() => {
9990
10705
  super(sandstoneCore);
9991
10706
  this.resource = resource;
9992
10707
  }
9993
- getValue = () => jsonStringify(this.resource.trialSpawnerJSON);
10708
+ getValue = () => jsonStringify(this.resource.trialSpawnerJSON, this.resource._resourceType);
9994
10709
  };
9995
10710
  TrialSpawnerClass = class TrialSpawnerClass extends ResourceClass {
9996
10711
  static resourceType = "trial_spawner";
@@ -10015,7 +10730,7 @@ var init_trimMaterial = __esm(() => {
10015
10730
  super(sandstoneCore);
10016
10731
  this.resource = resource;
10017
10732
  }
10018
- getValue = () => jsonStringify(this.resource.trimMaterialJSON);
10733
+ getValue = () => jsonStringify(this.resource.trimMaterialJSON, this.resource._resourceType);
10019
10734
  };
10020
10735
  TrimMaterialClass = class TrimMaterialClass extends ResourceClass {
10021
10736
  static resourceType = "trim_material";
@@ -10043,7 +10758,7 @@ var init_trimPattern = __esm(() => {
10043
10758
  super(sandstoneCore);
10044
10759
  this.resource = resource;
10045
10760
  }
10046
- getValue = () => jsonStringify(this.resource.trimPatternJSON);
10761
+ getValue = () => jsonStringify(this.resource.trimPatternJSON, this.resource._resourceType);
10047
10762
  };
10048
10763
  TrimPatternClass = class TrimPatternClass extends ResourceClass {
10049
10764
  static resourceType = "trim_pattern";
@@ -10067,7 +10782,7 @@ var init_variant = __esm(() => {
10067
10782
  super(sandstoneCore);
10068
10783
  this.resource = resource;
10069
10784
  }
10070
- getValue = () => jsonStringify(this.resource.variantJSON);
10785
+ getValue = () => jsonStringify(this.resource.variantJSON, this.resource._resourceType);
10071
10786
  };
10072
10787
  VariantClass = class VariantClass extends ResourceClass {
10073
10788
  variantType;
@@ -10094,7 +10809,7 @@ var init_villagerTrade = __esm(() => {
10094
10809
  super(sandstoneCore);
10095
10810
  this.resource = resource;
10096
10811
  }
10097
- getValue = () => jsonStringify(this.resource.villagerTradeJSON);
10812
+ getValue = () => jsonStringify(this.resource.villagerTradeJSON, this.resource._resourceType);
10098
10813
  };
10099
10814
  VillagerTradeClass = class VillagerTradeClass extends ResourceClass {
10100
10815
  static resourceType = "villager_trade";
@@ -10111,7 +10826,7 @@ var init_villagerTrade = __esm(() => {
10111
10826
  super(sandstoneCore);
10112
10827
  this.resource = resource;
10113
10828
  }
10114
- getValue = () => jsonStringify(this.resource.tradeSetJSON);
10829
+ getValue = () => jsonStringify(this.resource.tradeSetJSON, this.resource._resourceType);
10115
10830
  };
10116
10831
  TradeSetClass = class TradeSetClass extends ResourceClass {
10117
10832
  static resourceType = "trade_set";
@@ -10162,7 +10877,7 @@ var init_atlas = __esm(() => {
10162
10877
  super(sandstoneCore);
10163
10878
  this.resource = resource;
10164
10879
  }
10165
- getValue = () => jsonStringify(this.resource.atlasJSON);
10880
+ getValue = () => jsonStringify(this.resource.atlasJSON, this.resource._resourceType);
10166
10881
  };
10167
10882
  ATLAS_CLASS_BRAND = Symbol.for("sandstone.AtlasClass");
10168
10883
  AtlasClass = class AtlasClass extends ResourceClass {
@@ -10210,7 +10925,7 @@ var init_blockstate = __esm(() => {
10210
10925
  super(sandstoneCore);
10211
10926
  this.resource = resource;
10212
10927
  }
10213
- getValue = () => jsonStringify(this.resource.blockStateJSON);
10928
+ getValue = () => jsonStringify(this.resource.blockStateJSON, this.resource._resourceType);
10214
10929
  };
10215
10930
  BLOCK_STATE_CLASS_BRAND = Symbol.for("sandstone.BlockStateClass");
10216
10931
  BlockStateClass = class BlockStateClass extends ResourceClass {
@@ -10291,7 +11006,7 @@ var init_equipment = __esm(() => {
10291
11006
  super(sandstoneCore);
10292
11007
  this.resource = resource;
10293
11008
  }
10294
- getValue = () => jsonStringify(this.resource.equipmentJSON);
11009
+ getValue = () => jsonStringify(this.resource.equipmentJSON, this.resource._resourceType);
10295
11010
  };
10296
11011
  EquipmentClass = class EquipmentClass extends ResourceClass {
10297
11012
  static resourceType = "equipment";
@@ -10316,7 +11031,7 @@ var init_font = __esm(() => {
10316
11031
  super(sandstoneCore);
10317
11032
  this.resource = resource;
10318
11033
  }
10319
- getValue = () => jsonStringify(this.resource.fontJSON);
11034
+ getValue = () => jsonStringify(this.resource.fontJSON, this.resource._resourceType);
10320
11035
  };
10321
11036
  FONT_CLASS_BRAND = Symbol.for("sandstone.FontClass");
10322
11037
  FontClass = class FontClass extends ResourceClass {
@@ -10364,7 +11079,7 @@ var init_language = __esm(() => {
10364
11079
  super(sandstoneCore);
10365
11080
  this.resource = resource;
10366
11081
  }
10367
- getValue = () => jsonStringify(this.resource.languageJSON);
11082
+ getValue = () => jsonStringify(this.resource.languageJSON, this.resource._resourceType);
10368
11083
  };
10369
11084
  LANGUAGE_CLASS_BRAND = Symbol.for("sandstone.LanguageClass");
10370
11085
  LanguageClass = class LanguageClass extends ResourceClass {
@@ -10416,7 +11131,7 @@ var init_particle2 = __esm(() => {
10416
11131
  super(sandstoneCore);
10417
11132
  this.resource = resource;
10418
11133
  }
10419
- getValue = () => jsonStringify(this.resource.particleJSON);
11134
+ getValue = () => jsonStringify(this.resource.particleJSON, this.resource._resourceType);
10420
11135
  };
10421
11136
  ParticleClass = class ParticleClass extends ResourceClass {
10422
11137
  static resourceType = "particle";
@@ -10441,7 +11156,7 @@ var init_postEffect = __esm(() => {
10441
11156
  super(sandstoneCore);
10442
11157
  this.resource = resource;
10443
11158
  }
10444
- getValue = () => jsonStringify(this.resource.postEffectJSON);
11159
+ getValue = () => jsonStringify(this.resource.postEffectJSON, this.resource._resourceType);
10445
11160
  };
10446
11161
  PostEffectClass = class PostEffectClass extends ResourceClass {
10447
11162
  static resourceType = "post_effect";
@@ -10466,7 +11181,7 @@ var init_shader = __esm(() => {
10466
11181
  super(sandstoneCore);
10467
11182
  this.resource = resource;
10468
11183
  }
10469
- getValue = () => jsonStringify(this.resource.shaderJSON);
11184
+ getValue = () => jsonStringify(this.resource.shaderJSON, this.resource._resourceType);
10470
11185
  };
10471
11186
  ShaderClass = class ShaderClass extends ResourceClass {
10472
11187
  static resourceType = "shader";
@@ -10528,7 +11243,7 @@ var init_sound = __esm(() => {
10528
11243
  super(sandstoneCore);
10529
11244
  this.resource = resource;
10530
11245
  }
10531
- getValue = () => jsonStringify(this.resource.soundsJSON);
11246
+ getValue = () => jsonStringify(this.resource.soundsJSON, this.resource._resourceType);
10532
11247
  };
10533
11248
  SOUNDS_CLASS_BRAND = Symbol.for("sandstone.SoundsClass");
10534
11249
  SoundsClass = class SoundsClass extends ResourceClass {
@@ -10758,7 +11473,7 @@ var init_waypointStyle = __esm(() => {
10758
11473
  super(sandstoneCore);
10759
11474
  this.resource = resource;
10760
11475
  }
10761
- getValue = () => jsonStringify(this.resource.waypointStyleJSON);
11476
+ getValue = () => jsonStringify(this.resource.waypointStyleJSON, this.resource._resourceType);
10762
11477
  };
10763
11478
  WaypointStyleClass = class WaypointStyleClass extends ResourceClass {
10764
11479
  static resourceType = "waypoint_style";
@@ -11327,7 +12042,18 @@ class SandstoneCore {
11327
12042
  _path.splice(1, 0, packType2.resourceSubFolder);
11328
12043
  }
11329
12044
  const resourcePath = path4.join(..._path);
11330
- const value = await node.getValue();
12045
+ let value;
12046
+ try {
12047
+ value = await node.getValue();
12048
+ } catch (e) {
12049
+ console.log(`
12050
+
12051
+
12052
+
12053
+ `);
12054
+ console.log(node);
12055
+ throw e;
12056
+ }
11331
12057
  if (cliOptions.verbose) {
11332
12058
  console.log(`Path: ${resourcePath}.${fileExtension}
11333
12059