sandstone 1.0.0-beta.4 → 1.0.0

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 (150) hide show
  1. package/README.md +3 -4
  2. package/dist/_internal/index.d.ts +992 -335
  3. package/dist/_internal/index.js +516 -518
  4. package/dist/_internal/index.js.map +1 -1
  5. package/dist/_internal/types/arguments/coords.d.ts +13 -14
  6. package/dist/_internal/types/arguments/generated/_registry/activities.d.ts +1 -1
  7. package/dist/_internal/types/arguments/generated/_registry/atlases.d.ts +1 -1
  8. package/dist/_internal/types/arguments/generated/_registry/attribute_types.d.ts +1 -1
  9. package/dist/_internal/types/arguments/generated/_registry/attributes.d.ts +1 -1
  10. package/dist/_internal/types/arguments/generated/_registry/banner_patterns.d.ts +1 -1
  11. package/dist/_internal/types/arguments/generated/_registry/block_definitions.d.ts +1 -1
  12. package/dist/_internal/types/arguments/generated/_registry/block_entity_types.d.ts +1 -1
  13. package/dist/_internal/types/arguments/generated/_registry/block_types.d.ts +1 -1
  14. package/dist/_internal/types/arguments/generated/_registry/blocks.d.ts +1 -1
  15. package/dist/_internal/types/arguments/generated/_registry/chunk_statuses.d.ts +1 -1
  16. package/dist/_internal/types/arguments/generated/_registry/command_argument_types.d.ts +1 -1
  17. package/dist/_internal/types/arguments/generated/_registry/creative_mode_tabs.d.ts +1 -1
  18. package/dist/_internal/types/arguments/generated/_registry/custom_stats.d.ts +1 -1
  19. package/dist/_internal/types/arguments/generated/_registry/damage_types.d.ts +1 -1
  20. package/dist/_internal/types/arguments/generated/_registry/data_component_predicate_types.d.ts +1 -1
  21. package/dist/_internal/types/arguments/generated/_registry/data_component_types.d.ts +1 -1
  22. package/dist/_internal/types/arguments/generated/_registry/debug_subscriptions.d.ts +1 -1
  23. package/dist/_internal/types/arguments/generated/_registry/decorated_pot_patterns.d.ts +1 -1
  24. package/dist/_internal/types/arguments/generated/_registry/dimension_types.d.ts +1 -1
  25. package/dist/_internal/types/arguments/generated/_registry/enchantment_effect_component_types.d.ts +1 -1
  26. package/dist/_internal/types/arguments/generated/_registry/enchantment_entity_effect_types.d.ts +1 -1
  27. package/dist/_internal/types/arguments/generated/_registry/enchantment_level_based_value_types.d.ts +1 -1
  28. package/dist/_internal/types/arguments/generated/_registry/enchantment_location_based_effect_types.d.ts +1 -1
  29. package/dist/_internal/types/arguments/generated/_registry/enchantment_provider_types.d.ts +1 -1
  30. package/dist/_internal/types/arguments/generated/_registry/enchantment_value_effect_types.d.ts +1 -1
  31. package/dist/_internal/types/arguments/generated/_registry/enchantments.d.ts +1 -1
  32. package/dist/_internal/types/arguments/generated/_registry/equipments.d.ts +1 -1
  33. package/dist/_internal/types/arguments/generated/_registry/float_provider_types.d.ts +1 -1
  34. package/dist/_internal/types/arguments/generated/_registry/fluids.d.ts +1 -1
  35. package/dist/_internal/types/arguments/generated/_registry/game_events.d.ts +1 -1
  36. package/dist/_internal/types/arguments/generated/_registry/game_rules.d.ts +1 -1
  37. package/dist/_internal/types/arguments/generated/_registry/height_provider_types.d.ts +1 -1
  38. package/dist/_internal/types/arguments/generated/_registry/int_provider_types.d.ts +1 -1
  39. package/dist/_internal/types/arguments/generated/_registry/item_definitions.d.ts +1 -1
  40. package/dist/_internal/types/arguments/generated/_registry/items.d.ts +1 -1
  41. package/dist/_internal/types/arguments/generated/_registry/jukebox_songs.d.ts +1 -1
  42. package/dist/_internal/types/arguments/generated/_registry/loot_condition_types.d.ts +1 -1
  43. package/dist/_internal/types/arguments/generated/_registry/loot_function_types.d.ts +1 -1
  44. package/dist/_internal/types/arguments/generated/_registry/loot_nbt_provider_types.d.ts +1 -1
  45. package/dist/_internal/types/arguments/generated/_registry/loot_number_provider_types.d.ts +1 -1
  46. package/dist/_internal/types/arguments/generated/_registry/memory_module_types.d.ts +1 -1
  47. package/dist/_internal/types/arguments/generated/_registry/menus.d.ts +1 -1
  48. package/dist/_internal/types/arguments/generated/_registry/mob_effects.d.ts +1 -1
  49. package/dist/_internal/types/arguments/generated/_registry/models.d.ts +1 -1
  50. package/dist/_internal/types/arguments/generated/_registry/painting_variants.d.ts +1 -1
  51. package/dist/_internal/types/arguments/generated/_registry/particle_types.d.ts +1 -1
  52. package/dist/_internal/types/arguments/generated/_registry/point_of_interest_types.d.ts +1 -1
  53. package/dist/_internal/types/arguments/generated/_registry/post_effects.d.ts +1 -1
  54. package/dist/_internal/types/arguments/generated/_registry/potions.d.ts +1 -1
  55. package/dist/_internal/types/arguments/generated/_registry/recipe_displays.d.ts +1 -1
  56. package/dist/_internal/types/arguments/generated/_registry/recipe_serializers.d.ts +1 -1
  57. package/dist/_internal/types/arguments/generated/_registry/recipe_types.d.ts +1 -1
  58. package/dist/_internal/types/arguments/generated/_registry/recipes.d.ts +1 -1
  59. package/dist/_internal/types/arguments/generated/_registry/slot_displays.d.ts +1 -1
  60. package/dist/_internal/types/arguments/generated/_registry/slot_source_types.d.ts +1 -1
  61. package/dist/_internal/types/arguments/generated/_registry/structures.d.ts +1 -1
  62. package/dist/_internal/types/arguments/generated/_registry/tag_blocks.d.ts +1 -1
  63. package/dist/_internal/types/arguments/generated/_registry/tag_entity_types.d.ts +1 -1
  64. package/dist/_internal/types/arguments/generated/_registry/tag_fluids.d.ts +1 -1
  65. package/dist/_internal/types/arguments/generated/_registry/tag_items.d.ts +1 -1
  66. package/dist/_internal/types/arguments/generated/_registry/tag_point_of_interest_types.d.ts +1 -1
  67. package/dist/_internal/types/arguments/generated/_registry/tag_timelines.d.ts +1 -1
  68. package/dist/_internal/types/arguments/generated/_registry/tag_villager_trades.d.ts +1 -1
  69. package/dist/_internal/types/arguments/generated/_registry/tag_worldgen_structures.d.ts +1 -1
  70. package/dist/_internal/types/arguments/generated/_registry/textures.d.ts +1 -1
  71. package/dist/_internal/types/arguments/generated/_registry/ticket_types.d.ts +1 -1
  72. package/dist/_internal/types/arguments/generated/_registry/trigger_types.d.ts +1 -1
  73. package/dist/_internal/types/arguments/generated/_registry/trim_patterns.d.ts +1 -1
  74. package/dist/_internal/types/arguments/generated/_registry/villager_professions.d.ts +1 -1
  75. package/dist/_internal/types/arguments/generated/_registry/wolf_variants.d.ts +1 -1
  76. package/dist/_internal/types/arguments/generated/_registry/worldgen_biomes.d.ts +1 -1
  77. package/dist/_internal/types/arguments/generated/_registry/worldgen_density_function_types.d.ts +1 -1
  78. package/dist/_internal/types/arguments/generated/_registry/worldgen_features.d.ts +1 -1
  79. package/dist/_internal/types/arguments/generated/_registry/worldgen_material_conditions.d.ts +1 -1
  80. package/dist/_internal/types/arguments/generated/_registry/worldgen_noise_settings.d.ts +1 -1
  81. package/dist/_internal/types/arguments/generated/_registry/worldgen_noises.d.ts +1 -1
  82. package/dist/_internal/types/arguments/generated/_registry/worldgen_placed_features.d.ts +1 -1
  83. package/dist/_internal/types/arguments/generated/_registry/worldgen_placement_modifier_types.d.ts +1 -1
  84. package/dist/_internal/types/arguments/generated/_registry/worldgen_processor_lists.d.ts +1 -1
  85. package/dist/_internal/types/arguments/generated/_registry/worldgen_structure_sets.d.ts +1 -1
  86. package/dist/_internal/types/arguments/generated/_registry/worldgen_structure_types.d.ts +1 -1
  87. package/dist/_internal/types/arguments/generated/_registry/worldgen_structures.d.ts +1 -1
  88. package/dist/_internal/types/arguments/generated/_registry/worldgen_template_pools.d.ts +1 -1
  89. package/dist/_internal/types/arguments/generated/_registry/worldgen_tree_decorator_types.d.ts +1 -1
  90. package/dist/_internal/types/arguments/objective.d.ts +1 -1
  91. package/dist/_internal/types/arguments/range.d.ts +7 -7
  92. package/dist/_internal/types/commands/commands.d.ts +1 -4
  93. package/dist/_internal/types/commands/implementations/entity/execute.d.ts +9 -3
  94. package/dist/_internal/types/commands/implementations/server/gamerule.d.ts +38 -3
  95. package/dist/_internal/types/commands/implementations/server/random.d.ts +3 -3
  96. package/dist/_internal/types/commands/implementations/world/time.d.ts +6 -6
  97. package/dist/_internal/types/core/Macro.d.ts +0 -1
  98. package/dist/_internal/types/core/sandstoneCore.d.ts +8 -0
  99. package/dist/_internal/types/pack/pack.d.ts +2 -3
  100. package/dist/_internal/types/utils.d.ts +79 -0
  101. package/dist/_internal/types/variables/Score.d.ts +20 -4
  102. package/dist/_internal/types/variables/Sleep.d.ts +0 -3
  103. package/dist/_internal/types/variables/nbt/NBTs.d.ts +28 -1
  104. package/dist/browser/package.json +3 -0
  105. package/dist/browser/sandstone.esm.js +61581 -0
  106. package/dist/browser/sandstone.esm.js.map +1 -0
  107. package/dist/exports/commands/index.d.ts +1 -1
  108. package/dist/exports/core/index.d.ts +1 -1
  109. package/dist/exports/index.d.ts +1 -1
  110. package/dist/exports/index.js +1 -1
  111. package/package.json +22 -18
  112. package/src/arguments/coords.ts +11 -14
  113. package/src/arguments/objective.ts +1 -1
  114. package/src/arguments/range.ts +9 -9
  115. package/src/commands/commands.ts +3 -3
  116. package/src/commands/implementations/block/fill.ts +3 -3
  117. package/src/commands/implementations/block/setblock.ts +2 -2
  118. package/src/commands/implementations/entity/clear.ts +5 -1
  119. package/src/commands/implementations/entity/execute.ts +27 -6
  120. package/src/commands/implementations/entity/summon.ts +2 -2
  121. package/src/commands/implementations/player/dialog.ts +2 -2
  122. package/src/commands/implementations/player/give.ts +2 -2
  123. package/src/commands/implementations/player/particle.ts +2 -2
  124. package/src/commands/implementations/server/debug.ts +6 -1
  125. package/src/commands/implementations/server/function.ts +8 -3
  126. package/src/commands/implementations/server/gamerule.ts +75 -3
  127. package/src/commands/implementations/server/random.ts +3 -3
  128. package/src/commands/implementations/server/schedule.ts +10 -2
  129. package/src/commands/implementations/world/data.ts +5 -5
  130. package/src/commands/implementations/world/item.ts +2 -2
  131. package/src/commands/implementations/world/time.ts +5 -5
  132. package/src/core/Macro.ts +0 -2
  133. package/src/core/nodes.ts +17 -1
  134. package/src/core/resources/datapack/mcfunction.ts +12 -5
  135. package/src/core/resources/datapack/structure.ts +1 -0
  136. package/src/core/resources/resourcepack/sound.ts +2 -4
  137. package/src/core/sandstoneCore.ts +17 -0
  138. package/src/flow/conditions/variables/block.ts +2 -2
  139. package/src/flow/loops/for_i.ts +17 -15
  140. package/src/flow/loops/for_of.ts +0 -1
  141. package/src/pack/pack.ts +13 -6
  142. package/src/sandstone.ts +2 -2
  143. package/src/utils.ts +159 -0
  144. package/src/variables/Data.ts +3 -3
  145. package/src/variables/ItemPredicate.ts +2 -2
  146. package/src/variables/Score.ts +18 -10
  147. package/src/variables/Selector.ts +21 -3
  148. package/src/variables/Sleep.ts +2 -10
  149. package/src/variables/Trigger.ts +3 -5
  150. package/src/variables/nbt/NBTs.ts +70 -19
@@ -40,6 +40,11 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
40
40
 
41
41
  // Hoisted class definitions
42
42
 
43
+ class ComponentClass {
44
+ _toChatComponent() {
45
+ throw new Error("Not implemented");
46
+ }
47
+ }
43
48
  ConditionTextComponentClass = class ConditionTextComponentClass extends ComponentClass {
44
49
  _toChatComponent() {
45
50
  throw new Error("Not implemented");
@@ -69,6 +74,32 @@ VectorClass = class VectorClass {
69
74
  return this.values[Symbol.iterator]();
70
75
  }
71
76
  };
77
+ class MacroArgument {
78
+ sandstoneCore;
79
+ local;
80
+ toMacro;
81
+ constructor(sandstoneCore) {
82
+ this.sandstoneCore = sandstoneCore;
83
+ this.local = new Map;
84
+ this.toMacro = () => {
85
+ let currentMCFunctionName = "";
86
+ try {
87
+ currentMCFunctionName = sandstoneCore.getCurrentMCFunctionOrThrow().resource.name;
88
+ } catch {}
89
+ let result = this.local.get(this.sandstoneCore.currentNode) || this.local.get(currentMCFunctionName);
90
+ if (!result) {
91
+ let path = this.sandstoneCore.currentNode;
92
+ while (path.includes("/")) {
93
+ path = path.substring(0, path.lastIndexOf("/"));
94
+ result = this.local.get(path);
95
+ if (result)
96
+ break;
97
+ }
98
+ }
99
+ return `$(${result})`;
100
+ };
101
+ }
102
+ }
72
103
  MacroLiteral = class MacroLiteral extends MacroArgument {
73
104
  sandstoneCore;
74
105
  strings;
@@ -117,6 +148,8 @@ Set2 = class Set2 extends global.Set {
117
148
  return super.has(value);
118
149
  }
119
150
  };
151
+ class NBTClass {
152
+ }
120
153
  NBTPrimitive = class NBTPrimitive extends NBTClass {
121
154
  value;
122
155
  unit;
@@ -194,7 +227,7 @@ NotNBT = class NotNBT extends NBTClass {
194
227
  super();
195
228
  this.nbt = nbt;
196
229
  }
197
- [util2.inspect.custom] = () => `!${nbtStringifier(this.nbt)}`;
230
+ [util2.inspect.custom] = () => `!${nbtResolver(this.nbt)}`;
198
231
  };
199
232
  NBTString = class NBTString extends NBTPrimitive {
200
233
  };
@@ -225,7 +258,7 @@ Score = class Score extends MacroArgument {
225
258
  return `${this.target} ${this.objective}`;
226
259
  }
227
260
  toNBT() {
228
- return nbtStringifier(this._toChatComponent());
261
+ return nbtResolver(this._toChatComponent()).toString();
229
262
  }
230
263
  toJSON() {
231
264
  return this._toChatComponent();
@@ -326,6 +359,7 @@ Score = class Score extends MacroArgument {
326
359
  modulo(...args) {
327
360
  return this.binaryOperation("%=", ...args);
328
361
  }
362
+ mod = this.modulo;
329
363
  "%=" = this.modulo;
330
364
  swap(...args) {
331
365
  this.binaryOperation("><", ...args);
@@ -342,6 +376,7 @@ Score = class Score extends MacroArgument {
342
376
  multipliedBy(...args) {
343
377
  return createVariable(this.sandstonePack, this).binaryOperation("*=", ...args);
344
378
  }
379
+ times = this.multipliedBy;
345
380
  "*" = this.multipliedBy;
346
381
  dividedBy(...args) {
347
382
  return createVariable(this.sandstonePack, this).binaryOperation("/=", ...args);
@@ -350,6 +385,7 @@ Score = class Score extends MacroArgument {
350
385
  moduloBy(...args) {
351
386
  return createVariable(this.sandstonePack, this).binaryOperation("%=", ...args);
352
387
  }
388
+ modBy = this.moduloBy;
353
389
  "%" = this.moduloBy;
354
390
  comparison(operator, matchesRange, args) {
355
391
  const playerScore = this;
@@ -377,21 +413,22 @@ Score = class Score extends MacroArgument {
377
413
  return this.comparison(">", `${typeof args[0] === "number" ? args[0] + 1 : null}..`, args);
378
414
  }
379
415
  ">" = this.greaterThan;
380
- greaterOrEqualThan(...args) {
416
+ greaterThanOrEqualTo(...args) {
381
417
  return this.comparison(">=", `${args[0]}..`, args);
382
418
  }
383
- ">=" = this.greaterOrEqualThan;
419
+ ">=" = this.greaterThanOrEqualTo;
384
420
  lessThan(...args) {
385
421
  return this.comparison("<", `..${typeof args[0] === "number" ? args[0] - 1 : null}`, args);
386
422
  }
387
423
  "<" = this.lessThan;
388
- lessOrEqualThan(...args) {
424
+ lessThanOrEqualTo(...args) {
389
425
  return this.comparison("<=", `..${args[0]}`, args);
390
426
  }
391
- "<=" = this.lessOrEqualThan;
427
+ "<=" = this.lessThanOrEqualTo;
392
428
  equalTo(...args) {
393
429
  return this.comparison("=", args[0].toString(), args);
394
430
  }
431
+ equals = this.equalTo;
395
432
  "==" = this.equalTo;
396
433
  notEqualTo(...args) {
397
434
  return this.sandstonePack._.not(this.comparison("=", args[0].toString(), args));
@@ -588,7 +625,7 @@ DataPointClass = class DataPointClass extends MacroArgument {
588
625
  nbt: this.path,
589
626
  [this.type]: this.currentTarget
590
627
  });
591
- toNBT = () => nbtStringifier(this._toChatComponent());
628
+ toNBT = () => nbtResolver(this._toChatComponent()).toString();
592
629
  };
593
630
  StringDataPointClass = class StringDataPointClass extends DataPointClass {
594
631
  sandstonePack;
@@ -603,6 +640,27 @@ StringDataPointClass = class StringDataPointClass extends DataPointClass {
603
640
  this.sliceBounds.push(end);
604
641
  }
605
642
  };
643
+ class PackType {
644
+ type;
645
+ clientPath;
646
+ serverPath;
647
+ rootPath;
648
+ networkSides;
649
+ resourceSubFolder;
650
+ namespaced;
651
+ archiveOutput;
652
+ handleOutput;
653
+ constructor(type, clientPath, serverPath, rootPath, networkSides, archiveOutput = false, resourceSubFolder, namespaced = false) {
654
+ this.type = type;
655
+ this.clientPath = clientPath;
656
+ this.serverPath = serverPath;
657
+ this.rootPath = rootPath;
658
+ this.networkSides = networkSides;
659
+ this.archiveOutput = archiveOutput;
660
+ this.resourceSubFolder = resourceSubFolder;
661
+ this.namespaced = namespaced;
662
+ }
663
+ }
606
664
  DataPackDependencies = class DataPackDependencies extends PackType {
607
665
  constructor() {
608
666
  super("datapack_dependencies", "saves/$worldName$/datapacks", "world/datapacks", "datapacks", "server", false, undefined, false);
@@ -674,9 +732,17 @@ CommandNode = class CommandNode extends Node {
674
732
  for (const arg of this.args) {
675
733
  if (arg !== undefined && arg !== null) {
676
734
  if (typeof arg === "object") {
677
- if (isMacroArgument(this.sandstoneCore, arg)) {
735
+ if (arg instanceof ResolvedNBT) {
736
+ if (arg.containsMacro) {
737
+ this.isMacro = true;
738
+ }
739
+ filteredArgs.push(arg);
740
+ } else if (isMacroArgument(this.sandstoneCore, arg)) {
678
741
  this.isMacro = true;
679
742
  filteredArgs.push(arg.toMacro());
743
+ } else if (Object.hasOwn(arg, "_hasMacro") && arg._hasMacro) {
744
+ this.isMacro = true;
745
+ filteredArgs.push(arg);
680
746
  } else if (Object.hasOwn(arg, "toLoop")) {
681
747
  filteredArgs.push(arg.toLoop());
682
748
  } else {
@@ -735,50 +801,6 @@ ContainerCommandNode = class ContainerCommandNode extends CommandNode {
735
801
  AwaitNode = class AwaitNode extends ContainerCommandNode {
736
802
  mcfunction = undefined;
737
803
  };
738
- PlaceCommandNode = class PlaceCommandNode extends CommandNode {
739
- command = "place";
740
- };
741
- PlaceCommand = class PlaceCommand extends CommandArguments {
742
- NodeType = PlaceCommandNode;
743
- feature = (feature, pos = "~ ~ ~") => this.finalCommand(["feature", feature, coordinatesParser(pos)]);
744
- jigsaw = (pool, target, maxDepth, pos = "~ ~ ~") => this.finalCommand([
745
- "jigsaw",
746
- pool,
747
- target,
748
- `${validateIntegerRange(maxDepth, "Jigsaw max depth", 0, 7)}`,
749
- coordinatesParser(pos)
750
- ]);
751
- structure = (configuredStructure, pos = "~ ~ ~") => this.finalCommand(["structure", configuredStructure, coordinatesParser(pos)]);
752
- template = (structure, pos = "~ ~ ~", rotation, mirror, integrity = 1, seed = 0, mode) => {
753
- this.finalCommand([
754
- "template",
755
- `${structure}`,
756
- coordinatesParser(pos),
757
- structureRotationParser(rotation),
758
- structureMirrorParser(mirror),
759
- `${integrity}`,
760
- `${seed}`,
761
- ...mode === undefined ? [] : [mode]
762
- ]);
763
- };
764
- };
765
- DamageCommandNode = class DamageCommandNode extends CommandNode {
766
- command = "damage";
767
- };
768
- DamageCauseCommand = class DamageCauseCommand extends CommandArguments {
769
- from = (cause) => this.finalCommand(["from", targetParser(cause)]);
770
- };
771
- DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
772
- by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand, true);
773
- at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
774
- };
775
- DamageCommand = class DamageCommand extends CommandArguments {
776
- NodeType = DamageCommandNode;
777
- damage = (target, amount, damageType) => {
778
- validateIntegerRange(amount, "amount", 0, 1e6);
779
- return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand, true);
780
- };
781
- };
782
804
  CommentCommandNode = class CommentCommandNode extends CommandNode {
783
805
  command = "#";
784
806
  getValue() {
@@ -787,6 +809,50 @@ CommentCommandNode = class CommentCommandNode extends CommandNode {
787
809
  `);
788
810
  }
789
811
  };
812
+ class CommandArguments {
813
+ sandstonePack;
814
+ previousNode;
815
+ autoCommit;
816
+ NodeType;
817
+ sandstoneCore;
818
+ sandstoneCommands;
819
+ constructor(sandstonePack, previousNode, autoCommit = true) {
820
+ this.sandstonePack = sandstonePack;
821
+ this.previousNode = previousNode;
822
+ this.autoCommit = autoCommit;
823
+ this.sandstoneCore = sandstonePack.core;
824
+ this.sandstoneCommands = sandstonePack.commands;
825
+ }
826
+ getNode = () => {
827
+ if (this.previousNode) {
828
+ return this.previousNode;
829
+ }
830
+ if (this.NodeType) {
831
+ return new this.NodeType(this.sandstonePack);
832
+ }
833
+ throw new Error("No node type specified & no previous node for a non-root-level command");
834
+ };
835
+ finalCommand = (args, currentNode) => {
836
+ const node = currentNode ?? this.getNode();
837
+ if (args) {
838
+ node.args.push(...args);
839
+ }
840
+ if (this.autoCommit) {
841
+ node.commit();
842
+ }
843
+ return new FinalCommandOutput(node);
844
+ };
845
+ subCommand = (args, NextArgumentType, executable = false, additionalNextArgs = [], currentNode) => {
846
+ const node = currentNode ?? this.getNode();
847
+ if (args) {
848
+ node.args.push(...args);
849
+ }
850
+ if (executable && this.autoCommit) {
851
+ node.commit();
852
+ }
853
+ return new NextArgumentType(this.sandstonePack, node, this.autoCommit, ...additionalNextArgs);
854
+ };
855
+ }
790
856
  CommentCommand = class CommentCommand extends CommandArguments {
791
857
  NodeType = CommentCommandNode;
792
858
  comment = (...comments) => this.finalCommand([comments]);
@@ -847,7 +913,7 @@ SetBlockCommand = class SetBlockCommand extends CommandArguments {
847
913
  return this.finalCommand([coordinatesParser(pos), block, arg5]);
848
914
  }
849
915
  const state = typeof arg3 === "undefined" ? "" : blockStateStringifier(arg3);
850
- const nbt = typeof arg4 === "string" || arg4 === undefined ? "" : nbtStringifier(arg4);
916
+ const nbt = typeof arg4 === "string" || arg4 === undefined ? "" : nbtResolver(arg4).toString();
851
917
  const setblockType = typeof arg4 === "string" ? arg4 : arg5;
852
918
  return this.finalCommand([coordinatesParser(pos), `${block}${state}${nbt}`, setblockType]);
853
919
  }
@@ -859,7 +925,7 @@ FillCommand = class FillCommand extends CommandArguments {
859
925
  NodeType = FillCommandNode;
860
926
  fill(from, to, block, state, nbt) {
861
927
  const stateStr = state && Object.keys(state).length > 0 ? blockStateStringifier(state) : "";
862
- const nbtStr = nbt ? nbtStringifier(nbt) : "";
928
+ const nbtStr = nbt ? nbtResolver(nbt).toString() : "";
863
929
  const blockArg = `${block}${stateStr}${nbtStr}`;
864
930
  return this.subCommand([coordinatesParser(from), coordinatesParser(to), blockArg], FillArgumentsCommand, true);
865
931
  }
@@ -875,7 +941,7 @@ FillArgumentsCommand = class FillArgumentsCommand extends CommandArguments {
875
941
  return this.finalCommand(["replace"]);
876
942
  }
877
943
  const stateStr = filterState && Object.keys(filterState).length > 0 ? blockStateStringifier(filterState) : "";
878
- const nbtStr = filterNbt ? nbtStringifier(filterNbt) : "";
944
+ const nbtStr = filterNbt ? nbtResolver(filterNbt).toString() : "";
879
945
  return this.subCommand(["replace", `${filter}${stateStr}${nbtStr}`], FillReplaceFilterCommand, true);
880
946
  }
881
947
  };
@@ -885,6 +951,33 @@ FillReplaceFilterCommand = class FillReplaceFilterCommand extends CommandArgumen
885
951
  outline = () => this.finalCommand(["outline"]);
886
952
  strict = () => this.finalCommand(["strict"]);
887
953
  };
954
+ PlaceCommandNode = class PlaceCommandNode extends CommandNode {
955
+ command = "place";
956
+ };
957
+ PlaceCommand = class PlaceCommand extends CommandArguments {
958
+ NodeType = PlaceCommandNode;
959
+ feature = (feature, pos = "~ ~ ~") => this.finalCommand(["feature", feature, coordinatesParser(pos)]);
960
+ jigsaw = (pool, target, maxDepth, pos = "~ ~ ~") => this.finalCommand([
961
+ "jigsaw",
962
+ pool,
963
+ target,
964
+ `${validateIntegerRange(maxDepth, "Jigsaw max depth", 0, 7)}`,
965
+ coordinatesParser(pos)
966
+ ]);
967
+ structure = (configuredStructure, pos = "~ ~ ~") => this.finalCommand(["structure", configuredStructure, coordinatesParser(pos)]);
968
+ template = (structure, pos = "~ ~ ~", rotation, mirror, integrity = 1, seed = 0, mode) => {
969
+ this.finalCommand([
970
+ "template",
971
+ `${structure}`,
972
+ coordinatesParser(pos),
973
+ structureRotationParser(rotation),
974
+ structureMirrorParser(mirror),
975
+ `${integrity}`,
976
+ `${seed}`,
977
+ ...mode === undefined ? [] : [mode]
978
+ ]);
979
+ };
980
+ };
888
981
  AttributeCommandNode = class AttributeCommandNode extends CommandNode {
889
982
  command = "attribute";
890
983
  };
@@ -907,9 +1000,27 @@ ClearCommandNode = class ClearCommandNode extends CommandNode {
907
1000
  ClearCommand = class ClearCommand extends CommandArguments {
908
1001
  NodeType = ClearCommandNode;
909
1002
  clear(targets, itemOrPredicate, maxCount) {
910
- return this.finalCommand([targetParser(targets), `${itemOrPredicate}`, maxCount]);
1003
+ const itemArg = isMacroArgument(this.sandstoneCore, itemOrPredicate) ? itemOrPredicate : `${itemOrPredicate}`;
1004
+ return this.finalCommand([targetParser(targets), itemArg, maxCount]);
911
1005
  }
912
1006
  };
1007
+ DamageCommandNode = class DamageCommandNode extends CommandNode {
1008
+ command = "damage";
1009
+ };
1010
+ DamageCauseCommand = class DamageCauseCommand extends CommandArguments {
1011
+ from = (cause) => this.finalCommand(["from", targetParser(cause)]);
1012
+ };
1013
+ DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
1014
+ by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand, true);
1015
+ at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
1016
+ };
1017
+ DamageCommand = class DamageCommand extends CommandArguments {
1018
+ NodeType = DamageCommandNode;
1019
+ damage = (target, amount, damageType) => {
1020
+ validateIntegerRange(amount, "amount", 0, 1e6);
1021
+ return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand, true);
1022
+ };
1023
+ };
913
1024
  EffectCommandNode = class EffectCommandNode extends CommandNode {
914
1025
  command = "effect";
915
1026
  };
@@ -935,6 +1046,110 @@ EnchantCommand = class EnchantCommand extends CommandArguments {
935
1046
  return this.finalCommand([targetParser(targets), enchantment, level]);
936
1047
  };
937
1048
  };
1049
+ class ResourceClass {
1050
+ core;
1051
+ _resourceType;
1052
+ node;
1053
+ packType;
1054
+ fileExtension;
1055
+ fileEncoding;
1056
+ creator;
1057
+ commands;
1058
+ pack;
1059
+ path;
1060
+ addToSandstoneCore;
1061
+ onConflict;
1062
+ renameIndex = 2;
1063
+ constructor(core, file, NodeType, _resourceType, path, args) {
1064
+ this.core = core;
1065
+ this._resourceType = _resourceType;
1066
+ this.node = new NodeType(core, this);
1067
+ this.packType = args.packType || file.packType;
1068
+ this.fileExtension = file.extension || "json";
1069
+ this.fileEncoding = file.encoding ?? "utf8";
1070
+ this.pack = core.pack;
1071
+ this.commands = core.pack.commands;
1072
+ this.path = path;
1073
+ this.addToSandstoneCore = args.addToSandstoneCore;
1074
+ this.creator = args.creator ?? "sandstone";
1075
+ const conflictStrategies = hasContext() ? getSandstoneContext().conflictStrategies : undefined;
1076
+ const scopedStrategy = conflictStrategies?.[_resourceType];
1077
+ const defaultStrategy = conflictStrategies?.default;
1078
+ this.onConflict = args.onConflict ?? scopedStrategy ?? defaultStrategy ?? "throw";
1079
+ }
1080
+ handleConflicts() {
1081
+ const conflict = this.core.resourceNodes.get(this.node);
1082
+ let add2 = false;
1083
+ if (conflict) {
1084
+ const oldResource = conflict.resource;
1085
+ const newResource = this.node.resource;
1086
+ switch (this.onConflict) {
1087
+ case "throw": {
1088
+ throw new Error(`Created a ${this._resourceType} with the duplicate name ${newResource.name}, and onConflict was set to "throw".`);
1089
+ }
1090
+ case "replace":
1091
+ {
1092
+ this.core.resourceNodes.delete(conflict);
1093
+ add2 = true;
1094
+ }
1095
+ break;
1096
+ case "warn":
1097
+ {
1098
+ console.warn([
1099
+ "Warning:",
1100
+ `Tried to create a ${this._resourceType} named "${newResource.name}", but found an already existing one.`,
1101
+ "The new one has replaced the old one. To remove this warning, please change the options of the resource to { onConflict: '/* other option */' }."
1102
+ ].join(`
1103
+ `));
1104
+ this.core.resourceNodes.delete(conflict);
1105
+ add2 = true;
1106
+ }
1107
+ break;
1108
+ case "rename":
1109
+ {
1110
+ this.path[this.path.length - 1] += oldResource.renameIndex.toString();
1111
+ oldResource.renameIndex += 1;
1112
+ add2 = true;
1113
+ }
1114
+ break;
1115
+ case "prepend":
1116
+ {
1117
+ oldResource.unshift(newResource);
1118
+ }
1119
+ break;
1120
+ case "append":
1121
+ {
1122
+ oldResource.push(newResource);
1123
+ }
1124
+ break;
1125
+ default:
1126
+ break;
1127
+ }
1128
+ } else {
1129
+ add2 = true;
1130
+ }
1131
+ if (this.addToSandstoneCore && add2) {
1132
+ this.core.resourceNodes.add(this.node);
1133
+ }
1134
+ }
1135
+ getNode = () => this.node;
1136
+ get name() {
1137
+ return `${this.path[0]}:${this.path.slice(this._resourceType in RESOURCE_PATHS ? RESOURCE_PATHS[this._resourceType].path.length + 1 : 2).join("/")}`;
1138
+ }
1139
+ get namespace() {
1140
+ return this.path[0];
1141
+ }
1142
+ generate = () => {};
1143
+ toString() {
1144
+ return this.name;
1145
+ }
1146
+ toNBT() {
1147
+ return this.name;
1148
+ }
1149
+ toJSON() {
1150
+ return this.name;
1151
+ }
1152
+ }
938
1153
  CallableResourceClass = class CallableResourceClass extends ResourceClass {
939
1154
  _that;
940
1155
  get asCallable() {
@@ -1672,15 +1887,17 @@ _RawMCFunctionClass = class _RawMCFunctionClass extends CallableResourceClass {
1672
1887
  func = this;
1673
1888
  }
1674
1889
  if (typeof tag === "string") {
1675
- if (tags[tag]) {
1676
- tags[tag].push(func);
1890
+ const existing = this.core.functionTags.get(tag);
1891
+ if (existing) {
1892
+ existing.push(func);
1677
1893
  } else {
1678
- tags[tag] = new TagClass(this.core, "function", tag, {
1894
+ const newTag = new TagClass(this.core, "function", tag, {
1679
1895
  values: [func],
1680
1896
  addToSandstoneCore: true,
1681
1897
  creator: "sandstone",
1682
1898
  onConflict: "append"
1683
1899
  });
1900
+ this.core.functionTags.set(tag, newTag);
1684
1901
  }
1685
1902
  } else {
1686
1903
  tag.push(func);
@@ -1704,6 +1921,7 @@ _RawMCFunctionClass = class _RawMCFunctionClass extends CallableResourceClass {
1704
1921
  this.core.enterMCFunction(this);
1705
1922
  this.core.insideContext(this.node, () => this.callback(makeCallable(this, this.__call__.bind(undefined, ..._params)), ..._params), false);
1706
1923
  this.core.exitMCFunction();
1924
+ this.generated = true;
1707
1925
  } else if (this.callback.length > 1) {
1708
1926
  throw new Error(`[MCFunctionClass] Function ${this.name} expects ${this.callback.length - 1} params at the call-site`);
1709
1927
  }
@@ -2524,9 +2742,9 @@ SoundEventClass = class SoundEventClass extends ResourceClass {
2524
2742
  this.buffer = args.sound;
2525
2743
  }
2526
2744
  if (args.addToSounds) {
2527
- let def = sounds.get(this.path[0]);
2745
+ let def = this.core.sounds.get(this.path[0]);
2528
2746
  if (!def) {
2529
- def = sounds.set(this.path[0], new SoundsClass(this.core, this.path[0], {
2747
+ def = this.core.sounds.set(this.path[0], new SoundsClass(this.core, this.path[0], {
2530
2748
  addToSandstoneCore: true,
2531
2749
  creator: "sandstone"
2532
2750
  })).get(this.path[0]);
@@ -2803,10 +3021,11 @@ FunctionCommand = class FunctionCommand extends CommandArguments {
2803
3021
  args.push(point.type, point.currentTarget, point.path);
2804
3022
  }
2805
3023
  } else {
2806
- args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
3024
+ args.push(typeof params === "object" && params.toMacro ? params : nbtResolver(params));
2807
3025
  }
2808
3026
  }
2809
- return this.finalCommand([`${mcFunction}`, ...args]);
3027
+ const mcFunctionArg = isMacroArgument(this.sandstoneCore, mcFunction) ? mcFunction : `${mcFunction}`;
3028
+ return this.finalCommand([mcFunctionArg, ...args]);
2810
3029
  }
2811
3030
  };
2812
3031
  ExecuteCommandPart = class ExecuteCommandPart extends CommandArguments {
@@ -2886,6 +3105,9 @@ ExecuteCommandNode = class ExecuteCommandNode extends ContainerCommandNode {
2886
3105
  return `${this.isMacro ? "$" : ""}${executeString} run ${command}`;
2887
3106
  };
2888
3107
  createMCFunction = (currentMCFunction) => {
3108
+ if (this.createdMCFunction) {
3109
+ return { node: this, mcFunction: this.createdMCFunction.node };
3110
+ }
2889
3111
  if (this.isSingleExecute || !currentMCFunction) {
2890
3112
  return { node: this };
2891
3113
  }
@@ -2908,7 +3130,15 @@ ExecuteStoreArgsCommand = class ExecuteStoreArgsCommand extends ExecuteCommandPa
2908
3130
  block = (targetPos, path5, type, scale) => this.nestedExecute(["block", coordinatesParser(targetPos), path5, type, scale]);
2909
3131
  bossbar = (id2, type) => this.nestedExecute(["bossbar", id2, type]);
2910
3132
  entity = (target, path5, type, scale) => this.nestedExecute(["entity", targetParser(target), path5, type, scale]);
2911
- score = (targets, objective) => this.nestedExecute(["score", targetParser(targets), objective]);
3133
+ score(...args) {
3134
+ const finalArgs = ["score"];
3135
+ if (isScore(args[0])) {
3136
+ finalArgs.push(args[0].target, args[0].objective.name);
3137
+ } else {
3138
+ finalArgs.push(targetParser(args[0]), args[1]);
3139
+ }
3140
+ return this.nestedExecute(finalArgs);
3141
+ }
2912
3142
  storage = (target, path5, type, scale = 1) => this.nestedExecute(["storage", target, path5, type, scale]);
2913
3143
  };
2914
3144
  ExecuteStoreCommand = class ExecuteStoreCommand extends ExecuteCommandPart {
@@ -2946,7 +3176,7 @@ ExecuteItemsCommand = class ExecuteItemsCommand extends ExecuteCommandPart {
2946
3176
  ExecuteIfUnlessCommand = class ExecuteIfUnlessCommand extends ExecuteCommandPart {
2947
3177
  block(pos, block, state, nbt) {
2948
3178
  const stateStr = state && typeof state === "object" && Object.keys(state).length > 0 ? blockStateStringifier(state) : "";
2949
- const nbtStr = nbt ? nbtStringifier(nbt) : "";
3179
+ const nbtStr = nbt ? nbtResolver(nbt).toString() : "";
2950
3180
  return this.nestedExecute(["block", coordinatesParser(pos), `${block}${stateStr}${nbtStr}`], true);
2951
3181
  }
2952
3182
  blocks = (start, end, destination, scan_mode) => this.nestedExecute(["blocks", coordinatesParser(start), coordinatesParser(end), coordinatesParser(destination), scan_mode], true);
@@ -3196,7 +3426,7 @@ SummonCommand = class SummonCommand extends CommandArguments {
3196
3426
  args.push(coordinatesParser(pos));
3197
3427
  }
3198
3428
  if (nbt !== undefined) {
3199
- args.push(nbtStringifier(nbt));
3429
+ args.push(nbtResolver(nbt));
3200
3430
  }
3201
3431
  return this.finalCommand(args);
3202
3432
  }
@@ -3296,7 +3526,7 @@ DialogCommandNode = class DialogCommandNode extends CommandNode {
3296
3526
  DialogCommand = class DialogCommand extends CommandArguments {
3297
3527
  NodeType = DialogCommandNode;
3298
3528
  show(targets, dialog2) {
3299
- const dialogArg = typeof dialog2 === "string" || dialog2 instanceof ResourceClass ? dialog2 : nbtStringifier(dialog2);
3529
+ const dialogArg = typeof dialog2 === "string" || dialog2 instanceof ResourceClass ? dialog2 : nbtResolver(dialog2);
3300
3530
  return this.finalCommand(["show", targetParser(targets), dialogArg]);
3301
3531
  }
3302
3532
  clear = (targets) => this.finalCommand(["clear", targetParser(targets)]);
@@ -3342,7 +3572,7 @@ ParticleCommand = class ParticleCommand extends CommandArguments {
3342
3572
  NodeType = ParticleCommandNode;
3343
3573
  particle(name, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
3344
3574
  const hasOptions = arg2 !== undefined && typeof arg2 === "object" && !isCoordinates(arg2);
3345
- const [particleName, pos, delta, speed, count, mode, viewers] = hasOptions ? [`${name}${nbtStringifier(arg2)}`, arg3, arg4, arg5, arg6, arg7, arg8] : [name, arg2, arg3, arg4, arg5, arg6, arg7];
3575
+ const [particleName, pos, delta, speed, count, mode, viewers] = hasOptions ? [`${name}${nbtResolver(arg2)}`, arg3, arg4, arg5, arg6, arg7, arg8] : [name, arg2, arg3, arg4, arg5, arg6, arg7];
3346
3576
  return this.finalCommand([
3347
3577
  particleName,
3348
3578
  pos === undefined ? "~ ~ ~" : coordinatesParser(pos),
@@ -3522,7 +3752,8 @@ DebugCommand = class DebugCommand extends CommandArguments {
3522
3752
  this.sandstoneCore.insideContext(node, func, false);
3523
3753
  return this.finalCommand(["function", undefined], node);
3524
3754
  }
3525
- return this.finalCommand(["function", `${func}`], node);
3755
+ const funcArg = isMacroArgument(this.sandstoneCore, func) ? func : `${func}`;
3756
+ return this.finalCommand(["function", funcArg], node);
3526
3757
  }
3527
3758
  };
3528
3759
  DefaultGameModeCommandNode = class DefaultGameModeCommandNode extends CommandNode {
@@ -3729,7 +3960,8 @@ ScheduleCommandNode = class ScheduleCommandNode extends ContainerCommandNode {
3729
3960
  ScheduleCommand = class ScheduleCommand extends CommandArguments {
3730
3961
  NodeType = ScheduleCommandNode;
3731
3962
  clear = (func) => {
3732
- const result = this.finalCommand(["clear", `${func}`]);
3963
+ const funcArg = isMacroArgument(this.sandstoneCore, func) ? func : `${func}`;
3964
+ const result = this.finalCommand(["clear", funcArg]);
3733
3965
  return result;
3734
3966
  };
3735
3967
  function = (func, delay, type) => {
@@ -3741,7 +3973,8 @@ ScheduleCommand = class ScheduleCommand extends CommandArguments {
3741
3973
  this.sandstoneCore.insideContext(node, func, false);
3742
3974
  return this.finalCommand(["function", undefined, delay, type], node);
3743
3975
  }
3744
- return this.finalCommand(["function", `${func}`, delay, type], node);
3976
+ const funcArg = isMacroArgument(this.sandstoneCore, func) ? func : `${func}`;
3977
+ return this.finalCommand(["function", funcArg, delay, type], node);
3745
3978
  };
3746
3979
  };
3747
3980
  SetIdleTimeoutCommandNode = class SetIdleTimeoutCommandNode extends CommandNode {
@@ -3857,9 +4090,9 @@ DataGetCommand = class DataGetCommand extends CommandArguments {
3857
4090
  };
3858
4091
  };
3859
4092
  DataMergeCommand = class DataMergeCommand extends CommandArguments {
3860
- block = (targetPos, nbt) => this.finalCommand(["block", coordinatesParser(targetPos), nbtStringifier(nbt)]);
3861
- entity = (target, nbt) => this.finalCommand(["entity", targetParser(target), nbtStringifier(nbt)]);
3862
- storage = (target, nbt) => this.finalCommand(["storage", target, nbtStringifier(nbt)]);
4093
+ block = (targetPos, nbt) => this.finalCommand(["block", coordinatesParser(targetPos), nbtResolver(nbt)]);
4094
+ entity = (target, nbt) => this.finalCommand(["entity", targetParser(target), nbtResolver(nbt)]);
4095
+ storage = (target, nbt) => this.finalCommand(["storage", target, nbtResolver(nbt)]);
3863
4096
  };
3864
4097
  DataModifyFromCommand = class DataModifyFromCommand extends CommandArguments {
3865
4098
  block = (sourcePosition, sourcePath) => this.finalCommand(["block", coordinatesParser(sourcePosition), sourcePath]);
@@ -3920,7 +4153,7 @@ DataModifyValuesCommand = class DataModifyValuesCommand extends CommandArguments
3920
4153
  this.finalCommand(command);
3921
4154
  }
3922
4155
  };
3923
- value = (value) => this.finalCommand(["value", nbtStringifier(value)]);
4156
+ value = (value) => this.finalCommand(["value", nbtResolver(value)]);
3924
4157
  };
3925
4158
  DataModifyTypeCommand = class DataModifyTypeCommand extends CommandArguments {
3926
4159
  get append() {
@@ -3993,7 +4226,7 @@ ItemCommandNode = class ItemCommandNode extends CommandNode {
3993
4226
  ItemSourceCommand = class ItemSourceCommand extends CommandArguments {
3994
4227
  with(item, countOrNBT, count) {
3995
4228
  if (typeof countOrNBT === "object") {
3996
- return this.finalCommand(["with", `${item}${nbtStringifier(countOrNBT)}`, count]);
4229
+ return this.finalCommand(["with", `${item}${nbtResolver(countOrNBT)}`, count]);
3997
4230
  }
3998
4231
  return this.finalCommand(["with", item, countOrNBT]);
3999
4232
  }
@@ -4264,7 +4497,7 @@ BlockConditionNode = class BlockConditionNode extends SingleConditionNode {
4264
4497
  }
4265
4498
  getCondition() {
4266
4499
  const stateStr = this.state && Object.keys(this.state).length > 0 ? blockStateStringifier(this.state) : "";
4267
- const nbtStr = this.nbt ? nbtStringifier(this.nbt) : "";
4500
+ const nbtStr = this.nbt ? nbtResolver(this.nbt).toString() : "";
4268
4501
  return ["block", coordinatesParser(this.position), `${this.block}${stateStr}${nbtStr}`];
4269
4502
  }
4270
4503
  };
@@ -4516,15 +4749,6 @@ ForINode = class ForINode extends LoopNode {
4516
4749
  const iterator = sandstoneCore2.pack.Variable(initialValue, "loop_iterator");
4517
4750
  const condition2 = conditionToNode(endCondition(iterator));
4518
4751
  const _continue = () => sandstoneCore2.pack.commands.returnCmd.run(() => new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack)));
4519
- const analysisResult = typeof initialValue === "number" ? analyzeCondition(condition2, iterator, initialValue) : { canAnalyze: false };
4520
- if (analysisResult.canAnalyze) {
4521
- if (analysisResult.result) {
4522
- callback(iterator, _continue);
4523
- iterate(iterator);
4524
- } else {
4525
- warnStaticallyFalseCondition("for", `initial value ${initialValue} does not satisfy condition`);
4526
- }
4527
- }
4528
4752
  super(sandstoneCore2, condition2, () => callback(iterator, _continue), () => {
4529
4753
  iterate(iterator);
4530
4754
  new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack));
@@ -4632,6 +4856,61 @@ DefaultCaseNode = class DefaultCaseNode extends ContainerNode {
4632
4856
  }
4633
4857
  getValue = () => null;
4634
4858
  };
4859
+ class GenericCoreVisitor {
4860
+ core;
4861
+ methodCache;
4862
+ constructor(core) {
4863
+ this.core = core;
4864
+ this.methodCache = new Map;
4865
+ }
4866
+ getSingleNodeMethod = (nodeName) => {
4867
+ const methodName = `visit${nodeName}`;
4868
+ const that = this;
4869
+ const method = that[methodName];
4870
+ return method;
4871
+ };
4872
+ getNodeMethods = (prototype) => {
4873
+ const key = prototype.name;
4874
+ const cachedResult = this.methodCache.get(key);
4875
+ if (cachedResult) {
4876
+ return cachedResult;
4877
+ }
4878
+ const names = ancestors(prototype);
4879
+ for (const name of names) {
4880
+ const method = this.getSingleNodeMethod(name);
4881
+ if (method) {
4882
+ this.methodCache.set(key, method);
4883
+ return method;
4884
+ }
4885
+ }
4886
+ const result = (node_) => node_;
4887
+ this.methodCache.set(key, result);
4888
+ return result;
4889
+ };
4890
+ visit = (node) => this.getNodeMethods(node.constructor)(node);
4891
+ genericVisit = (node) => {
4892
+ if (node instanceof ContainerNode || node instanceof ContainerCommandNode) {
4893
+ node.body = node.body.flatMap((n) => this.visit(n));
4894
+ }
4895
+ return node;
4896
+ };
4897
+ onStart = () => {};
4898
+ onEnd = () => {};
4899
+ genericNodeVisitor = () => (node) => this.genericVisit(node);
4900
+ visitCommandNode = this.genericNodeVisitor();
4901
+ visitContainerCommandNode = this.genericNodeVisitor();
4902
+ visitContainerNode = this.genericNodeVisitor();
4903
+ visitNode;
4904
+ visitMCFunctionNode;
4905
+ visitAdvancementNode;
4906
+ visitItemModifierNode;
4907
+ visitLootTableNode;
4908
+ visitPredicateNode;
4909
+ visitRecipeNode;
4910
+ visitTagNode;
4911
+ visitTrimMaterialNode;
4912
+ visitTrimPatternNode;
4913
+ }
4635
4914
  GenericSandstoneVisitor = class GenericSandstoneVisitor extends GenericCoreVisitor {
4636
4915
  pack;
4637
4916
  constructor(pack) {
@@ -5357,7 +5636,7 @@ ItemPredicateClass = class ItemPredicateClass {
5357
5636
  if (test2.operator === "exists") {
5358
5637
  return `${prefix}${test2.component}`;
5359
5638
  }
5360
- const valueStr = nbtStringifier(test2.value);
5639
+ const valueStr = nbtResolver(test2.value).toString();
5361
5640
  return `${prefix}${test2.component}${test2.operator}${valueStr}`;
5362
5641
  }
5363
5642
  stringifyOrGroup(group) {
@@ -5826,6 +6105,7 @@ SelectorClass = class SelectorClass {
5826
6105
  sandstonePack;
5827
6106
  target;
5828
6107
  arguments;
6108
+ _hasMacro = false;
5829
6109
  constructor(sandstonePack2, target, selectorArguments) {
5830
6110
  this.sandstonePack = sandstonePack2;
5831
6111
  this.target = target;
@@ -5836,6 +6116,7 @@ SelectorClass = class SelectorClass {
5836
6116
  };
5837
6117
  toString() {
5838
6118
  if (!this.arguments || !Object.keys(this.arguments).length) {
6119
+ this._hasMacro = false;
5839
6120
  return this.target;
5840
6121
  }
5841
6122
  const result = [];
@@ -5844,12 +6125,18 @@ SelectorClass = class SelectorClass {
5844
6125
  scores: (scores) => result.push(["scores", parseScore(this.sandstonePack.core, scores)]),
5845
6126
  nbt: (nbt2) => {
5846
6127
  const nbts = Array.isArray(nbt2) ? nbt2 : [nbt2];
5847
- result.push(...nbts.map((nbt_) => ["nbt", nbtStringifier(nbt_)]));
6128
+ for (const nbt_ of nbts) {
6129
+ const resolved = nbtResolver(nbt_);
6130
+ if (resolved.containsMacro) {
6131
+ this._hasMacro = true;
6132
+ }
6133
+ result.push(["nbt", resolved]);
6134
+ }
5848
6135
  },
5849
6136
  advancements: (advancements) => result.push(["advancements", parseAdvancements(advancements)]),
5850
6137
  tag: (tag4) => {
5851
- const tags2 = Array.isArray(tag4) ? tag4 : [tag4];
5852
- result.push(...tags2.map((tag_) => ["tag", tag_]));
6138
+ const tags = Array.isArray(tag4) ? tag4 : [tag4];
6139
+ result.push(...tags.map((tag_) => ["tag", tag_]));
5853
6140
  },
5854
6141
  gamemode: (gamemode2) => {
5855
6142
  const gamemodes = Array.isArray(gamemode2) ? gamemode2 : [gamemode2];
@@ -5907,6 +6194,32 @@ SelectorClass = class SelectorClass {
5907
6194
  return formatDebugString(this.constructor.name, this.toString(), undefined, undefined);
5908
6195
  }
5909
6196
  };
6197
+ class _RawLabelClass {
6198
+ pack;
6199
+ name;
6200
+ fullName;
6201
+ description;
6202
+ constructor(pack2, name, description) {
6203
+ this.pack = pack2;
6204
+ if (name.includes(":")) {
6205
+ this.name = name.split(":")[1];
6206
+ this.fullName = name.replace(":", ".");
6207
+ } else {
6208
+ this.name = name;
6209
+ this.fullName = `${pack2.defaultNamespace}.${name}`;
6210
+ }
6211
+ if (description)
6212
+ this.description = description;
6213
+ }
6214
+ LabelHolder = (entity) => {
6215
+ if (typeof entity === "string")
6216
+ return new EntityLabel(this.pack, new SelectorClass(this.pack, entity), this);
6217
+ return new EntityLabel(this.pack, entity, this);
6218
+ };
6219
+ toString = () => `${this.fullName}${this.description ? `; ${this.description}` : ""}`;
6220
+ toNBT = () => `'${this.fullName}'`;
6221
+ __call__ = (entity) => this.LabelHolder(entity);
6222
+ }
5910
6223
  LabelClass = makeClassCallable(_RawLabelClass);
5911
6224
  LoopArgument = class LoopArgument extends Node {
5912
6225
  pack;
@@ -6003,6 +6316,7 @@ SleepClass = class SleepClass extends AwaitNode {
6003
6316
  const { execute: execute2 } = commands2;
6004
6317
  const name = `__sandstone:asyncTimer.${currentFunction.resource.name.replace(/[:/]/g, ".")}`;
6005
6318
  const timer = new ObjectiveClass(core.pack, name.replace(":", "."), "dummy", undefined, { creator: "sandstone" });
6319
+ core.pack.registerNewObjective(timer);
6006
6320
  execute2.store.result(timer("@s")).run.time.query("gametime");
6007
6321
  timer("@s").add(Duration);
6008
6322
  const label2 = Label(name);
@@ -6019,23 +6333,10 @@ SleepClass = class SleepClass extends AwaitNode {
6019
6333
  currentFunction.enterContext(this);
6020
6334
  core.awaitNodes.add(this);
6021
6335
  }
6022
- promise() {
6023
- return {
6024
- then: async (onfullfilled) => {
6025
- await onfullfilled?.();
6026
- return this;
6027
- }
6028
- };
6029
- }
6030
6336
  };
6031
6337
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
6032
6338
 
6033
6339
  // src/variables/abstractClasses.ts
6034
- class ComponentClass {
6035
- _toChatComponent() {
6036
- throw new Error("Not implemented");
6037
- }
6038
- }
6039
6340
 
6040
6341
  class ConditionClass {
6041
6342
  _toMinecraftCondition() {
@@ -6093,32 +6394,6 @@ var init_Coordinates = __esm(() => {
6093
6394
  });
6094
6395
 
6095
6396
  // src/core/Macro.ts
6096
- class MacroArgument {
6097
- sandstoneCore;
6098
- local;
6099
- toMacro;
6100
- constructor(sandstoneCore) {
6101
- this.sandstoneCore = sandstoneCore;
6102
- this.local = new Map;
6103
- this.toMacro = () => {
6104
- let currentMCFunctionName = "";
6105
- try {
6106
- currentMCFunctionName = sandstoneCore.getCurrentMCFunctionOrThrow().resource.name;
6107
- } catch {}
6108
- let result = this.local.get(this.sandstoneCore.currentNode) || this.local.get(currentMCFunctionName);
6109
- if (!result) {
6110
- let path = this.sandstoneCore.currentNode;
6111
- while (path.includes("/")) {
6112
- path = path.substring(0, path.lastIndexOf("/"));
6113
- result = this.local.get(path);
6114
- if (result)
6115
- break;
6116
- }
6117
- }
6118
- return `$(${result})`;
6119
- };
6120
- }
6121
- }
6122
6397
  function isMacroArgument(core, arg) {
6123
6398
  if (typeof arg === "object" && Object.hasOwn(arg, "toMacro")) {
6124
6399
  const local2 = arg.local;
@@ -6876,8 +7151,6 @@ var init_parser = __esm(() => {
6876
7151
  // src/variables/nbt/NBTs.ts
6877
7152
  import * as util2 from "util";
6878
7153
 
6879
- class NBTClass {
6880
- }
6881
7154
  function customNumber(num, _class) {
6882
7155
  if (Array.isArray(num)) {
6883
7156
  return num.map((n) => new _class(n));
@@ -6886,18 +7159,30 @@ function customNumber(num, _class) {
6886
7159
  }
6887
7160
  function dynamicNBT(template, ...args) {
6888
7161
  const mixedArgs = template.flatMap((s, i) => [s, args[i]]).slice(0, -1);
6889
- const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtStringifier(element) : element.toString()).join("");
7162
+ const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtResolver(element).toString() : element.toString()).join("");
6890
7163
  return parseNBT(NBT, result);
6891
7164
  }
6892
- var NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, NBTTypedArray, NBTLongArray, NBTByteArray, NBTIntArray, NotNBT, NBTString, NBTAnyValue, NBT, nbtStringifier = (nbt) => {
7165
+
7166
+ class ResolvedNBT {
7167
+ value;
7168
+ containsMacro;
7169
+ constructor(value, containsMacro) {
7170
+ this.value = value;
7171
+ this.containsMacro = containsMacro;
7172
+ }
7173
+ toString() {
7174
+ return this.value;
7175
+ }
7176
+ }
7177
+ var NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, NBTTypedArray, NBTLongArray, NBTByteArray, NBTIntArray, NotNBT, NBTString, NBTAnyValue, NBT, resolve = (nbt) => {
6893
7178
  if (nbt === null || nbt === undefined) {
6894
7179
  throw new Error("Nullish nbt values are not allowed");
6895
7180
  }
6896
7181
  if (typeof nbt === "number") {
6897
- return `${nbt}d`;
7182
+ return new ResolvedNBT(`${nbt}d`, false);
6898
7183
  }
6899
7184
  if (typeof nbt === "boolean") {
6900
- return nbt.toString();
7185
+ return new ResolvedNBT(nbt.toString(), false);
6901
7186
  }
6902
7187
  if (typeof nbt === "string") {
6903
7188
  const inspectedStr = util2.inspect(nbt, {
@@ -6907,16 +7192,22 @@ var NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, NBTTy
6907
7192
  depth: Number.POSITIVE_INFINITY
6908
7193
  });
6909
7194
  if (inspectedStr[0] === "`") {
6910
- return JSON.stringify(nbt);
7195
+ return new ResolvedNBT(JSON.stringify(nbt), false);
6911
7196
  }
6912
- return inspectedStr;
7197
+ return new ResolvedNBT(inspectedStr, false);
6913
7198
  }
6914
7199
  if (Array.isArray(nbt)) {
6915
- const itemsStr = nbt.map(nbtStringifier).join(",");
6916
- return `[${itemsStr}]`;
7200
+ let containsMacro2 = false;
7201
+ const itemsStr = nbt.map((item) => {
7202
+ const resolved = resolve(item);
7203
+ if (resolved.containsMacro)
7204
+ containsMacro2 = true;
7205
+ return resolved.value;
7206
+ }).join(",");
7207
+ return new ResolvedNBT(`[${itemsStr}]`, containsMacro2);
6917
7208
  }
6918
7209
  if (nbt instanceof NBTClass) {
6919
- return nbt[util2.inspect.custom]();
7210
+ return new ResolvedNBT(nbt[util2.inspect.custom](), false);
6920
7211
  }
6921
7212
  if (typeof nbt === "object" || typeof nbt === "function") {
6922
7213
  let failedMacro = false;
@@ -6925,28 +7216,38 @@ var NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, NBTTy
6925
7216
  if (macro === "$()") {
6926
7217
  failedMacro = true;
6927
7218
  } else {
6928
- return macro;
7219
+ return new ResolvedNBT(macro, true);
6929
7220
  }
6930
7221
  }
6931
7222
  if ("toNBT" in nbt) {
6932
- return nbt.toNBT();
7223
+ const toNbtResult = nbt.toNBT();
7224
+ if (toNbtResult instanceof ResolvedNBT) {
7225
+ return toNbtResult;
7226
+ }
7227
+ return new ResolvedNBT(String(toNbtResult), false);
6933
7228
  } else if (failedMacro) {
6934
- throw new Error("[nbtStringifier] A macro variable NBT insertion was attempted in an mcfunction without macros defined.");
7229
+ throw new Error("[nbtResolver] A macro variable NBT insertion was attempted in an mcfunction without macros defined.");
6935
7230
  }
6936
7231
  if (typeof nbt === "function") {
6937
- 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.`);
7232
+ throw new Error(`[nbtResolver] This should never happen. A function or callable instance (${nbt.constructor?.name}) without toNBT was passed in as an NBT value.`);
6938
7233
  }
6939
7234
  if (nbt.constructor.name !== "Object") {
6940
7235
  if ("toString" in nbt) {
6941
- return `${toString}`;
7236
+ return new ResolvedNBT(`${toString}`, false);
6942
7237
  } else {
6943
- throw new Error(`[nbtStringifier] A ${nbt.constructor?.name} was passed in as an NBT value. Hint: define toNBT or toString if this was intentional`);
7238
+ throw new Error(`[nbtResolver] A ${nbt.constructor?.name} was passed in as an NBT value. Hint: define toNBT or toString if this was intentional`);
6944
7239
  }
6945
7240
  }
6946
7241
  }
6947
- const objectStr = Object.entries(nbt).map(([key, value]) => `${key}:${nbtStringifier(value)}`).join(",");
6948
- return `{${objectStr}}`;
6949
- };
7242
+ let containsMacro = false;
7243
+ const objectStr = Object.entries(nbt).map(([key, value]) => {
7244
+ const resolved = resolve(value);
7245
+ if (resolved.containsMacro)
7246
+ containsMacro = true;
7247
+ return `${key}:${resolved.value}`;
7248
+ }).join(",");
7249
+ return new ResolvedNBT(`{${objectStr}}`, containsMacro);
7250
+ }, nbtResolver = (nbt) => resolve(nbt);
6950
7251
  var init_NBTs = __esm(() => {
6951
7252
  init_utils();
6952
7253
  init_parser();
@@ -6961,7 +7262,7 @@ var init_NBTs = __esm(() => {
6961
7262
  longArray: (numbers) => new NBTLongArray(numbers),
6962
7263
  byteArray: (numbers) => new NBTByteArray(numbers),
6963
7264
  not: (nbt) => new NotNBT(nbt),
6964
- stringify: (nbt) => nbtStringifier(nbt),
7265
+ stringify: (nbt) => nbtResolver(nbt).toString(),
6965
7266
  parse: (nbt) => parseNBT(NBT, nbt)
6966
7267
  }, dynamicNBT);
6967
7268
  });
@@ -7155,7 +7456,7 @@ function NBTpathToString(pack, paths) {
7155
7456
  } else if (Array.isArray(path) && path.length === 1 && typeof path[0] === "number" && Number.isInteger(path[0])) {
7156
7457
  parsedPaths.push(`[${path[0]}]`);
7157
7458
  } else {
7158
- parsedPaths.push(nbtStringifier(path));
7459
+ parsedPaths.push(nbtResolver(path).toString());
7159
7460
  }
7160
7461
  } else if (path !== "") {
7161
7462
  parsedPaths.push(`${path}${i === paths.length - 1 ? "" : "."}`);
@@ -7236,27 +7537,6 @@ var init_basics = __esm(() => {
7236
7537
  init_arguments();
7237
7538
  });
7238
7539
  // src/pack/packType.ts
7239
- class PackType {
7240
- type;
7241
- clientPath;
7242
- serverPath;
7243
- rootPath;
7244
- networkSides;
7245
- resourceSubFolder;
7246
- namespaced;
7247
- archiveOutput;
7248
- handleOutput;
7249
- constructor(type, clientPath, serverPath, rootPath, networkSides, archiveOutput = false, resourceSubFolder, namespaced = false) {
7250
- this.type = type;
7251
- this.clientPath = clientPath;
7252
- this.serverPath = serverPath;
7253
- this.rootPath = rootPath;
7254
- this.networkSides = networkSides;
7255
- this.archiveOutput = archiveOutput;
7256
- this.resourceSubFolder = resourceSubFolder;
7257
- this.namespaced = namespaced;
7258
- }
7259
- }
7260
7540
 
7261
7541
  // src/pack/dependencies.ts
7262
7542
  var DataPackDependencies, ResourcePackDependencies;
@@ -7267,6 +7547,7 @@ var init_dependencies = __esm(() => {
7267
7547
  import * as util4 from "util";
7268
7548
  var Node, ContainerNode, CommandNode, ContainerCommandNode, AwaitNode;
7269
7549
  var init_nodes = __esm(() => {
7550
+ init_NBTs();
7270
7551
  init_utils();
7271
7552
  init_Macro();
7272
7553
  });
@@ -7279,78 +7560,6 @@ class FinalCommandOutput {
7279
7560
  }
7280
7561
  }
7281
7562
 
7282
- class CommandArguments {
7283
- sandstonePack;
7284
- previousNode;
7285
- autoCommit;
7286
- NodeType;
7287
- sandstoneCore;
7288
- sandstoneCommands;
7289
- constructor(sandstonePack, previousNode, autoCommit = true) {
7290
- this.sandstonePack = sandstonePack;
7291
- this.previousNode = previousNode;
7292
- this.autoCommit = autoCommit;
7293
- this.sandstoneCore = sandstonePack.core;
7294
- this.sandstoneCommands = sandstonePack.commands;
7295
- }
7296
- getNode = () => {
7297
- if (this.previousNode) {
7298
- return this.previousNode;
7299
- }
7300
- if (this.NodeType) {
7301
- return new this.NodeType(this.sandstonePack);
7302
- }
7303
- throw new Error("No node type specified & no previous node for a non-root-level command");
7304
- };
7305
- finalCommand = (args, currentNode) => {
7306
- const node = currentNode ?? this.getNode();
7307
- if (args) {
7308
- node.args.push(...args);
7309
- }
7310
- if (this.autoCommit) {
7311
- node.commit();
7312
- }
7313
- return new FinalCommandOutput(node);
7314
- };
7315
- subCommand = (args, NextArgumentType, executable = false, additionalNextArgs = [], currentNode) => {
7316
- const node = currentNode ?? this.getNode();
7317
- if (args) {
7318
- node.args.push(...args);
7319
- }
7320
- if (executable && this.autoCommit) {
7321
- node.commit();
7322
- }
7323
- return new NextArgumentType(this.sandstonePack, node, this.autoCommit, ...additionalNextArgs);
7324
- };
7325
- }
7326
-
7327
- // src/commands/validators.ts
7328
- function validateIntegerRange(integer, name, minimum = 0, maximum = 2147483647) {
7329
- if (typeof integer !== "number") {
7330
- return integer;
7331
- }
7332
- if (integer && integer <= minimum) {
7333
- throw new Error(`\`${name}\` must be greater than or equal to ${minimum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
7334
- }
7335
- if (integer && integer >= maximum) {
7336
- throw new Error(`\`${name}\` must be lower than or equal to ${maximum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
7337
- }
7338
- return integer;
7339
- }
7340
-
7341
- // src/commands/implementations/block/place.ts
7342
- var PlaceCommandNode, PlaceCommand;
7343
- var init_place = __esm(() => {
7344
- init_nodes();
7345
- init_parsers();
7346
- });
7347
-
7348
- // src/commands/implementations/entity/damage.ts
7349
- var DamageCommandNode, DamageCauseCommand, DamageSourceCommand, DamageCommand;
7350
- var init_damage = __esm(() => {
7351
- init_nodes();
7352
- init_parsers();
7353
- });
7354
7563
 
7355
7564
  // src/commands/implementations/_fake/comment.ts
7356
7565
  var CommentCommandNode, CommentCommand;
@@ -7393,6 +7602,27 @@ var init_fill = __esm(() => {
7393
7602
  init_setblock();
7394
7603
  });
7395
7604
 
7605
+ // src/commands/validators.ts
7606
+ function validateIntegerRange(integer, name, minimum = 0, maximum = 2147483647) {
7607
+ if (typeof integer !== "number") {
7608
+ return integer;
7609
+ }
7610
+ if (integer && integer <= minimum) {
7611
+ throw new Error(`\`${name}\` must be greater than or equal to ${minimum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
7612
+ }
7613
+ if (integer && integer >= maximum) {
7614
+ throw new Error(`\`${name}\` must be lower than or equal to ${maximum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
7615
+ }
7616
+ return integer;
7617
+ }
7618
+
7619
+ // src/commands/implementations/block/place.ts
7620
+ var PlaceCommandNode, PlaceCommand;
7621
+ var init_place = __esm(() => {
7622
+ init_nodes();
7623
+ init_parsers();
7624
+ });
7625
+
7396
7626
  // src/commands/implementations/entity/attribute.ts
7397
7627
  var AttributeCommandNode, AttributeCommand, AttributeOperationCommand;
7398
7628
  var init_attribute = __esm(() => {
@@ -7403,10 +7633,18 @@ var init_attribute = __esm(() => {
7403
7633
  // src/commands/implementations/entity/clear.ts
7404
7634
  var ClearCommandNode, ClearCommand;
7405
7635
  var init_clear = __esm(() => {
7636
+ init_Macro();
7406
7637
  init_nodes();
7407
7638
  init_parsers();
7408
7639
  });
7409
7640
 
7641
+ // src/commands/implementations/entity/damage.ts
7642
+ var DamageCommandNode, DamageCauseCommand, DamageSourceCommand, DamageCommand;
7643
+ var init_damage = __esm(() => {
7644
+ init_nodes();
7645
+ init_parsers();
7646
+ });
7647
+
7410
7648
  // src/commands/implementations/entity/effect.ts
7411
7649
  var EffectCommandNode, EffectCommand;
7412
7650
  var init_effect = __esm(() => {
@@ -7506,110 +7744,6 @@ var init_resource_paths = __esm(() => {
7506
7744
  });
7507
7745
 
7508
7746
  // src/core/resources/resource.ts
7509
- class ResourceClass {
7510
- core;
7511
- _resourceType;
7512
- node;
7513
- packType;
7514
- fileExtension;
7515
- fileEncoding;
7516
- creator;
7517
- commands;
7518
- pack;
7519
- path;
7520
- addToSandstoneCore;
7521
- onConflict;
7522
- renameIndex = 2;
7523
- constructor(core, file, NodeType, _resourceType, path, args) {
7524
- this.core = core;
7525
- this._resourceType = _resourceType;
7526
- this.node = new NodeType(core, this);
7527
- this.packType = args.packType || file.packType;
7528
- this.fileExtension = file.extension || "json";
7529
- this.fileEncoding = file.encoding ?? "utf8";
7530
- this.pack = core.pack;
7531
- this.commands = core.pack.commands;
7532
- this.path = path;
7533
- this.addToSandstoneCore = args.addToSandstoneCore;
7534
- this.creator = args.creator ?? "sandstone";
7535
- const conflictStrategies = hasContext() ? getSandstoneContext().conflictStrategies : undefined;
7536
- const scopedStrategy = conflictStrategies?.[_resourceType];
7537
- const defaultStrategy = conflictStrategies?.default;
7538
- this.onConflict = args.onConflict ?? scopedStrategy ?? defaultStrategy ?? "throw";
7539
- }
7540
- handleConflicts() {
7541
- const conflict = this.core.resourceNodes.get(this.node);
7542
- let add2 = false;
7543
- if (conflict) {
7544
- const oldResource = conflict.resource;
7545
- const newResource = this.node.resource;
7546
- switch (this.onConflict) {
7547
- case "throw": {
7548
- throw new Error(`Created a ${this._resourceType} with the duplicate name ${newResource.name}, and onConflict was set to "throw".`);
7549
- }
7550
- case "replace":
7551
- {
7552
- this.core.resourceNodes.delete(conflict);
7553
- add2 = true;
7554
- }
7555
- break;
7556
- case "warn":
7557
- {
7558
- console.warn([
7559
- "Warning:",
7560
- `Tried to create a ${this._resourceType} named "${newResource.name}", but found an already existing one.`,
7561
- "The new one has replaced the old one. To remove this warning, please change the options of the resource to { onConflict: '/* other option */' }."
7562
- ].join(`
7563
- `));
7564
- this.core.resourceNodes.delete(conflict);
7565
- add2 = true;
7566
- }
7567
- break;
7568
- case "rename":
7569
- {
7570
- this.path[this.path.length - 1] += oldResource.renameIndex.toString();
7571
- oldResource.renameIndex += 1;
7572
- add2 = true;
7573
- }
7574
- break;
7575
- case "prepend":
7576
- {
7577
- oldResource.unshift(newResource);
7578
- }
7579
- break;
7580
- case "append":
7581
- {
7582
- oldResource.push(newResource);
7583
- }
7584
- break;
7585
- default:
7586
- break;
7587
- }
7588
- } else {
7589
- add2 = true;
7590
- }
7591
- if (this.addToSandstoneCore && add2) {
7592
- this.core.resourceNodes.add(this.node);
7593
- }
7594
- }
7595
- getNode = () => this.node;
7596
- get name() {
7597
- return `${this.path[0]}:${this.path.slice(this._resourceType in RESOURCE_PATHS ? RESOURCE_PATHS[this._resourceType].path.length + 1 : 2).join("/")}`;
7598
- }
7599
- get namespace() {
7600
- return this.path[0];
7601
- }
7602
- generate = () => {};
7603
- toString() {
7604
- return this.name;
7605
- }
7606
- toNBT() {
7607
- return this.name;
7608
- }
7609
- toJSON() {
7610
- return this.name;
7611
- }
7612
- }
7613
7747
 
7614
7748
  class ListResource {
7615
7749
  push(..._args) {}
@@ -7811,14 +7945,13 @@ var init_tag = __esm(() => {
7811
7945
 
7812
7946
  // src/core/resources/datapack/mcfunction.ts
7813
7947
  import * as util6 from "util";
7814
- var tags, MCFunctionNode, _RawMCFunctionClass, MCFunctionClass;
7948
+ var MCFunctionNode, _RawMCFunctionClass, MCFunctionClass;
7815
7949
  var init_mcfunction = __esm(() => {
7816
7950
  init_utils();
7817
7951
  init_ResolveNBT();
7818
7952
  init_nodes();
7819
7953
  init_resource();
7820
7954
  init_tag();
7821
- tags = {};
7822
7955
  });
7823
7956
 
7824
7957
  // src/core/resources/datapack/predicate.ts
@@ -8027,12 +8160,11 @@ var init_shader = __esm(() => {
8027
8160
 
8028
8161
  // src/core/resources/resourcepack/sound.ts
8029
8162
  import path from "node:path";
8030
- var sounds, SoundEventNode, SoundEventClass, SoundsNode, SoundsClass;
8163
+ var SoundEventNode, SoundEventClass, SoundsNode, SoundsClass;
8031
8164
  var init_sound = __esm(() => {
8032
8165
  init_arguments();
8033
8166
  init_nodes();
8034
8167
  init_resource();
8035
- sounds = new Map;
8036
8168
  });
8037
8169
 
8038
8170
  // src/core/resources/resourcepack/text.ts
@@ -8452,11 +8584,17 @@ class SandstoneCore {
8452
8584
  _mcMetaCache = false;
8453
8585
  _smithed = false;
8454
8586
  dependencies = [];
8587
+ functionTags = new Map;
8588
+ sounds = new Map;
8589
+ checkTriggers = {};
8455
8590
  constructor(pack) {
8456
8591
  this.pack = pack;
8457
8592
  this.resourceNodes = new ResourceNodesMap;
8458
8593
  this.mcfunctionStack = [];
8459
8594
  this.awaitNodes = new Set;
8595
+ this.functionTags = new Map;
8596
+ this.sounds = new Map;
8597
+ this.checkTriggers = {};
8460
8598
  for (const method of Object.getOwnPropertyNames(Object.getPrototypeOf(this))) {
8461
8599
  if (method !== "constructor" && typeof this[method] === "function" && typeof this[method].bind === "function") {
8462
8600
  this[method] = this[method].bind(this);
@@ -8471,6 +8609,9 @@ class SandstoneCore {
8471
8609
  this._mcMetaCache = undefined;
8472
8610
  this._smithed = undefined;
8473
8611
  this.dependencies = [];
8612
+ this.functionTags.clear();
8613
+ this.sounds.clear();
8614
+ this.checkTriggers = {};
8474
8615
  };
8475
8616
  get currentMCFunction() {
8476
8617
  return this.mcfunctionStack[this.mcfunctionStack.length - 1];
@@ -8624,6 +8765,7 @@ var init_core = __esm(() => {
8624
8765
  // src/commands/implementations/server/function.ts
8625
8766
  var FunctionCommandNode, FunctionCommand;
8626
8767
  var init_function = __esm(() => {
8768
+ init_Macro();
8627
8769
  init_nodes();
8628
8770
  init_NBTs();
8629
8771
  });
@@ -8891,7 +9033,7 @@ function componentPatchStringifier(components) {
8891
9033
  throw new Error(`Attempted to insert a negation component patch of ${key} with a value, use {} instead.`);
8892
9034
  }
8893
9035
  } else {
8894
- resultPairs.push(`${key}=${nbtStringifier(value)}`);
9036
+ resultPairs.push(`${key}=${nbtResolver(value).toString()}`);
8895
9037
  }
8896
9038
  }
8897
9039
  return `[${resultPairs.join(",")}]`;
@@ -8979,6 +9121,7 @@ var init_datapack2 = __esm(() => {
8979
9121
  var DebugCommandNode, DebugCommand;
8980
9122
  var init_debug = __esm(() => {
8981
9123
  init_nodes();
9124
+ init_Macro();
8982
9125
  });
8983
9126
 
8984
9127
  // src/commands/implementations/server/defaultgamemode.ts
@@ -9054,6 +9197,7 @@ var init_say = __esm(() => {
9054
9197
  // src/commands/implementations/server/schedule.ts
9055
9198
  var ScheduleCommandNode, ScheduleCommand;
9056
9199
  var init_schedule = __esm(() => {
9200
+ init_Macro();
9057
9201
  init_nodes();
9058
9202
  });
9059
9203
 
@@ -9532,10 +9676,7 @@ class SandstoneCommands {
9532
9676
  }
9533
9677
  }
9534
9678
  var init_commands = __esm(() => {
9535
- init_place();
9536
- init_damage();
9537
9679
  init_implementations();
9538
- init_random();
9539
9680
  });
9540
9681
 
9541
9682
  // src/commands/index.ts
@@ -9789,75 +9930,6 @@ var init_loop = __esm(() => {
9789
9930
  init_core();
9790
9931
  });
9791
9932
 
9792
- // src/flow/loops/staticAnalysis.ts
9793
- function valueMatchesRange(value, rangeStr) {
9794
- if (rangeStr.includes("..")) {
9795
- const [minStr, maxStr] = rangeStr.split("..");
9796
- const min = minStr !== "" ? parseInt(minStr, 10) : Number.NEGATIVE_INFINITY;
9797
- const max = maxStr !== "" ? parseInt(maxStr, 10) : Number.POSITIVE_INFINITY;
9798
- return value >= min && value <= max;
9799
- }
9800
- return value === parseInt(rangeStr, 10);
9801
- }
9802
- function analyzeCondition(condition2, targetScore, value, negated = false) {
9803
- if (condition2 instanceof ScoreConditionNode) {
9804
- const args = condition2.args;
9805
- if (args.length >= 4 && args[2] === "matches") {
9806
- const [target, objective, , rangeStr] = args;
9807
- if (target !== `${targetScore.target}` || objective !== `${targetScore.objective}`) {
9808
- return { canAnalyze: false };
9809
- }
9810
- let result = valueMatchesRange(value, rangeStr);
9811
- if (negated)
9812
- result = !result;
9813
- return { canAnalyze: true, result };
9814
- }
9815
- return { canAnalyze: false };
9816
- }
9817
- if (condition2 instanceof AndNode) {
9818
- for (const subCondition of condition2.conditions) {
9819
- const subResult = analyzeCondition(subCondition, targetScore, value, negated);
9820
- if (!subResult.canAnalyze)
9821
- return { canAnalyze: false };
9822
- if (!subResult.result)
9823
- return { canAnalyze: true, result: false };
9824
- }
9825
- return { canAnalyze: true, result: true };
9826
- }
9827
- if (condition2 instanceof OrNode) {
9828
- let anyTrue = false;
9829
- for (const subCondition of condition2.conditions) {
9830
- const subResult = analyzeCondition(subCondition, targetScore, value, negated);
9831
- if (!subResult.canAnalyze)
9832
- return { canAnalyze: false };
9833
- if (subResult.result)
9834
- anyTrue = true;
9835
- }
9836
- return { canAnalyze: true, result: anyTrue };
9837
- }
9838
- if (condition2 instanceof NotNode) {
9839
- return analyzeCondition(condition2.condition, targetScore, value, !negated);
9840
- }
9841
- return { canAnalyze: false };
9842
- }
9843
- function getDeclarationLocation() {
9844
- const stack = new Error().stack;
9845
- const locationMatch = stack?.split(`
9846
- `).find((line) => line.includes(".ts:") && !line.includes("/loops/") && !line.includes("node_modules"));
9847
- return locationMatch?.trim() || "unknown location";
9848
- }
9849
- function warnStaticallyFalseCondition(loopType, details) {
9850
- const location = getDeclarationLocation();
9851
- 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.
9852
- ` + ` at ${location}`);
9853
- }
9854
- var init_staticAnalysis = __esm(() => {
9855
- init_score();
9856
- init_and();
9857
- init_or();
9858
- init_not();
9859
- });
9860
-
9861
9933
  // src/flow/loops/for_i.ts
9862
9934
  class ForIStatement {
9863
9935
  sandstoneCore;
@@ -9882,7 +9954,6 @@ var init_for_i = __esm(() => {
9882
9954
  init_flow();
9883
9955
  init_if_else();
9884
9956
  init_loop();
9885
- init_staticAnalysis();
9886
9957
  });
9887
9958
 
9888
9959
  // src/flow/loops/for_of.ts
@@ -10186,61 +10257,6 @@ function ancestors(prototype) {
10186
10257
  return [prototype.name, ...ancestors(Object.getPrototypeOf(prototype))];
10187
10258
  }
10188
10259
 
10189
- class GenericCoreVisitor {
10190
- core;
10191
- methodCache;
10192
- constructor(core) {
10193
- this.core = core;
10194
- this.methodCache = new Map;
10195
- }
10196
- getSingleNodeMethod = (nodeName) => {
10197
- const methodName = `visit${nodeName}`;
10198
- const that = this;
10199
- const method = that[methodName];
10200
- return method;
10201
- };
10202
- getNodeMethods = (prototype) => {
10203
- const key = prototype.name;
10204
- const cachedResult = this.methodCache.get(key);
10205
- if (cachedResult) {
10206
- return cachedResult;
10207
- }
10208
- const names = ancestors(prototype);
10209
- for (const name of names) {
10210
- const method = this.getSingleNodeMethod(name);
10211
- if (method) {
10212
- this.methodCache.set(key, method);
10213
- return method;
10214
- }
10215
- }
10216
- const result = (node_) => node_;
10217
- this.methodCache.set(key, result);
10218
- return result;
10219
- };
10220
- visit = (node) => this.getNodeMethods(node.constructor)(node);
10221
- genericVisit = (node) => {
10222
- if (node instanceof ContainerNode || node instanceof ContainerCommandNode) {
10223
- node.body = node.body.flatMap((n) => this.visit(n));
10224
- }
10225
- return node;
10226
- };
10227
- onStart = () => {};
10228
- onEnd = () => {};
10229
- genericNodeVisitor = () => (node) => this.genericVisit(node);
10230
- visitCommandNode = this.genericNodeVisitor();
10231
- visitContainerCommandNode = this.genericNodeVisitor();
10232
- visitContainerNode = this.genericNodeVisitor();
10233
- visitNode;
10234
- visitMCFunctionNode;
10235
- visitAdvancementNode;
10236
- visitItemModifierNode;
10237
- visitLootTableNode;
10238
- visitPredicateNode;
10239
- visitRecipeNode;
10240
- visitTagNode;
10241
- visitTrimMaterialNode;
10242
- visitTrimPatternNode;
10243
- }
10244
10260
  var init_visitors = __esm(() => {
10245
10261
  init_core();
10246
10262
  });
@@ -10564,6 +10580,9 @@ class SandstonePack {
10564
10580
  this.initMCFunction.push(() => loadStatus(this.defaultNamespace).set(loadVersion));
10565
10581
  };
10566
10582
  resourceToPath = (name, resourceFolders) => {
10583
+ if (name === "") {
10584
+ throw new Error("A resource name must not be empty!");
10585
+ }
10567
10586
  let namespace = this.defaultNamespace;
10568
10587
  let fullName = name;
10569
10588
  if (name.includes(":")) {
@@ -10579,6 +10598,11 @@ class SandstonePack {
10579
10598
  return this.flow;
10580
10599
  }
10581
10600
  registerNewObjective = (objective) => {
10601
+ for (const obj of this.objectives) {
10602
+ if (obj.name === objective.name) {
10603
+ return;
10604
+ }
10605
+ }
10582
10606
  this.objectives.add(objective);
10583
10607
  };
10584
10608
  registerNewConstant(amount) {
@@ -10613,7 +10637,7 @@ class SandstonePack {
10613
10637
  return `anon_${this.packUid}_${this.anonymousScoreId++}`;
10614
10638
  } else {
10615
10639
  this.namedVariableIds[name] ??= 0;
10616
- return `${name}_${this.namedVariableIds[name]}_${this.packUid}`;
10640
+ return `${name}_${this.namedVariableIds[name]++}_${this.packUid}`;
10617
10641
  }
10618
10642
  }
10619
10643
  Variable(...args) {
@@ -10725,7 +10749,7 @@ class SandstonePack {
10725
10749
  const tag4 = this.ticked[runEvery] ?? (() => {
10726
10750
  const name = `__sandstone:ticked/${runEvery}`;
10727
10751
  this.ticked[runEvery] = this.Tag("function", name, []);
10728
- this.MCFunction(name, (self) => {
10752
+ const looped = this.MCFunction(name, (self) => {
10729
10753
  this.commands.functionCmd(this.ticked[runEvery]);
10730
10754
  self.schedule.function(runEvery, "replace");
10731
10755
  });
@@ -10733,7 +10757,7 @@ class SandstonePack {
10733
10757
  this.startAllTicked = this.MCFunction(`__sandstone:ticked/start/${this.packUid.toLowerCase()}`);
10734
10758
  this.loadTags.load.push(this.startAllTicked);
10735
10759
  }
10736
- this.startAllTicked.push(() => this.commands.schedule.function(this.ticked[runEvery], runEvery, "replace"));
10760
+ this.startAllTicked.push(() => looped());
10737
10761
  return this.ticked[runEvery];
10738
10762
  })();
10739
10763
  if (func.env === undefined) {
@@ -10752,7 +10776,7 @@ class SandstonePack {
10752
10776
  }
10753
10777
  this.tickedCommands[runEvery].push(callback);
10754
10778
  }
10755
- sleep = (delay) => new SleepClass(this.core, delay).promise();
10779
+ sleep = (delay) => new SleepClass(this.core, delay);
10756
10780
  Loop = () => new LoopArgument(this);
10757
10781
  __customResourceTypes = [];
10758
10782
  registerCustomResource(type) {
@@ -50817,32 +50841,6 @@ var init_Selector = __esm(() => {
50817
50841
  });
50818
50842
 
50819
50843
  // src/variables/Label.ts
50820
- class _RawLabelClass {
50821
- pack;
50822
- name;
50823
- fullName;
50824
- description;
50825
- constructor(pack2, name, description) {
50826
- this.pack = pack2;
50827
- if (name.includes(":")) {
50828
- this.name = name.split(":")[1];
50829
- this.fullName = name.replace(":", ".");
50830
- } else {
50831
- this.name = name;
50832
- this.fullName = `${pack2.defaultNamespace}.${name}`;
50833
- }
50834
- if (description)
50835
- this.description = description;
50836
- }
50837
- LabelHolder = (entity) => {
50838
- if (typeof entity === "string")
50839
- return new EntityLabel(this.pack, new SelectorClass(this.pack, entity), this);
50840
- return new EntityLabel(this.pack, entity, this);
50841
- };
50842
- toString = () => `${this.fullName}${this.description ? `; ${this.description}` : ""}`;
50843
- toNBT = () => `'${this.fullName}'`;
50844
- __call__ = (entity) => this.LabelHolder(entity);
50845
- }
50846
50844
 
50847
50845
  class EntityLabel {
50848
50846
  pack;
@@ -50933,13 +50931,13 @@ class TriggerClass {
50933
50931
  this.objective = new ObjectiveClass(sandstoneCore2.pack, name, "dummy", undefined, { creator: "sandstone" });
50934
50932
  const { registerNewObjective, MCFunction, commands: commands2 } = sandstoneCore2.pack;
50935
50933
  registerNewObjective(this.objective);
50936
- if (!checkTriggers[pollingEvery]) {
50937
- checkTriggers[pollingEvery] = MCFunction(`triggers/check/${pollingEvery}`, {
50934
+ if (!sandstoneCore2.checkTriggers[pollingEvery]) {
50935
+ sandstoneCore2.checkTriggers[pollingEvery] = MCFunction(`triggers/check/${pollingEvery}`, {
50938
50936
  creator: "sandstone",
50939
50937
  runEvery: pollingEvery
50940
50938
  });
50941
50939
  }
50942
- checkTriggers[pollingEvery].push(() => {
50940
+ sandstoneCore2.checkTriggers[pollingEvery].push(() => {
50943
50941
  commands2.execute.as(`@a[scores={${name}=1..}]`).run(() => {
50944
50942
  const score2 = this.objective("@s");
50945
50943
  if (callback instanceof _RawMCFunctionClass || typeof callback === "function") {
@@ -50955,11 +50953,9 @@ class TriggerClass {
50955
50953
  }
50956
50954
  toString = () => this.name;
50957
50955
  }
50958
- var checkTriggers;
50959
50956
  var init_Trigger = __esm(() => {
50960
50957
  init_mcfunction();
50961
50958
  init_Objective();
50962
- checkTriggers = {};
50963
50959
  });
50964
50960
 
50965
50961
  // src/variables/UUID.ts
@@ -51573,6 +51569,7 @@ export {
51573
51569
  recipe3 as recipe,
51574
51570
  raw2 as raw,
51575
51571
  rangeParser,
51572
+ randomUUID,
51576
51573
  random2 as random,
51577
51574
  playsound2 as playsound,
51578
51575
  place2 as place,
@@ -51580,7 +51577,7 @@ export {
51580
51577
  particle3 as particle,
51581
51578
  parseNBT,
51582
51579
  parseJSONText,
51583
- nbtStringifier,
51580
+ nbtResolver,
51584
51581
  msg,
51585
51582
  me2 as me,
51586
51583
  mcMetaCache2 as mcMetaCache,
@@ -51886,6 +51883,7 @@ export {
51886
51883
  ResourcePack,
51887
51884
  ResourceNodesMap,
51888
51885
  ResourceClass,
51886
+ ResolvedNBT,
51889
51887
  ResolveNBTPartClass,
51890
51888
  ResolveNBTPart,
51891
51889
  ResolveNBTClass,
@@ -52260,5 +52258,5 @@ export {
52260
52258
  ACTIVITIES_SET
52261
52259
  };
52262
52260
 
52263
- //# debugId=097BEFB5602A878F64756E2164756E21
52261
+ //# debugId=CD6B0FD0ECC93B9764756E2164756E21
52264
52262
  //# sourceMappingURL=index.js.map