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.
- package/CLAUDE.md +315 -16
- package/bun.lock +18 -22
- package/dist/arguments/index.js +1093 -367
- package/dist/arguments/selector.d.ts +6 -6
- package/dist/commands/implementations/block/setblock.d.ts +6 -9
- package/dist/commands/implementations/entity/execute.d.ts +36 -21
- package/dist/commands/implementations/server/return.d.ts +14 -7
- package/dist/commands/implementations/world/data.d.ts +29 -32
- package/dist/commands/index.js +1102 -364
- package/dist/core/index.js +2207 -1481
- package/dist/core/resources/datapack/mcfunction.d.ts +1 -1
- package/dist/core/resources/datapack/variant.d.ts +1 -1
- package/dist/core/resources/resource.d.ts +4 -4
- package/dist/flow/Flow.d.ts +21 -22
- package/dist/flow/if_else.d.ts +8 -3
- package/dist/flow/index.d.ts +1 -0
- package/dist/flow/index.js +2196 -1451
- package/dist/flow/loop.d.ts +5 -4
- package/dist/flow/loops/for_i.d.ts +1 -1
- package/dist/flow/loops/for_of.d.ts +4 -3
- package/dist/flow/loops/staticAnalysis.d.ts +26 -0
- package/dist/flow/loops/while.d.ts +1 -1
- package/dist/flow/switch_case.d.ts +94 -12
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1093 -367
- package/dist/pack/index.js +1103 -364
- package/dist/pack/pack.d.ts +12 -12
- package/dist/pack/visitors/index.d.ts +1 -0
- package/dist/pack/visitors/loopTransformationVisitor.d.ts +13 -6
- package/dist/pack/visitors/simplifyExecuteFunction.d.ts +3 -2
- package/dist/pack/visitors/simplifyReturnRunFunction.d.ts +2 -1
- package/dist/pack/visitors/switchTransformationVisitor.d.ts +31 -0
- package/dist/pack/visitors/unifyChainedExecutes.d.ts +3 -2
- package/dist/pack/visitors/visitor.d.ts +5 -1
- package/dist/utils.d.ts +34 -3
- package/dist/variables/Data.d.ts +7 -5
- package/dist/variables/DataSets.d.ts +17 -14
- package/dist/variables/Label.d.ts +1 -0
- package/dist/variables/Loop.d.ts +10 -2
- package/dist/variables/ResolveNBT.d.ts +4 -3
- package/dist/variables/Score.d.ts +49 -3
- package/dist/variables/index.js +1066 -328
- package/package.json +1 -1
- package/src/arguments/selector.ts +12 -0
- package/src/commands/implementations/block/setblock.ts +8 -12
- package/src/commands/implementations/entity/damage.ts +2 -2
- package/src/commands/implementations/entity/execute.ts +103 -34
- package/src/commands/implementations/server/return.ts +15 -7
- package/src/commands/implementations/world/data.ts +96 -48
- package/src/core/Macro.ts +18 -1
- package/src/core/resources/datapack/advancement.ts +1 -1
- package/src/core/resources/datapack/bannerPattern.ts +1 -1
- package/src/core/resources/datapack/chatType.ts +1 -1
- package/src/core/resources/datapack/damageType.ts +1 -1
- package/src/core/resources/datapack/dialog.ts +1 -1
- package/src/core/resources/datapack/enchantment.ts +2 -2
- package/src/core/resources/datapack/gametest.ts +2 -2
- package/src/core/resources/datapack/instrument.ts +1 -1
- package/src/core/resources/datapack/itemModifier.ts +1 -1
- package/src/core/resources/datapack/jukeboxSong.ts +1 -1
- package/src/core/resources/datapack/lootTable.ts +1 -1
- package/src/core/resources/datapack/mcfunction.ts +36 -17
- package/src/core/resources/datapack/predicate.ts +1 -1
- package/src/core/resources/datapack/recipe.ts +1 -1
- package/src/core/resources/datapack/structure.ts +1 -1
- package/src/core/resources/datapack/tag.ts +4 -4
- package/src/core/resources/datapack/timeline.ts +2 -2
- package/src/core/resources/datapack/trialSpawner.ts +1 -1
- package/src/core/resources/datapack/trimMaterial.ts +1 -1
- package/src/core/resources/datapack/trimPattern.ts +1 -1
- package/src/core/resources/datapack/variant.ts +2 -2
- package/src/core/resources/datapack/villagerTrade.ts +2 -2
- package/src/core/resources/resource.ts +22 -11
- package/src/core/resources/resourcepack/atlas.ts +1 -1
- package/src/core/resources/resourcepack/blockstate.ts +1 -1
- package/src/core/resources/resourcepack/equipment.ts +1 -1
- package/src/core/resources/resourcepack/font.ts +1 -1
- package/src/core/resources/resourcepack/itemDefinition.ts +1 -1
- package/src/core/resources/resourcepack/language.ts +1 -1
- package/src/core/resources/resourcepack/model.ts +1 -1
- package/src/core/resources/resourcepack/particle.ts +1 -1
- package/src/core/resources/resourcepack/postEffect.ts +1 -1
- package/src/core/resources/resourcepack/shader.ts +1 -1
- package/src/core/resources/resourcepack/sound.ts +1 -1
- package/src/core/resources/resourcepack/waypointStyle.ts +1 -1
- package/src/core/sandstoneCore.ts +9 -1
- package/src/flow/Flow.ts +58 -94
- package/src/flow/conditions/command.ts +1 -1
- package/src/flow/conditions/variables/dataPoint.ts +2 -2
- package/src/flow/if_else.ts +14 -3
- package/src/flow/index.ts +1 -0
- package/src/flow/loop.ts +10 -6
- package/src/flow/loops/for_i.ts +21 -17
- package/src/flow/loops/for_of.ts +43 -36
- package/src/flow/loops/staticAnalysis.ts +114 -0
- package/src/flow/loops/while.ts +8 -5
- package/src/flow/switch_case.ts +214 -13
- package/src/index.ts +6 -1
- package/src/pack/pack.ts +24 -19
- package/src/pack/visitors/containerCommandsToMCFunction.ts +12 -5
- package/src/pack/visitors/ifElseTransformationVisitor.ts +44 -16
- package/src/pack/visitors/index.ts +1 -0
- package/src/pack/visitors/initConstantsVisitor.ts +13 -11
- package/src/pack/visitors/loopTransformationVisitor.ts +30 -7
- package/src/pack/visitors/simplifyExecuteFunction.ts +43 -6
- package/src/pack/visitors/simplifyReturnRunFunction.ts +40 -17
- package/src/pack/visitors/switchTransformationVisitor.ts +452 -0
- package/src/pack/visitors/unifyChainedExecutes.ts +9 -1
- package/src/pack/visitors/visitor.ts +9 -1
- package/src/utils.ts +53 -12
- package/src/variables/Data.ts +20 -4
- package/src/variables/DataSets.ts +57 -23
- package/src/variables/JSONTextComponentClass.ts +6 -1
- package/src/variables/Label.ts +0 -3
- package/src/variables/Loop.ts +30 -1
- package/src/variables/Objective.ts +0 -1
- package/src/variables/ResolveNBT.ts +5 -3
- package/src/variables/Score.ts +238 -8
- package/src/variables/Sleep.ts +2 -2
- package/src/variables/UUID.ts +8 -6
- package/src/variables/nbt/NBTs.ts +14 -0
package/dist/flow/index.js
CHANGED
|
@@ -42,7 +42,17 @@ class MacroArgument {
|
|
|
42
42
|
try {
|
|
43
43
|
currentMCFunctionName = sandstoneCore.getCurrentMCFunctionOrThrow().resource.name;
|
|
44
44
|
} catch {}
|
|
45
|
-
|
|
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,6 +178,16 @@ function randomUUID() {
|
|
|
165
178
|
}
|
|
166
179
|
return array;
|
|
167
180
|
}
|
|
181
|
+
function add(obj) {
|
|
182
|
+
const filtered = {};
|
|
183
|
+
for (const key of Object.keys(obj)) {
|
|
184
|
+
const value = obj[key];
|
|
185
|
+
if (value !== undefined) {
|
|
186
|
+
filtered[key] = value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return filtered;
|
|
190
|
+
}
|
|
168
191
|
async function safeWrite(...args) {
|
|
169
192
|
if (typeof args[0] !== "string")
|
|
170
193
|
throw new Error("unimplemented");
|
|
@@ -181,6 +204,14 @@ function formatDebugString(className, args, body, currentIndent) {
|
|
|
181
204
|
argsString = args;
|
|
182
205
|
} else if (Array.isArray(args)) {
|
|
183
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
|
+
}
|
|
184
215
|
} else if (args && typeof args === "object") {
|
|
185
216
|
argsString = Object.entries(args).map(([key, value]) => `${key}: ${util.inspect(value, options)}`).join(", ");
|
|
186
217
|
} else {
|
|
@@ -431,1196 +462,1197 @@ function hasContext() {
|
|
|
431
462
|
}
|
|
432
463
|
var _context;
|
|
433
464
|
|
|
434
|
-
// src/
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
+
var VECTOR_CLASS_BRAND, VectorClass;
|
|
525
|
+
var init_Coordinates = __esm(() => {
|
|
526
|
+
VECTOR_CLASS_BRAND = Symbol.for("sandstone.VectorClass");
|
|
527
|
+
VectorClass = class VectorClass {
|
|
528
|
+
[VECTOR_CLASS_BRAND] = true;
|
|
529
|
+
values;
|
|
530
|
+
constructor(values) {
|
|
531
|
+
if (!Array.isArray(values) || !values.every((i) => typeof i === "string")) {
|
|
532
|
+
throw new Error(`Expected array of string for Vector values, got ${inspect3(values)}`);
|
|
533
|
+
}
|
|
534
|
+
this.values = values;
|
|
535
|
+
}
|
|
536
|
+
toString() {
|
|
537
|
+
return this.values.join(" ");
|
|
538
|
+
}
|
|
539
|
+
toJSON() {
|
|
540
|
+
return this.toString();
|
|
541
|
+
}
|
|
542
|
+
toNBT() {
|
|
543
|
+
return this.toString();
|
|
544
|
+
}
|
|
545
|
+
[Symbol.iterator]() {
|
|
546
|
+
return this.values[Symbol.iterator]();
|
|
547
|
+
}
|
|
548
|
+
static [Symbol.hasInstance](instance) {
|
|
549
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[VECTOR_CLASS_BRAND] === true;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
// src/variables/parsers.ts
|
|
555
|
+
function coordinatesParser(coordinates) {
|
|
556
|
+
if (Array.isArray(coordinates)) {
|
|
557
|
+
if (coordinates.length === 3 || coordinates.length === 2) {
|
|
558
|
+
return new VectorClass(coordinates.map((coord) => {
|
|
559
|
+
if (typeof coord === "string") {
|
|
560
|
+
return coord;
|
|
460
561
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
{ name: "unsigned_int$ebnf$1", symbols: [/[0-9]/] },
|
|
464
|
-
{ name: "unsigned_int$ebnf$1", symbols: ["unsigned_int$ebnf$1", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
465
|
-
{
|
|
466
|
-
name: "unsigned_int",
|
|
467
|
-
symbols: ["unsigned_int$ebnf$1"],
|
|
468
|
-
postprocess(d) {
|
|
469
|
-
return Number.parseInt(d[0].join(""));
|
|
562
|
+
if (typeof coord === "number") {
|
|
563
|
+
return `${coord}`;
|
|
470
564
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
{ name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "+" }] },
|
|
474
|
-
{ name: "int$ebnf$1", symbols: ["int$ebnf$1$subexpression$1"], postprocess: id },
|
|
475
|
-
{ name: "int$ebnf$1", symbols: [], postprocess: () => null },
|
|
476
|
-
{ name: "int$ebnf$2", symbols: [/[0-9]/] },
|
|
477
|
-
{ name: "int$ebnf$2", symbols: ["int$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
478
|
-
{
|
|
479
|
-
name: "int",
|
|
480
|
-
symbols: ["int$ebnf$1", "int$ebnf$2"],
|
|
481
|
-
postprocess(d) {
|
|
482
|
-
if (d[0]) {
|
|
483
|
-
return Number.parseInt(d[0][0] + d[1].join(""));
|
|
484
|
-
}
|
|
485
|
-
return Number.parseInt(d[1].join(""));
|
|
565
|
+
if ("toMacro" in coord) {
|
|
566
|
+
return coord.toMacro();
|
|
486
567
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
name: "unsigned_decimal$ebnf$2$subexpression$1",
|
|
502
|
-
symbols: [{ literal: "." }, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]
|
|
503
|
-
},
|
|
504
|
-
{ name: "unsigned_decimal$ebnf$2", symbols: ["unsigned_decimal$ebnf$2$subexpression$1"], postprocess: id },
|
|
505
|
-
{ name: "unsigned_decimal$ebnf$2", symbols: [], postprocess: () => null },
|
|
506
|
-
{
|
|
507
|
-
name: "unsigned_decimal",
|
|
508
|
-
symbols: ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"],
|
|
509
|
-
postprocess(d) {
|
|
510
|
-
return Number.parseFloat(d[0].join("") + (d[1] ? `.${d[1][1].join("")}` : ""));
|
|
568
|
+
throw new Error(`[coordinatesParser] Unsupported vector component ${coord}`);
|
|
569
|
+
}));
|
|
570
|
+
}
|
|
571
|
+
throw new Error(`[coordinatesParser] Unsupported vector size ${coordinates.length}`);
|
|
572
|
+
} else {
|
|
573
|
+
return coordinates;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function rotationParser(rotation) {
|
|
577
|
+
if (Array.isArray(rotation)) {
|
|
578
|
+
if (rotation.length === 2) {
|
|
579
|
+
return new VectorClass(rotation.map((coord) => {
|
|
580
|
+
if (typeof coord === "string") {
|
|
581
|
+
return coord;
|
|
511
582
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
{ name: "decimal$ebnf$1", symbols: [], postprocess: () => null },
|
|
515
|
-
{ name: "decimal$ebnf$2", symbols: [/[0-9]/] },
|
|
516
|
-
{ name: "decimal$ebnf$2", symbols: ["decimal$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
517
|
-
{ name: "decimal$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
|
|
518
|
-
{
|
|
519
|
-
name: "decimal$ebnf$3$subexpression$1$ebnf$1",
|
|
520
|
-
symbols: ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
|
|
521
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
522
|
-
},
|
|
523
|
-
{ name: "decimal$ebnf$3$subexpression$1", symbols: [{ literal: "." }, "decimal$ebnf$3$subexpression$1$ebnf$1"] },
|
|
524
|
-
{ name: "decimal$ebnf$3", symbols: ["decimal$ebnf$3$subexpression$1"], postprocess: id },
|
|
525
|
-
{ name: "decimal$ebnf$3", symbols: [], postprocess: () => null },
|
|
526
|
-
{
|
|
527
|
-
name: "decimal",
|
|
528
|
-
symbols: ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"],
|
|
529
|
-
postprocess(d) {
|
|
530
|
-
return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : ""));
|
|
583
|
+
if (typeof coord === "number") {
|
|
584
|
+
return `${coord}`;
|
|
531
585
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
name: "percentage",
|
|
535
|
-
symbols: ["decimal", { literal: "%" }],
|
|
536
|
-
postprocess(d) {
|
|
537
|
-
return d[0] / 100;
|
|
586
|
+
if ("toMacro" in coord) {
|
|
587
|
+
return coord.toMacro();
|
|
538
588
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
{ name: "jsonfloat$ebnf$1", symbols: [], postprocess: () => null },
|
|
542
|
-
{ name: "jsonfloat$ebnf$2", symbols: [/[0-9]/] },
|
|
543
|
-
{ name: "jsonfloat$ebnf$2", symbols: ["jsonfloat$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
544
|
-
{ name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
|
|
545
|
-
{
|
|
546
|
-
name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1",
|
|
547
|
-
symbols: ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
|
|
548
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
name: "jsonfloat$ebnf$3$subexpression$1",
|
|
552
|
-
symbols: [{ literal: "." }, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]
|
|
553
|
-
},
|
|
554
|
-
{ name: "jsonfloat$ebnf$3", symbols: ["jsonfloat$ebnf$3$subexpression$1"], postprocess: id },
|
|
555
|
-
{ name: "jsonfloat$ebnf$3", symbols: [], postprocess: () => null },
|
|
556
|
-
{ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [/[+-]/], postprocess: id },
|
|
557
|
-
{ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [], postprocess: () => null },
|
|
558
|
-
{ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2", symbols: [/[0-9]/] },
|
|
559
|
-
{
|
|
560
|
-
name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2",
|
|
561
|
-
symbols: ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/],
|
|
562
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
563
|
-
},
|
|
564
|
-
{
|
|
565
|
-
name: "jsonfloat$ebnf$4$subexpression$1",
|
|
566
|
-
symbols: [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"]
|
|
567
|
-
},
|
|
568
|
-
{ name: "jsonfloat$ebnf$4", symbols: ["jsonfloat$ebnf$4$subexpression$1"], postprocess: id },
|
|
569
|
-
{ name: "jsonfloat$ebnf$4", symbols: [], postprocess: () => null },
|
|
570
|
-
{
|
|
571
|
-
name: "jsonfloat",
|
|
572
|
-
symbols: ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"],
|
|
573
|
-
postprocess(d) {
|
|
574
|
-
return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : "") + (d[3] ? `e${d[3][1] || "+"}${d[3][2].join("")}` : ""));
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
{ name: "dqstring$ebnf$1", symbols: [] },
|
|
578
|
-
{ name: "dqstring$ebnf$1", symbols: ["dqstring$ebnf$1", "dstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
|
|
579
|
-
{
|
|
580
|
-
name: "dqstring",
|
|
581
|
-
symbols: [{ literal: '"' }, "dqstring$ebnf$1", { literal: '"' }],
|
|
582
|
-
postprocess(d) {
|
|
583
|
-
return d[1].join("");
|
|
584
|
-
}
|
|
585
|
-
},
|
|
586
|
-
{ name: "sqstring$ebnf$1", symbols: [] },
|
|
587
|
-
{ name: "sqstring$ebnf$1", symbols: ["sqstring$ebnf$1", "sstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
|
|
588
|
-
{
|
|
589
|
-
name: "sqstring",
|
|
590
|
-
symbols: [{ literal: "'" }, "sqstring$ebnf$1", { literal: "'" }],
|
|
591
|
-
postprocess(d) {
|
|
592
|
-
return d[1].join("");
|
|
593
|
-
}
|
|
594
|
-
},
|
|
595
|
-
{ name: "btstring$ebnf$1", symbols: [] },
|
|
596
|
-
{ name: "btstring$ebnf$1", symbols: ["btstring$ebnf$1", /[^`]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
597
|
-
{
|
|
598
|
-
name: "btstring",
|
|
599
|
-
symbols: [{ literal: "`" }, "btstring$ebnf$1", { literal: "`" }],
|
|
600
|
-
postprocess(d) {
|
|
601
|
-
return d[1].join("");
|
|
602
|
-
}
|
|
603
|
-
},
|
|
604
|
-
{ name: "dstrchar", symbols: [/[^\\"\n]/], postprocess: id },
|
|
605
|
-
{
|
|
606
|
-
name: "dstrchar",
|
|
607
|
-
symbols: [{ literal: "\\" }, "strescape"],
|
|
608
|
-
postprocess(d) {
|
|
609
|
-
return JSON.parse(`"${d.join("")}"`);
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
{ name: "sstrchar", symbols: [/[^\\'\n]/], postprocess: id },
|
|
613
|
-
{
|
|
614
|
-
name: "sstrchar",
|
|
615
|
-
symbols: [{ literal: "\\" }, "strescape"],
|
|
616
|
-
postprocess(d) {
|
|
617
|
-
return JSON.parse(`"${d.join("")}"`);
|
|
618
|
-
}
|
|
619
|
-
},
|
|
620
|
-
{ name: "sstrchar$string$1", symbols: [{ literal: "\\" }, { literal: "'" }], postprocess: (d) => d.join("") },
|
|
621
|
-
{
|
|
622
|
-
name: "sstrchar",
|
|
623
|
-
symbols: ["sstrchar$string$1"],
|
|
624
|
-
postprocess(d) {
|
|
625
|
-
return "'";
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
{ name: "strescape", symbols: [/["\\/bfnrt]/], postprocess: id },
|
|
629
|
-
{
|
|
630
|
-
name: "strescape",
|
|
631
|
-
symbols: [{ literal: "u" }, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/],
|
|
632
|
-
postprocess(d) {
|
|
633
|
-
return d.join("");
|
|
634
|
-
}
|
|
635
|
-
},
|
|
636
|
-
{ name: "expression$subexpression$1", symbols: ["string"] },
|
|
637
|
-
{ name: "expression$subexpression$1", symbols: ["typedNum"] },
|
|
638
|
-
{ name: "expression$subexpression$1", symbols: ["number"] },
|
|
639
|
-
{ name: "expression$subexpression$1", symbols: ["boolean"] },
|
|
640
|
-
{ name: "expression$subexpression$1", symbols: ["byteArray"] },
|
|
641
|
-
{ name: "expression$subexpression$1", symbols: ["intArray"] },
|
|
642
|
-
{ name: "expression$subexpression$1", symbols: ["longArray"] },
|
|
643
|
-
{ name: "expression$subexpression$1", symbols: ["array"] },
|
|
644
|
-
{ name: "expression$subexpression$1", symbols: ["object"] },
|
|
645
|
-
{
|
|
646
|
-
name: "expression",
|
|
647
|
-
symbols: ["expression$subexpression$1"],
|
|
648
|
-
postprocess: (data) => data[0][0]
|
|
649
|
-
},
|
|
650
|
-
{
|
|
651
|
-
name: "object",
|
|
652
|
-
symbols: [{ literal: "{" }, "objectInner", { literal: "}" }],
|
|
653
|
-
postprocess: (data) => Object.fromEntries([
|
|
654
|
-
...data[1].map(({ key, value }) => [key, value]),
|
|
655
|
-
[isCompoundSymbol, true]
|
|
656
|
-
])
|
|
657
|
-
},
|
|
658
|
-
{ name: "objectInner", symbols: ["_"], postprocess: (data) => [] },
|
|
659
|
-
{ name: "objectInner$ebnf$1", symbols: [] },
|
|
660
|
-
{ name: "objectInner$ebnf$1$subexpression$1", symbols: ["objectKeyValue", "_", { literal: "," }, "_"] },
|
|
661
|
-
{
|
|
662
|
-
name: "objectInner$ebnf$1",
|
|
663
|
-
symbols: ["objectInner$ebnf$1", "objectInner$ebnf$1$subexpression$1"],
|
|
664
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
665
|
-
},
|
|
666
|
-
{ name: "objectInner$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
667
|
-
{ name: "objectInner$ebnf$2", symbols: ["objectInner$ebnf$2$subexpression$1"], postprocess: id },
|
|
668
|
-
{ name: "objectInner$ebnf$2", symbols: [], postprocess: () => null },
|
|
669
|
-
{
|
|
670
|
-
name: "objectInner",
|
|
671
|
-
symbols: ["_", "objectInner$ebnf$1", "objectKeyValue", "objectInner$ebnf$2", "_"],
|
|
672
|
-
postprocess: (data) => {
|
|
673
|
-
const firstKeyValues = data[1].map(([keyValue]) => keyValue);
|
|
674
|
-
const keyValues = [...firstKeyValues, data[2]];
|
|
675
|
-
return keyValues;
|
|
676
|
-
}
|
|
677
|
-
},
|
|
678
|
-
{ name: "objectKeyValue$ebnf$1", symbols: [/[a-zA-Z]/] },
|
|
679
|
-
{
|
|
680
|
-
name: "objectKeyValue$ebnf$1",
|
|
681
|
-
symbols: ["objectKeyValue$ebnf$1", /[a-zA-Z]/],
|
|
682
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
name: "objectKeyValue",
|
|
686
|
-
symbols: ["objectKeyValue$ebnf$1", "_", { literal: ":" }, "_", "expression"],
|
|
687
|
-
postprocess: (data) => ({ key: data[0].join(""), value: data[4] })
|
|
688
|
-
},
|
|
689
|
-
{
|
|
690
|
-
name: "objectKeyValue",
|
|
691
|
-
symbols: ["string", "_", { literal: ":" }, "_", "expression"],
|
|
692
|
-
postprocess: (data) => ({ key: data[0].value, value: data[4] })
|
|
693
|
-
},
|
|
694
|
-
{ name: "array$macrocall$2", symbols: ["expression"] },
|
|
695
|
-
{ name: "array$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
696
|
-
{ name: "array$macrocall$1$ebnf$1", symbols: [] },
|
|
697
|
-
{ name: "array$macrocall$1$ebnf$1$subexpression$1", symbols: ["array$macrocall$2", "_", { literal: "," }, "_"] },
|
|
698
|
-
{
|
|
699
|
-
name: "array$macrocall$1$ebnf$1",
|
|
700
|
-
symbols: ["array$macrocall$1$ebnf$1", "array$macrocall$1$ebnf$1$subexpression$1"],
|
|
701
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
702
|
-
},
|
|
703
|
-
{ name: "array$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
704
|
-
{ name: "array$macrocall$1$ebnf$2", symbols: ["array$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
|
|
705
|
-
{ name: "array$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
706
|
-
{
|
|
707
|
-
name: "array$macrocall$1",
|
|
708
|
-
symbols: ["_", "array$macrocall$1$ebnf$1", "array$macrocall$2", "array$macrocall$1$ebnf$2", "_"],
|
|
709
|
-
postprocess: (data) => {
|
|
710
|
-
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
711
|
-
return [...firstArray, data[2][0]];
|
|
712
|
-
}
|
|
713
|
-
},
|
|
714
|
-
{
|
|
715
|
-
name: "array",
|
|
716
|
-
symbols: [{ literal: "[" }, "array$macrocall$1", { literal: "]" }],
|
|
717
|
-
postprocess: (data) => data[1]
|
|
718
|
-
},
|
|
719
|
-
{ name: "byteArray$macrocall$2", symbols: ["typedByte"] },
|
|
720
|
-
{ name: "byteArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
721
|
-
{ name: "byteArray$macrocall$1$ebnf$1", symbols: [] },
|
|
722
|
-
{
|
|
723
|
-
name: "byteArray$macrocall$1$ebnf$1$subexpression$1",
|
|
724
|
-
symbols: ["byteArray$macrocall$2", "_", { literal: "," }, "_"]
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
name: "byteArray$macrocall$1$ebnf$1",
|
|
728
|
-
symbols: ["byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$1$ebnf$1$subexpression$1"],
|
|
729
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
730
|
-
},
|
|
731
|
-
{ name: "byteArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
732
|
-
{
|
|
733
|
-
name: "byteArray$macrocall$1$ebnf$2",
|
|
734
|
-
symbols: ["byteArray$macrocall$1$ebnf$2$subexpression$1"],
|
|
735
|
-
postprocess: id
|
|
736
|
-
},
|
|
737
|
-
{ name: "byteArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
738
|
-
{
|
|
739
|
-
name: "byteArray$macrocall$1",
|
|
740
|
-
symbols: ["_", "byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$2", "byteArray$macrocall$1$ebnf$2", "_"],
|
|
741
|
-
postprocess: (data) => {
|
|
742
|
-
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
743
|
-
return [...firstArray, data[2][0]];
|
|
744
|
-
}
|
|
745
|
-
},
|
|
746
|
-
{
|
|
747
|
-
name: "byteArray",
|
|
748
|
-
symbols: [
|
|
749
|
-
{ literal: "[" },
|
|
750
|
-
"_",
|
|
751
|
-
{ literal: "B" },
|
|
752
|
-
"_",
|
|
753
|
-
{ literal: ";" },
|
|
754
|
-
"byteArray$macrocall$1",
|
|
755
|
-
{ literal: "]" }
|
|
756
|
-
],
|
|
757
|
-
postprocess: (data) => ({ dataType: "byteArray", value: data[5] })
|
|
758
|
-
},
|
|
759
|
-
{ name: "intArray$macrocall$2", symbols: ["number"] },
|
|
760
|
-
{ name: "intArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
761
|
-
{ name: "intArray$macrocall$1$ebnf$1", symbols: [] },
|
|
762
|
-
{
|
|
763
|
-
name: "intArray$macrocall$1$ebnf$1$subexpression$1",
|
|
764
|
-
symbols: ["intArray$macrocall$2", "_", { literal: "," }, "_"]
|
|
765
|
-
},
|
|
766
|
-
{
|
|
767
|
-
name: "intArray$macrocall$1$ebnf$1",
|
|
768
|
-
symbols: ["intArray$macrocall$1$ebnf$1", "intArray$macrocall$1$ebnf$1$subexpression$1"],
|
|
769
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
770
|
-
},
|
|
771
|
-
{ name: "intArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
772
|
-
{ name: "intArray$macrocall$1$ebnf$2", symbols: ["intArray$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
|
|
773
|
-
{ name: "intArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
774
|
-
{
|
|
775
|
-
name: "intArray$macrocall$1",
|
|
776
|
-
symbols: ["_", "intArray$macrocall$1$ebnf$1", "intArray$macrocall$2", "intArray$macrocall$1$ebnf$2", "_"],
|
|
777
|
-
postprocess: (data) => {
|
|
778
|
-
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
779
|
-
return [...firstArray, data[2][0]];
|
|
780
|
-
}
|
|
781
|
-
},
|
|
782
|
-
{
|
|
783
|
-
name: "intArray",
|
|
784
|
-
symbols: [
|
|
785
|
-
{ literal: "[" },
|
|
786
|
-
"_",
|
|
787
|
-
{ literal: "I" },
|
|
788
|
-
"_",
|
|
789
|
-
{ literal: ";" },
|
|
790
|
-
"intArray$macrocall$1",
|
|
791
|
-
{ literal: "]" }
|
|
792
|
-
],
|
|
793
|
-
postprocess: (data) => ({ dataType: "intArray", value: data[5] })
|
|
794
|
-
},
|
|
795
|
-
{ name: "longArray$macrocall$2", symbols: ["typedLong"] },
|
|
796
|
-
{ name: "longArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
797
|
-
{ name: "longArray$macrocall$1$ebnf$1", symbols: [] },
|
|
798
|
-
{
|
|
799
|
-
name: "longArray$macrocall$1$ebnf$1$subexpression$1",
|
|
800
|
-
symbols: ["longArray$macrocall$2", "_", { literal: "," }, "_"]
|
|
801
|
-
},
|
|
802
|
-
{
|
|
803
|
-
name: "longArray$macrocall$1$ebnf$1",
|
|
804
|
-
symbols: ["longArray$macrocall$1$ebnf$1", "longArray$macrocall$1$ebnf$1$subexpression$1"],
|
|
805
|
-
postprocess: (d) => d[0].concat([d[1]])
|
|
806
|
-
},
|
|
807
|
-
{ name: "longArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
808
|
-
{
|
|
809
|
-
name: "longArray$macrocall$1$ebnf$2",
|
|
810
|
-
symbols: ["longArray$macrocall$1$ebnf$2$subexpression$1"],
|
|
811
|
-
postprocess: id
|
|
812
|
-
},
|
|
813
|
-
{ name: "longArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
814
|
-
{
|
|
815
|
-
name: "longArray$macrocall$1",
|
|
816
|
-
symbols: ["_", "longArray$macrocall$1$ebnf$1", "longArray$macrocall$2", "longArray$macrocall$1$ebnf$2", "_"],
|
|
817
|
-
postprocess: (data) => {
|
|
818
|
-
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
819
|
-
return [...firstArray, data[2][0]];
|
|
820
|
-
}
|
|
821
|
-
},
|
|
822
|
-
{
|
|
823
|
-
name: "longArray",
|
|
824
|
-
symbols: [
|
|
825
|
-
{ literal: "[" },
|
|
826
|
-
"_",
|
|
827
|
-
{ literal: "L" },
|
|
828
|
-
"_",
|
|
829
|
-
{ literal: ";" },
|
|
830
|
-
"longArray$macrocall$1",
|
|
831
|
-
{ literal: "]" }
|
|
832
|
-
],
|
|
833
|
-
postprocess: (data) => ({ dataType: "longArray", value: data[5] })
|
|
834
|
-
},
|
|
835
|
-
{ name: "string$subexpression$1", symbols: ["dqstring"] },
|
|
836
|
-
{ name: "string$subexpression$1", symbols: ["sqstring"] },
|
|
837
|
-
{
|
|
838
|
-
name: "string",
|
|
839
|
-
symbols: ["string$subexpression$1"],
|
|
840
|
-
postprocess: (data) => ({ dataType: "string", value: data[0][0] })
|
|
841
|
-
},
|
|
842
|
-
{ name: "typedNum$subexpression$1", symbols: ["typedByte"] },
|
|
843
|
-
{ name: "typedNum$subexpression$1", symbols: ["typedShort"] },
|
|
844
|
-
{ name: "typedNum$subexpression$1", symbols: ["typedLong"] },
|
|
845
|
-
{ name: "typedNum$subexpression$1", symbols: ["typedFloat"] },
|
|
846
|
-
{ name: "typedNum", symbols: ["typedNum$subexpression$1"], postprocess: (data) => data[0][0] },
|
|
847
|
-
{
|
|
848
|
-
name: "typedByte$subexpression$1",
|
|
849
|
-
symbols: [/[bB]/],
|
|
850
|
-
postprocess(d) {
|
|
851
|
-
return d.join("");
|
|
852
|
-
}
|
|
853
|
-
},
|
|
854
|
-
{
|
|
855
|
-
name: "typedByte",
|
|
856
|
-
symbols: ["int", "typedByte$subexpression$1"],
|
|
857
|
-
postprocess: (data) => ({ dataType: "byte", value: data[0] })
|
|
858
|
-
},
|
|
859
|
-
{
|
|
860
|
-
name: "typedShort$subexpression$1",
|
|
861
|
-
symbols: [/[sS]/],
|
|
862
|
-
postprocess(d) {
|
|
863
|
-
return d.join("");
|
|
864
|
-
}
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
name: "typedShort",
|
|
868
|
-
symbols: ["int", "typedShort$subexpression$1"],
|
|
869
|
-
postprocess: (data) => ({ dataType: "short", value: data[0] })
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
name: "typedLong$subexpression$1",
|
|
873
|
-
symbols: [/[lL]/],
|
|
874
|
-
postprocess(d) {
|
|
875
|
-
return d.join("");
|
|
876
|
-
}
|
|
877
|
-
},
|
|
878
|
-
{
|
|
879
|
-
name: "typedLong",
|
|
880
|
-
symbols: ["int", "typedLong$subexpression$1"],
|
|
881
|
-
postprocess: (data) => ({ dataType: "long", value: data[0] })
|
|
882
|
-
},
|
|
883
|
-
{
|
|
884
|
-
name: "typedFloat$subexpression$1",
|
|
885
|
-
symbols: [/[dD]/],
|
|
886
|
-
postprocess(d) {
|
|
887
|
-
return d.join("");
|
|
888
|
-
}
|
|
889
|
-
},
|
|
890
|
-
{
|
|
891
|
-
name: "typedFloat",
|
|
892
|
-
symbols: ["decimal", "typedFloat$subexpression$1"],
|
|
893
|
-
postprocess: (data) => ({ dataType: "double", value: data[0] })
|
|
894
|
-
},
|
|
895
|
-
{
|
|
896
|
-
name: "typedFloat$subexpression$2",
|
|
897
|
-
symbols: [/[fF]/],
|
|
898
|
-
postprocess(d) {
|
|
899
|
-
return d.join("");
|
|
900
|
-
}
|
|
901
|
-
},
|
|
902
|
-
{
|
|
903
|
-
name: "typedFloat",
|
|
904
|
-
symbols: ["decimal", "typedFloat$subexpression$2"],
|
|
905
|
-
postprocess: (data) => ({ dataType: "float", value: data[0] })
|
|
906
|
-
},
|
|
907
|
-
{ name: "number$subexpression$1", symbols: ["decimal"] },
|
|
908
|
-
{
|
|
909
|
-
name: "number",
|
|
910
|
-
symbols: ["number$subexpression$1"],
|
|
911
|
-
postprocess: (data) => ({ dataType: "number", value: data[0][0] })
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
name: "boolean$subexpression$1$string$1",
|
|
915
|
-
symbols: [{ literal: "t" }, { literal: "r" }, { literal: "u" }, { literal: "e" }],
|
|
916
|
-
postprocess: (d) => d.join("")
|
|
917
|
-
},
|
|
918
|
-
{ name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$1"] },
|
|
919
|
-
{
|
|
920
|
-
name: "boolean$subexpression$1$string$2",
|
|
921
|
-
symbols: [{ literal: "f" }, { literal: "a" }, { literal: "l" }, { literal: "s" }, { literal: "e" }],
|
|
922
|
-
postprocess: (d) => d.join("")
|
|
923
|
-
},
|
|
924
|
-
{ name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$2"] },
|
|
925
|
-
{
|
|
926
|
-
name: "boolean",
|
|
927
|
-
symbols: ["boolean$subexpression$1"],
|
|
928
|
-
postprocess: (data) => ({ dataType: "boolean", value: data[0].join("") === "true" })
|
|
929
|
-
}
|
|
930
|
-
],
|
|
931
|
-
ParserStart: "expression"
|
|
932
|
-
};
|
|
933
|
-
grammar_default = grammar;
|
|
934
|
-
});
|
|
935
|
-
|
|
936
|
-
// src/variables/nbt/parser.ts
|
|
937
|
-
import nearley from "nearley";
|
|
938
|
-
function isCompoundNbt(nbt) {
|
|
939
|
-
return !!nbt[isCompoundSymbol];
|
|
940
|
-
}
|
|
941
|
-
function parseRaw(nbt) {
|
|
942
|
-
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar_default));
|
|
943
|
-
parser.feed(nbt);
|
|
944
|
-
parser.finish();
|
|
945
|
-
return parser.results[0];
|
|
946
|
-
}
|
|
947
|
-
function parseExpression(NBT, nbt) {
|
|
948
|
-
if (Array.isArray(nbt)) {
|
|
949
|
-
return nbt.map((x) => parseExpression(NBT, x));
|
|
950
|
-
}
|
|
951
|
-
if (typeof nbt === "object") {
|
|
952
|
-
if (isCompoundNbt(nbt)) {
|
|
953
|
-
return Object.keys(nbt).reduce((acc, key) => {
|
|
954
|
-
acc[key] = parseExpression(NBT, nbt[key]);
|
|
955
|
-
return acc;
|
|
956
|
-
}, {});
|
|
957
|
-
}
|
|
958
|
-
switch (nbt.dataType) {
|
|
959
|
-
case "byte":
|
|
960
|
-
return NBT.byte(nbt.value);
|
|
961
|
-
case "short":
|
|
962
|
-
return NBT.short(nbt.value);
|
|
963
|
-
case "long":
|
|
964
|
-
return NBT.long(nbt.value);
|
|
965
|
-
case "float":
|
|
966
|
-
return NBT.float(nbt.value);
|
|
967
|
-
case "double":
|
|
968
|
-
return NBT.double(nbt.value);
|
|
969
|
-
case "number":
|
|
970
|
-
return nbt.value;
|
|
971
|
-
case "string":
|
|
972
|
-
return nbt.value;
|
|
973
|
-
case "byteArray":
|
|
974
|
-
return NBT.byteArray(nbt.value.map((x) => x.value));
|
|
975
|
-
case "intArray":
|
|
976
|
-
return NBT.intArray(nbt.value.map((x) => x.value));
|
|
977
|
-
case "longArray":
|
|
978
|
-
return NBT.longArray(nbt.value.map((x) => x.value));
|
|
589
|
+
throw new Error(`[rotationParser] Unsupported vector component ${coord}`);
|
|
590
|
+
}));
|
|
979
591
|
}
|
|
592
|
+
throw new Error(`[rotationParser] Unsupported vector size ${rotation.length}`);
|
|
593
|
+
} else {
|
|
594
|
+
return rotation;
|
|
980
595
|
}
|
|
981
|
-
throw new Error(`Unrecognized data type: ${nbt.dataType}`);
|
|
982
596
|
}
|
|
983
|
-
function
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
}
|
|
987
|
-
var init_parser = __esm(() => {
|
|
988
|
-
init_grammar();
|
|
989
|
-
});
|
|
990
|
-
|
|
991
|
-
// src/variables/nbt/NBTs.ts
|
|
992
|
-
import * as util3 from "util";
|
|
993
|
-
function customNumber(num, _class) {
|
|
994
|
-
if (Array.isArray(num)) {
|
|
995
|
-
return num.map((n) => new _class(n));
|
|
597
|
+
function targetParser(target) {
|
|
598
|
+
if (target === undefined) {
|
|
599
|
+
throw new Error("Target cannot be undefined.");
|
|
996
600
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
601
|
+
if (typeof target === "string") {
|
|
602
|
+
return target;
|
|
603
|
+
}
|
|
604
|
+
if (target._toSelector) {
|
|
605
|
+
return target._toSelector();
|
|
606
|
+
}
|
|
607
|
+
if (target.toMacro) {
|
|
608
|
+
return target;
|
|
609
|
+
}
|
|
610
|
+
return target.toString();
|
|
1003
611
|
}
|
|
1004
|
-
var
|
|
1005
|
-
if (
|
|
1006
|
-
|
|
612
|
+
var sanitizeValue = (core, value) => {
|
|
613
|
+
if (value === undefined || value === null) {
|
|
614
|
+
return "";
|
|
1007
615
|
}
|
|
1008
|
-
if (typeof
|
|
1009
|
-
return
|
|
616
|
+
if (typeof value === "string") {
|
|
617
|
+
return value;
|
|
1010
618
|
}
|
|
1011
|
-
if (
|
|
1012
|
-
return
|
|
619
|
+
if (isMacroArgument(core, value)) {
|
|
620
|
+
return value.toMacro();
|
|
1013
621
|
}
|
|
1014
|
-
if (
|
|
1015
|
-
|
|
1016
|
-
breakLength: Number.POSITIVE_INFINITY,
|
|
1017
|
-
compact: true,
|
|
1018
|
-
maxStringLength: Number.POSITIVE_INFINITY,
|
|
1019
|
-
depth: Number.POSITIVE_INFINITY
|
|
1020
|
-
});
|
|
1021
|
-
if (inspectedStr[0] === "`") {
|
|
1022
|
-
return JSON.stringify(nbt);
|
|
1023
|
-
}
|
|
1024
|
-
return inspectedStr;
|
|
622
|
+
if (Number.isFinite(value)) {
|
|
623
|
+
return value.toString();
|
|
1025
624
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
625
|
+
return "";
|
|
626
|
+
}, rangeParser = (core, range) => {
|
|
627
|
+
if (Array.isArray(range)) {
|
|
628
|
+
return `${sanitizeValue(core, range[0])}..${sanitizeValue(core, range[1])}`;
|
|
1029
629
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
630
|
+
return range.toString();
|
|
631
|
+
}, structureRotationParser = (rotation) => {
|
|
632
|
+
if (!rotation) {
|
|
633
|
+
return "none";
|
|
1032
634
|
}
|
|
1033
|
-
if (typeof
|
|
1034
|
-
|
|
1035
|
-
if ("toMacro" in nbt) {
|
|
1036
|
-
const macro = nbt.toMacro();
|
|
1037
|
-
if (macro === "$()") {
|
|
1038
|
-
failedMacro = true;
|
|
1039
|
-
} else {
|
|
1040
|
-
return macro;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
if ("toNBT" in nbt) {
|
|
1044
|
-
return nbt.toNBT();
|
|
1045
|
-
} else if (failedMacro) {
|
|
1046
|
-
throw new Error("[nbtStringifier] A macro variable NBT insertion was attempted in an mcfunction without macros defined.");
|
|
1047
|
-
}
|
|
1048
|
-
if (typeof nbt === "function") {
|
|
1049
|
-
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.`);
|
|
1050
|
-
}
|
|
1051
|
-
if (nbt.constructor.name !== "Object") {
|
|
1052
|
-
if ("toString" in nbt) {
|
|
1053
|
-
return `${toString}`;
|
|
1054
|
-
} else {
|
|
1055
|
-
throw new Error(`[nbtStringifier] A ${nbt.constructor?.name} was passed in as an NBT value. Hint: define toNBT or toString if this was intentional`);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
635
|
+
if (typeof rotation === "object") {
|
|
636
|
+
return rotation;
|
|
1058
637
|
}
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
638
|
+
const numToLiteral = (angle) => {
|
|
639
|
+
switch (angle) {
|
|
640
|
+
case 0:
|
|
641
|
+
return "none";
|
|
642
|
+
case 90:
|
|
643
|
+
return "clockwise_90";
|
|
644
|
+
case 180:
|
|
645
|
+
return "180";
|
|
646
|
+
case 270:
|
|
647
|
+
return "counterclockwise_90";
|
|
648
|
+
case -90:
|
|
649
|
+
return "counterclockwise_90";
|
|
650
|
+
case -180:
|
|
651
|
+
return "180";
|
|
652
|
+
case -270:
|
|
653
|
+
return "clockwise_90";
|
|
654
|
+
default: {
|
|
655
|
+
if (!Number.isInteger(angle / 90)) {
|
|
656
|
+
throw new Error("Structure rotation must be in increments of 90!");
|
|
657
|
+
}
|
|
658
|
+
angle %= 360;
|
|
659
|
+
angle = (angle + 360) % 360;
|
|
660
|
+
if (angle > 180)
|
|
661
|
+
angle -= 360;
|
|
662
|
+
return numToLiteral(angle);
|
|
663
|
+
}
|
|
1085
664
|
}
|
|
1086
665
|
};
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
666
|
+
if (typeof rotation === "number") {
|
|
667
|
+
return numToLiteral(rotation);
|
|
668
|
+
}
|
|
669
|
+
if (rotation === "clockwise_90" || rotation === "counterclockwise_90") {
|
|
670
|
+
return rotation;
|
|
671
|
+
}
|
|
672
|
+
return numToLiteral(Number(rotation));
|
|
673
|
+
}, structureMirrorParser = (mirror) => {
|
|
674
|
+
if (typeof mirror === "object") {
|
|
675
|
+
return mirror.toMacro();
|
|
676
|
+
}
|
|
677
|
+
if (typeof mirror === "string") {
|
|
678
|
+
const lastCharacter = mirror.slice(0, -1);
|
|
679
|
+
if (lastCharacter === "x") {
|
|
680
|
+
return "left_right";
|
|
1090
681
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
constructor(value) {
|
|
1094
|
-
super(value, "b");
|
|
682
|
+
if (lastCharacter === "z") {
|
|
683
|
+
return "front_back";
|
|
1095
684
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
685
|
+
return mirror;
|
|
686
|
+
}
|
|
687
|
+
if (mirror) {
|
|
688
|
+
return "left_right";
|
|
689
|
+
}
|
|
690
|
+
return "none";
|
|
691
|
+
};
|
|
692
|
+
var init_parsers = __esm(() => {
|
|
693
|
+
init_Macro();
|
|
694
|
+
init_Coordinates();
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// src/commands/helpers.ts
|
|
698
|
+
class FinalCommandOutput {
|
|
699
|
+
node;
|
|
700
|
+
constructor(node) {
|
|
701
|
+
this.node = node;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
class CommandArguments {
|
|
706
|
+
sandstonePack;
|
|
707
|
+
previousNode;
|
|
708
|
+
autoCommit;
|
|
709
|
+
NodeType;
|
|
710
|
+
sandstoneCore;
|
|
711
|
+
sandstoneCommands;
|
|
712
|
+
constructor(sandstonePack, previousNode, autoCommit = true) {
|
|
713
|
+
this.sandstonePack = sandstonePack;
|
|
714
|
+
this.previousNode = previousNode;
|
|
715
|
+
this.autoCommit = autoCommit;
|
|
716
|
+
this.sandstoneCore = sandstonePack.core;
|
|
717
|
+
this.sandstoneCommands = sandstonePack.commands;
|
|
718
|
+
}
|
|
719
|
+
getNode = () => {
|
|
720
|
+
if (this.previousNode) {
|
|
721
|
+
return this.previousNode;
|
|
1100
722
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
constructor(value) {
|
|
1104
|
-
super(value, "f");
|
|
723
|
+
if (this.NodeType) {
|
|
724
|
+
return new this.NodeType(this.sandstonePack);
|
|
1105
725
|
}
|
|
726
|
+
throw new Error("No node type specified & no previous node for a non-root-level command");
|
|
1106
727
|
};
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
728
|
+
finalCommand = (args, currentNode) => {
|
|
729
|
+
const node = currentNode ?? this.getNode();
|
|
730
|
+
if (args) {
|
|
731
|
+
node.args.push(...args);
|
|
1110
732
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
constructor(value) {
|
|
1114
|
-
super(value, "d");
|
|
733
|
+
if (this.autoCommit) {
|
|
734
|
+
node.commit();
|
|
1115
735
|
}
|
|
736
|
+
return new FinalCommandOutput(node);
|
|
1116
737
|
};
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
unit;
|
|
1122
|
-
constructor(values, unit) {
|
|
1123
|
-
super();
|
|
1124
|
-
this.values = values;
|
|
1125
|
-
this.unit = unit;
|
|
738
|
+
subCommand = (args, NextArgumentType, executable = false, additionalNextArgs = [], currentNode) => {
|
|
739
|
+
const node = currentNode ?? this.getNode();
|
|
740
|
+
if (args) {
|
|
741
|
+
node.args.push(...args);
|
|
1126
742
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_TYPED_ARRAY_BRAND] === true;
|
|
743
|
+
if (executable && this.autoCommit) {
|
|
744
|
+
node.commit();
|
|
1130
745
|
}
|
|
746
|
+
return new NextArgumentType(this.sandstonePack, node, this.autoCommit, ...additionalNextArgs);
|
|
1131
747
|
};
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// src/commands/validators.ts
|
|
751
|
+
function validateIntegerRange(integer, name, minimum = 0, maximum = 2147483647) {
|
|
752
|
+
if (typeof integer !== "number") {
|
|
753
|
+
return integer;
|
|
754
|
+
}
|
|
755
|
+
if (integer && integer <= minimum) {
|
|
756
|
+
throw new Error(`\`${name}\` must be greater than or equal to ${minimum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
|
|
757
|
+
}
|
|
758
|
+
if (integer && integer >= maximum) {
|
|
759
|
+
throw new Error(`\`${name}\` must be lower than or equal to ${maximum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
|
|
760
|
+
}
|
|
761
|
+
return integer;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/commands/implementations/block/place.ts
|
|
765
|
+
var PlaceCommandNode, PlaceCommand;
|
|
766
|
+
var init_place = __esm(() => {
|
|
767
|
+
init_nodes();
|
|
768
|
+
init_parsers();
|
|
769
|
+
PlaceCommandNode = class PlaceCommandNode extends CommandNode {
|
|
770
|
+
command = "place";
|
|
1136
771
|
};
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
772
|
+
PlaceCommand = class PlaceCommand extends CommandArguments {
|
|
773
|
+
NodeType = PlaceCommandNode;
|
|
774
|
+
feature = (feature, pos = "~ ~ ~") => this.finalCommand(["feature", feature, coordinatesParser(pos)]);
|
|
775
|
+
jigsaw = (pool, target, maxDepth, pos = "~ ~ ~") => this.finalCommand([
|
|
776
|
+
"jigsaw",
|
|
777
|
+
pool,
|
|
778
|
+
target,
|
|
779
|
+
`${validateIntegerRange(maxDepth, "Jigsaw max depth", 0, 7)}`,
|
|
780
|
+
coordinatesParser(pos)
|
|
781
|
+
]);
|
|
782
|
+
structure = (configuredStructure, pos = "~ ~ ~") => this.finalCommand(["structure", configuredStructure, coordinatesParser(pos)]);
|
|
783
|
+
template = (structure, pos = "~ ~ ~", rotation, mirror, integrity = 1, seed = 0, mode) => {
|
|
784
|
+
this.finalCommand([
|
|
785
|
+
"template",
|
|
786
|
+
`${structure}`,
|
|
787
|
+
coordinatesParser(pos),
|
|
788
|
+
structureRotationParser(rotation),
|
|
789
|
+
structureMirrorParser(mirror),
|
|
790
|
+
`${integrity}`,
|
|
791
|
+
`${seed}`,
|
|
792
|
+
...mode === undefined ? [] : [mode]
|
|
793
|
+
]);
|
|
794
|
+
};
|
|
1141
795
|
};
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// src/commands/implementations/entity/damage.ts
|
|
799
|
+
var DamageCommandNode, DamageCauseCommand, DamageSourceCommand, DamageCommand;
|
|
800
|
+
var init_damage = __esm(() => {
|
|
801
|
+
init_nodes();
|
|
802
|
+
init_parsers();
|
|
803
|
+
DamageCommandNode = class DamageCommandNode extends CommandNode {
|
|
804
|
+
command = "damage";
|
|
1146
805
|
};
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
constructor(nbt) {
|
|
1150
|
-
super();
|
|
1151
|
-
this.nbt = nbt;
|
|
1152
|
-
}
|
|
1153
|
-
[util3.inspect.custom] = () => `!${nbtStringifier(this.nbt)}`;
|
|
806
|
+
DamageCauseCommand = class DamageCauseCommand extends CommandArguments {
|
|
807
|
+
from = (cause) => this.finalCommand(["from", targetParser(cause)]);
|
|
1154
808
|
};
|
|
1155
|
-
|
|
809
|
+
DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
|
|
810
|
+
by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand, true);
|
|
811
|
+
at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
|
|
1156
812
|
};
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
long: (num) => customNumber(num, NBTLong),
|
|
1164
|
-
intArray: (numbers) => new NBTIntArray(numbers),
|
|
1165
|
-
longArray: (numbers) => new NBTLongArray(numbers),
|
|
1166
|
-
byteArray: (numbers) => new NBTByteArray(numbers),
|
|
1167
|
-
not: (nbt) => new NotNBT(nbt),
|
|
1168
|
-
stringify: (nbt) => nbtStringifier(nbt),
|
|
1169
|
-
parse: (nbt) => parseNBT(NBT, nbt)
|
|
1170
|
-
}, dynamicNBT);
|
|
1171
|
-
});
|
|
1172
|
-
|
|
1173
|
-
// src/arguments/basics.ts
|
|
1174
|
-
var init_basics = __esm(() => {
|
|
1175
|
-
init_arguments();
|
|
1176
|
-
});
|
|
1177
|
-
// src/pack/packType.ts
|
|
1178
|
-
var PACK_TYPE_BRAND, PackType;
|
|
1179
|
-
var init_packType = __esm(() => {
|
|
1180
|
-
PACK_TYPE_BRAND = Symbol.for("sandstone.PackType");
|
|
1181
|
-
PackType = class PackType {
|
|
1182
|
-
[PACK_TYPE_BRAND] = true;
|
|
1183
|
-
type;
|
|
1184
|
-
clientPath;
|
|
1185
|
-
serverPath;
|
|
1186
|
-
rootPath;
|
|
1187
|
-
networkSides;
|
|
1188
|
-
resourceSubFolder;
|
|
1189
|
-
namespaced;
|
|
1190
|
-
archiveOutput;
|
|
1191
|
-
handleOutput;
|
|
1192
|
-
constructor(type, clientPath, serverPath, rootPath, networkSides, archiveOutput = false, resourceSubFolder, namespaced = false) {
|
|
1193
|
-
this.type = type;
|
|
1194
|
-
this.clientPath = clientPath;
|
|
1195
|
-
this.serverPath = serverPath;
|
|
1196
|
-
this.rootPath = rootPath;
|
|
1197
|
-
this.networkSides = networkSides;
|
|
1198
|
-
this.archiveOutput = archiveOutput;
|
|
1199
|
-
this.resourceSubFolder = resourceSubFolder;
|
|
1200
|
-
this.namespaced = namespaced;
|
|
1201
|
-
}
|
|
1202
|
-
static [Symbol.hasInstance](instance) {
|
|
1203
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[PACK_TYPE_BRAND] === true;
|
|
1204
|
-
}
|
|
813
|
+
DamageCommand = class DamageCommand extends CommandArguments {
|
|
814
|
+
NodeType = DamageCommandNode;
|
|
815
|
+
damage = (target, amount, damageType) => {
|
|
816
|
+
validateIntegerRange(amount, "amount", 0, 1e6);
|
|
817
|
+
return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand, true);
|
|
818
|
+
};
|
|
1205
819
|
};
|
|
1206
820
|
});
|
|
1207
821
|
|
|
1208
|
-
// src/
|
|
1209
|
-
var
|
|
1210
|
-
var
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
822
|
+
// src/commands/implementations/_fake/comment.ts
|
|
823
|
+
var CommentCommandNode, CommentCommand;
|
|
824
|
+
var init_comment = __esm(() => {
|
|
825
|
+
init_nodes();
|
|
826
|
+
CommentCommandNode = class CommentCommandNode extends CommandNode {
|
|
827
|
+
command = "#";
|
|
828
|
+
getValue() {
|
|
829
|
+
return this.args[0].join(" ").split(`
|
|
830
|
+
`).map((line) => `# ${line}`).join(`
|
|
831
|
+
`);
|
|
1215
832
|
}
|
|
1216
|
-
handleOutput = async (type) => {
|
|
1217
|
-
if (type === "output") {}
|
|
1218
|
-
};
|
|
1219
833
|
};
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
}
|
|
1224
|
-
handleOutput = async (type) => {
|
|
1225
|
-
if (type === "output") {}
|
|
1226
|
-
};
|
|
834
|
+
CommentCommand = class CommentCommand extends CommandArguments {
|
|
835
|
+
NodeType = CommentCommandNode;
|
|
836
|
+
comment = (...comments) => this.finalCommand([comments]);
|
|
1227
837
|
};
|
|
1228
838
|
});
|
|
1229
839
|
|
|
1230
|
-
// src/
|
|
1231
|
-
|
|
1232
|
-
var
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
840
|
+
// src/commands/implementations/_fake/raw.ts
|
|
841
|
+
var RawCommandNode, RawCommand;
|
|
842
|
+
var init_raw = __esm(() => {
|
|
843
|
+
init_nodes();
|
|
844
|
+
RawCommandNode = class RawCommandNode extends CommandNode {
|
|
845
|
+
command = "";
|
|
846
|
+
};
|
|
847
|
+
RawCommand = class RawCommand extends CommandArguments {
|
|
848
|
+
NodeType = RawCommandNode;
|
|
849
|
+
raw = (...args) => this.finalCommand([...args]);
|
|
850
|
+
};
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
// src/commands/implementations/block/clone.ts
|
|
854
|
+
var CloneCommandNode, CloneCommand, CloneFromDimensionCommand, CloneToDimensionCommand, CloneOptionsCommand, CloneStrictOptionsCommand, CloneModeCommand;
|
|
855
|
+
var init_clone = __esm(() => {
|
|
856
|
+
init_nodes();
|
|
857
|
+
init_parsers();
|
|
858
|
+
CloneCommandNode = class CloneCommandNode extends CommandNode {
|
|
859
|
+
command = "clone";
|
|
860
|
+
};
|
|
861
|
+
CloneCommand = class CloneCommand extends CommandArguments {
|
|
862
|
+
NodeType = CloneCommandNode;
|
|
863
|
+
clone(begin, end, destination) {
|
|
864
|
+
if (begin === undefined) {
|
|
865
|
+
return this.subCommand([], CloneFromDimensionCommand, false);
|
|
1241
866
|
}
|
|
1242
|
-
this.
|
|
867
|
+
return this.subCommand([begin, end, destination].map(coordinatesParser), CloneOptionsCommand, true);
|
|
1243
868
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
869
|
+
};
|
|
870
|
+
CloneFromDimensionCommand = class CloneFromDimensionCommand extends CommandArguments {
|
|
871
|
+
from(dimension, begin, end, destination) {
|
|
872
|
+
if (destination === undefined) {
|
|
873
|
+
return this.subCommand(["from", dimension, coordinatesParser(begin), coordinatesParser(end)], CloneToDimensionCommand, false);
|
|
874
|
+
}
|
|
875
|
+
return this.subCommand(["from", ...[begin, end, destination].map(coordinatesParser)], CloneOptionsCommand, true);
|
|
1246
876
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
877
|
+
};
|
|
878
|
+
CloneToDimensionCommand = class CloneToDimensionCommand extends CommandArguments {
|
|
879
|
+
to = (dimension, destination) => this.subCommand(["to", dimension, coordinatesParser(destination)], CloneOptionsCommand, true);
|
|
880
|
+
};
|
|
881
|
+
CloneOptionsCommand = class CloneOptionsCommand extends CommandArguments {
|
|
882
|
+
replace = () => this.subCommand(["replace"], CloneModeCommand, true);
|
|
883
|
+
strict = () => this.subCommand(["strict"], CloneStrictOptionsCommand, true);
|
|
884
|
+
masked = () => this.subCommand(["masked"], CloneModeCommand, true);
|
|
885
|
+
filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
|
|
886
|
+
};
|
|
887
|
+
CloneStrictOptionsCommand = class CloneStrictOptionsCommand extends CommandArguments {
|
|
888
|
+
replace = () => this.subCommand(["replace"], CloneModeCommand, true);
|
|
889
|
+
masked = () => this.subCommand(["masked"], CloneModeCommand, true);
|
|
890
|
+
filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
|
|
891
|
+
};
|
|
892
|
+
CloneModeCommand = class CloneModeCommand extends CommandArguments {
|
|
893
|
+
force = () => this.finalCommand(["force"]);
|
|
894
|
+
move = () => this.finalCommand(["move"]);
|
|
895
|
+
normal = () => this.finalCommand(["normal"]);
|
|
896
|
+
};
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
// src/variables/abstractClasses.ts
|
|
900
|
+
var CONDITION_CLASS_BRAND, SELECTOR_PICK_CLASS_BRAND, SelectorPickClass;
|
|
901
|
+
var init_abstractClasses = __esm(() => {
|
|
902
|
+
CONDITION_CLASS_BRAND = Symbol.for("sandstone.ConditionClass");
|
|
903
|
+
SELECTOR_PICK_CLASS_BRAND = Symbol.for("sandstone.SelectorPickClass");
|
|
904
|
+
SelectorPickClass = class SelectorPickClass {
|
|
905
|
+
[SELECTOR_PICK_CLASS_BRAND] = true;
|
|
906
|
+
_toSelector() {
|
|
907
|
+
throw new Error("Not implemented");
|
|
1249
908
|
}
|
|
1250
909
|
toNBT() {
|
|
1251
|
-
|
|
1252
|
-
}
|
|
1253
|
-
[Symbol.iterator]() {
|
|
1254
|
-
return this.values[Symbol.iterator]();
|
|
910
|
+
throw new Error("Not implemented");
|
|
1255
911
|
}
|
|
1256
912
|
static [Symbol.hasInstance](instance) {
|
|
1257
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[
|
|
913
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SELECTOR_PICK_CLASS_BRAND] === true;
|
|
1258
914
|
}
|
|
1259
915
|
};
|
|
1260
916
|
});
|
|
1261
917
|
|
|
1262
|
-
// src/variables/
|
|
1263
|
-
function
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
918
|
+
// src/variables/nbt/grammar.ts
|
|
919
|
+
function id(d) {
|
|
920
|
+
return d[0];
|
|
921
|
+
}
|
|
922
|
+
var isCompoundSymbol, grammar, grammar_default;
|
|
923
|
+
var init_grammar = __esm(() => {
|
|
924
|
+
isCompoundSymbol = Symbol("isCompound");
|
|
925
|
+
grammar = {
|
|
926
|
+
Lexer: undefined,
|
|
927
|
+
ParserRules: [
|
|
928
|
+
{ name: "_$ebnf$1", symbols: [] },
|
|
929
|
+
{ name: "_$ebnf$1", symbols: ["_$ebnf$1", "wschar"], postprocess: (d) => d[0].concat([d[1]]) },
|
|
930
|
+
{
|
|
931
|
+
name: "_",
|
|
932
|
+
symbols: ["_$ebnf$1"],
|
|
933
|
+
postprocess(d) {
|
|
934
|
+
return null;
|
|
935
|
+
}
|
|
936
|
+
},
|
|
937
|
+
{ name: "__$ebnf$1", symbols: ["wschar"] },
|
|
938
|
+
{ name: "__$ebnf$1", symbols: ["__$ebnf$1", "wschar"], postprocess: (d) => d[0].concat([d[1]]) },
|
|
939
|
+
{
|
|
940
|
+
name: "__",
|
|
941
|
+
symbols: ["__$ebnf$1"],
|
|
942
|
+
postprocess(d) {
|
|
943
|
+
return null;
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
{ name: "wschar", symbols: [/[ \t\n\v\f]/], postprocess: id },
|
|
947
|
+
{ name: "unsigned_int$ebnf$1", symbols: [/[0-9]/] },
|
|
948
|
+
{ name: "unsigned_int$ebnf$1", symbols: ["unsigned_int$ebnf$1", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
949
|
+
{
|
|
950
|
+
name: "unsigned_int",
|
|
951
|
+
symbols: ["unsigned_int$ebnf$1"],
|
|
952
|
+
postprocess(d) {
|
|
953
|
+
return Number.parseInt(d[0].join(""));
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
{ name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "-" }] },
|
|
957
|
+
{ name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "+" }] },
|
|
958
|
+
{ name: "int$ebnf$1", symbols: ["int$ebnf$1$subexpression$1"], postprocess: id },
|
|
959
|
+
{ name: "int$ebnf$1", symbols: [], postprocess: () => null },
|
|
960
|
+
{ name: "int$ebnf$2", symbols: [/[0-9]/] },
|
|
961
|
+
{ name: "int$ebnf$2", symbols: ["int$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
962
|
+
{
|
|
963
|
+
name: "int",
|
|
964
|
+
symbols: ["int$ebnf$1", "int$ebnf$2"],
|
|
965
|
+
postprocess(d) {
|
|
966
|
+
if (d[0]) {
|
|
967
|
+
return Number.parseInt(d[0][0] + d[1].join(""));
|
|
968
|
+
}
|
|
969
|
+
return Number.parseInt(d[1].join(""));
|
|
970
|
+
}
|
|
971
|
+
},
|
|
972
|
+
{ name: "unsigned_decimal$ebnf$1", symbols: [/[0-9]/] },
|
|
973
|
+
{
|
|
974
|
+
name: "unsigned_decimal$ebnf$1",
|
|
975
|
+
symbols: ["unsigned_decimal$ebnf$1", /[0-9]/],
|
|
976
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
977
|
+
},
|
|
978
|
+
{ name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
|
|
979
|
+
{
|
|
980
|
+
name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1",
|
|
981
|
+
symbols: ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/],
|
|
982
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
983
|
+
},
|
|
984
|
+
{
|
|
985
|
+
name: "unsigned_decimal$ebnf$2$subexpression$1",
|
|
986
|
+
symbols: [{ literal: "." }, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]
|
|
987
|
+
},
|
|
988
|
+
{ name: "unsigned_decimal$ebnf$2", symbols: ["unsigned_decimal$ebnf$2$subexpression$1"], postprocess: id },
|
|
989
|
+
{ name: "unsigned_decimal$ebnf$2", symbols: [], postprocess: () => null },
|
|
990
|
+
{
|
|
991
|
+
name: "unsigned_decimal",
|
|
992
|
+
symbols: ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"],
|
|
993
|
+
postprocess(d) {
|
|
994
|
+
return Number.parseFloat(d[0].join("") + (d[1] ? `.${d[1][1].join("")}` : ""));
|
|
995
|
+
}
|
|
996
|
+
},
|
|
997
|
+
{ name: "decimal$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
|
|
998
|
+
{ name: "decimal$ebnf$1", symbols: [], postprocess: () => null },
|
|
999
|
+
{ name: "decimal$ebnf$2", symbols: [/[0-9]/] },
|
|
1000
|
+
{ name: "decimal$ebnf$2", symbols: ["decimal$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
1001
|
+
{ name: "decimal$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
|
|
1002
|
+
{
|
|
1003
|
+
name: "decimal$ebnf$3$subexpression$1$ebnf$1",
|
|
1004
|
+
symbols: ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
|
|
1005
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1006
|
+
},
|
|
1007
|
+
{ name: "decimal$ebnf$3$subexpression$1", symbols: [{ literal: "." }, "decimal$ebnf$3$subexpression$1$ebnf$1"] },
|
|
1008
|
+
{ name: "decimal$ebnf$3", symbols: ["decimal$ebnf$3$subexpression$1"], postprocess: id },
|
|
1009
|
+
{ name: "decimal$ebnf$3", symbols: [], postprocess: () => null },
|
|
1010
|
+
{
|
|
1011
|
+
name: "decimal",
|
|
1012
|
+
symbols: ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"],
|
|
1013
|
+
postprocess(d) {
|
|
1014
|
+
return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : ""));
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
name: "percentage",
|
|
1019
|
+
symbols: ["decimal", { literal: "%" }],
|
|
1020
|
+
postprocess(d) {
|
|
1021
|
+
return d[0] / 100;
|
|
1022
|
+
}
|
|
1023
|
+
},
|
|
1024
|
+
{ name: "jsonfloat$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
|
|
1025
|
+
{ name: "jsonfloat$ebnf$1", symbols: [], postprocess: () => null },
|
|
1026
|
+
{ name: "jsonfloat$ebnf$2", symbols: [/[0-9]/] },
|
|
1027
|
+
{ name: "jsonfloat$ebnf$2", symbols: ["jsonfloat$ebnf$2", /[0-9]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
1028
|
+
{ name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
|
|
1029
|
+
{
|
|
1030
|
+
name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1",
|
|
1031
|
+
symbols: ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
|
|
1032
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
name: "jsonfloat$ebnf$3$subexpression$1",
|
|
1036
|
+
symbols: [{ literal: "." }, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]
|
|
1037
|
+
},
|
|
1038
|
+
{ name: "jsonfloat$ebnf$3", symbols: ["jsonfloat$ebnf$3$subexpression$1"], postprocess: id },
|
|
1039
|
+
{ name: "jsonfloat$ebnf$3", symbols: [], postprocess: () => null },
|
|
1040
|
+
{ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [/[+-]/], postprocess: id },
|
|
1041
|
+
{ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [], postprocess: () => null },
|
|
1042
|
+
{ name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2", symbols: [/[0-9]/] },
|
|
1043
|
+
{
|
|
1044
|
+
name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2",
|
|
1045
|
+
symbols: ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/],
|
|
1046
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1047
|
+
},
|
|
1048
|
+
{
|
|
1049
|
+
name: "jsonfloat$ebnf$4$subexpression$1",
|
|
1050
|
+
symbols: [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"]
|
|
1051
|
+
},
|
|
1052
|
+
{ name: "jsonfloat$ebnf$4", symbols: ["jsonfloat$ebnf$4$subexpression$1"], postprocess: id },
|
|
1053
|
+
{ name: "jsonfloat$ebnf$4", symbols: [], postprocess: () => null },
|
|
1054
|
+
{
|
|
1055
|
+
name: "jsonfloat",
|
|
1056
|
+
symbols: ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"],
|
|
1057
|
+
postprocess(d) {
|
|
1058
|
+
return Number.parseFloat((d[0] || "") + d[1].join("") + (d[2] ? `.${d[2][1].join("")}` : "") + (d[3] ? `e${d[3][1] || "+"}${d[3][2].join("")}` : ""));
|
|
1269
1059
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1060
|
+
},
|
|
1061
|
+
{ name: "dqstring$ebnf$1", symbols: [] },
|
|
1062
|
+
{ name: "dqstring$ebnf$1", symbols: ["dqstring$ebnf$1", "dstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
|
|
1063
|
+
{
|
|
1064
|
+
name: "dqstring",
|
|
1065
|
+
symbols: [{ literal: '"' }, "dqstring$ebnf$1", { literal: '"' }],
|
|
1066
|
+
postprocess(d) {
|
|
1067
|
+
return d[1].join("");
|
|
1272
1068
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1069
|
+
},
|
|
1070
|
+
{ name: "sqstring$ebnf$1", symbols: [] },
|
|
1071
|
+
{ name: "sqstring$ebnf$1", symbols: ["sqstring$ebnf$1", "sstrchar"], postprocess: (d) => d[0].concat([d[1]]) },
|
|
1072
|
+
{
|
|
1073
|
+
name: "sqstring",
|
|
1074
|
+
symbols: [{ literal: "'" }, "sqstring$ebnf$1", { literal: "'" }],
|
|
1075
|
+
postprocess(d) {
|
|
1076
|
+
return d[1].join("");
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
{ name: "btstring$ebnf$1", symbols: [] },
|
|
1080
|
+
{ name: "btstring$ebnf$1", symbols: ["btstring$ebnf$1", /[^`]/], postprocess: (d) => d[0].concat([d[1]]) },
|
|
1081
|
+
{
|
|
1082
|
+
name: "btstring",
|
|
1083
|
+
symbols: [{ literal: "`" }, "btstring$ebnf$1", { literal: "`" }],
|
|
1084
|
+
postprocess(d) {
|
|
1085
|
+
return d[1].join("");
|
|
1086
|
+
}
|
|
1087
|
+
},
|
|
1088
|
+
{ name: "dstrchar", symbols: [/[^\\"\n]/], postprocess: id },
|
|
1089
|
+
{
|
|
1090
|
+
name: "dstrchar",
|
|
1091
|
+
symbols: [{ literal: "\\" }, "strescape"],
|
|
1092
|
+
postprocess(d) {
|
|
1093
|
+
return JSON.parse(`"${d.join("")}"`);
|
|
1094
|
+
}
|
|
1095
|
+
},
|
|
1096
|
+
{ name: "sstrchar", symbols: [/[^\\'\n]/], postprocess: id },
|
|
1097
|
+
{
|
|
1098
|
+
name: "sstrchar",
|
|
1099
|
+
symbols: [{ literal: "\\" }, "strescape"],
|
|
1100
|
+
postprocess(d) {
|
|
1101
|
+
return JSON.parse(`"${d.join("")}"`);
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
{ name: "sstrchar$string$1", symbols: [{ literal: "\\" }, { literal: "'" }], postprocess: (d) => d.join("") },
|
|
1105
|
+
{
|
|
1106
|
+
name: "sstrchar",
|
|
1107
|
+
symbols: ["sstrchar$string$1"],
|
|
1108
|
+
postprocess(d) {
|
|
1109
|
+
return "'";
|
|
1110
|
+
}
|
|
1111
|
+
},
|
|
1112
|
+
{ name: "strescape", symbols: [/["\\/bfnrt]/], postprocess: id },
|
|
1113
|
+
{
|
|
1114
|
+
name: "strescape",
|
|
1115
|
+
symbols: [{ literal: "u" }, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/],
|
|
1116
|
+
postprocess(d) {
|
|
1117
|
+
return d.join("");
|
|
1118
|
+
}
|
|
1119
|
+
},
|
|
1120
|
+
{ name: "expression$subexpression$1", symbols: ["string"] },
|
|
1121
|
+
{ name: "expression$subexpression$1", symbols: ["typedNum"] },
|
|
1122
|
+
{ name: "expression$subexpression$1", symbols: ["number"] },
|
|
1123
|
+
{ name: "expression$subexpression$1", symbols: ["boolean"] },
|
|
1124
|
+
{ name: "expression$subexpression$1", symbols: ["byteArray"] },
|
|
1125
|
+
{ name: "expression$subexpression$1", symbols: ["intArray"] },
|
|
1126
|
+
{ name: "expression$subexpression$1", symbols: ["longArray"] },
|
|
1127
|
+
{ name: "expression$subexpression$1", symbols: ["array"] },
|
|
1128
|
+
{ name: "expression$subexpression$1", symbols: ["object"] },
|
|
1129
|
+
{
|
|
1130
|
+
name: "expression",
|
|
1131
|
+
symbols: ["expression$subexpression$1"],
|
|
1132
|
+
postprocess: (data) => data[0][0]
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
name: "object",
|
|
1136
|
+
symbols: [{ literal: "{" }, "objectInner", { literal: "}" }],
|
|
1137
|
+
postprocess: (data) => Object.fromEntries([
|
|
1138
|
+
...data[1].map(({ key, value }) => [key, value]),
|
|
1139
|
+
[isCompoundSymbol, true]
|
|
1140
|
+
])
|
|
1141
|
+
},
|
|
1142
|
+
{ name: "objectInner", symbols: ["_"], postprocess: (data) => [] },
|
|
1143
|
+
{ name: "objectInner$ebnf$1", symbols: [] },
|
|
1144
|
+
{ name: "objectInner$ebnf$1$subexpression$1", symbols: ["objectKeyValue", "_", { literal: "," }, "_"] },
|
|
1145
|
+
{
|
|
1146
|
+
name: "objectInner$ebnf$1",
|
|
1147
|
+
symbols: ["objectInner$ebnf$1", "objectInner$ebnf$1$subexpression$1"],
|
|
1148
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1149
|
+
},
|
|
1150
|
+
{ name: "objectInner$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
1151
|
+
{ name: "objectInner$ebnf$2", symbols: ["objectInner$ebnf$2$subexpression$1"], postprocess: id },
|
|
1152
|
+
{ name: "objectInner$ebnf$2", symbols: [], postprocess: () => null },
|
|
1153
|
+
{
|
|
1154
|
+
name: "objectInner",
|
|
1155
|
+
symbols: ["_", "objectInner$ebnf$1", "objectKeyValue", "objectInner$ebnf$2", "_"],
|
|
1156
|
+
postprocess: (data) => {
|
|
1157
|
+
const firstKeyValues = data[1].map(([keyValue]) => keyValue);
|
|
1158
|
+
const keyValues = [...firstKeyValues, data[2]];
|
|
1159
|
+
return keyValues;
|
|
1160
|
+
}
|
|
1161
|
+
},
|
|
1162
|
+
{ name: "objectKeyValue$ebnf$1", symbols: [/[a-zA-Z]/] },
|
|
1163
|
+
{
|
|
1164
|
+
name: "objectKeyValue$ebnf$1",
|
|
1165
|
+
symbols: ["objectKeyValue$ebnf$1", /[a-zA-Z]/],
|
|
1166
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
name: "objectKeyValue",
|
|
1170
|
+
symbols: ["objectKeyValue$ebnf$1", "_", { literal: ":" }, "_", "expression"],
|
|
1171
|
+
postprocess: (data) => ({ key: data[0].join(""), value: data[4] })
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
name: "objectKeyValue",
|
|
1175
|
+
symbols: ["string", "_", { literal: ":" }, "_", "expression"],
|
|
1176
|
+
postprocess: (data) => ({ key: data[0].value, value: data[4] })
|
|
1177
|
+
},
|
|
1178
|
+
{ name: "array$macrocall$2", symbols: ["expression"] },
|
|
1179
|
+
{ name: "array$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
1180
|
+
{ name: "array$macrocall$1$ebnf$1", symbols: [] },
|
|
1181
|
+
{ name: "array$macrocall$1$ebnf$1$subexpression$1", symbols: ["array$macrocall$2", "_", { literal: "," }, "_"] },
|
|
1182
|
+
{
|
|
1183
|
+
name: "array$macrocall$1$ebnf$1",
|
|
1184
|
+
symbols: ["array$macrocall$1$ebnf$1", "array$macrocall$1$ebnf$1$subexpression$1"],
|
|
1185
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1186
|
+
},
|
|
1187
|
+
{ name: "array$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
1188
|
+
{ name: "array$macrocall$1$ebnf$2", symbols: ["array$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
|
|
1189
|
+
{ name: "array$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
1190
|
+
{
|
|
1191
|
+
name: "array$macrocall$1",
|
|
1192
|
+
symbols: ["_", "array$macrocall$1$ebnf$1", "array$macrocall$2", "array$macrocall$1$ebnf$2", "_"],
|
|
1193
|
+
postprocess: (data) => {
|
|
1194
|
+
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
1195
|
+
return [...firstArray, data[2][0]];
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
{
|
|
1199
|
+
name: "array",
|
|
1200
|
+
symbols: [{ literal: "[" }, "array$macrocall$1", { literal: "]" }],
|
|
1201
|
+
postprocess: (data) => data[1]
|
|
1202
|
+
},
|
|
1203
|
+
{ name: "byteArray$macrocall$2", symbols: ["typedByte"] },
|
|
1204
|
+
{ name: "byteArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
1205
|
+
{ name: "byteArray$macrocall$1$ebnf$1", symbols: [] },
|
|
1206
|
+
{
|
|
1207
|
+
name: "byteArray$macrocall$1$ebnf$1$subexpression$1",
|
|
1208
|
+
symbols: ["byteArray$macrocall$2", "_", { literal: "," }, "_"]
|
|
1209
|
+
},
|
|
1210
|
+
{
|
|
1211
|
+
name: "byteArray$macrocall$1$ebnf$1",
|
|
1212
|
+
symbols: ["byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$1$ebnf$1$subexpression$1"],
|
|
1213
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1214
|
+
},
|
|
1215
|
+
{ name: "byteArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
1216
|
+
{
|
|
1217
|
+
name: "byteArray$macrocall$1$ebnf$2",
|
|
1218
|
+
symbols: ["byteArray$macrocall$1$ebnf$2$subexpression$1"],
|
|
1219
|
+
postprocess: id
|
|
1220
|
+
},
|
|
1221
|
+
{ name: "byteArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
1222
|
+
{
|
|
1223
|
+
name: "byteArray$macrocall$1",
|
|
1224
|
+
symbols: ["_", "byteArray$macrocall$1$ebnf$1", "byteArray$macrocall$2", "byteArray$macrocall$1$ebnf$2", "_"],
|
|
1225
|
+
postprocess: (data) => {
|
|
1226
|
+
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
1227
|
+
return [...firstArray, data[2][0]];
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
name: "byteArray",
|
|
1232
|
+
symbols: [
|
|
1233
|
+
{ literal: "[" },
|
|
1234
|
+
"_",
|
|
1235
|
+
{ literal: "B" },
|
|
1236
|
+
"_",
|
|
1237
|
+
{ literal: ";" },
|
|
1238
|
+
"byteArray$macrocall$1",
|
|
1239
|
+
{ literal: "]" }
|
|
1240
|
+
],
|
|
1241
|
+
postprocess: (data) => ({ dataType: "byteArray", value: data[5] })
|
|
1242
|
+
},
|
|
1243
|
+
{ name: "intArray$macrocall$2", symbols: ["number"] },
|
|
1244
|
+
{ name: "intArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
1245
|
+
{ name: "intArray$macrocall$1$ebnf$1", symbols: [] },
|
|
1246
|
+
{
|
|
1247
|
+
name: "intArray$macrocall$1$ebnf$1$subexpression$1",
|
|
1248
|
+
symbols: ["intArray$macrocall$2", "_", { literal: "," }, "_"]
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
name: "intArray$macrocall$1$ebnf$1",
|
|
1252
|
+
symbols: ["intArray$macrocall$1$ebnf$1", "intArray$macrocall$1$ebnf$1$subexpression$1"],
|
|
1253
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1254
|
+
},
|
|
1255
|
+
{ name: "intArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
1256
|
+
{ name: "intArray$macrocall$1$ebnf$2", symbols: ["intArray$macrocall$1$ebnf$2$subexpression$1"], postprocess: id },
|
|
1257
|
+
{ name: "intArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
1258
|
+
{
|
|
1259
|
+
name: "intArray$macrocall$1",
|
|
1260
|
+
symbols: ["_", "intArray$macrocall$1$ebnf$1", "intArray$macrocall$2", "intArray$macrocall$1$ebnf$2", "_"],
|
|
1261
|
+
postprocess: (data) => {
|
|
1262
|
+
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
1263
|
+
return [...firstArray, data[2][0]];
|
|
1264
|
+
}
|
|
1265
|
+
},
|
|
1266
|
+
{
|
|
1267
|
+
name: "intArray",
|
|
1268
|
+
symbols: [
|
|
1269
|
+
{ literal: "[" },
|
|
1270
|
+
"_",
|
|
1271
|
+
{ literal: "I" },
|
|
1272
|
+
"_",
|
|
1273
|
+
{ literal: ";" },
|
|
1274
|
+
"intArray$macrocall$1",
|
|
1275
|
+
{ literal: "]" }
|
|
1276
|
+
],
|
|
1277
|
+
postprocess: (data) => ({ dataType: "intArray", value: data[5] })
|
|
1278
|
+
},
|
|
1279
|
+
{ name: "longArray$macrocall$2", symbols: ["typedLong"] },
|
|
1280
|
+
{ name: "longArray$macrocall$1", symbols: ["_"], postprocess: () => [] },
|
|
1281
|
+
{ name: "longArray$macrocall$1$ebnf$1", symbols: [] },
|
|
1282
|
+
{
|
|
1283
|
+
name: "longArray$macrocall$1$ebnf$1$subexpression$1",
|
|
1284
|
+
symbols: ["longArray$macrocall$2", "_", { literal: "," }, "_"]
|
|
1285
|
+
},
|
|
1286
|
+
{
|
|
1287
|
+
name: "longArray$macrocall$1$ebnf$1",
|
|
1288
|
+
symbols: ["longArray$macrocall$1$ebnf$1", "longArray$macrocall$1$ebnf$1$subexpression$1"],
|
|
1289
|
+
postprocess: (d) => d[0].concat([d[1]])
|
|
1290
|
+
},
|
|
1291
|
+
{ name: "longArray$macrocall$1$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }] },
|
|
1292
|
+
{
|
|
1293
|
+
name: "longArray$macrocall$1$ebnf$2",
|
|
1294
|
+
symbols: ["longArray$macrocall$1$ebnf$2$subexpression$1"],
|
|
1295
|
+
postprocess: id
|
|
1296
|
+
},
|
|
1297
|
+
{ name: "longArray$macrocall$1$ebnf$2", symbols: [], postprocess: () => null },
|
|
1298
|
+
{
|
|
1299
|
+
name: "longArray$macrocall$1",
|
|
1300
|
+
symbols: ["_", "longArray$macrocall$1$ebnf$1", "longArray$macrocall$2", "longArray$macrocall$1$ebnf$2", "_"],
|
|
1301
|
+
postprocess: (data) => {
|
|
1302
|
+
const firstArray = data[1].map(([expression]) => expression[0]);
|
|
1303
|
+
return [...firstArray, data[2][0]];
|
|
1304
|
+
}
|
|
1305
|
+
},
|
|
1306
|
+
{
|
|
1307
|
+
name: "longArray",
|
|
1308
|
+
symbols: [
|
|
1309
|
+
{ literal: "[" },
|
|
1310
|
+
"_",
|
|
1311
|
+
{ literal: "L" },
|
|
1312
|
+
"_",
|
|
1313
|
+
{ literal: ";" },
|
|
1314
|
+
"longArray$macrocall$1",
|
|
1315
|
+
{ literal: "]" }
|
|
1316
|
+
],
|
|
1317
|
+
postprocess: (data) => ({ dataType: "longArray", value: data[5] })
|
|
1318
|
+
},
|
|
1319
|
+
{ name: "string$subexpression$1", symbols: ["dqstring"] },
|
|
1320
|
+
{ name: "string$subexpression$1", symbols: ["sqstring"] },
|
|
1321
|
+
{
|
|
1322
|
+
name: "string",
|
|
1323
|
+
symbols: ["string$subexpression$1"],
|
|
1324
|
+
postprocess: (data) => ({ dataType: "string", value: data[0][0] })
|
|
1325
|
+
},
|
|
1326
|
+
{ name: "typedNum$subexpression$1", symbols: ["typedByte"] },
|
|
1327
|
+
{ name: "typedNum$subexpression$1", symbols: ["typedShort"] },
|
|
1328
|
+
{ name: "typedNum$subexpression$1", symbols: ["typedLong"] },
|
|
1329
|
+
{ name: "typedNum$subexpression$1", symbols: ["typedFloat"] },
|
|
1330
|
+
{ name: "typedNum", symbols: ["typedNum$subexpression$1"], postprocess: (data) => data[0][0] },
|
|
1331
|
+
{
|
|
1332
|
+
name: "typedByte$subexpression$1",
|
|
1333
|
+
symbols: [/[bB]/],
|
|
1334
|
+
postprocess(d) {
|
|
1335
|
+
return d.join("");
|
|
1275
1336
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
return new VectorClass(rotation.map((coord) => {
|
|
1288
|
-
if (typeof coord === "string") {
|
|
1289
|
-
return coord;
|
|
1337
|
+
},
|
|
1338
|
+
{
|
|
1339
|
+
name: "typedByte",
|
|
1340
|
+
symbols: ["int", "typedByte$subexpression$1"],
|
|
1341
|
+
postprocess: (data) => ({ dataType: "byte", value: data[0] })
|
|
1342
|
+
},
|
|
1343
|
+
{
|
|
1344
|
+
name: "typedShort$subexpression$1",
|
|
1345
|
+
symbols: [/[sS]/],
|
|
1346
|
+
postprocess(d) {
|
|
1347
|
+
return d.join("");
|
|
1290
1348
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1349
|
+
},
|
|
1350
|
+
{
|
|
1351
|
+
name: "typedShort",
|
|
1352
|
+
symbols: ["int", "typedShort$subexpression$1"],
|
|
1353
|
+
postprocess: (data) => ({ dataType: "short", value: data[0] })
|
|
1354
|
+
},
|
|
1355
|
+
{
|
|
1356
|
+
name: "typedLong$subexpression$1",
|
|
1357
|
+
symbols: [/[lL]/],
|
|
1358
|
+
postprocess(d) {
|
|
1359
|
+
return d.join("");
|
|
1293
1360
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1361
|
+
},
|
|
1362
|
+
{
|
|
1363
|
+
name: "typedLong",
|
|
1364
|
+
symbols: ["int", "typedLong$subexpression$1"],
|
|
1365
|
+
postprocess: (data) => ({ dataType: "long", value: data[0] })
|
|
1366
|
+
},
|
|
1367
|
+
{
|
|
1368
|
+
name: "typedFloat$subexpression$1",
|
|
1369
|
+
symbols: [/[dD]/],
|
|
1370
|
+
postprocess(d) {
|
|
1371
|
+
return d.join("");
|
|
1296
1372
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
if (typeof target === "string") {
|
|
1310
|
-
return target;
|
|
1311
|
-
}
|
|
1312
|
-
if (target._toSelector) {
|
|
1313
|
-
return target._toSelector();
|
|
1314
|
-
}
|
|
1315
|
-
if (target.toMacro) {
|
|
1316
|
-
return target;
|
|
1317
|
-
}
|
|
1318
|
-
return target.toString();
|
|
1319
|
-
}
|
|
1320
|
-
var sanitizeValue = (core, value) => {
|
|
1321
|
-
if (value === undefined || value === null) {
|
|
1322
|
-
return "";
|
|
1323
|
-
}
|
|
1324
|
-
if (typeof value === "string") {
|
|
1325
|
-
return value;
|
|
1326
|
-
}
|
|
1327
|
-
if (isMacroArgument(core, value)) {
|
|
1328
|
-
return value.toMacro();
|
|
1329
|
-
}
|
|
1330
|
-
if (Number.isFinite(value)) {
|
|
1331
|
-
return value.toString();
|
|
1332
|
-
}
|
|
1333
|
-
return "";
|
|
1334
|
-
}, rangeParser = (core, range) => {
|
|
1335
|
-
if (Array.isArray(range)) {
|
|
1336
|
-
return `${sanitizeValue(core, range[0])}..${sanitizeValue(core, range[1])}`;
|
|
1337
|
-
}
|
|
1338
|
-
return range.toString();
|
|
1339
|
-
}, structureRotationParser = (rotation) => {
|
|
1340
|
-
if (!rotation) {
|
|
1341
|
-
return "none";
|
|
1342
|
-
}
|
|
1343
|
-
if (typeof rotation === "object") {
|
|
1344
|
-
return rotation;
|
|
1345
|
-
}
|
|
1346
|
-
const numToLiteral = (angle) => {
|
|
1347
|
-
switch (angle) {
|
|
1348
|
-
case 0:
|
|
1349
|
-
return "none";
|
|
1350
|
-
case 90:
|
|
1351
|
-
return "clockwise_90";
|
|
1352
|
-
case 180:
|
|
1353
|
-
return "180";
|
|
1354
|
-
case 270:
|
|
1355
|
-
return "counterclockwise_90";
|
|
1356
|
-
case -90:
|
|
1357
|
-
return "counterclockwise_90";
|
|
1358
|
-
case -180:
|
|
1359
|
-
return "180";
|
|
1360
|
-
case -270:
|
|
1361
|
-
return "clockwise_90";
|
|
1362
|
-
default: {
|
|
1363
|
-
if (!Number.isInteger(angle / 90)) {
|
|
1364
|
-
throw new Error("Structure rotation must be in increments of 90!");
|
|
1373
|
+
},
|
|
1374
|
+
{
|
|
1375
|
+
name: "typedFloat",
|
|
1376
|
+
symbols: ["decimal", "typedFloat$subexpression$1"],
|
|
1377
|
+
postprocess: (data) => ({ dataType: "double", value: data[0] })
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
name: "typedFloat$subexpression$2",
|
|
1381
|
+
symbols: [/[fF]/],
|
|
1382
|
+
postprocess(d) {
|
|
1383
|
+
return d.join("");
|
|
1365
1384
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1385
|
+
},
|
|
1386
|
+
{
|
|
1387
|
+
name: "typedFloat",
|
|
1388
|
+
symbols: ["decimal", "typedFloat$subexpression$2"],
|
|
1389
|
+
postprocess: (data) => ({ dataType: "float", value: data[0] })
|
|
1390
|
+
},
|
|
1391
|
+
{ name: "number$subexpression$1", symbols: ["decimal"] },
|
|
1392
|
+
{
|
|
1393
|
+
name: "number",
|
|
1394
|
+
symbols: ["number$subexpression$1"],
|
|
1395
|
+
postprocess: (data) => ({ dataType: "number", value: data[0][0] })
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
name: "boolean$subexpression$1$string$1",
|
|
1399
|
+
symbols: [{ literal: "t" }, { literal: "r" }, { literal: "u" }, { literal: "e" }],
|
|
1400
|
+
postprocess: (d) => d.join("")
|
|
1401
|
+
},
|
|
1402
|
+
{ name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$1"] },
|
|
1403
|
+
{
|
|
1404
|
+
name: "boolean$subexpression$1$string$2",
|
|
1405
|
+
symbols: [{ literal: "f" }, { literal: "a" }, { literal: "l" }, { literal: "s" }, { literal: "e" }],
|
|
1406
|
+
postprocess: (d) => d.join("")
|
|
1407
|
+
},
|
|
1408
|
+
{ name: "boolean$subexpression$1", symbols: ["boolean$subexpression$1$string$2"] },
|
|
1409
|
+
{
|
|
1410
|
+
name: "boolean",
|
|
1411
|
+
symbols: ["boolean$subexpression$1"],
|
|
1412
|
+
postprocess: (data) => ({ dataType: "boolean", value: data[0].join("") === "true" })
|
|
1371
1413
|
}
|
|
1372
|
-
|
|
1414
|
+
],
|
|
1415
|
+
ParserStart: "expression"
|
|
1373
1416
|
};
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
return
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1417
|
+
grammar_default = grammar;
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
// src/variables/nbt/parser.ts
|
|
1421
|
+
import nearley from "nearley";
|
|
1422
|
+
function isCompoundNbt(nbt) {
|
|
1423
|
+
return !!nbt[isCompoundSymbol];
|
|
1424
|
+
}
|
|
1425
|
+
function parseRaw(nbt) {
|
|
1426
|
+
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar_default));
|
|
1427
|
+
parser.feed(nbt);
|
|
1428
|
+
parser.finish();
|
|
1429
|
+
return parser.results[0];
|
|
1430
|
+
}
|
|
1431
|
+
function parseExpression(NBT, nbt) {
|
|
1432
|
+
if (Array.isArray(nbt)) {
|
|
1433
|
+
return nbt.map((x) => parseExpression(NBT, x));
|
|
1384
1434
|
}
|
|
1385
|
-
if (typeof
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1435
|
+
if (typeof nbt === "object") {
|
|
1436
|
+
if (isCompoundNbt(nbt)) {
|
|
1437
|
+
return Object.keys(nbt).reduce((acc, key) => {
|
|
1438
|
+
acc[key] = parseExpression(NBT, nbt[key]);
|
|
1439
|
+
return acc;
|
|
1440
|
+
}, {});
|
|
1389
1441
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1442
|
+
switch (nbt.dataType) {
|
|
1443
|
+
case "byte":
|
|
1444
|
+
return NBT.byte(nbt.value);
|
|
1445
|
+
case "short":
|
|
1446
|
+
return NBT.short(nbt.value);
|
|
1447
|
+
case "long":
|
|
1448
|
+
return NBT.long(nbt.value);
|
|
1449
|
+
case "float":
|
|
1450
|
+
return NBT.float(nbt.value);
|
|
1451
|
+
case "double":
|
|
1452
|
+
return NBT.double(nbt.value);
|
|
1453
|
+
case "number":
|
|
1454
|
+
return nbt.value;
|
|
1455
|
+
case "string":
|
|
1456
|
+
return nbt.value;
|
|
1457
|
+
case "byteArray":
|
|
1458
|
+
return NBT.byteArray(nbt.value.map((x) => x.value));
|
|
1459
|
+
case "intArray":
|
|
1460
|
+
return NBT.intArray(nbt.value.map((x) => x.value));
|
|
1461
|
+
case "longArray":
|
|
1462
|
+
return NBT.longArray(nbt.value.map((x) => x.value));
|
|
1392
1463
|
}
|
|
1393
|
-
return mirror;
|
|
1394
|
-
}
|
|
1395
|
-
if (mirror) {
|
|
1396
|
-
return "left_right";
|
|
1397
1464
|
}
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1465
|
+
throw new Error(`Unrecognized data type: ${nbt.dataType}`);
|
|
1466
|
+
}
|
|
1467
|
+
function parseNBT(NBT, nbt) {
|
|
1468
|
+
const rawResult = parseRaw(nbt);
|
|
1469
|
+
return parseExpression(NBT, rawResult);
|
|
1470
|
+
}
|
|
1471
|
+
var init_parser = __esm(() => {
|
|
1472
|
+
init_grammar();
|
|
1403
1473
|
});
|
|
1404
1474
|
|
|
1405
|
-
// src/
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1475
|
+
// src/variables/nbt/NBTs.ts
|
|
1476
|
+
import * as util3 from "util";
|
|
1477
|
+
function customNumber(num, _class) {
|
|
1478
|
+
if (Array.isArray(num)) {
|
|
1479
|
+
return num.map((n) => new _class(n));
|
|
1410
1480
|
}
|
|
1481
|
+
return new _class(num);
|
|
1411
1482
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
constructor(sandstonePack, previousNode, autoCommit = true) {
|
|
1421
|
-
this.sandstonePack = sandstonePack;
|
|
1422
|
-
this.previousNode = previousNode;
|
|
1423
|
-
this.autoCommit = autoCommit;
|
|
1424
|
-
this.sandstoneCore = sandstonePack.core;
|
|
1425
|
-
this.sandstoneCommands = sandstonePack.commands;
|
|
1483
|
+
function dynamicNBT(template, ...args) {
|
|
1484
|
+
const mixedArgs = template.flatMap((s, i) => [s, args[i]]).slice(0, -1);
|
|
1485
|
+
const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtStringifier(element) : element.toString()).join("");
|
|
1486
|
+
return parseNBT(NBT, result);
|
|
1487
|
+
}
|
|
1488
|
+
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) => {
|
|
1489
|
+
if (nbt === null || nbt === undefined) {
|
|
1490
|
+
throw new Error("Nullish nbt values are not allowed");
|
|
1426
1491
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1492
|
+
if (typeof nbt === "number") {
|
|
1493
|
+
return `${nbt}d`;
|
|
1494
|
+
}
|
|
1495
|
+
if (typeof nbt === "boolean") {
|
|
1496
|
+
return nbt.toString();
|
|
1497
|
+
}
|
|
1498
|
+
if (typeof nbt === "string") {
|
|
1499
|
+
const inspectedStr = util3.inspect(nbt, {
|
|
1500
|
+
breakLength: Number.POSITIVE_INFINITY,
|
|
1501
|
+
compact: true,
|
|
1502
|
+
maxStringLength: Number.POSITIVE_INFINITY,
|
|
1503
|
+
depth: Number.POSITIVE_INFINITY
|
|
1504
|
+
});
|
|
1505
|
+
if (inspectedStr[0] === "`") {
|
|
1506
|
+
return JSON.stringify(nbt);
|
|
1433
1507
|
}
|
|
1434
|
-
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
const
|
|
1438
|
-
|
|
1439
|
-
|
|
1508
|
+
return inspectedStr;
|
|
1509
|
+
}
|
|
1510
|
+
if (Array.isArray(nbt)) {
|
|
1511
|
+
const itemsStr = nbt.map(nbtStringifier).join(",");
|
|
1512
|
+
return `[${itemsStr}]`;
|
|
1513
|
+
}
|
|
1514
|
+
if (nbt instanceof NBTClass) {
|
|
1515
|
+
return nbt[util3.inspect.custom]();
|
|
1516
|
+
}
|
|
1517
|
+
if (typeof nbt === "object" || typeof nbt === "function") {
|
|
1518
|
+
let failedMacro = false;
|
|
1519
|
+
if ("toMacro" in nbt) {
|
|
1520
|
+
const macro = nbt.toMacro();
|
|
1521
|
+
if (macro === "$()") {
|
|
1522
|
+
failedMacro = true;
|
|
1523
|
+
} else {
|
|
1524
|
+
return macro;
|
|
1525
|
+
}
|
|
1440
1526
|
}
|
|
1441
|
-
if (
|
|
1442
|
-
|
|
1527
|
+
if ("toNBT" in nbt) {
|
|
1528
|
+
return nbt.toNBT();
|
|
1529
|
+
} else if (failedMacro) {
|
|
1530
|
+
throw new Error("[nbtStringifier] A macro variable NBT insertion was attempted in an mcfunction without macros defined.");
|
|
1443
1531
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
subCommand = (args, NextArgumentType, executable = false, additionalNextArgs = [], currentNode) => {
|
|
1447
|
-
const node = currentNode ?? this.getNode();
|
|
1448
|
-
if (args) {
|
|
1449
|
-
node.args.push(...args);
|
|
1532
|
+
if (typeof nbt === "function") {
|
|
1533
|
+
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.`);
|
|
1450
1534
|
}
|
|
1451
|
-
if (
|
|
1452
|
-
|
|
1535
|
+
if (nbt.constructor.name !== "Object") {
|
|
1536
|
+
if ("toString" in nbt) {
|
|
1537
|
+
return `${toString}`;
|
|
1538
|
+
} else {
|
|
1539
|
+
throw new Error(`[nbtStringifier] A ${nbt.constructor?.name} was passed in as an NBT value. Hint: define toNBT or toString if this was intentional`);
|
|
1540
|
+
}
|
|
1453
1541
|
}
|
|
1454
|
-
return new NextArgumentType(this.sandstonePack, node, this.autoCommit, ...additionalNextArgs);
|
|
1455
|
-
};
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
// src/commands/validators.ts
|
|
1459
|
-
function validateIntegerRange(integer, name, minimum = 0, maximum = 2147483647) {
|
|
1460
|
-
if (typeof integer !== "number") {
|
|
1461
|
-
return integer;
|
|
1462
|
-
}
|
|
1463
|
-
if (integer && integer <= minimum) {
|
|
1464
|
-
throw new Error(`\`${name}\` must be greater than or equal to ${minimum.toLocaleString()}, got \`${integer.toLocaleString()}\`.`);
|
|
1465
1542
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
PlaceCommandNode = class PlaceCommandNode extends CommandNode {
|
|
1478
|
-
command = "place";
|
|
1479
|
-
};
|
|
1480
|
-
PlaceCommand = class PlaceCommand extends CommandArguments {
|
|
1481
|
-
NodeType = PlaceCommandNode;
|
|
1482
|
-
feature = (feature, pos = "~ ~ ~") => this.finalCommand(["feature", feature, coordinatesParser(pos)]);
|
|
1483
|
-
jigsaw = (pool, target, maxDepth, pos = "~ ~ ~") => this.finalCommand([
|
|
1484
|
-
"jigsaw",
|
|
1485
|
-
pool,
|
|
1486
|
-
target,
|
|
1487
|
-
`${validateIntegerRange(maxDepth, "Jigsaw max depth", 0, 7)}`,
|
|
1488
|
-
coordinatesParser(pos)
|
|
1489
|
-
]);
|
|
1490
|
-
structure = (configuredStructure, pos = "~ ~ ~") => this.finalCommand(["structure", configuredStructure, coordinatesParser(pos)]);
|
|
1491
|
-
template = (structure, pos = "~ ~ ~", rotation, mirror, integrity = 1, seed = 0, mode) => {
|
|
1492
|
-
this.finalCommand([
|
|
1493
|
-
"template",
|
|
1494
|
-
`${structure}`,
|
|
1495
|
-
coordinatesParser(pos),
|
|
1496
|
-
structureRotationParser(rotation),
|
|
1497
|
-
structureMirrorParser(mirror),
|
|
1498
|
-
`${integrity}`,
|
|
1499
|
-
`${seed}`,
|
|
1500
|
-
...mode === undefined ? [] : [mode]
|
|
1501
|
-
]);
|
|
1502
|
-
};
|
|
1503
|
-
};
|
|
1504
|
-
});
|
|
1505
|
-
|
|
1506
|
-
// src/commands/implementations/entity/damage.ts
|
|
1507
|
-
var DamageCommandNode, DamageCauseCommand, DamageSourceCommand, DamageCommand;
|
|
1508
|
-
var init_damage = __esm(() => {
|
|
1509
|
-
init_nodes();
|
|
1510
|
-
init_parsers();
|
|
1511
|
-
DamageCommandNode = class DamageCommandNode extends CommandNode {
|
|
1512
|
-
command = "damage";
|
|
1513
|
-
};
|
|
1514
|
-
DamageCauseCommand = class DamageCauseCommand extends CommandArguments {
|
|
1515
|
-
from = (cause) => this.finalCommand(["from", targetParser(cause)]);
|
|
1516
|
-
};
|
|
1517
|
-
DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
|
|
1518
|
-
by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand);
|
|
1519
|
-
at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
|
|
1520
|
-
};
|
|
1521
|
-
DamageCommand = class DamageCommand extends CommandArguments {
|
|
1522
|
-
NodeType = DamageCommandNode;
|
|
1523
|
-
damage = (target, amount, damageType) => {
|
|
1524
|
-
validateIntegerRange(amount, "amount", 0, 1e6);
|
|
1525
|
-
return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand);
|
|
1526
|
-
};
|
|
1527
|
-
};
|
|
1528
|
-
});
|
|
1529
|
-
|
|
1530
|
-
// src/commands/implementations/_fake/comment.ts
|
|
1531
|
-
var CommentCommandNode, CommentCommand;
|
|
1532
|
-
var init_comment = __esm(() => {
|
|
1533
|
-
init_nodes();
|
|
1534
|
-
CommentCommandNode = class CommentCommandNode extends CommandNode {
|
|
1535
|
-
command = "#";
|
|
1536
|
-
getValue() {
|
|
1537
|
-
return this.args[0].join(" ").split(`
|
|
1538
|
-
`).map((line) => `# ${line}`).join(`
|
|
1539
|
-
`);
|
|
1543
|
+
const objectStr = Object.entries(nbt).map(([key, value]) => `${key}:${nbtStringifier(value)}`).join(",");
|
|
1544
|
+
return `{${objectStr}}`;
|
|
1545
|
+
};
|
|
1546
|
+
var init_NBTs = __esm(() => {
|
|
1547
|
+
init_utils();
|
|
1548
|
+
init_parser();
|
|
1549
|
+
N_B_T_CLASS_BRAND = Symbol.for("sandstone.NBTClass");
|
|
1550
|
+
NBTClass = class NBTClass {
|
|
1551
|
+
[N_B_T_CLASS_BRAND] = true;
|
|
1552
|
+
static [Symbol.hasInstance](instance) {
|
|
1553
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_CLASS_BRAND] === true;
|
|
1540
1554
|
}
|
|
1541
1555
|
};
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1556
|
+
N_B_T_PRIMITIVE_BRAND = Symbol.for("sandstone.NBTPrimitive");
|
|
1557
|
+
NBTPrimitive = class NBTPrimitive extends NBTClass {
|
|
1558
|
+
[N_B_T_PRIMITIVE_BRAND] = true;
|
|
1559
|
+
value;
|
|
1560
|
+
unit;
|
|
1561
|
+
constructor(value, unit) {
|
|
1562
|
+
super();
|
|
1563
|
+
this.value = value;
|
|
1564
|
+
this.unit = unit;
|
|
1565
|
+
}
|
|
1566
|
+
toJSON() {
|
|
1567
|
+
return this.value;
|
|
1568
|
+
}
|
|
1569
|
+
[util3.inspect.custom] = () => `${this.value}${this.unit}`;
|
|
1570
|
+
static [Symbol.hasInstance](instance) {
|
|
1571
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_PRIMITIVE_BRAND] === true;
|
|
1572
|
+
}
|
|
1558
1573
|
};
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
var init_clone = __esm(() => {
|
|
1564
|
-
init_nodes();
|
|
1565
|
-
init_parsers();
|
|
1566
|
-
CloneCommandNode = class CloneCommandNode extends CommandNode {
|
|
1567
|
-
command = "clone";
|
|
1574
|
+
NBTLong = class NBTLong extends NBTPrimitive {
|
|
1575
|
+
constructor(value) {
|
|
1576
|
+
super(value, "l");
|
|
1577
|
+
}
|
|
1568
1578
|
};
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
if (begin === undefined) {
|
|
1573
|
-
return this.subCommand([], CloneFromDimensionCommand, false);
|
|
1574
|
-
}
|
|
1575
|
-
return this.subCommand([begin, end, destination].map(coordinatesParser), CloneOptionsCommand, true);
|
|
1579
|
+
NBTByte = class NBTByte extends NBTPrimitive {
|
|
1580
|
+
constructor(value) {
|
|
1581
|
+
super(value, "b");
|
|
1576
1582
|
}
|
|
1577
1583
|
};
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
return this.subCommand(["from", dimension, coordinatesParser(begin), coordinatesParser(end)], CloneToDimensionCommand, false);
|
|
1582
|
-
}
|
|
1583
|
-
return this.subCommand(["from", ...[begin, end, destination].map(coordinatesParser)], CloneOptionsCommand, true);
|
|
1584
|
+
NBTShort = class NBTShort extends NBTPrimitive {
|
|
1585
|
+
constructor(value) {
|
|
1586
|
+
super(value, "s");
|
|
1584
1587
|
}
|
|
1585
1588
|
};
|
|
1586
|
-
|
|
1587
|
-
|
|
1589
|
+
NBTFloat = class NBTFloat extends NBTPrimitive {
|
|
1590
|
+
constructor(value) {
|
|
1591
|
+
super(value, "f");
|
|
1592
|
+
}
|
|
1588
1593
|
};
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
filtered = (filter) => this.subCommand(["filtered", filter], CloneModeCommand, true);
|
|
1594
|
+
NBTInt = class NBTInt extends NBTPrimitive {
|
|
1595
|
+
constructor(value) {
|
|
1596
|
+
super(value, "i");
|
|
1597
|
+
}
|
|
1594
1598
|
};
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
+
NBTDouble = class NBTDouble extends NBTPrimitive {
|
|
1600
|
+
constructor(value) {
|
|
1601
|
+
super(value, "d");
|
|
1602
|
+
}
|
|
1599
1603
|
};
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
+
NBTTypedArray = class NBTTypedArray extends NBTClass {
|
|
1605
|
+
values;
|
|
1606
|
+
unit;
|
|
1607
|
+
constructor(values, unit) {
|
|
1608
|
+
super();
|
|
1609
|
+
this.values = values;
|
|
1610
|
+
this.unit = unit;
|
|
1611
|
+
}
|
|
1612
|
+
toJSON() {
|
|
1613
|
+
return this.values;
|
|
1614
|
+
}
|
|
1615
|
+
[util3.inspect.custom] = () => `[${this.unit};${this.values.length === 0 ? "" : this.values.join(",")}]`;
|
|
1604
1616
|
};
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
var CONDITION_CLASS_BRAND, SELECTOR_PICK_CLASS_BRAND, SelectorPickClass;
|
|
1609
|
-
var init_abstractClasses = __esm(() => {
|
|
1610
|
-
CONDITION_CLASS_BRAND = Symbol.for("sandstone.ConditionClass");
|
|
1611
|
-
SELECTOR_PICK_CLASS_BRAND = Symbol.for("sandstone.SelectorPickClass");
|
|
1612
|
-
SelectorPickClass = class SelectorPickClass {
|
|
1613
|
-
[SELECTOR_PICK_CLASS_BRAND] = true;
|
|
1614
|
-
_toSelector() {
|
|
1615
|
-
throw new Error("Not implemented");
|
|
1617
|
+
NBTLongArray = class NBTLongArray extends NBTTypedArray {
|
|
1618
|
+
constructor(values) {
|
|
1619
|
+
super(values, "L");
|
|
1616
1620
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1621
|
+
};
|
|
1622
|
+
NBTByteArray = class NBTByteArray extends NBTTypedArray {
|
|
1623
|
+
constructor(values) {
|
|
1624
|
+
super(values, "B");
|
|
1619
1625
|
}
|
|
1620
|
-
|
|
1621
|
-
|
|
1626
|
+
};
|
|
1627
|
+
NBTIntArray = class NBTIntArray extends NBTTypedArray {
|
|
1628
|
+
constructor(values) {
|
|
1629
|
+
super(values, "I");
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
NotNBT = class NotNBT extends NBTClass {
|
|
1633
|
+
nbt;
|
|
1634
|
+
constructor(nbt) {
|
|
1635
|
+
super();
|
|
1636
|
+
this.nbt = nbt;
|
|
1622
1637
|
}
|
|
1638
|
+
[util3.inspect.custom] = () => `!${nbtStringifier(this.nbt)}`;
|
|
1639
|
+
};
|
|
1640
|
+
NBTAnyValue = class NBTAnyValue extends NBTPrimitive {
|
|
1623
1641
|
};
|
|
1642
|
+
NBT = makeCallable({
|
|
1643
|
+
int: (num) => customNumber(num, NBTInt),
|
|
1644
|
+
float: (num) => customNumber(num, NBTFloat),
|
|
1645
|
+
double: (num) => customNumber(num, NBTDouble),
|
|
1646
|
+
byte: (num) => customNumber(num, NBTByte),
|
|
1647
|
+
short: (num) => customNumber(num, NBTShort),
|
|
1648
|
+
long: (num) => customNumber(num, NBTLong),
|
|
1649
|
+
intArray: (numbers) => new NBTIntArray(numbers),
|
|
1650
|
+
longArray: (numbers) => new NBTLongArray(numbers),
|
|
1651
|
+
byteArray: (numbers) => new NBTByteArray(numbers),
|
|
1652
|
+
not: (nbt) => new NotNBT(nbt),
|
|
1653
|
+
stringify: (nbt) => nbtStringifier(nbt),
|
|
1654
|
+
parse: (nbt) => parseNBT(NBT, nbt)
|
|
1655
|
+
}, dynamicNBT);
|
|
1624
1656
|
});
|
|
1625
1657
|
|
|
1626
1658
|
// src/variables/Score.ts
|
|
@@ -1684,6 +1716,9 @@ var init_Score = __esm(() => {
|
|
|
1684
1716
|
]));
|
|
1685
1717
|
unaryOperation(operation, operator, ...args) {
|
|
1686
1718
|
if (typeof args[0] === "number") {
|
|
1719
|
+
if (args[0] < 0 && operation !== "set") {
|
|
1720
|
+
return this.binaryOperation(operator, args[0]);
|
|
1721
|
+
}
|
|
1687
1722
|
this.commands.scoreboard.players[operation](this, args[0]);
|
|
1688
1723
|
} else if (args[0] instanceof Score) {
|
|
1689
1724
|
this.commands.scoreboard.players.operation(this, operator, args[0].target, args[0].objective);
|
|
@@ -1700,7 +1735,7 @@ var init_Score = __esm(() => {
|
|
|
1700
1735
|
let objective = args[1] ?? this.objective;
|
|
1701
1736
|
if (typeof args[0] === "number") {
|
|
1702
1737
|
this.sandstonePack.registerNewConstant(args[0]);
|
|
1703
|
-
objective = "
|
|
1738
|
+
objective = "__sandstone";
|
|
1704
1739
|
}
|
|
1705
1740
|
this.commands.scoreboard.players.operation(this, operator, args[0], objective);
|
|
1706
1741
|
return this;
|
|
@@ -1856,7 +1891,99 @@ Warning: Score.match() will have to create ${maximum - minimum} mcfunction files
|
|
|
1856
1891
|
}
|
|
1857
1892
|
return MCFunction(`__sandstone:score_match/${matcher}`, [score], () => Macro.returnCmd.run.functionCmd(Macro`__sandstone:score_match/${matcher}/${score}`));
|
|
1858
1893
|
};
|
|
1859
|
-
|
|
1894
|
+
getDecomposer(size, splitsOrCount, componentCount = 31, includeSign = true) {
|
|
1895
|
+
if (typeof this.target !== "string" || this.target.search(/-|@/) !== -1) {
|
|
1896
|
+
throw new Error("[Score#getDecomposer] Must use a fake-player Score for decomposition.");
|
|
1897
|
+
}
|
|
1898
|
+
const { MCFunction, _, commands } = this.sandstonePack;
|
|
1899
|
+
const { execute, returnCmd } = commands;
|
|
1900
|
+
const newScore = this.objective.ScoreHolder;
|
|
1901
|
+
const components = [];
|
|
1902
|
+
const sign = includeSign ? newScore(`${this.target}._32`) : undefined;
|
|
1903
|
+
let decompose;
|
|
1904
|
+
if (size === "bit" || size === undefined) {
|
|
1905
|
+
for (let i = 1;i <= componentCount; i++) {
|
|
1906
|
+
components.push(newScore(`${this.target}._${i}`));
|
|
1907
|
+
}
|
|
1908
|
+
decompose = MCFunction(`__sandstone:score/decompose_bits/${componentCount}_${splitsOrCount === undefined ? 0 : splitsOrCount.size}/${this.target.replaceAll(".", "/").toLowerCase()}`, () => {
|
|
1909
|
+
const resetBits = execute.store.result(components[0]);
|
|
1910
|
+
for (const component of components.slice(1, -1)) {
|
|
1911
|
+
resetBits.store.result(component);
|
|
1912
|
+
resetBits.nestedExecute(["\\\n "], false);
|
|
1913
|
+
}
|
|
1914
|
+
if (includeSign) {
|
|
1915
|
+
resetBits.store.result(components.at(-1));
|
|
1916
|
+
resetBits.nestedExecute(["\\\n "], false);
|
|
1917
|
+
resetBits.run(() => sign["="](0));
|
|
1918
|
+
} else {
|
|
1919
|
+
resetBits.run(() => components.at(-1)["="](0));
|
|
1920
|
+
}
|
|
1921
|
+
const input = newScore(`${this.target}._bf_iterator`);
|
|
1922
|
+
const splits = splitsOrCount ?? new Set;
|
|
1923
|
+
const bitExecute = (bit) => execute.store.success(components[bit - 1]);
|
|
1924
|
+
input["="](this);
|
|
1925
|
+
_.if(this["=="](0), () => {
|
|
1926
|
+
returnCmd(1);
|
|
1927
|
+
});
|
|
1928
|
+
if (includeSign) {
|
|
1929
|
+
execute.store.success(sign).if.score(input, "matches", [null, -1]).run(() => {
|
|
1930
|
+
input["*="](-1);
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
input.decomposeBits(splits, componentCount, bitExecute);
|
|
1934
|
+
}, {
|
|
1935
|
+
creator: "sandstone",
|
|
1936
|
+
onConflict: "rename",
|
|
1937
|
+
addToSandstoneCore: true
|
|
1938
|
+
});
|
|
1939
|
+
} else {
|
|
1940
|
+
throw new Error("[Score#getDecomposer(byte)] Byte decomposition is not yet supported");
|
|
1941
|
+
}
|
|
1942
|
+
const result = {
|
|
1943
|
+
components,
|
|
1944
|
+
...add({ sign })
|
|
1945
|
+
};
|
|
1946
|
+
return {
|
|
1947
|
+
...result,
|
|
1948
|
+
decompose: () => {
|
|
1949
|
+
decompose();
|
|
1950
|
+
return result;
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1954
|
+
decomposeBits(splits, componentCount, bitExecute, extra) {
|
|
1955
|
+
const { _ } = this.sandstonePack;
|
|
1956
|
+
const sortedSplits = [...splits].filter((s) => s > 0 && s < componentCount).sort((a, b) => b - a);
|
|
1957
|
+
const boundaries = [componentCount, ...sortedSplits, 0];
|
|
1958
|
+
const processRange = (high, low) => {
|
|
1959
|
+
let halvedAgain = 2 ** high;
|
|
1960
|
+
for (let bit = high;bit >= low; bit--) {
|
|
1961
|
+
halvedAgain /= 2;
|
|
1962
|
+
bitExecute(bit, halvedAgain).if.score(this, "matches", [halvedAgain, null]).run(() => {
|
|
1963
|
+
this["-="](halvedAgain);
|
|
1964
|
+
extra?.(bit, halvedAgain);
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
const buildNested = (rangeIndex) => {
|
|
1969
|
+
const high = boundaries[rangeIndex];
|
|
1970
|
+
const low = boundaries[rangeIndex + 1] + 1;
|
|
1971
|
+
if (rangeIndex > 0) {
|
|
1972
|
+
const higherMinValue = 2 ** boundaries[rangeIndex];
|
|
1973
|
+
_.if(this.matches([higherMinValue, null]), () => {
|
|
1974
|
+
buildNested(rangeIndex - 1);
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
processRange(high, low);
|
|
1978
|
+
};
|
|
1979
|
+
if (splits.size === 0) {
|
|
1980
|
+
processRange(componentCount, 1);
|
|
1981
|
+
} else {
|
|
1982
|
+
const lowestRangeIndex = boundaries.length - 2;
|
|
1983
|
+
buildNested(lowestRangeIndex);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
[util4.inspect.custom](_depth, options) {
|
|
1860
1987
|
return formatDebugString(this.constructor.name, {
|
|
1861
1988
|
target: this.target,
|
|
1862
1989
|
display: this.display,
|
|
@@ -1916,7 +2043,9 @@ class TargetlessDataClass {
|
|
|
1916
2043
|
this.sandstonePack = sandstonePack;
|
|
1917
2044
|
this.type = type;
|
|
1918
2045
|
}
|
|
1919
|
-
target = (target) =>
|
|
2046
|
+
target = (target) => {
|
|
2047
|
+
return new DataClass(this.sandstonePack, this.type, target);
|
|
2048
|
+
};
|
|
1920
2049
|
select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, path);
|
|
1921
2050
|
}
|
|
1922
2051
|
|
|
@@ -1929,7 +2058,9 @@ class TargetlessDataPointClass {
|
|
|
1929
2058
|
this.type = type;
|
|
1930
2059
|
this.path = NBTpathToString(sandstonePack, path);
|
|
1931
2060
|
}
|
|
1932
|
-
target = (target) =>
|
|
2061
|
+
target = (target) => {
|
|
2062
|
+
return new DataPointClass(this.sandstonePack, this.type, target, [this.path]);
|
|
2063
|
+
};
|
|
1933
2064
|
select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, [this.path, ...path]);
|
|
1934
2065
|
}
|
|
1935
2066
|
|
|
@@ -2017,7 +2148,9 @@ var init_Data = __esm(() => {
|
|
|
2017
2148
|
append = (value) => this.modify((data) => data.append, value);
|
|
2018
2149
|
prepend = (value) => this.modify((data) => data.prepend, value);
|
|
2019
2150
|
insert = (value, index) => this.modify((data) => data.insert(index), value);
|
|
2020
|
-
remove = () =>
|
|
2151
|
+
remove = () => {
|
|
2152
|
+
return this.sandstonePack.commands.data.remove[this.type](this.currentTarget, this.path);
|
|
2153
|
+
};
|
|
2021
2154
|
slice = (start, end) => new StringDataPointClass(this.sandstonePack, this.type, this.currentTarget, this.path, start, end);
|
|
2022
2155
|
_toMinecraftCondition = () => new this.sandstonePack.conditions.DataPointExists(this.sandstonePack.core, this);
|
|
2023
2156
|
equals = (value) => new this.sandstonePack.conditions.DataPointEquals(this.sandstonePack.core, this, value);
|
|
@@ -2062,7 +2195,7 @@ function isTagClass(v) {
|
|
|
2062
2195
|
}
|
|
2063
2196
|
function objectToString(value) {
|
|
2064
2197
|
if (isMCFunctionClass(value)) {
|
|
2065
|
-
if (value.
|
|
2198
|
+
if (value.env && value.callback.length < 2) {
|
|
2066
2199
|
return value.node.sandstoneCore.pack.MCFunction(`${value.name}/_env`, () => value(), {
|
|
2067
2200
|
creator: "sandstone",
|
|
2068
2201
|
onConflict: "rename"
|
|
@@ -2078,7 +2211,7 @@ function objectToString(value) {
|
|
|
2078
2211
|
}
|
|
2079
2212
|
if (typeof value === "object") {
|
|
2080
2213
|
if (isMCFunctionClass(value.id)) {
|
|
2081
|
-
if (value.id.
|
|
2214
|
+
if (value.id.env && value.id.callback.length < 2) {
|
|
2082
2215
|
return {
|
|
2083
2216
|
id: value.id.node.sandstoneCore.pack.MCFunction(`${value.id.name}/_env`, () => value.id(), { creator: "sandstone", onConflict: "rename" }).name,
|
|
2084
2217
|
required: value.required
|
|
@@ -2112,7 +2245,7 @@ var init_tag = __esm(() => {
|
|
|
2112
2245
|
super(sandstoneCore);
|
|
2113
2246
|
this.resource = resource;
|
|
2114
2247
|
}
|
|
2115
|
-
getValue = () => jsonStringify(this.resource.tagJSON);
|
|
2248
|
+
getValue = () => jsonStringify(this.resource.tagJSON, this.resource._resourceType);
|
|
2116
2249
|
};
|
|
2117
2250
|
TAG_CLASS_BRAND = Symbol.for("sandstone.TagClass");
|
|
2118
2251
|
TagClass = class TagClass extends ResourceClass {
|
|
@@ -2205,7 +2338,7 @@ var init_model = __esm(() => {
|
|
|
2205
2338
|
super(sandstoneCore);
|
|
2206
2339
|
this.resource = resource;
|
|
2207
2340
|
}
|
|
2208
|
-
getValue = () => jsonStringify(this.resource.modelJSON);
|
|
2341
|
+
getValue = () => jsonStringify(this.resource.modelJSON, this.resource._resourceType);
|
|
2209
2342
|
};
|
|
2210
2343
|
MODEL_CLASS_BRAND = Symbol.for("sandstone.ModelClass");
|
|
2211
2344
|
ModelClass = class ModelClass extends ResourceClass {
|
|
@@ -2409,7 +2542,7 @@ var init_itemDefinition = __esm(() => {
|
|
|
2409
2542
|
super(sandstoneCore);
|
|
2410
2543
|
this.resource = resource;
|
|
2411
2544
|
}
|
|
2412
|
-
getValue = () => jsonStringify(this.resource.itemDefinitionJSON);
|
|
2545
|
+
getValue = () => jsonStringify(this.resource.itemDefinitionJSON, this.resource._resourceType);
|
|
2413
2546
|
};
|
|
2414
2547
|
ItemModelDefinitionClass = class ItemModelDefinitionClass extends ResourceClass {
|
|
2415
2548
|
static resourceType = "item_definition";
|
|
@@ -2577,7 +2710,12 @@ var init_DataSets = __esm(() => {
|
|
|
2577
2710
|
init_Data();
|
|
2578
2711
|
init_Score();
|
|
2579
2712
|
IterableDataClass = class IterableDataClass extends ConditionalDataPointPickClass {
|
|
2580
|
-
|
|
2713
|
+
iteratorType;
|
|
2714
|
+
constructor(sandstoneCore, iteratorType) {
|
|
2715
|
+
super(sandstoneCore);
|
|
2716
|
+
this.iteratorType = iteratorType;
|
|
2717
|
+
}
|
|
2718
|
+
iterator(_callback, _direction = "normal") {
|
|
2581
2719
|
throw new Error("Not implemented");
|
|
2582
2720
|
}
|
|
2583
2721
|
size() {
|
|
@@ -2586,24 +2724,30 @@ var init_DataSets = __esm(() => {
|
|
|
2586
2724
|
last() {
|
|
2587
2725
|
throw new Error("Not implemented");
|
|
2588
2726
|
}
|
|
2589
|
-
|
|
2727
|
+
continue(direction = "normal") {
|
|
2590
2728
|
throw new Error("Not implemented");
|
|
2591
2729
|
}
|
|
2592
2730
|
};
|
|
2593
2731
|
DataIndexMapClass = class DataIndexMapClass extends IterableDataClass {
|
|
2594
2732
|
pack;
|
|
2595
|
-
initialize;
|
|
2596
2733
|
entries = {};
|
|
2597
2734
|
dataPoint;
|
|
2598
2735
|
constructor(pack, initialize, dataPoint) {
|
|
2599
|
-
super(pack.core);
|
|
2736
|
+
super(pack.core, "map");
|
|
2600
2737
|
this.pack = pack;
|
|
2601
|
-
this.initialize = initialize;
|
|
2602
2738
|
if (dataPoint) {
|
|
2603
2739
|
this.dataPoint = dataPoint;
|
|
2604
2740
|
} else {
|
|
2605
2741
|
this.dataPoint = this.pack.DataVariable(undefined, "IndexMap");
|
|
2606
2742
|
}
|
|
2743
|
+
if (pack.core.currentMCFunction) {
|
|
2744
|
+
this.init(initialize);
|
|
2745
|
+
} else {
|
|
2746
|
+
const init = this.init;
|
|
2747
|
+
pack.initMCFunction.push(() => init(initialize));
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
init(initialize) {
|
|
2607
2751
|
for (const [i, [key, value]] of Object.entries(initialize).entries()) {
|
|
2608
2752
|
this.dataPoint.select("Index").select(key).set(i);
|
|
2609
2753
|
this.dataPoint.select("Entries").append([]);
|
|
@@ -2614,21 +2758,22 @@ var init_DataSets = __esm(() => {
|
|
|
2614
2758
|
}
|
|
2615
2759
|
}
|
|
2616
2760
|
__entryIterator;
|
|
2617
|
-
|
|
2761
|
+
entryIterator(direction) {
|
|
2618
2762
|
if (!this.__entryIterator) {
|
|
2619
|
-
this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select("
|
|
2763
|
+
this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select(`[${direction === "normal" ? 0 : -1}]`);
|
|
2620
2764
|
}
|
|
2621
2765
|
return this.__entryIterator;
|
|
2622
2766
|
}
|
|
2623
|
-
iterator(callback) {
|
|
2767
|
+
iterator(callback, direction = "normal") {
|
|
2624
2768
|
this.__entryIterator = undefined;
|
|
2769
|
+
const entryIterator = this.entryIterator(direction);
|
|
2625
2770
|
return () => {
|
|
2626
|
-
callback([
|
|
2627
|
-
|
|
2771
|
+
callback([entryIterator.select("[0]").slice(0), entryIterator.select("[1]")]);
|
|
2772
|
+
entryIterator.remove();
|
|
2628
2773
|
};
|
|
2629
2774
|
}
|
|
2630
|
-
|
|
2631
|
-
return this.entryIterator._toMinecraftCondition();
|
|
2775
|
+
continue(direction = "normal") {
|
|
2776
|
+
return this.entryIterator(direction)._toMinecraftCondition();
|
|
2632
2777
|
}
|
|
2633
2778
|
size = () => this.dataPoint.select("Entries");
|
|
2634
2779
|
last = () => [this.dataPoint.select("Entries[-1][0]").slice(0), this.dataPoint.select("Entries[-1][1]")];
|
|
@@ -2737,33 +2882,42 @@ var init_DataSets = __esm(() => {
|
|
|
2737
2882
|
pack;
|
|
2738
2883
|
dataPoint;
|
|
2739
2884
|
constructor(pack, initialize, dataPoint) {
|
|
2740
|
-
super(pack.core);
|
|
2885
|
+
super(pack.core, "list");
|
|
2741
2886
|
this.pack = pack;
|
|
2742
2887
|
if (dataPoint) {
|
|
2743
2888
|
this.dataPoint = dataPoint;
|
|
2744
2889
|
} else {
|
|
2745
2890
|
this.dataPoint = this.pack.DataVariable([], "Array");
|
|
2746
2891
|
}
|
|
2892
|
+
if (pack.core.currentMCFunction) {
|
|
2893
|
+
this.init(initialize);
|
|
2894
|
+
} else {
|
|
2895
|
+
const init = this.init;
|
|
2896
|
+
pack.initMCFunction.push(() => init(initialize));
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
init(initialize) {
|
|
2747
2900
|
for (const entry of initialize) {
|
|
2748
2901
|
this.dataPoint.append(entry);
|
|
2749
2902
|
}
|
|
2750
2903
|
}
|
|
2751
2904
|
__entryIterator;
|
|
2752
|
-
|
|
2905
|
+
entryIterator(direction) {
|
|
2753
2906
|
if (!this.__entryIterator) {
|
|
2754
|
-
this.__entryIterator = this.pack.DataVariable(this.dataPoint).select("
|
|
2907
|
+
this.__entryIterator = this.pack.DataVariable(this.dataPoint).select(`[${direction === "normal" ? 0 : -1}]`);
|
|
2755
2908
|
}
|
|
2756
2909
|
return this.__entryIterator;
|
|
2757
2910
|
}
|
|
2758
|
-
iterator(callback) {
|
|
2911
|
+
iterator(callback, direction = "normal") {
|
|
2759
2912
|
this.__entryIterator = undefined;
|
|
2913
|
+
const entryIterator = this.entryIterator(direction);
|
|
2760
2914
|
return () => {
|
|
2761
|
-
callback([
|
|
2762
|
-
|
|
2915
|
+
callback([entryIterator]);
|
|
2916
|
+
entryIterator.remove();
|
|
2763
2917
|
};
|
|
2764
2918
|
}
|
|
2765
|
-
|
|
2766
|
-
return this.entryIterator._toMinecraftCondition();
|
|
2919
|
+
continue(direction = "normal") {
|
|
2920
|
+
return this.entryIterator(direction)._toMinecraftCondition();
|
|
2767
2921
|
}
|
|
2768
2922
|
size = () => this.dataPoint;
|
|
2769
2923
|
last = () => this.dataPoint.select("[-1]");
|
|
@@ -2845,7 +2999,11 @@ var init_JSONTextComponentClass = __esm(() => {
|
|
|
2845
2999
|
this.jsonTextComponent = jsonTextComponent;
|
|
2846
3000
|
}
|
|
2847
3001
|
toString() {
|
|
2848
|
-
|
|
3002
|
+
const component = toComponent(this.jsonTextComponent);
|
|
3003
|
+
if (typeof component === "string") {
|
|
3004
|
+
return `"${component}"`;
|
|
3005
|
+
}
|
|
3006
|
+
return JSON.stringify(component, function(key, value) {
|
|
2849
3007
|
if (Array.isArray(this)) {
|
|
2850
3008
|
const realValue = this[Number.parseInt(key, 10)];
|
|
2851
3009
|
return toComponent(realValue);
|
|
@@ -3060,14 +3218,52 @@ var init_Label = __esm(() => {
|
|
|
3060
3218
|
LabelClass = makeClassCallable(_RawLabelClass);
|
|
3061
3219
|
});
|
|
3062
3220
|
|
|
3221
|
+
// src/commands/implementations/server/function.ts
|
|
3222
|
+
var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
|
|
3223
|
+
var init_function = __esm(() => {
|
|
3224
|
+
init_nodes();
|
|
3225
|
+
init_tag();
|
|
3226
|
+
init_NBTs();
|
|
3227
|
+
FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
|
|
3228
|
+
FunctionCommandNode = class FunctionCommandNode extends CommandNode {
|
|
3229
|
+
[FUNCTION_COMMAND_NODE_BRAND] = true;
|
|
3230
|
+
command = "function";
|
|
3231
|
+
static [Symbol.hasInstance](instance) {
|
|
3232
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
FunctionCommand = class FunctionCommand extends CommandArguments {
|
|
3236
|
+
NodeType = FunctionCommandNode;
|
|
3237
|
+
function(mcFunction, params, pointOrType, target, path) {
|
|
3238
|
+
const args = [];
|
|
3239
|
+
if (params) {
|
|
3240
|
+
if (params === "with" && pointOrType) {
|
|
3241
|
+
args.push("with");
|
|
3242
|
+
if (typeof pointOrType === "string") {
|
|
3243
|
+
args.push(pointOrType, target, path ?? "{}");
|
|
3244
|
+
} else {
|
|
3245
|
+
const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
|
|
3246
|
+
args.push(point.type, point.currentTarget, point.path);
|
|
3247
|
+
}
|
|
3248
|
+
} else {
|
|
3249
|
+
args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
|
|
3253
|
+
}
|
|
3254
|
+
};
|
|
3255
|
+
});
|
|
3256
|
+
|
|
3063
3257
|
// src/variables/Loop.ts
|
|
3064
3258
|
var LOOP_ARGUMENT_BRAND, LoopArgument;
|
|
3065
3259
|
var init_Loop = __esm(() => {
|
|
3260
|
+
init_function();
|
|
3066
3261
|
init_nodes();
|
|
3067
3262
|
LOOP_ARGUMENT_BRAND = Symbol.for("sandstone.LoopArgument");
|
|
3068
3263
|
LoopArgument = class LoopArgument extends Node {
|
|
3069
3264
|
pack;
|
|
3070
3265
|
[LOOP_ARGUMENT_BRAND] = true;
|
|
3266
|
+
loopIfNode = null;
|
|
3071
3267
|
constructor(pack) {
|
|
3072
3268
|
super(pack.core);
|
|
3073
3269
|
this.pack = pack;
|
|
@@ -3077,7 +3273,15 @@ var init_Loop = __esm(() => {
|
|
|
3077
3273
|
return this.toLoop();
|
|
3078
3274
|
}
|
|
3079
3275
|
toLoop() {
|
|
3080
|
-
|
|
3276
|
+
const loopExecute = this.loopIfNode?.resultingExecuteNode;
|
|
3277
|
+
if (loopExecute?.createdMCFunction) {
|
|
3278
|
+
const funcNode = new FunctionCommandNode(this.pack, loopExecute.createdMCFunction.name);
|
|
3279
|
+
if (loopExecute.macroStorage) {
|
|
3280
|
+
funcNode.args.push("with", "storage", loopExecute.macroStorage.currentTarget, loopExecute.macroStorage.path);
|
|
3281
|
+
}
|
|
3282
|
+
return funcNode.getValue();
|
|
3283
|
+
}
|
|
3284
|
+
return new FunctionCommandNode(this.pack, this.pack.core.currentNode);
|
|
3081
3285
|
}
|
|
3082
3286
|
static [Symbol.hasInstance](instance) {
|
|
3083
3287
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[LOOP_ARGUMENT_BRAND] === true;
|
|
@@ -3117,7 +3321,6 @@ var init_Objective = __esm(() => {
|
|
|
3117
3321
|
return formatDebugString(this.constructor.name, {
|
|
3118
3322
|
name: this.name,
|
|
3119
3323
|
criteria: this.criteria,
|
|
3120
|
-
display: this.display,
|
|
3121
3324
|
creator: this.creator
|
|
3122
3325
|
}, undefined, options.indent);
|
|
3123
3326
|
}
|
|
@@ -3314,13 +3517,13 @@ var init_Sleep = __esm(() => {
|
|
|
3314
3517
|
const { execute } = commands;
|
|
3315
3518
|
const name = `__sandstone:asyncTimer.${currentFunction.resource.name.replace(/[:/]/g, ".")}`;
|
|
3316
3519
|
const timer = new ObjectiveClass(core.pack, name.replace(":", "."), "dummy", undefined, { creator: "sandstone" });
|
|
3317
|
-
execute.store.result
|
|
3520
|
+
execute.store.result(timer("@s")).run.time.query("gametime");
|
|
3318
3521
|
timer("@s").add(Duration);
|
|
3319
3522
|
const label = Label(name);
|
|
3320
3523
|
label("@s").add();
|
|
3321
3524
|
this.mcfunction.unshift(() => label("@s").remove());
|
|
3322
3525
|
schedule = MCFunction(`${this.mcfunction.name}/_context`, () => {
|
|
3323
|
-
execute.store.result
|
|
3526
|
+
execute.store.result(timer("#current")).run.time.query("gametime");
|
|
3324
3527
|
execute.as(Selector("@e", { tag: label.fullName })).if.score(timer("@s"), "=", timer("#current")).at("@s").run.functionCmd(this.mcfunction);
|
|
3325
3528
|
}, {
|
|
3326
3529
|
packType: currentFunction.resource.packType
|
|
@@ -3405,7 +3608,7 @@ var init_mcfunction = __esm(() => {
|
|
|
3405
3608
|
return this.body.filter((node) => node.getValue() !== null).map((node) => node.getValue()).join(`
|
|
3406
3609
|
`);
|
|
3407
3610
|
};
|
|
3408
|
-
[util10.inspect.custom](
|
|
3611
|
+
[util10.inspect.custom](_depth, options) {
|
|
3409
3612
|
return formatDebugString(this.constructor.name, {
|
|
3410
3613
|
name: this.resource.name
|
|
3411
3614
|
}, this.body, options.indent);
|
|
@@ -3421,6 +3624,7 @@ var init_mcfunction = __esm(() => {
|
|
|
3421
3624
|
tags;
|
|
3422
3625
|
lazy;
|
|
3423
3626
|
env;
|
|
3627
|
+
macroPoint;
|
|
3424
3628
|
constructor(core, name, args, env) {
|
|
3425
3629
|
if (name.startsWith("./")) {
|
|
3426
3630
|
const currentMCFunctionName = core.currentMCFunction?.resource.name;
|
|
@@ -3443,11 +3647,16 @@ var init_mcfunction = __esm(() => {
|
|
|
3443
3647
|
this.lazy = !!args.lazy;
|
|
3444
3648
|
this.addToSandstoneCore = !!args.addToSandstoneCore;
|
|
3445
3649
|
this.tags = args.tags;
|
|
3446
|
-
if (env) {
|
|
3650
|
+
if (env && env.length !== 0) {
|
|
3447
3651
|
this.env = env;
|
|
3448
3652
|
}
|
|
3653
|
+
if (this.env || this.callback.length > 1) {
|
|
3654
|
+
this.macroPoint = core.pack.DataVariable();
|
|
3655
|
+
} else {
|
|
3656
|
+
this.macroPoint = undefined;
|
|
3657
|
+
}
|
|
3449
3658
|
if (args.runOnLoad) {
|
|
3450
|
-
if (env) {
|
|
3659
|
+
if (this.env) {
|
|
3451
3660
|
core.pack.loadTags.load.push(core.pack.MCFunction(`load_${this.name.split(":")[1]}`, () => {
|
|
3452
3661
|
this.__call__();
|
|
3453
3662
|
}));
|
|
@@ -3501,21 +3710,25 @@ var init_mcfunction = __esm(() => {
|
|
|
3501
3710
|
__call__ = (..._params) => {
|
|
3502
3711
|
if (this.env || _params.length !== 0) {
|
|
3503
3712
|
const args = {};
|
|
3713
|
+
if (this.env) {
|
|
3714
|
+
for (const [i, env] of this.env.entries()) {
|
|
3715
|
+
args[`env_${i}`] = ResolveNBTPart(env);
|
|
3716
|
+
env.local.set(this.name, `env_${i}`);
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3504
3719
|
if (_params.length !== 0) {
|
|
3505
3720
|
for (const [i, param] of _params.entries()) {
|
|
3506
3721
|
args[`param_${i}`] = ResolveNBTPart(param);
|
|
3507
3722
|
param.local.set(this.name, `param_${i}`);
|
|
3508
3723
|
}
|
|
3509
3724
|
this.node.body = [];
|
|
3725
|
+
this.core.enterMCFunction(this);
|
|
3510
3726
|
this.core.insideContext(this.node, () => this.callback(makeCallable(this, this.__call__.bind(undefined, ..._params)), ..._params), false);
|
|
3727
|
+
this.core.exitMCFunction();
|
|
3728
|
+
} else if (this.callback.length > 1) {
|
|
3729
|
+
throw new Error(`[MCFunctionClass] Function ${this.name} expects ${this.callback.length - 1} params at the call-site`);
|
|
3511
3730
|
}
|
|
3512
|
-
|
|
3513
|
-
for (const [i, env] of this.env.entries()) {
|
|
3514
|
-
args[`env_${i}`] = ResolveNBTPart(env);
|
|
3515
|
-
env.local.set(this.name, `env_${i}`);
|
|
3516
|
-
}
|
|
3517
|
-
}
|
|
3518
|
-
return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args).dataPoint);
|
|
3731
|
+
return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args, this.macroPoint).dataPoint);
|
|
3519
3732
|
}
|
|
3520
3733
|
return this.commands.functionCmd(this.name);
|
|
3521
3734
|
};
|
|
@@ -3545,12 +3758,14 @@ var init_mcfunction = __esm(() => {
|
|
|
3545
3758
|
});
|
|
3546
3759
|
if (contents[0] instanceof _RawMCFunctionClass) {
|
|
3547
3760
|
for (const mcfunction of contents) {
|
|
3761
|
+
mcfunction.generate();
|
|
3548
3762
|
this.node.body.unshift(...mcfunction.node.body);
|
|
3549
3763
|
}
|
|
3550
3764
|
} else {
|
|
3551
3765
|
this.core.enterMCFunction(fake);
|
|
3552
3766
|
this.core.insideContext(fake.node, contents[0], false);
|
|
3553
3767
|
this.core.exitMCFunction();
|
|
3768
|
+
fake.generate();
|
|
3554
3769
|
this.node.body.unshift(...fake.node.body);
|
|
3555
3770
|
}
|
|
3556
3771
|
}
|
|
@@ -3563,12 +3778,14 @@ var init_mcfunction = __esm(() => {
|
|
|
3563
3778
|
const fullBody = [];
|
|
3564
3779
|
if (contents[0] instanceof _RawMCFunctionClass) {
|
|
3565
3780
|
for (const mcfunction of contents) {
|
|
3781
|
+
mcfunction.generate();
|
|
3566
3782
|
fullBody.push(...mcfunction.node.body);
|
|
3567
3783
|
}
|
|
3568
3784
|
} else {
|
|
3569
3785
|
this.core.enterMCFunction(fake);
|
|
3570
3786
|
this.core.insideContext(fake.node, contents[0], false);
|
|
3571
3787
|
this.core.exitMCFunction();
|
|
3788
|
+
fake.generate();
|
|
3572
3789
|
fullBody.push(...fake.node.body);
|
|
3573
3790
|
}
|
|
3574
3791
|
this.node.body.splice(start, removeItems === "auto" ? fullBody.length : removeItems, ...fullBody);
|
|
@@ -3656,42 +3873,6 @@ var init_setblock = __esm(() => {
|
|
|
3656
3873
|
};
|
|
3657
3874
|
});
|
|
3658
3875
|
|
|
3659
|
-
// src/commands/implementations/server/function.ts
|
|
3660
|
-
var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
|
|
3661
|
-
var init_function = __esm(() => {
|
|
3662
|
-
init_nodes();
|
|
3663
|
-
init_tag();
|
|
3664
|
-
init_NBTs();
|
|
3665
|
-
FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
|
|
3666
|
-
FunctionCommandNode = class FunctionCommandNode extends CommandNode {
|
|
3667
|
-
[FUNCTION_COMMAND_NODE_BRAND] = true;
|
|
3668
|
-
command = "function";
|
|
3669
|
-
static [Symbol.hasInstance](instance) {
|
|
3670
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
|
|
3671
|
-
}
|
|
3672
|
-
};
|
|
3673
|
-
FunctionCommand = class FunctionCommand extends CommandArguments {
|
|
3674
|
-
NodeType = FunctionCommandNode;
|
|
3675
|
-
function(mcFunction, params, pointOrType, target, path) {
|
|
3676
|
-
const args = [];
|
|
3677
|
-
if (params) {
|
|
3678
|
-
if (params === "with" && pointOrType) {
|
|
3679
|
-
args.push("with");
|
|
3680
|
-
if (typeof pointOrType === "string") {
|
|
3681
|
-
args.push(pointOrType, target, path ?? "{}");
|
|
3682
|
-
} else {
|
|
3683
|
-
const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
|
|
3684
|
-
args.push(point.type, point.currentTarget, point.path);
|
|
3685
|
-
}
|
|
3686
|
-
} else {
|
|
3687
|
-
args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
|
|
3688
|
-
}
|
|
3689
|
-
}
|
|
3690
|
-
return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
|
|
3691
|
-
}
|
|
3692
|
-
};
|
|
3693
|
-
});
|
|
3694
|
-
|
|
3695
3876
|
// src/commands/implementations/entity/execute.ts
|
|
3696
3877
|
function createDeferredMacroExecute(pack, executeChain, options) {
|
|
3697
3878
|
const { childFunctionName, prependArgs } = options;
|
|
@@ -3714,7 +3895,7 @@ function createDeferredMacroExecute(pack, executeChain, options) {
|
|
|
3714
3895
|
childFunctionNode = childFunction.node;
|
|
3715
3896
|
} else {
|
|
3716
3897
|
const childFunction = pack.MCFunction(`${currentFunction.resource.name}/${childFunctionName}`, () => {}, { creator: "sandstone", onConflict: "rename" });
|
|
3717
|
-
pack.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage);
|
|
3898
|
+
pack.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage.currentTarget, options.macroStorage.path);
|
|
3718
3899
|
childFunctionNode = childFunction.node;
|
|
3719
3900
|
}
|
|
3720
3901
|
childFunctionNode.body.push(macroNode);
|
|
@@ -3798,15 +3979,15 @@ var init_execute = __esm(() => {
|
|
|
3798
3979
|
isSingleExecute;
|
|
3799
3980
|
givenCallbackName;
|
|
3800
3981
|
macroStorage;
|
|
3801
|
-
|
|
3982
|
+
pendingCommit;
|
|
3983
|
+
createdMCFunction = null;
|
|
3984
|
+
constructor(sandstonePack, args = [], { isFake = false, isSingleExecute = true, givenCallbackName = undefined, body = [], macroStorage = undefined, pendingCommit = false } = {}) {
|
|
3802
3985
|
super(sandstonePack, ...args);
|
|
3803
3986
|
this.givenCallbackName = givenCallbackName;
|
|
3804
3987
|
this.isSingleExecute = isSingleExecute;
|
|
3805
3988
|
this.isFake = isFake;
|
|
3806
3989
|
this.macroStorage = macroStorage;
|
|
3807
|
-
|
|
3808
|
-
this.isMacro = true;
|
|
3809
|
-
}
|
|
3990
|
+
this.pendingCommit = pendingCommit;
|
|
3810
3991
|
this.append(...body);
|
|
3811
3992
|
}
|
|
3812
3993
|
get callbackName() {
|
|
@@ -3817,6 +3998,9 @@ var init_execute = __esm(() => {
|
|
|
3817
3998
|
this.body.push(node);
|
|
3818
3999
|
if (this.isSingleExecute) {
|
|
3819
4000
|
this.sandstoneCore.getCurrentMCFunctionOrThrow().exitContext();
|
|
4001
|
+
if (this.pendingCommit && !this.commited) {
|
|
4002
|
+
this.commit();
|
|
4003
|
+
}
|
|
3820
4004
|
}
|
|
3821
4005
|
}
|
|
3822
4006
|
return nodes.length === 1 ? nodes[0] : nodes;
|
|
@@ -3865,9 +4049,10 @@ var init_execute = __esm(() => {
|
|
|
3865
4049
|
});
|
|
3866
4050
|
const mcFunctionNode = mcFunction.node;
|
|
3867
4051
|
mcFunctionNode.body = this.body;
|
|
4052
|
+
this.createdMCFunction = mcFunction;
|
|
3868
4053
|
const mcFunctionCall = new FunctionCommandNode(this.sandstonePack, mcFunction);
|
|
3869
4054
|
if (this.macroStorage) {
|
|
3870
|
-
mcFunctionCall.args.push("with", "storage", this.macroStorage,
|
|
4055
|
+
mcFunctionCall.args.push("with", "storage", this.macroStorage.currentTarget, this.macroStorage.path);
|
|
3871
4056
|
}
|
|
3872
4057
|
this.body = [mcFunctionCall];
|
|
3873
4058
|
return { node: this, mcFunction: mcFunctionNode };
|
|
@@ -3880,20 +4065,30 @@ var init_execute = __esm(() => {
|
|
|
3880
4065
|
block = (targetPos, path, type, scale) => this.nestedExecute(["block", coordinatesParser(targetPos), path, type, scale]);
|
|
3881
4066
|
bossbar = (id2, type) => this.nestedExecute(["bossbar", id2, type]);
|
|
3882
4067
|
entity = (target, path, type, scale) => this.nestedExecute(["entity", targetParser(target), path, type, scale]);
|
|
3883
|
-
score(
|
|
3884
|
-
if (isScore(args[0])) {
|
|
3885
|
-
return this.nestedExecute(["score", args[0]]);
|
|
3886
|
-
}
|
|
3887
|
-
return this.nestedExecute(["score", targetParser(args[0]), args[1]]);
|
|
3888
|
-
}
|
|
4068
|
+
score = (targets, objective) => this.nestedExecute(["score", targetParser(targets), objective]);
|
|
3889
4069
|
storage = (target, path, type, scale = 1) => this.nestedExecute(["storage", target, path, type, scale]);
|
|
3890
4070
|
};
|
|
3891
4071
|
ExecuteStoreCommand = class ExecuteStoreCommand extends ExecuteCommandPart {
|
|
4072
|
+
_storeCallable(cmd, target, type, scale) {
|
|
4073
|
+
if (isScore(target)) {
|
|
4074
|
+
return cmd.score(target.target, target.objective);
|
|
4075
|
+
}
|
|
4076
|
+
const resolvedType = type ?? "int";
|
|
4077
|
+
if (target.type === "block") {
|
|
4078
|
+
return cmd.block(coordinatesParser(target.currentTarget), target.path, resolvedType, scale);
|
|
4079
|
+
}
|
|
4080
|
+
if (target.type === "entity") {
|
|
4081
|
+
return cmd.entity(target.currentTarget, target.path, resolvedType, scale);
|
|
4082
|
+
}
|
|
4083
|
+
return cmd.storage(target.currentTarget, target.path, resolvedType, scale);
|
|
4084
|
+
}
|
|
3892
4085
|
get result() {
|
|
3893
|
-
|
|
4086
|
+
const cmd = this.subCommand([["result"]], ExecuteStoreArgsCommand, false);
|
|
4087
|
+
return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
|
|
3894
4088
|
}
|
|
3895
4089
|
get success() {
|
|
3896
|
-
|
|
4090
|
+
const cmd = this.subCommand([["success"]], ExecuteStoreArgsCommand, false);
|
|
4091
|
+
return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
|
|
3897
4092
|
}
|
|
3898
4093
|
};
|
|
3899
4094
|
ExecuteDataArgsCommand = class ExecuteDataArgsCommand extends ExecuteCommandPart {
|
|
@@ -4018,6 +4213,9 @@ var init_execute = __esm(() => {
|
|
|
4018
4213
|
const node = this.getNode();
|
|
4019
4214
|
const commands = new Proxy(this.sandstonePack.commands, {
|
|
4020
4215
|
get: (_t, p, _r) => {
|
|
4216
|
+
if (!node.commited) {
|
|
4217
|
+
node.pendingCommit = true;
|
|
4218
|
+
}
|
|
4021
4219
|
this.sandstoneCore.getCurrentMCFunctionOrThrow().enterContext(node, false);
|
|
4022
4220
|
return this.sandstonePack.commands[p];
|
|
4023
4221
|
}
|
|
@@ -4028,7 +4226,7 @@ var init_execute = __esm(() => {
|
|
|
4028
4226
|
node.givenCallbackName = args[0];
|
|
4029
4227
|
}
|
|
4030
4228
|
node.isSingleExecute = false;
|
|
4031
|
-
this.sandstoneCore.insideContext(node, callback,
|
|
4229
|
+
this.sandstoneCore.insideContext(node, callback, !node.commited);
|
|
4032
4230
|
return new FinalCommandOutput(node);
|
|
4033
4231
|
}, true);
|
|
4034
4232
|
}
|
|
@@ -4248,7 +4446,7 @@ class UUIDClass {
|
|
|
4248
4446
|
}
|
|
4249
4447
|
if (this.data || this.scores) {
|
|
4250
4448
|
const pack = this.core.pack;
|
|
4251
|
-
const { MCFunction, getTempStorage, commands: commands2 } = pack;
|
|
4449
|
+
const { MCFunction, getTempStorage, commands: commands2, Macro, Data } = pack;
|
|
4252
4450
|
const { data } = commands2;
|
|
4253
4451
|
let sourceData = this.data;
|
|
4254
4452
|
if (!sourceData && this.scores) {
|
|
@@ -4262,15 +4460,15 @@ class UUIDClass {
|
|
|
4262
4460
|
tempUUID.set(sourceData);
|
|
4263
4461
|
const cacheKeyVar = this.primarySource === "scores" && this.scores ? this.scores[0] : tempUUID;
|
|
4264
4462
|
const currentFunction = this.core.getCurrentMCFunctionOrThrow();
|
|
4265
|
-
const
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4463
|
+
const uuidLookup = Data("storage", "__sandstone:temp", "uuid_lookup");
|
|
4464
|
+
MCFunction(`${currentFunction.resource.name}/__uuid_lookup`, [cacheKeyVar], () => {
|
|
4465
|
+
Macro.data.modify(uuidLookup.select("uuid_string")).set.from.storage(UUID_CACHE.STORAGE, Macro`"${cacheKeyVar}"`);
|
|
4466
|
+
}, { creator: "sandstone", onConflict: "rename" })();
|
|
4269
4467
|
const deferredExecute = new ExecuteCommand(pack, undefined, false);
|
|
4270
4468
|
return createDeferredMacroExecute(pack, deferredExecute, {
|
|
4271
4469
|
childFunctionName: "__uuid_execute",
|
|
4272
4470
|
prependArgs: () => [["as", "$(uuid_string)"]],
|
|
4273
|
-
macroStorage:
|
|
4471
|
+
macroStorage: uuidLookup
|
|
4274
4472
|
});
|
|
4275
4473
|
}
|
|
4276
4474
|
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.");
|
|
@@ -5295,7 +5493,7 @@ var init_reload = __esm(() => {
|
|
|
5295
5493
|
});
|
|
5296
5494
|
|
|
5297
5495
|
// src/commands/implementations/server/return.ts
|
|
5298
|
-
var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, ReturnCommandNode, ReturnCommand;
|
|
5496
|
+
var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, RETURN_COMMAND_NODE_BRAND, ReturnCommandNode, ReturnCommand;
|
|
5299
5497
|
var init_return = __esm(() => {
|
|
5300
5498
|
init_nodes();
|
|
5301
5499
|
init_utils();
|
|
@@ -5305,9 +5503,11 @@ var init_return = __esm(() => {
|
|
|
5305
5503
|
[RETURN_RUN_COMMAND_NODE_BRAND] = true;
|
|
5306
5504
|
command = "return";
|
|
5307
5505
|
isSingleExecute;
|
|
5308
|
-
|
|
5506
|
+
isFlowControl;
|
|
5507
|
+
constructor(sandstonePack, args = [], { isSingleExecute = true, body = [], isFlowControl = false } = {}) {
|
|
5309
5508
|
super(sandstonePack, ...args);
|
|
5310
5509
|
this.isSingleExecute = isSingleExecute;
|
|
5510
|
+
this.isFlowControl = isFlowControl;
|
|
5311
5511
|
this.append(...body);
|
|
5312
5512
|
}
|
|
5313
5513
|
getValue = () => {
|
|
@@ -5367,8 +5567,13 @@ var init_return = __esm(() => {
|
|
|
5367
5567
|
}, true);
|
|
5368
5568
|
}
|
|
5369
5569
|
};
|
|
5570
|
+
RETURN_COMMAND_NODE_BRAND = Symbol.for("sandstone.ReturnCommandNode");
|
|
5370
5571
|
ReturnCommandNode = class ReturnCommandNode extends CommandNode {
|
|
5572
|
+
[RETURN_COMMAND_NODE_BRAND] = true;
|
|
5371
5573
|
command = "return";
|
|
5574
|
+
static [Symbol.hasInstance](instance) {
|
|
5575
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RETURN_COMMAND_NODE_BRAND] === true;
|
|
5576
|
+
}
|
|
5372
5577
|
};
|
|
5373
5578
|
ReturnCommand = class ReturnCommand extends CommandArguments {
|
|
5374
5579
|
NodeType = ReturnCommandNode;
|
|
@@ -5550,8 +5755,8 @@ var init_version = __esm(() => {
|
|
|
5550
5755
|
// src/commands/implementations/world/data.ts
|
|
5551
5756
|
var DataCommandNode, DataCommand, DataGetCommand, DataMergeCommand, DataModifyFromCommand, DataModifyValuesCommand, DataModifyTypeCommand, DataModifyCommand, DataRemoveCommand;
|
|
5552
5757
|
var init_data = __esm(() => {
|
|
5553
|
-
init_core();
|
|
5554
5758
|
init_nodes();
|
|
5759
|
+
init_utils();
|
|
5555
5760
|
init_NBTs();
|
|
5556
5761
|
init_parsers();
|
|
5557
5762
|
DataCommandNode = class DataCommandNode extends CommandNode {
|
|
@@ -5560,22 +5765,55 @@ var init_data = __esm(() => {
|
|
|
5560
5765
|
DataCommand = class DataCommand extends CommandArguments {
|
|
5561
5766
|
NodeType = DataCommandNode;
|
|
5562
5767
|
get get() {
|
|
5563
|
-
|
|
5768
|
+
const cmd = this.subCommand(["get"], DataGetCommand, false);
|
|
5769
|
+
return makeCallable(cmd, (dataPoint, scale) => {
|
|
5770
|
+
if (dataPoint.type === "block") {
|
|
5771
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path, scale);
|
|
5772
|
+
}
|
|
5773
|
+
if (dataPoint.type === "entity") {
|
|
5774
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path, scale);
|
|
5775
|
+
}
|
|
5776
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path, scale);
|
|
5777
|
+
});
|
|
5564
5778
|
}
|
|
5565
5779
|
get merge() {
|
|
5566
5780
|
return this.subCommand(["merge"], DataMergeCommand, false);
|
|
5567
5781
|
}
|
|
5568
5782
|
get modify() {
|
|
5569
|
-
|
|
5783
|
+
const cmd = this.subCommand(["modify"], DataModifyCommand, false);
|
|
5784
|
+
return makeCallable(cmd, (dataPoint) => {
|
|
5785
|
+
if (dataPoint.type === "block") {
|
|
5786
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
|
|
5787
|
+
}
|
|
5788
|
+
if (dataPoint.type === "entity") {
|
|
5789
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path);
|
|
5790
|
+
}
|
|
5791
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path);
|
|
5792
|
+
});
|
|
5570
5793
|
}
|
|
5571
5794
|
get remove() {
|
|
5572
|
-
|
|
5795
|
+
const cmd = this.subCommand(["remove"], DataRemoveCommand, false);
|
|
5796
|
+
return makeCallable(cmd, (dataPoint) => {
|
|
5797
|
+
if (dataPoint.type === "block") {
|
|
5798
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
|
|
5799
|
+
}
|
|
5800
|
+
if (dataPoint.type === "entity") {
|
|
5801
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path);
|
|
5802
|
+
}
|
|
5803
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path);
|
|
5804
|
+
});
|
|
5573
5805
|
}
|
|
5574
5806
|
};
|
|
5575
5807
|
DataGetCommand = class DataGetCommand extends CommandArguments {
|
|
5576
|
-
block = (targetPos, path, scale) =>
|
|
5577
|
-
|
|
5578
|
-
|
|
5808
|
+
block = (targetPos, path, scale) => {
|
|
5809
|
+
return this.finalCommand(["block", coordinatesParser(targetPos), path, scale]);
|
|
5810
|
+
};
|
|
5811
|
+
entity = (target, path, scale) => {
|
|
5812
|
+
return this.finalCommand(["entity", targetParser(target), path, scale]);
|
|
5813
|
+
};
|
|
5814
|
+
storage = (target, path, scale) => {
|
|
5815
|
+
return this.finalCommand(["storage", target, path, scale]);
|
|
5816
|
+
};
|
|
5579
5817
|
};
|
|
5580
5818
|
DataMergeCommand = class DataMergeCommand extends CommandArguments {
|
|
5581
5819
|
block = (targetPos, nbt2) => this.finalCommand(["block", coordinatesParser(targetPos), nbtStringifier(nbt2)]);
|
|
@@ -5585,20 +5823,22 @@ var init_data = __esm(() => {
|
|
|
5585
5823
|
DataModifyFromCommand = class DataModifyFromCommand extends CommandArguments {
|
|
5586
5824
|
block = (sourcePosition, sourcePath) => this.finalCommand(["block", coordinatesParser(sourcePosition), sourcePath]);
|
|
5587
5825
|
entity = (source, sourcePath) => this.finalCommand(["entity", targetParser(source), sourcePath]);
|
|
5588
|
-
storage(source, sourcePath) {
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
storageArg = source;
|
|
5592
|
-
} else {
|
|
5593
|
-
const dataPoint = source;
|
|
5594
|
-
storageArg = `${dataPoint.currentTarget} ${dataPoint.path}`;
|
|
5595
|
-
}
|
|
5596
|
-
return this.finalCommand(["storage", storageArg, sourcePath]);
|
|
5597
|
-
}
|
|
5826
|
+
storage = (source, sourcePath) => {
|
|
5827
|
+
return this.finalCommand(["storage", source, sourcePath]);
|
|
5828
|
+
};
|
|
5598
5829
|
};
|
|
5599
5830
|
DataModifyValuesCommand = class DataModifyValuesCommand extends CommandArguments {
|
|
5600
5831
|
get from() {
|
|
5601
|
-
|
|
5832
|
+
const cmd = this.subCommand(["from"], DataModifyFromCommand, false);
|
|
5833
|
+
return makeCallable(cmd, (dataPoint) => {
|
|
5834
|
+
if (dataPoint.type === "block") {
|
|
5835
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
|
|
5836
|
+
}
|
|
5837
|
+
if (dataPoint.type === "entity") {
|
|
5838
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path);
|
|
5839
|
+
}
|
|
5840
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path);
|
|
5841
|
+
});
|
|
5602
5842
|
}
|
|
5603
5843
|
string = {
|
|
5604
5844
|
block: (sourcePosition, sourcePath, start, end) => {
|
|
@@ -5657,14 +5897,26 @@ var init_data = __esm(() => {
|
|
|
5657
5897
|
}
|
|
5658
5898
|
};
|
|
5659
5899
|
DataModifyCommand = class DataModifyCommand extends CommandArguments {
|
|
5660
|
-
block = (targetPos, targetPath) =>
|
|
5661
|
-
|
|
5662
|
-
|
|
5900
|
+
block = (targetPos, targetPath) => {
|
|
5901
|
+
return this.subCommand(["block", coordinatesParser(targetPos), targetPath], DataModifyTypeCommand, false);
|
|
5902
|
+
};
|
|
5903
|
+
entity = (target, targetPath) => {
|
|
5904
|
+
return this.subCommand(["entity", targetParser(target), targetPath], DataModifyTypeCommand, false);
|
|
5905
|
+
};
|
|
5906
|
+
storage = (target, targetPath) => {
|
|
5907
|
+
return this.subCommand(["storage", target, targetPath], DataModifyTypeCommand, false);
|
|
5908
|
+
};
|
|
5663
5909
|
};
|
|
5664
5910
|
DataRemoveCommand = class DataRemoveCommand extends CommandArguments {
|
|
5665
|
-
block = (targetPos, targetPath) =>
|
|
5666
|
-
|
|
5667
|
-
|
|
5911
|
+
block = (targetPos, targetPath) => {
|
|
5912
|
+
return this.finalCommand(["block", coordinatesParser(targetPos), targetPath]);
|
|
5913
|
+
};
|
|
5914
|
+
entity = (target, targetPath) => {
|
|
5915
|
+
return this.finalCommand(["entity", targetParser(target), targetPath]);
|
|
5916
|
+
};
|
|
5917
|
+
storage = (target, targetPath) => {
|
|
5918
|
+
return this.finalCommand(["storage", target, targetPath]);
|
|
5919
|
+
};
|
|
5668
5920
|
};
|
|
5669
5921
|
});
|
|
5670
5922
|
|
|
@@ -6375,6 +6627,10 @@ var init_visitor = __esm(() => {
|
|
|
6375
6627
|
visitIfNode;
|
|
6376
6628
|
visitElseNode;
|
|
6377
6629
|
visitLoopNode;
|
|
6630
|
+
visitSwitchNode;
|
|
6631
|
+
visitStaticCaseNode;
|
|
6632
|
+
visitConditionCaseNode;
|
|
6633
|
+
visitDefaultCaseNode;
|
|
6378
6634
|
visitLoopArgumentNode;
|
|
6379
6635
|
visitAdvancementCommandNode;
|
|
6380
6636
|
visitAttributeCommandNode;
|
|
@@ -6404,6 +6660,7 @@ var init_addAwaitBodyToMCFunctions = __esm(() => {
|
|
|
6404
6660
|
// src/pack/visitors/containerCommandsToMCFunction.ts
|
|
6405
6661
|
var ContainerCommandsToMCFunctionVisitor;
|
|
6406
6662
|
var init_containerCommandsToMCFunction = __esm(() => {
|
|
6663
|
+
init_commands2();
|
|
6407
6664
|
init_core();
|
|
6408
6665
|
init_visitor();
|
|
6409
6666
|
ContainerCommandsToMCFunctionVisitor = class ContainerCommandsToMCFunctionVisitor extends GenericSandstoneVisitor {
|
|
@@ -6423,6 +6680,14 @@ var init_containerCommandsToMCFunction = __esm(() => {
|
|
|
6423
6680
|
this.currentMCFunction = node;
|
|
6424
6681
|
this.core.currentNode = node.resource.name;
|
|
6425
6682
|
const result = this.genericVisit(node);
|
|
6683
|
+
if (node.resource.creator === "sandstone" && node.body.length > 0) {
|
|
6684
|
+
const lastNode = node.body.at(-1);
|
|
6685
|
+
if (lastNode instanceof FunctionCommandNode) {
|
|
6686
|
+
const returnRunNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
6687
|
+
returnRunNode.body = [lastNode];
|
|
6688
|
+
node.body[node.body.length - 1] = returnRunNode;
|
|
6689
|
+
}
|
|
6690
|
+
}
|
|
6426
6691
|
this.core.currentNode = prev?.resource.name ?? "";
|
|
6427
6692
|
this.currentMCFunction = prev;
|
|
6428
6693
|
return result;
|
|
@@ -6465,7 +6730,7 @@ function* flattenIfNode(node) {
|
|
|
6465
6730
|
yield next;
|
|
6466
6731
|
}
|
|
6467
6732
|
}
|
|
6468
|
-
function handleMultipleNodes(visitor, nodes) {
|
|
6733
|
+
function handleMultipleNodes(visitor, nodes, macroStorage) {
|
|
6469
6734
|
return nodes.flatMap((node, i) => {
|
|
6470
6735
|
const { body } = node;
|
|
6471
6736
|
if (node instanceof IfNode) {
|
|
@@ -6476,25 +6741,32 @@ function handleMultipleNodes(visitor, nodes) {
|
|
|
6476
6741
|
if (Array.isArray(child)) {
|
|
6477
6742
|
actualBody = child;
|
|
6478
6743
|
} else {
|
|
6479
|
-
return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6744
|
+
return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6480
6745
|
isSingleExecute: false,
|
|
6481
6746
|
givenCallbackName: callbackName,
|
|
6482
|
-
body: [i === nodes.length - 1 ? child : new
|
|
6483
|
-
|
|
6747
|
+
body: [i === nodes.length - 1 ? child : new ReturnRunCommandNode(visitor.pack, ["run"], {
|
|
6748
|
+
isSingleExecute: false,
|
|
6749
|
+
isFlowControl: true,
|
|
6750
|
+
body: [child]
|
|
6751
|
+
})],
|
|
6752
|
+
macroStorage
|
|
6753
|
+
}));
|
|
6484
6754
|
}
|
|
6485
6755
|
}
|
|
6486
|
-
return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6756
|
+
return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6487
6757
|
isSingleExecute: false,
|
|
6488
6758
|
givenCallbackName: `${i}_${callbackName}`,
|
|
6489
6759
|
body: [
|
|
6490
6760
|
new ReturnRunCommandNode(visitor.pack, ["run"], {
|
|
6491
6761
|
isSingleExecute: false,
|
|
6762
|
+
isFlowControl: true,
|
|
6492
6763
|
body: actualBody
|
|
6493
6764
|
})
|
|
6494
|
-
]
|
|
6495
|
-
|
|
6765
|
+
],
|
|
6766
|
+
macroStorage
|
|
6767
|
+
}));
|
|
6496
6768
|
}
|
|
6497
|
-
return body;
|
|
6769
|
+
return body.flatMap((n) => visitor.visit(n));
|
|
6498
6770
|
});
|
|
6499
6771
|
}
|
|
6500
6772
|
var IfElseTransformationVisitor;
|
|
@@ -6508,19 +6780,30 @@ var init_ifElseTransformationVisitor = __esm(() => {
|
|
|
6508
6780
|
return [];
|
|
6509
6781
|
}
|
|
6510
6782
|
const nodes = Array.from(flattenIfNode(node_));
|
|
6783
|
+
const { parentMCFunction, condition, givenCallbackName, body } = node_;
|
|
6784
|
+
const callbackName = givenCallbackName ?? "if";
|
|
6785
|
+
const macroStorage = parentMCFunction.resource.macroPoint;
|
|
6511
6786
|
if (nodes.length === 1) {
|
|
6512
|
-
|
|
6787
|
+
const executeNode = new ExecuteCommandNode(this.pack, [[condition.getValue()]], {
|
|
6513
6788
|
isSingleExecute: false,
|
|
6514
|
-
givenCallbackName:
|
|
6515
|
-
body
|
|
6516
|
-
|
|
6789
|
+
givenCallbackName: callbackName,
|
|
6790
|
+
body,
|
|
6791
|
+
macroStorage
|
|
6792
|
+
});
|
|
6793
|
+
node_.resultingExecuteNode = executeNode;
|
|
6794
|
+
return this.visit(executeNode);
|
|
6795
|
+
}
|
|
6796
|
+
if (nodes.at(-1) === parentMCFunction.body.at(-1)) {
|
|
6797
|
+
return handleMultipleNodes(this, nodes, macroStorage);
|
|
6517
6798
|
}
|
|
6518
6799
|
const wrapper = new ExecuteCommandNode(this.pack, [], {
|
|
6519
6800
|
isFake: true,
|
|
6520
6801
|
isSingleExecute: false,
|
|
6521
|
-
givenCallbackName:
|
|
6522
|
-
body: handleMultipleNodes(this, nodes)
|
|
6802
|
+
givenCallbackName: callbackName,
|
|
6803
|
+
body: handleMultipleNodes(this, nodes, macroStorage),
|
|
6804
|
+
macroStorage
|
|
6523
6805
|
});
|
|
6806
|
+
node_.resultingExecuteNode = wrapper;
|
|
6524
6807
|
return this.visit(wrapper);
|
|
6525
6808
|
};
|
|
6526
6809
|
};
|
|
@@ -6529,19 +6812,15 @@ var init_ifElseTransformationVisitor = __esm(() => {
|
|
|
6529
6812
|
// src/pack/visitors/initConstantsVisitor.ts
|
|
6530
6813
|
var InitConstantsVisitor;
|
|
6531
6814
|
var init_initConstantsVisitor = __esm(() => {
|
|
6815
|
+
init_commands2();
|
|
6532
6816
|
init_visitor();
|
|
6533
6817
|
InitConstantsVisitor = class InitConstantsVisitor extends GenericSandstoneVisitor {
|
|
6534
6818
|
onStart = () => {
|
|
6535
6819
|
const { pack } = this;
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
pack.initMCFunction.unshift(() => {
|
|
6541
|
-
for (const constant of constants) {
|
|
6542
|
-
scoreboard2.players.set(constant, pack.rootObjective, constant);
|
|
6543
|
-
}
|
|
6544
|
-
});
|
|
6820
|
+
if (pack.constants.size !== 0) {
|
|
6821
|
+
for (const constant of pack.constants) {
|
|
6822
|
+
pack.initMCFunction.node.body.push(new ScoreboardCommandNode(pack, "players", "set", constant, pack.rootObjective, constant));
|
|
6823
|
+
}
|
|
6545
6824
|
}
|
|
6546
6825
|
};
|
|
6547
6826
|
};
|
|
@@ -6617,15 +6896,24 @@ var init_inlineFunctionCallVisitor = __esm(() => {
|
|
|
6617
6896
|
// src/pack/visitors/loopTransformationVisitor.ts
|
|
6618
6897
|
var LoopTransformationVisitor;
|
|
6619
6898
|
var init_loopTransformationVisitor = __esm(() => {
|
|
6620
|
-
|
|
6899
|
+
init_flow();
|
|
6621
6900
|
init_visitor();
|
|
6622
6901
|
LoopTransformationVisitor = class LoopTransformationVisitor extends GenericSandstoneVisitor {
|
|
6902
|
+
currentLoopIfNode = null;
|
|
6623
6903
|
visitLoopNode = (node_) => {
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6904
|
+
const ifNode = new IfNode(this.core, node_.condition, undefined, node_.parentMCFunction);
|
|
6905
|
+
ifNode.givenCallbackName = "loop";
|
|
6906
|
+
const previousLoopIfNode = this.currentLoopIfNode;
|
|
6907
|
+
this.currentLoopIfNode = ifNode;
|
|
6908
|
+
ifNode.body = node_.body.flatMap((node) => this.visit(node));
|
|
6909
|
+
this.currentLoopIfNode = previousLoopIfNode;
|
|
6910
|
+
return ifNode;
|
|
6911
|
+
};
|
|
6912
|
+
visitLoopArgument = (node_) => {
|
|
6913
|
+
if (this.currentLoopIfNode) {
|
|
6914
|
+
node_.loopIfNode = this.currentLoopIfNode;
|
|
6915
|
+
}
|
|
6916
|
+
return node_;
|
|
6629
6917
|
};
|
|
6630
6918
|
visitWhileNode = this.visitLoopNode;
|
|
6631
6919
|
visitForINode = this.visitLoopNode;
|
|
@@ -6724,7 +7012,7 @@ var init_simplifyExecuteFunction = __esm(() => {
|
|
|
6724
7012
|
return this.genericVisit(node);
|
|
6725
7013
|
}
|
|
6726
7014
|
const mcFunction = functionNode.args[0];
|
|
6727
|
-
if (typeof mcFunction === "string") {
|
|
7015
|
+
if (typeof mcFunction === "string" || !mcFunction?.node) {
|
|
6728
7016
|
return this.genericVisit(node);
|
|
6729
7017
|
}
|
|
6730
7018
|
const mcFunctionNode = mcFunction.node;
|
|
@@ -6736,11 +7024,33 @@ var init_simplifyExecuteFunction = __esm(() => {
|
|
|
6736
7024
|
return this.genericVisit(node);
|
|
6737
7025
|
}
|
|
6738
7026
|
}
|
|
7027
|
+
if (command instanceof LoopArgument) {
|
|
7028
|
+
const loopExecute = command.loopIfNode?.resultingExecuteNode;
|
|
7029
|
+
const loopFunctionName = loopExecute?.createdMCFunction?.name;
|
|
7030
|
+
if (loopFunctionName) {
|
|
7031
|
+
node.body = [new FunctionCommandNode(this.pack, loopFunctionName)];
|
|
7032
|
+
if (mcFunction.creator === "sandstone") {
|
|
7033
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
7034
|
+
}
|
|
7035
|
+
return this.genericVisit(node);
|
|
7036
|
+
}
|
|
7037
|
+
return this.genericVisit(node);
|
|
7038
|
+
}
|
|
6739
7039
|
if (!(command instanceof CommandNode)) {
|
|
6740
7040
|
return this.genericVisit(node);
|
|
6741
7041
|
}
|
|
6742
|
-
if (command instanceof
|
|
6743
|
-
|
|
7042
|
+
if (command instanceof ReturnRunCommandNode) {
|
|
7043
|
+
if (mcFunction.creator === "sandstone") {
|
|
7044
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
7045
|
+
}
|
|
7046
|
+
if (command.isFlowControl) {
|
|
7047
|
+
node.body = [this.genericVisit(command)];
|
|
7048
|
+
} else {
|
|
7049
|
+
const returnCmd = this.visit(command);
|
|
7050
|
+
node.body = returnCmd.body;
|
|
7051
|
+
return this.visitExecuteCommandNode(node);
|
|
7052
|
+
}
|
|
7053
|
+
return this.genericVisit(node);
|
|
6744
7054
|
}
|
|
6745
7055
|
if (command instanceof FunctionCommandNode) {
|
|
6746
7056
|
const innerMCFunction = command.args[0];
|
|
@@ -6783,17 +7093,24 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6783
7093
|
init_nodes();
|
|
6784
7094
|
init_flow();
|
|
6785
7095
|
init_visitor();
|
|
7096
|
+
init_Macro();
|
|
6786
7097
|
SimplifyReturnRunFunctionVisitor = class SimplifyReturnRunFunctionVisitor extends GenericSandstoneVisitor {
|
|
6787
7098
|
visitReturnRunCommandNode = (node) => {
|
|
6788
7099
|
if (node.body.length === 0 || node.body.length > 1) {
|
|
6789
7100
|
return this.genericVisit(node);
|
|
6790
7101
|
}
|
|
6791
|
-
const
|
|
6792
|
-
if (!(
|
|
7102
|
+
const childNode = node.body[0];
|
|
7103
|
+
if (!(childNode instanceof FunctionCommandNode)) {
|
|
7104
|
+
if (childNode instanceof ReturnRunCommandNode) {
|
|
7105
|
+
return this.visitReturnRunCommandNode(childNode);
|
|
7106
|
+
}
|
|
7107
|
+
if (childNode instanceof ReturnCommandNode) {
|
|
7108
|
+
return this.genericVisit(childNode);
|
|
7109
|
+
}
|
|
6793
7110
|
return this.genericVisit(node);
|
|
6794
7111
|
}
|
|
6795
|
-
const mcFunction =
|
|
6796
|
-
if (typeof mcFunction === "string") {
|
|
7112
|
+
const mcFunction = childNode.args[0];
|
|
7113
|
+
if (typeof mcFunction === "string" || isMacroArgument(this.core, mcFunction)) {
|
|
6797
7114
|
return this.genericVisit(node);
|
|
6798
7115
|
}
|
|
6799
7116
|
const mcFunctionNode = mcFunction.node;
|
|
@@ -6809,10 +7126,6 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6809
7126
|
return this.genericVisit(node);
|
|
6810
7127
|
}
|
|
6811
7128
|
if (command instanceof FunctionCommandNode) {
|
|
6812
|
-
const innerMCFunction = command.args[0];
|
|
6813
|
-
if (typeof innerMCFunction === "string") {
|
|
6814
|
-
return this.genericVisit(node);
|
|
6815
|
-
}
|
|
6816
7129
|
node.body = [command];
|
|
6817
7130
|
if (mcFunction.creator === "sandstone") {
|
|
6818
7131
|
this.core.resourceNodes.delete(mcFunctionNode);
|
|
@@ -6820,7 +7133,18 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6820
7133
|
return this.genericVisit(node);
|
|
6821
7134
|
}
|
|
6822
7135
|
if (command instanceof ReturnRunCommandNode) {
|
|
6823
|
-
|
|
7136
|
+
node.body = command.body;
|
|
7137
|
+
node.isFlowControl = node.isFlowControl || command.isFlowControl;
|
|
7138
|
+
if (mcFunction.creator === "sandstone") {
|
|
7139
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
7140
|
+
}
|
|
7141
|
+
return this.visitReturnRunCommandNode(node);
|
|
7142
|
+
}
|
|
7143
|
+
if (command instanceof ReturnCommandNode) {
|
|
7144
|
+
if (mcFunction.creator === "sandstone") {
|
|
7145
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
7146
|
+
}
|
|
7147
|
+
return this.genericVisit(command);
|
|
6824
7148
|
}
|
|
6825
7149
|
node.body = [this.genericVisit(command)];
|
|
6826
7150
|
if (mcFunction.creator === "sandstone") {
|
|
@@ -6831,6 +7155,233 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6831
7155
|
};
|
|
6832
7156
|
});
|
|
6833
7157
|
|
|
7158
|
+
// src/pack/visitors/switchTransformationVisitor.ts
|
|
7159
|
+
var SwitchTransformationVisitor;
|
|
7160
|
+
var init_switchTransformationVisitor = __esm(() => {
|
|
7161
|
+
init_commands2();
|
|
7162
|
+
init_core();
|
|
7163
|
+
init_flow();
|
|
7164
|
+
init_variables();
|
|
7165
|
+
init_visitor();
|
|
7166
|
+
SwitchTransformationVisitor = class SwitchTransformationVisitor extends GenericSandstoneVisitor {
|
|
7167
|
+
visitSwitchNode = (node) => {
|
|
7168
|
+
const { value, staticCases, conditionCases, defaultCase, parentMCFunction } = node;
|
|
7169
|
+
const { Data: Data2, initMCFunction, Macro, commands: commands2 } = this.pack;
|
|
7170
|
+
const { functionCmd } = commands2;
|
|
7171
|
+
const parentName = parentMCFunction?.resource.name ?? "__sandstone:switch";
|
|
7172
|
+
const hasStaticCases = staticCases.length > 0;
|
|
7173
|
+
const switchMCFunction = new MCFunctionClass(this.core, `${parentName}/switch`, {
|
|
7174
|
+
addToSandstoneCore: true,
|
|
7175
|
+
creator: "sandstone",
|
|
7176
|
+
onConflict: "rename"
|
|
7177
|
+
}, hasStaticCases ? [value] : undefined);
|
|
7178
|
+
const storageKey = `__sandstone:${switchMCFunction.name.replace(/[:/]/g, "_")}`;
|
|
7179
|
+
const values = Data2("storage", storageKey, "Values");
|
|
7180
|
+
if (hasStaticCases) {
|
|
7181
|
+
const isScoreSwitch = value instanceof Score;
|
|
7182
|
+
if (typeof value.local?.set === "function") {
|
|
7183
|
+
value.local.set(switchMCFunction.name, "env_0");
|
|
7184
|
+
}
|
|
7185
|
+
this.core.enterMCFunction(switchMCFunction);
|
|
7186
|
+
if (isScoreSwitch) {
|
|
7187
|
+
for (const caseNode of staticCases) {
|
|
7188
|
+
const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${caseNode.value}`, {
|
|
7189
|
+
addToSandstoneCore: true,
|
|
7190
|
+
creator: "sandstone",
|
|
7191
|
+
onConflict: "rename"
|
|
7192
|
+
});
|
|
7193
|
+
caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
|
|
7194
|
+
}
|
|
7195
|
+
const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
|
|
7196
|
+
if (hasFallback) {
|
|
7197
|
+
const tryCaseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/try_case`, {
|
|
7198
|
+
addToSandstoneCore: true,
|
|
7199
|
+
creator: "sandstone",
|
|
7200
|
+
onConflict: "rename"
|
|
7201
|
+
});
|
|
7202
|
+
this.core.enterMCFunction(tryCaseMCFunction);
|
|
7203
|
+
Macro.returnCmd.run.functionCmd(Macro`${switchMCFunction.name}/case_${value}`);
|
|
7204
|
+
this.core.exitMCFunction();
|
|
7205
|
+
const successScore = this.pack.rootObjective("$switch_success");
|
|
7206
|
+
const resultScore = this.pack.rootObjective("$switch_result");
|
|
7207
|
+
commands2.execute.store.success(successScore).store.result(resultScore).run.functionCmd(tryCaseMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
7208
|
+
commands2.execute.if.score(successScore, "matches", 1).run.returnCmd.run.scoreboard.players.get(resultScore);
|
|
7209
|
+
this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
|
|
7210
|
+
} else {
|
|
7211
|
+
const dispatchMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/dispatch`, {
|
|
7212
|
+
addToSandstoneCore: true,
|
|
7213
|
+
creator: "sandstone",
|
|
7214
|
+
onConflict: "rename"
|
|
7215
|
+
});
|
|
7216
|
+
this.core.enterMCFunction(dispatchMCFunction);
|
|
7217
|
+
Macro.returnCmd.run.functionCmd(Macro`${switchMCFunction.name}/case_${value}`);
|
|
7218
|
+
this.core.exitMCFunction();
|
|
7219
|
+
commands2.returnCmd.run.functionCmd(dispatchMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
7220
|
+
}
|
|
7221
|
+
const macroPoint = switchMCFunction.macroPoint;
|
|
7222
|
+
const env0Point = macroPoint.select("env_0");
|
|
7223
|
+
commands2.execute.store.result.storage(env0Point.currentTarget, env0Point.path, "int").run.scoreboard.players.get(value);
|
|
7224
|
+
const copyNode = switchMCFunction.node.body.pop();
|
|
7225
|
+
switchMCFunction.node.body.unshift(copyNode);
|
|
7226
|
+
const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
7227
|
+
if (canInline) {
|
|
7228
|
+
this.core.exitMCFunction();
|
|
7229
|
+
this.core.resourceNodes.delete(switchMCFunction.node);
|
|
7230
|
+
return switchMCFunction.node.body;
|
|
7231
|
+
}
|
|
7232
|
+
} else {
|
|
7233
|
+
const index = switchMCFunction.macroPoint.select("Index");
|
|
7234
|
+
index.local.set(switchMCFunction.name, "Index");
|
|
7235
|
+
index.remove();
|
|
7236
|
+
Macro.data.modify.storage(index.currentTarget, index.path).set.from.storage(values.currentTarget, Macro`Values[{Value:${value}}].Index`);
|
|
7237
|
+
const caseData = [];
|
|
7238
|
+
for (let i = 0;i < staticCases.length; i++) {
|
|
7239
|
+
const caseNode = staticCases[i];
|
|
7240
|
+
const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${i}`, {
|
|
7241
|
+
addToSandstoneCore: true,
|
|
7242
|
+
creator: "sandstone",
|
|
7243
|
+
onConflict: "rename"
|
|
7244
|
+
});
|
|
7245
|
+
caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
|
|
7246
|
+
caseData.push({
|
|
7247
|
+
Value: caseNode.value,
|
|
7248
|
+
Index: NBT.int(i)
|
|
7249
|
+
});
|
|
7250
|
+
}
|
|
7251
|
+
initMCFunction.push(() => values.set(caseData));
|
|
7252
|
+
const innerMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/inner`, {
|
|
7253
|
+
addToSandstoneCore: true,
|
|
7254
|
+
creator: "sandstone",
|
|
7255
|
+
onConflict: "rename"
|
|
7256
|
+
});
|
|
7257
|
+
this.core.enterMCFunction(innerMCFunction);
|
|
7258
|
+
Macro.returnCmd.run.functionCmd(Macro`${switchMCFunction.name}/case_${index}`);
|
|
7259
|
+
this.core.exitMCFunction();
|
|
7260
|
+
const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
|
|
7261
|
+
if (hasFallback) {
|
|
7262
|
+
const ifNode = new IfNode(this.core, index._toMinecraftCondition(), undefined, switchMCFunction.node);
|
|
7263
|
+
switchMCFunction.node.enterContext(ifNode, false);
|
|
7264
|
+
functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
7265
|
+
switchMCFunction.node.exitContext();
|
|
7266
|
+
switchMCFunction.node.body.push(ifNode);
|
|
7267
|
+
this.buildFallback(ifNode, value, conditionCases, defaultCase, switchMCFunction);
|
|
7268
|
+
} else {
|
|
7269
|
+
this.pack.commands.execute.if.data.storage(index.currentTarget, index.path).run.returnCmd.run.functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
7270
|
+
}
|
|
7271
|
+
}
|
|
7272
|
+
this.core.exitMCFunction();
|
|
7273
|
+
} else {
|
|
7274
|
+
this.core.enterMCFunction(switchMCFunction);
|
|
7275
|
+
this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
|
|
7276
|
+
this.core.exitMCFunction();
|
|
7277
|
+
const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
7278
|
+
if (canInline) {
|
|
7279
|
+
this.core.resourceNodes.delete(switchMCFunction.node);
|
|
7280
|
+
for (const bodyNode of switchMCFunction.node.body) {
|
|
7281
|
+
if (bodyNode instanceof IfNode) {
|
|
7282
|
+
bodyNode.parentMCFunction = parentMCFunction;
|
|
7283
|
+
let lastIfNode = bodyNode;
|
|
7284
|
+
while (lastIfNode.nextFlowNode instanceof IfNode) {
|
|
7285
|
+
lastIfNode.nextFlowNode.parentMCFunction = parentMCFunction;
|
|
7286
|
+
lastIfNode = lastIfNode.nextFlowNode;
|
|
7287
|
+
}
|
|
7288
|
+
if (lastIfNode !== bodyNode) {
|
|
7289
|
+
switchMCFunction.node.body.push(lastIfNode);
|
|
7290
|
+
}
|
|
7291
|
+
}
|
|
7292
|
+
}
|
|
7293
|
+
return switchMCFunction.node.body;
|
|
7294
|
+
}
|
|
7295
|
+
}
|
|
7296
|
+
const isLastNode = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
7297
|
+
if (hasStaticCases && !(value instanceof Score)) {
|
|
7298
|
+
const macroPoint = switchMCFunction.macroPoint;
|
|
7299
|
+
const resolvedValue = value instanceof DataPointPickClass ? value._toDataPoint() : value;
|
|
7300
|
+
const env0Point = macroPoint.select("env_0");
|
|
7301
|
+
const copyNode = new DataCommandNode(this.pack);
|
|
7302
|
+
copyNode.args = [
|
|
7303
|
+
"modify",
|
|
7304
|
+
"storage",
|
|
7305
|
+
env0Point.currentTarget,
|
|
7306
|
+
env0Point.path,
|
|
7307
|
+
"set",
|
|
7308
|
+
"from",
|
|
7309
|
+
resolvedValue.type,
|
|
7310
|
+
resolvedValue.currentTarget,
|
|
7311
|
+
resolvedValue.path
|
|
7312
|
+
];
|
|
7313
|
+
const funcNode2 = new FunctionCommandNode(this.pack, switchMCFunction.name);
|
|
7314
|
+
funcNode2.args.push("with", macroPoint.type, macroPoint.currentTarget, macroPoint.path);
|
|
7315
|
+
if (isLastNode) {
|
|
7316
|
+
const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
7317
|
+
callNode.body = [funcNode2];
|
|
7318
|
+
return [copyNode, callNode].flatMap((n) => this.visit(n));
|
|
7319
|
+
}
|
|
7320
|
+
return [copyNode, funcNode2].flatMap((n) => this.visit(n));
|
|
7321
|
+
}
|
|
7322
|
+
const funcNode = new FunctionCommandNode(this.pack, switchMCFunction.name);
|
|
7323
|
+
if (isLastNode) {
|
|
7324
|
+
const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
7325
|
+
callNode.body = [funcNode];
|
|
7326
|
+
return this.visit(callNode);
|
|
7327
|
+
}
|
|
7328
|
+
return this.visit(funcNode);
|
|
7329
|
+
};
|
|
7330
|
+
buildFallback(_if, value, conditionCases, defaultCase, switchMCFunction, targetBody) {
|
|
7331
|
+
if (conditionCases.length === 0 && !defaultCase)
|
|
7332
|
+
return;
|
|
7333
|
+
const body = targetBody ?? switchMCFunction.node.body;
|
|
7334
|
+
if (conditionCases.length > 0) {
|
|
7335
|
+
const firstCondition = conditionCases[0].condition(value);
|
|
7336
|
+
const firstConditionNode = conditionToNode(firstCondition);
|
|
7337
|
+
let currentIfNode;
|
|
7338
|
+
if (_if === undefined) {
|
|
7339
|
+
currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
|
|
7340
|
+
currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
|
|
7341
|
+
body.push(currentIfNode);
|
|
7342
|
+
} else {
|
|
7343
|
+
currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
|
|
7344
|
+
currentIfNode._isElseIf = true;
|
|
7345
|
+
_if.nextFlowNode = currentIfNode;
|
|
7346
|
+
currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
|
|
7347
|
+
}
|
|
7348
|
+
for (let i = 1;i < conditionCases.length; i++) {
|
|
7349
|
+
const condition = conditionCases[i].condition(value);
|
|
7350
|
+
const conditionNode = conditionToNode(condition);
|
|
7351
|
+
const nextIfNode = new IfNode(this.core, conditionNode, undefined, switchMCFunction.node);
|
|
7352
|
+
nextIfNode._isElseIf = true;
|
|
7353
|
+
currentIfNode.nextFlowNode = nextIfNode;
|
|
7354
|
+
nextIfNode.body = conditionCases[i].body.flatMap((n) => this.visit(n));
|
|
7355
|
+
currentIfNode = nextIfNode;
|
|
7356
|
+
}
|
|
7357
|
+
if (defaultCase) {
|
|
7358
|
+
const elseNode = new ElseNode2(this.core, () => {});
|
|
7359
|
+
elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
|
|
7360
|
+
currentIfNode.nextFlowNode = elseNode;
|
|
7361
|
+
}
|
|
7362
|
+
} else if (defaultCase) {
|
|
7363
|
+
if (_if === undefined) {
|
|
7364
|
+
const visitedNodes = defaultCase.body.flatMap((n) => this.visit(n));
|
|
7365
|
+
body.push(...visitedNodes);
|
|
7366
|
+
} else {
|
|
7367
|
+
const elseNode = new ElseNode2(this.core, () => {});
|
|
7368
|
+
elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
|
|
7369
|
+
_if.nextFlowNode = elseNode;
|
|
7370
|
+
}
|
|
7371
|
+
}
|
|
7372
|
+
}
|
|
7373
|
+
visitStaticCaseNode = (_node) => {
|
|
7374
|
+
return [];
|
|
7375
|
+
};
|
|
7376
|
+
visitConditionCaseNode = (_node) => {
|
|
7377
|
+
return [];
|
|
7378
|
+
};
|
|
7379
|
+
visitDefaultCaseNode = (_node) => {
|
|
7380
|
+
return [];
|
|
7381
|
+
};
|
|
7382
|
+
};
|
|
7383
|
+
});
|
|
7384
|
+
|
|
6834
7385
|
// src/pack/visitors/unifyChainedExecutes.ts
|
|
6835
7386
|
var UnifyChainedExecutesVisitor;
|
|
6836
7387
|
var init_unifyChainedExecutes = __esm(() => {
|
|
@@ -6846,6 +7397,10 @@ var init_unifyChainedExecutes = __esm(() => {
|
|
|
6846
7397
|
node.body = chainedCommand.body;
|
|
6847
7398
|
node.args.push(...chainedCommand.args);
|
|
6848
7399
|
}
|
|
7400
|
+
const flattenedArgs = node.args.flat(1).filter((a) => a !== undefined && a !== null);
|
|
7401
|
+
if (flattenedArgs.length === 0 && node.body.length === 1) {
|
|
7402
|
+
return this.genericVisit(node.body[0]);
|
|
7403
|
+
}
|
|
6849
7404
|
return this.genericVisit(node);
|
|
6850
7405
|
};
|
|
6851
7406
|
};
|
|
@@ -6863,6 +7418,7 @@ var init_visitors2 = __esm(() => {
|
|
|
6863
7418
|
init_orTransformationVisitor();
|
|
6864
7419
|
init_simplifyExecuteFunction();
|
|
6865
7420
|
init_simplifyReturnRunFunction();
|
|
7421
|
+
init_switchTransformationVisitor();
|
|
6866
7422
|
init_unifyChainedExecutes();
|
|
6867
7423
|
});
|
|
6868
7424
|
|
|
@@ -6932,6 +7488,8 @@ class SandstonePack {
|
|
|
6932
7488
|
this.__rootObjective = undefined;
|
|
6933
7489
|
this.__initMCFunction = undefined;
|
|
6934
7490
|
this.objectives.clear();
|
|
7491
|
+
this.anonymousDataId = 0;
|
|
7492
|
+
this.anonymousScoreId = 0;
|
|
6935
7493
|
this.constants.clear();
|
|
6936
7494
|
this.tickedLoops = {};
|
|
6937
7495
|
this.dependencies.clear();
|
|
@@ -6994,7 +7552,7 @@ class SandstonePack {
|
|
|
6994
7552
|
return [namespace, ...resourceFolders, ...fullPath];
|
|
6995
7553
|
};
|
|
6996
7554
|
get _() {
|
|
6997
|
-
return
|
|
7555
|
+
return this.flow;
|
|
6998
7556
|
}
|
|
6999
7557
|
registerNewObjective = (objective) => {
|
|
7000
7558
|
this.objectives.add(objective);
|
|
@@ -7033,7 +7591,7 @@ class SandstonePack {
|
|
|
7033
7591
|
return this.Variable(undefined, name2).set(nbt2, scale);
|
|
7034
7592
|
}
|
|
7035
7593
|
const [initialValue, name] = args;
|
|
7036
|
-
const anonymousScore = score(`${name ?? "anon"}_${this.packUid}_${this.anonymousScoreId++}`);
|
|
7594
|
+
const anonymousScore = score(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousScoreId++}` : ""}`);
|
|
7037
7595
|
if (initialValue === undefined) {
|
|
7038
7596
|
return anonymousScore;
|
|
7039
7597
|
}
|
|
@@ -7077,7 +7635,7 @@ class SandstonePack {
|
|
|
7077
7635
|
return this.DataVariable(undefined, name2).set(score, storeType || "int", scale || 1);
|
|
7078
7636
|
}
|
|
7079
7637
|
const [initialValue, name] = args;
|
|
7080
|
-
const anonymousData = data2.select(`${name ?? "anon"}_${this.packUid}_${this.anonymousDataId++}`);
|
|
7638
|
+
const anonymousData = data2.select(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousDataId++}` : ""}`);
|
|
7081
7639
|
if (initialValue === undefined) {
|
|
7082
7640
|
return anonymousData;
|
|
7083
7641
|
}
|
|
@@ -7480,6 +8038,7 @@ class SandstonePack {
|
|
|
7480
8038
|
new InitConstantsVisitor(this),
|
|
7481
8039
|
new GenerateLazyMCFunction(this),
|
|
7482
8040
|
new LoopTransformationVisitor(this),
|
|
8041
|
+
new SwitchTransformationVisitor(this),
|
|
7483
8042
|
new OrTransformationVisitor(this),
|
|
7484
8043
|
new IfElseTransformationVisitor(this),
|
|
7485
8044
|
new ContainerCommandsToMCFunctionVisitor(this),
|
|
@@ -7530,7 +8089,7 @@ var init_pack = __esm(() => {
|
|
|
7530
8089
|
}
|
|
7531
8090
|
handleOutput = async (type, readFile, writeFile) => {
|
|
7532
8091
|
if (type === "output") {
|
|
7533
|
-
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
|
|
8092
|
+
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
|
|
7534
8093
|
}
|
|
7535
8094
|
};
|
|
7536
8095
|
};
|
|
@@ -7551,7 +8110,7 @@ var init_pack = __esm(() => {
|
|
|
7551
8110
|
}
|
|
7552
8111
|
handleOutput = async (type, readFile, writeFile) => {
|
|
7553
8112
|
if (type === "output") {
|
|
7554
|
-
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
|
|
8113
|
+
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
|
|
7555
8114
|
}
|
|
7556
8115
|
};
|
|
7557
8116
|
};
|
|
@@ -7626,7 +8185,11 @@ var init_src = __esm(() => {
|
|
|
7626
8185
|
return new Proxy(fn, {
|
|
7627
8186
|
get(_target, subProp) {
|
|
7628
8187
|
const method = sandstonePack[prop];
|
|
7629
|
-
|
|
8188
|
+
const value = method[subProp];
|
|
8189
|
+
if (typeof value === "function") {
|
|
8190
|
+
return value.bind(method);
|
|
8191
|
+
}
|
|
8192
|
+
return value;
|
|
7630
8193
|
},
|
|
7631
8194
|
apply(_target, _thisArg, args) {
|
|
7632
8195
|
const method = sandstonePack[prop];
|
|
@@ -7882,20 +8445,16 @@ var init_arguments = __esm(() => {
|
|
|
7882
8445
|
});
|
|
7883
8446
|
|
|
7884
8447
|
// src/core/resources/resource.ts
|
|
7885
|
-
function jsonStringify(json) {
|
|
7886
|
-
return JSON.stringify(json, (
|
|
7887
|
-
if (value
|
|
7888
|
-
return value.
|
|
7889
|
-
}
|
|
7890
|
-
if (value instanceof NBTTypedArray) {
|
|
7891
|
-
return value.values;
|
|
8448
|
+
function jsonStringify(json, resourceType) {
|
|
8449
|
+
return JSON.stringify(json, function(key, value) {
|
|
8450
|
+
if ((typeof value === "object" || typeof value === "function") && value.constructor.name !== "Object" && "toResourceJSON" in value) {
|
|
8451
|
+
return value.toResourceJSON(key, this, resourceType, json);
|
|
7892
8452
|
}
|
|
7893
8453
|
return value;
|
|
7894
8454
|
}, 2);
|
|
7895
8455
|
}
|
|
7896
8456
|
var RESOURCE_CLASS_BRAND, ResourceClass, CallableResourceClass, ResourceNodesMap;
|
|
7897
8457
|
var init_resource = __esm(() => {
|
|
7898
|
-
init_NBTs();
|
|
7899
8458
|
init_arguments();
|
|
7900
8459
|
RESOURCE_CLASS_BRAND = Symbol.for("sandstone.ResourceClass");
|
|
7901
8460
|
ResourceClass = class ResourceClass {
|
|
@@ -7932,7 +8491,7 @@ var init_resource = __esm(() => {
|
|
|
7932
8491
|
}
|
|
7933
8492
|
handleConflicts() {
|
|
7934
8493
|
const conflict = this.core.resourceNodes.get(this.node);
|
|
7935
|
-
let
|
|
8494
|
+
let add2 = false;
|
|
7936
8495
|
if (conflict) {
|
|
7937
8496
|
const oldResource = conflict.resource;
|
|
7938
8497
|
const newResource = this.node.resource;
|
|
@@ -7943,7 +8502,7 @@ var init_resource = __esm(() => {
|
|
|
7943
8502
|
case "replace":
|
|
7944
8503
|
{
|
|
7945
8504
|
this.core.resourceNodes.delete(conflict);
|
|
7946
|
-
|
|
8505
|
+
add2 = true;
|
|
7947
8506
|
}
|
|
7948
8507
|
break;
|
|
7949
8508
|
case "warn":
|
|
@@ -7955,14 +8514,14 @@ var init_resource = __esm(() => {
|
|
|
7955
8514
|
].join(`
|
|
7956
8515
|
`));
|
|
7957
8516
|
this.core.resourceNodes.delete(conflict);
|
|
7958
|
-
|
|
8517
|
+
add2 = true;
|
|
7959
8518
|
}
|
|
7960
8519
|
break;
|
|
7961
8520
|
case "rename":
|
|
7962
8521
|
{
|
|
7963
8522
|
this.path[this.path.length - 1] += oldResource.renameIndex.toString();
|
|
7964
8523
|
oldResource.renameIndex += 1;
|
|
7965
|
-
|
|
8524
|
+
add2 = true;
|
|
7966
8525
|
}
|
|
7967
8526
|
break;
|
|
7968
8527
|
case "prepend":
|
|
@@ -7979,9 +8538,9 @@ var init_resource = __esm(() => {
|
|
|
7979
8538
|
break;
|
|
7980
8539
|
}
|
|
7981
8540
|
} else {
|
|
7982
|
-
|
|
8541
|
+
add2 = true;
|
|
7983
8542
|
}
|
|
7984
|
-
if (this.addToSandstoneCore &&
|
|
8543
|
+
if (this.addToSandstoneCore && add2) {
|
|
7985
8544
|
this.core.resourceNodes.add(this.node);
|
|
7986
8545
|
}
|
|
7987
8546
|
}
|
|
@@ -7999,6 +8558,9 @@ var init_resource = __esm(() => {
|
|
|
7999
8558
|
toNBT() {
|
|
8000
8559
|
return this.name;
|
|
8001
8560
|
}
|
|
8561
|
+
toJSON() {
|
|
8562
|
+
return this.name;
|
|
8563
|
+
}
|
|
8002
8564
|
static [Symbol.hasInstance](instance) {
|
|
8003
8565
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RESOURCE_CLASS_BRAND] === true;
|
|
8004
8566
|
}
|
|
@@ -8098,7 +8660,7 @@ var init_advancement2 = __esm(() => {
|
|
|
8098
8660
|
super(sandstoneCore);
|
|
8099
8661
|
this.resource = resource;
|
|
8100
8662
|
}
|
|
8101
|
-
getValue = () => jsonStringify(this.resource.advancementJSON);
|
|
8663
|
+
getValue = () => jsonStringify(this.resource.advancementJSON, this.resource._resourceType);
|
|
8102
8664
|
};
|
|
8103
8665
|
ADVANCEMENT_CLASS_BRAND = Symbol.for("sandstone.AdvancementClass");
|
|
8104
8666
|
AdvancementClass = class AdvancementClass extends ResourceClass {
|
|
@@ -8156,7 +8718,7 @@ var init_bannerPattern = __esm(() => {
|
|
|
8156
8718
|
super(sandstoneCore);
|
|
8157
8719
|
this.resource = resource;
|
|
8158
8720
|
}
|
|
8159
|
-
getValue = () => jsonStringify(this.resource.bannerPatternJSON);
|
|
8721
|
+
getValue = () => jsonStringify(this.resource.bannerPatternJSON, this.resource._resourceType);
|
|
8160
8722
|
};
|
|
8161
8723
|
BannerPatternClass = class BannerPatternClass extends ResourceClass {
|
|
8162
8724
|
static resourceType = "banner_pattern";
|
|
@@ -8181,7 +8743,7 @@ var init_chatType = __esm(() => {
|
|
|
8181
8743
|
super(sandstoneCore);
|
|
8182
8744
|
this.resource = resource;
|
|
8183
8745
|
}
|
|
8184
|
-
getValue = () => jsonStringify(this.resource.chatTypeJSON);
|
|
8746
|
+
getValue = () => jsonStringify(this.resource.chatTypeJSON, this.resource._resourceType);
|
|
8185
8747
|
};
|
|
8186
8748
|
ChatTypeClass = class ChatTypeClass extends ResourceClass {
|
|
8187
8749
|
static resourceType = "chat_type";
|
|
@@ -8207,7 +8769,7 @@ var init_damageType = __esm(() => {
|
|
|
8207
8769
|
super(sandstoneCore);
|
|
8208
8770
|
this.resource = resource;
|
|
8209
8771
|
}
|
|
8210
|
-
getValue = () => jsonStringify(this.resource.damageTypeJSON);
|
|
8772
|
+
getValue = () => jsonStringify(this.resource.damageTypeJSON, this.resource._resourceType);
|
|
8211
8773
|
};
|
|
8212
8774
|
DamageTypeClass = class DamageTypeClass extends ResourceClass {
|
|
8213
8775
|
static resourceType = "damage_type";
|
|
@@ -8269,7 +8831,7 @@ var init_dialog2 = __esm(() => {
|
|
|
8269
8831
|
super(sandstoneCore);
|
|
8270
8832
|
this.resource = resource;
|
|
8271
8833
|
}
|
|
8272
|
-
getValue = () => jsonStringify(this.resource.dialogJSON);
|
|
8834
|
+
getValue = () => jsonStringify(this.resource.dialogJSON, this.resource._resourceType);
|
|
8273
8835
|
};
|
|
8274
8836
|
DialogClass = class DialogClass extends ResourceClass {
|
|
8275
8837
|
static resourceType = "dialog";
|
|
@@ -8294,7 +8856,7 @@ var init_enchantment = __esm(() => {
|
|
|
8294
8856
|
super(sandstoneCore);
|
|
8295
8857
|
this.resource = resource;
|
|
8296
8858
|
}
|
|
8297
|
-
getValue = () => jsonStringify(this.resource.enchantmentJSON);
|
|
8859
|
+
getValue = () => jsonStringify(this.resource.enchantmentJSON, this.resource._resourceType);
|
|
8298
8860
|
};
|
|
8299
8861
|
EnchantmentClass = class EnchantmentClass extends ResourceClass {
|
|
8300
8862
|
static resourceType = "enchantment";
|
|
@@ -8311,7 +8873,7 @@ var init_enchantment = __esm(() => {
|
|
|
8311
8873
|
super(sandstoneCore);
|
|
8312
8874
|
this.resource = resource;
|
|
8313
8875
|
}
|
|
8314
|
-
getValue = () => jsonStringify(this.resource.enchantmentProviderJSON);
|
|
8876
|
+
getValue = () => jsonStringify(this.resource.enchantmentProviderJSON, this.resource._resourceType);
|
|
8315
8877
|
};
|
|
8316
8878
|
EnchantmentProviderClass = class EnchantmentProviderClass extends ResourceClass {
|
|
8317
8879
|
static resourceType = "enchantment_provider";
|
|
@@ -8336,7 +8898,7 @@ var init_gametest = __esm(() => {
|
|
|
8336
8898
|
super(sandstoneCore);
|
|
8337
8899
|
this.resource = resource;
|
|
8338
8900
|
}
|
|
8339
|
-
getValue = () => jsonStringify(this.resource.testEnvironmentJSON);
|
|
8901
|
+
getValue = () => jsonStringify(this.resource.testEnvironmentJSON, this.resource._resourceType);
|
|
8340
8902
|
};
|
|
8341
8903
|
TestEnvironmentClass = class TestEnvironmentClass extends ResourceClass {
|
|
8342
8904
|
static resourceType = "test_environment";
|
|
@@ -8353,7 +8915,7 @@ var init_gametest = __esm(() => {
|
|
|
8353
8915
|
super(sandstoneCore);
|
|
8354
8916
|
this.resource = resource;
|
|
8355
8917
|
}
|
|
8356
|
-
getValue = () => jsonStringify(this.resource.testInstanceJSON);
|
|
8918
|
+
getValue = () => jsonStringify(this.resource.testInstanceJSON, this.resource._resourceType);
|
|
8357
8919
|
};
|
|
8358
8920
|
TestInstanceClass = class TestInstanceClass extends ResourceClass {
|
|
8359
8921
|
static resourceType = "test_instance";
|
|
@@ -8378,7 +8940,7 @@ var init_instrument = __esm(() => {
|
|
|
8378
8940
|
super(sandstoneCore);
|
|
8379
8941
|
this.resource = resource;
|
|
8380
8942
|
}
|
|
8381
|
-
getValue = () => jsonStringify(this.resource.instrumentJSON);
|
|
8943
|
+
getValue = () => jsonStringify(this.resource.instrumentJSON, this.resource._resourceType);
|
|
8382
8944
|
};
|
|
8383
8945
|
InstrumentClass = class InstrumentClass extends ResourceClass {
|
|
8384
8946
|
static resourceType = "instrument";
|
|
@@ -8404,7 +8966,7 @@ var init_itemModifier = __esm(() => {
|
|
|
8404
8966
|
super(sandstoneCore);
|
|
8405
8967
|
this.resource = resource;
|
|
8406
8968
|
}
|
|
8407
|
-
getValue = () => jsonStringify(this.resource.itemModifierJSON);
|
|
8969
|
+
getValue = () => jsonStringify(this.resource.itemModifierJSON, this.resource._resourceType);
|
|
8408
8970
|
};
|
|
8409
8971
|
ITEM_MODIFIER_CLASS_BRAND = Symbol.for("sandstone.ItemModifierClass");
|
|
8410
8972
|
ItemModifierClass = class ItemModifierClass extends ResourceClass {
|
|
@@ -8480,7 +9042,7 @@ var init_jukeboxSong = __esm(() => {
|
|
|
8480
9042
|
super(sandstoneCore);
|
|
8481
9043
|
this.resource = resource;
|
|
8482
9044
|
}
|
|
8483
|
-
getValue = () => jsonStringify(this.resource.jukeboxSongJSON);
|
|
9045
|
+
getValue = () => jsonStringify(this.resource.jukeboxSongJSON, this.resource._resourceType);
|
|
8484
9046
|
};
|
|
8485
9047
|
JukeboxSongClass = class JukeboxSongClass extends ResourceClass {
|
|
8486
9048
|
static resourceType = "jukebox_song";
|
|
@@ -8505,7 +9067,7 @@ var init_lootTable = __esm(() => {
|
|
|
8505
9067
|
super(sandstoneCore);
|
|
8506
9068
|
this.resource = resource;
|
|
8507
9069
|
}
|
|
8508
|
-
getValue = () => jsonStringify(this.resource.lootTableJSON);
|
|
9070
|
+
getValue = () => jsonStringify(this.resource.lootTableJSON, this.resource._resourceType);
|
|
8509
9071
|
};
|
|
8510
9072
|
LootTableClass = class LootTableClass extends ResourceClass {
|
|
8511
9073
|
static resourceType = "loot_table";
|
|
@@ -8538,7 +9100,7 @@ var init_predicate = __esm(() => {
|
|
|
8538
9100
|
super(sandstoneCore);
|
|
8539
9101
|
this.resource = resource;
|
|
8540
9102
|
}
|
|
8541
|
-
getValue = () => jsonStringify(this.resource.predicateJSON);
|
|
9103
|
+
getValue = () => jsonStringify(this.resource.predicateJSON, this.resource._resourceType);
|
|
8542
9104
|
};
|
|
8543
9105
|
PREDICATE_CLASS_BRAND = Symbol.for("sandstone.PredicateClass");
|
|
8544
9106
|
PredicateClass = class PredicateClass extends ResourceClass {
|
|
@@ -8608,7 +9170,7 @@ var init_recipe2 = __esm(() => {
|
|
|
8608
9170
|
super(sandstoneCore);
|
|
8609
9171
|
this.resource = resource;
|
|
8610
9172
|
}
|
|
8611
|
-
getValue = () => jsonStringify(this.resource.recipeJSON);
|
|
9173
|
+
getValue = () => jsonStringify(this.resource.recipeJSON, this.resource._resourceType);
|
|
8612
9174
|
};
|
|
8613
9175
|
RecipeClass = class RecipeClass extends ResourceClass {
|
|
8614
9176
|
static resourceType = "recipe";
|
|
@@ -8653,7 +9215,7 @@ var init_timeline = __esm(() => {
|
|
|
8653
9215
|
super(sandstoneCore);
|
|
8654
9216
|
this.resource = resource;
|
|
8655
9217
|
}
|
|
8656
|
-
getValue = () => jsonStringify(this.resource.timelineJSON);
|
|
9218
|
+
getValue = () => jsonStringify(this.resource.timelineJSON, this.resource._resourceType);
|
|
8657
9219
|
};
|
|
8658
9220
|
TimelineClass = class TimelineClass extends ResourceClass {
|
|
8659
9221
|
static resourceType = "timeline";
|
|
@@ -8670,7 +9232,7 @@ var init_timeline = __esm(() => {
|
|
|
8670
9232
|
super(sandstoneCore);
|
|
8671
9233
|
this.resource = resource;
|
|
8672
9234
|
}
|
|
8673
|
-
getValue = () => jsonStringify(this.resource.worldClockJSON);
|
|
9235
|
+
getValue = () => jsonStringify(this.resource.worldClockJSON, this.resource._resourceType);
|
|
8674
9236
|
};
|
|
8675
9237
|
WorldClockClass = class WorldClockClass extends ResourceClass {
|
|
8676
9238
|
static resourceType = "world_clock";
|
|
@@ -8698,7 +9260,7 @@ var init_trialSpawner = __esm(() => {
|
|
|
8698
9260
|
super(sandstoneCore);
|
|
8699
9261
|
this.resource = resource;
|
|
8700
9262
|
}
|
|
8701
|
-
getValue = () => jsonStringify(this.resource.trialSpawnerJSON);
|
|
9263
|
+
getValue = () => jsonStringify(this.resource.trialSpawnerJSON, this.resource._resourceType);
|
|
8702
9264
|
};
|
|
8703
9265
|
TrialSpawnerClass = class TrialSpawnerClass extends ResourceClass {
|
|
8704
9266
|
static resourceType = "trial_spawner";
|
|
@@ -8723,7 +9285,7 @@ var init_trimMaterial = __esm(() => {
|
|
|
8723
9285
|
super(sandstoneCore);
|
|
8724
9286
|
this.resource = resource;
|
|
8725
9287
|
}
|
|
8726
|
-
getValue = () => jsonStringify(this.resource.trimMaterialJSON);
|
|
9288
|
+
getValue = () => jsonStringify(this.resource.trimMaterialJSON, this.resource._resourceType);
|
|
8727
9289
|
};
|
|
8728
9290
|
TrimMaterialClass = class TrimMaterialClass extends ResourceClass {
|
|
8729
9291
|
static resourceType = "trim_material";
|
|
@@ -8751,7 +9313,7 @@ var init_trimPattern = __esm(() => {
|
|
|
8751
9313
|
super(sandstoneCore);
|
|
8752
9314
|
this.resource = resource;
|
|
8753
9315
|
}
|
|
8754
|
-
getValue = () => jsonStringify(this.resource.trimPatternJSON);
|
|
9316
|
+
getValue = () => jsonStringify(this.resource.trimPatternJSON, this.resource._resourceType);
|
|
8755
9317
|
};
|
|
8756
9318
|
TrimPatternClass = class TrimPatternClass extends ResourceClass {
|
|
8757
9319
|
static resourceType = "trim_pattern";
|
|
@@ -8775,7 +9337,7 @@ var init_variant = __esm(() => {
|
|
|
8775
9337
|
super(sandstoneCore);
|
|
8776
9338
|
this.resource = resource;
|
|
8777
9339
|
}
|
|
8778
|
-
getValue = () => jsonStringify(this.resource.variantJSON);
|
|
9340
|
+
getValue = () => jsonStringify(this.resource.variantJSON, this.resource._resourceType);
|
|
8779
9341
|
};
|
|
8780
9342
|
VariantClass = class VariantClass extends ResourceClass {
|
|
8781
9343
|
variantType;
|
|
@@ -8802,7 +9364,7 @@ var init_villagerTrade = __esm(() => {
|
|
|
8802
9364
|
super(sandstoneCore);
|
|
8803
9365
|
this.resource = resource;
|
|
8804
9366
|
}
|
|
8805
|
-
getValue = () => jsonStringify(this.resource.villagerTradeJSON);
|
|
9367
|
+
getValue = () => jsonStringify(this.resource.villagerTradeJSON, this.resource._resourceType);
|
|
8806
9368
|
};
|
|
8807
9369
|
VillagerTradeClass = class VillagerTradeClass extends ResourceClass {
|
|
8808
9370
|
static resourceType = "villager_trade";
|
|
@@ -8819,7 +9381,7 @@ var init_villagerTrade = __esm(() => {
|
|
|
8819
9381
|
super(sandstoneCore);
|
|
8820
9382
|
this.resource = resource;
|
|
8821
9383
|
}
|
|
8822
|
-
getValue = () => jsonStringify(this.resource.tradeSetJSON);
|
|
9384
|
+
getValue = () => jsonStringify(this.resource.tradeSetJSON, this.resource._resourceType);
|
|
8823
9385
|
};
|
|
8824
9386
|
TradeSetClass = class TradeSetClass extends ResourceClass {
|
|
8825
9387
|
static resourceType = "trade_set";
|
|
@@ -8870,7 +9432,7 @@ var init_atlas = __esm(() => {
|
|
|
8870
9432
|
super(sandstoneCore);
|
|
8871
9433
|
this.resource = resource;
|
|
8872
9434
|
}
|
|
8873
|
-
getValue = () => jsonStringify(this.resource.atlasJSON);
|
|
9435
|
+
getValue = () => jsonStringify(this.resource.atlasJSON, this.resource._resourceType);
|
|
8874
9436
|
};
|
|
8875
9437
|
ATLAS_CLASS_BRAND = Symbol.for("sandstone.AtlasClass");
|
|
8876
9438
|
AtlasClass = class AtlasClass extends ResourceClass {
|
|
@@ -8918,7 +9480,7 @@ var init_blockstate = __esm(() => {
|
|
|
8918
9480
|
super(sandstoneCore);
|
|
8919
9481
|
this.resource = resource;
|
|
8920
9482
|
}
|
|
8921
|
-
getValue = () => jsonStringify(this.resource.blockStateJSON);
|
|
9483
|
+
getValue = () => jsonStringify(this.resource.blockStateJSON, this.resource._resourceType);
|
|
8922
9484
|
};
|
|
8923
9485
|
BLOCK_STATE_CLASS_BRAND = Symbol.for("sandstone.BlockStateClass");
|
|
8924
9486
|
BlockStateClass = class BlockStateClass extends ResourceClass {
|
|
@@ -8999,7 +9561,7 @@ var init_equipment = __esm(() => {
|
|
|
8999
9561
|
super(sandstoneCore);
|
|
9000
9562
|
this.resource = resource;
|
|
9001
9563
|
}
|
|
9002
|
-
getValue = () => jsonStringify(this.resource.equipmentJSON);
|
|
9564
|
+
getValue = () => jsonStringify(this.resource.equipmentJSON, this.resource._resourceType);
|
|
9003
9565
|
};
|
|
9004
9566
|
EquipmentClass = class EquipmentClass extends ResourceClass {
|
|
9005
9567
|
static resourceType = "equipment";
|
|
@@ -9024,7 +9586,7 @@ var init_font = __esm(() => {
|
|
|
9024
9586
|
super(sandstoneCore);
|
|
9025
9587
|
this.resource = resource;
|
|
9026
9588
|
}
|
|
9027
|
-
getValue = () => jsonStringify(this.resource.fontJSON);
|
|
9589
|
+
getValue = () => jsonStringify(this.resource.fontJSON, this.resource._resourceType);
|
|
9028
9590
|
};
|
|
9029
9591
|
FONT_CLASS_BRAND = Symbol.for("sandstone.FontClass");
|
|
9030
9592
|
FontClass = class FontClass extends ResourceClass {
|
|
@@ -9072,7 +9634,7 @@ var init_language = __esm(() => {
|
|
|
9072
9634
|
super(sandstoneCore);
|
|
9073
9635
|
this.resource = resource;
|
|
9074
9636
|
}
|
|
9075
|
-
getValue = () => jsonStringify(this.resource.languageJSON);
|
|
9637
|
+
getValue = () => jsonStringify(this.resource.languageJSON, this.resource._resourceType);
|
|
9076
9638
|
};
|
|
9077
9639
|
LANGUAGE_CLASS_BRAND = Symbol.for("sandstone.LanguageClass");
|
|
9078
9640
|
LanguageClass = class LanguageClass extends ResourceClass {
|
|
@@ -9124,7 +9686,7 @@ var init_particle2 = __esm(() => {
|
|
|
9124
9686
|
super(sandstoneCore);
|
|
9125
9687
|
this.resource = resource;
|
|
9126
9688
|
}
|
|
9127
|
-
getValue = () => jsonStringify(this.resource.particleJSON);
|
|
9689
|
+
getValue = () => jsonStringify(this.resource.particleJSON, this.resource._resourceType);
|
|
9128
9690
|
};
|
|
9129
9691
|
ParticleClass = class ParticleClass extends ResourceClass {
|
|
9130
9692
|
static resourceType = "particle";
|
|
@@ -9149,7 +9711,7 @@ var init_postEffect = __esm(() => {
|
|
|
9149
9711
|
super(sandstoneCore);
|
|
9150
9712
|
this.resource = resource;
|
|
9151
9713
|
}
|
|
9152
|
-
getValue = () => jsonStringify(this.resource.postEffectJSON);
|
|
9714
|
+
getValue = () => jsonStringify(this.resource.postEffectJSON, this.resource._resourceType);
|
|
9153
9715
|
};
|
|
9154
9716
|
PostEffectClass = class PostEffectClass extends ResourceClass {
|
|
9155
9717
|
static resourceType = "post_effect";
|
|
@@ -9174,7 +9736,7 @@ var init_shader = __esm(() => {
|
|
|
9174
9736
|
super(sandstoneCore);
|
|
9175
9737
|
this.resource = resource;
|
|
9176
9738
|
}
|
|
9177
|
-
getValue = () => jsonStringify(this.resource.shaderJSON);
|
|
9739
|
+
getValue = () => jsonStringify(this.resource.shaderJSON, this.resource._resourceType);
|
|
9178
9740
|
};
|
|
9179
9741
|
ShaderClass = class ShaderClass extends ResourceClass {
|
|
9180
9742
|
static resourceType = "shader";
|
|
@@ -9236,7 +9798,7 @@ var init_sound = __esm(() => {
|
|
|
9236
9798
|
super(sandstoneCore);
|
|
9237
9799
|
this.resource = resource;
|
|
9238
9800
|
}
|
|
9239
|
-
getValue = () => jsonStringify(this.resource.soundsJSON);
|
|
9801
|
+
getValue = () => jsonStringify(this.resource.soundsJSON, this.resource._resourceType);
|
|
9240
9802
|
};
|
|
9241
9803
|
SOUNDS_CLASS_BRAND = Symbol.for("sandstone.SoundsClass");
|
|
9242
9804
|
SoundsClass = class SoundsClass extends ResourceClass {
|
|
@@ -9466,7 +10028,7 @@ var init_waypointStyle = __esm(() => {
|
|
|
9466
10028
|
super(sandstoneCore);
|
|
9467
10029
|
this.resource = resource;
|
|
9468
10030
|
}
|
|
9469
|
-
getValue = () => jsonStringify(this.resource.waypointStyleJSON);
|
|
10031
|
+
getValue = () => jsonStringify(this.resource.waypointStyleJSON, this.resource._resourceType);
|
|
9470
10032
|
};
|
|
9471
10033
|
WaypointStyleClass = class WaypointStyleClass extends ResourceClass {
|
|
9472
10034
|
static resourceType = "waypoint_style";
|
|
@@ -10035,7 +10597,18 @@ class SandstoneCore {
|
|
|
10035
10597
|
_path.splice(1, 0, packType2.resourceSubFolder);
|
|
10036
10598
|
}
|
|
10037
10599
|
const resourcePath = path4.join(..._path);
|
|
10038
|
-
|
|
10600
|
+
let value;
|
|
10601
|
+
try {
|
|
10602
|
+
value = await node.getValue();
|
|
10603
|
+
} catch (e) {
|
|
10604
|
+
console.log(`
|
|
10605
|
+
|
|
10606
|
+
|
|
10607
|
+
|
|
10608
|
+
`);
|
|
10609
|
+
console.log(node);
|
|
10610
|
+
throw e;
|
|
10611
|
+
}
|
|
10039
10612
|
if (cliOptions.verbose) {
|
|
10040
10613
|
console.log(`Path: ${resourcePath}.${fileExtension}
|
|
10041
10614
|
|
|
@@ -10319,11 +10892,11 @@ var init_dataPoint = __esm(() => {
|
|
|
10319
10892
|
const { execute: execute2 } = commands2;
|
|
10320
10893
|
const anon = DataVariable(this.dataPoint);
|
|
10321
10894
|
this.conditional = Variable();
|
|
10322
|
-
execute2.store.result
|
|
10895
|
+
execute2.store.result(this.conditional).run(() => anon.set(this.value));
|
|
10323
10896
|
}
|
|
10324
10897
|
getValue = (negated) => (negated ? ["if", ...this.getCondition()] : ["unless", ...this.getCondition()]).join(" ");
|
|
10325
10898
|
getCondition() {
|
|
10326
|
-
return ["score", "matches", "0.."];
|
|
10899
|
+
return ["score", this.conditional, "matches", "0.."];
|
|
10327
10900
|
}
|
|
10328
10901
|
};
|
|
10329
10902
|
});
|
|
@@ -10410,7 +10983,7 @@ var init_command = __esm(() => {
|
|
|
10410
10983
|
this.result = result;
|
|
10411
10984
|
const store = sandstoneCore2.pack.commands.execute.store[type];
|
|
10412
10985
|
this.variable = sandstoneCore2.pack.Variable(undefined, "condition");
|
|
10413
|
-
command(store
|
|
10986
|
+
command(store(this.variable));
|
|
10414
10987
|
}
|
|
10415
10988
|
getCondition() {
|
|
10416
10989
|
if (this.type === "success") {
|
|
@@ -10462,11 +11035,13 @@ var init_loaded = __esm(() => {
|
|
|
10462
11035
|
});
|
|
10463
11036
|
|
|
10464
11037
|
// src/flow/conditions/variables/score.ts
|
|
10465
|
-
var ScoreConditionNode;
|
|
11038
|
+
var SCORE_CONDITION_NODE_BRAND, ScoreConditionNode;
|
|
10466
11039
|
var init_score = __esm(() => {
|
|
10467
11040
|
init_condition();
|
|
11041
|
+
SCORE_CONDITION_NODE_BRAND = Symbol.for("sandstone.ScoreConditionNode");
|
|
10468
11042
|
ScoreConditionNode = class ScoreConditionNode extends SingleConditionNode {
|
|
10469
11043
|
args;
|
|
11044
|
+
[SCORE_CONDITION_NODE_BRAND] = true;
|
|
10470
11045
|
constructor(sandstoneCore2, args) {
|
|
10471
11046
|
super(sandstoneCore2);
|
|
10472
11047
|
this.args = args;
|
|
@@ -10474,6 +11049,9 @@ var init_score = __esm(() => {
|
|
|
10474
11049
|
getCondition() {
|
|
10475
11050
|
return ["score", ...this.args];
|
|
10476
11051
|
}
|
|
11052
|
+
static [Symbol.hasInstance](instance) {
|
|
11053
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SCORE_CONDITION_NODE_BRAND] === true;
|
|
11054
|
+
}
|
|
10477
11055
|
};
|
|
10478
11056
|
});
|
|
10479
11057
|
|
|
@@ -10576,7 +11154,7 @@ class IfStatement {
|
|
|
10576
11154
|
this.node = new IfNode(sandstoneCore2, condition2, callback);
|
|
10577
11155
|
}
|
|
10578
11156
|
elseIf = (condition2, callback) => {
|
|
10579
|
-
const statement = new IfStatement(this.sandstoneCore,
|
|
11157
|
+
const statement = new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
10580
11158
|
this.node.nextFlowNode = statement.getNode();
|
|
10581
11159
|
statement.node._isElseIf = true;
|
|
10582
11160
|
return statement;
|
|
@@ -10604,6 +11182,7 @@ var IF_NODE_BRAND, IfNode, ELSE_NODE_BRAND, ElseNode2;
|
|
|
10604
11182
|
var init_if_else = __esm(() => {
|
|
10605
11183
|
init_core();
|
|
10606
11184
|
init_utils();
|
|
11185
|
+
init_Flow();
|
|
10607
11186
|
IF_NODE_BRAND = Symbol.for("sandstone.IfNode");
|
|
10608
11187
|
IfNode = class IfNode extends ContainerNode {
|
|
10609
11188
|
condition;
|
|
@@ -10611,10 +11190,14 @@ var init_if_else = __esm(() => {
|
|
|
10611
11190
|
[IF_NODE_BRAND] = true;
|
|
10612
11191
|
nextFlowNode;
|
|
10613
11192
|
_isElseIf = false;
|
|
10614
|
-
|
|
11193
|
+
parentMCFunction;
|
|
11194
|
+
givenCallbackName;
|
|
11195
|
+
resultingExecuteNode;
|
|
11196
|
+
constructor(sandstoneCore2, condition2, callback, parentMCFunction) {
|
|
10615
11197
|
super(sandstoneCore2);
|
|
10616
11198
|
this.condition = condition2;
|
|
10617
11199
|
this.callback = callback;
|
|
11200
|
+
this.parentMCFunction = parentMCFunction ?? sandstoneCore2.getCurrentMCFunctionOrThrow();
|
|
10618
11201
|
if (callback && callback.toString() !== "() => {}") {
|
|
10619
11202
|
this.sandstoneCore.insideContext(this, callback, true);
|
|
10620
11203
|
}
|
|
@@ -10656,26 +11239,6 @@ ${indent}${nextFormatting}`;
|
|
|
10656
11239
|
});
|
|
10657
11240
|
|
|
10658
11241
|
// src/flow/loops/binary_for.ts
|
|
10659
|
-
function binaryFor(flow, from, to, callback, maximum = 128) {
|
|
10660
|
-
if (typeof from === "number" && typeof to === "number") {
|
|
10661
|
-
callback(to - from);
|
|
10662
|
-
}
|
|
10663
|
-
const { Variable } = flow.sandstoneCore.pack;
|
|
10664
|
-
const realStart = from instanceof Score ? from : Variable(from);
|
|
10665
|
-
const realEnd = to instanceof Score ? to : Variable(to);
|
|
10666
|
-
const iterations = realEnd.minus(realStart);
|
|
10667
|
-
const _ = flow;
|
|
10668
|
-
_.while(iterations.lessThan(maximum), () => {
|
|
10669
|
-
callback(maximum);
|
|
10670
|
-
iterations.remove(maximum);
|
|
10671
|
-
});
|
|
10672
|
-
for (let i = 1;i < maximum; i *= 2) {
|
|
10673
|
-
_.if(iterations.moduloBy(2).equalTo(1), () => {
|
|
10674
|
-
callback(i);
|
|
10675
|
-
});
|
|
10676
|
-
iterations.dividedBy(2);
|
|
10677
|
-
}
|
|
10678
|
-
}
|
|
10679
11242
|
var init_binary_for = __esm(() => {
|
|
10680
11243
|
init_variables();
|
|
10681
11244
|
});
|
|
@@ -10685,16 +11248,18 @@ var LoopNode;
|
|
|
10685
11248
|
var init_loop = __esm(() => {
|
|
10686
11249
|
init_core();
|
|
10687
11250
|
LoopNode = class LoopNode extends ContainerNode {
|
|
10688
|
-
|
|
11251
|
+
condition;
|
|
10689
11252
|
callback;
|
|
10690
11253
|
loopback;
|
|
10691
|
-
|
|
11254
|
+
parentMCFunction;
|
|
11255
|
+
constructor(sandstoneCore2, condition2, callback, loopback) {
|
|
10692
11256
|
super(sandstoneCore2);
|
|
10693
|
-
this.
|
|
11257
|
+
this.condition = condition2;
|
|
10694
11258
|
this.callback = callback;
|
|
10695
11259
|
this.loopback = loopback;
|
|
11260
|
+
const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
|
|
11261
|
+
this.parentMCFunction = currentNode;
|
|
10696
11262
|
if (callback.toString() !== "() => {}") {
|
|
10697
|
-
const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
|
|
10698
11263
|
currentNode.enterContext(this);
|
|
10699
11264
|
this.callback();
|
|
10700
11265
|
this.loopback();
|
|
@@ -10707,6 +11272,75 @@ var init_loop = __esm(() => {
|
|
|
10707
11272
|
};
|
|
10708
11273
|
});
|
|
10709
11274
|
|
|
11275
|
+
// src/flow/loops/staticAnalysis.ts
|
|
11276
|
+
function valueMatchesRange(value, rangeStr) {
|
|
11277
|
+
if (rangeStr.includes("..")) {
|
|
11278
|
+
const [minStr, maxStr] = rangeStr.split("..");
|
|
11279
|
+
const min = minStr !== "" ? parseInt(minStr, 10) : Number.NEGATIVE_INFINITY;
|
|
11280
|
+
const max = maxStr !== "" ? parseInt(maxStr, 10) : Number.POSITIVE_INFINITY;
|
|
11281
|
+
return value >= min && value <= max;
|
|
11282
|
+
}
|
|
11283
|
+
return value === parseInt(rangeStr, 10);
|
|
11284
|
+
}
|
|
11285
|
+
function analyzeCondition(condition2, targetScore, value, negated = false) {
|
|
11286
|
+
if (condition2 instanceof ScoreConditionNode) {
|
|
11287
|
+
const args = condition2.args;
|
|
11288
|
+
if (args.length >= 4 && args[2] === "matches") {
|
|
11289
|
+
const [target, objective2, , rangeStr] = args;
|
|
11290
|
+
if (target !== `${targetScore.target}` || objective2 !== `${targetScore.objective}`) {
|
|
11291
|
+
return { canAnalyze: false };
|
|
11292
|
+
}
|
|
11293
|
+
let result = valueMatchesRange(value, rangeStr);
|
|
11294
|
+
if (negated)
|
|
11295
|
+
result = !result;
|
|
11296
|
+
return { canAnalyze: true, result };
|
|
11297
|
+
}
|
|
11298
|
+
return { canAnalyze: false };
|
|
11299
|
+
}
|
|
11300
|
+
if (condition2 instanceof AndNode) {
|
|
11301
|
+
for (const subCondition of condition2.conditions) {
|
|
11302
|
+
const subResult = analyzeCondition(subCondition, targetScore, value, negated);
|
|
11303
|
+
if (!subResult.canAnalyze)
|
|
11304
|
+
return { canAnalyze: false };
|
|
11305
|
+
if (!subResult.result)
|
|
11306
|
+
return { canAnalyze: true, result: false };
|
|
11307
|
+
}
|
|
11308
|
+
return { canAnalyze: true, result: true };
|
|
11309
|
+
}
|
|
11310
|
+
if (condition2 instanceof OrNode) {
|
|
11311
|
+
let anyTrue = false;
|
|
11312
|
+
for (const subCondition of condition2.conditions) {
|
|
11313
|
+
const subResult = analyzeCondition(subCondition, targetScore, value, negated);
|
|
11314
|
+
if (!subResult.canAnalyze)
|
|
11315
|
+
return { canAnalyze: false };
|
|
11316
|
+
if (subResult.result)
|
|
11317
|
+
anyTrue = true;
|
|
11318
|
+
}
|
|
11319
|
+
return { canAnalyze: true, result: anyTrue };
|
|
11320
|
+
}
|
|
11321
|
+
if (condition2 instanceof NotNode) {
|
|
11322
|
+
return analyzeCondition(condition2.condition, targetScore, value, !negated);
|
|
11323
|
+
}
|
|
11324
|
+
return { canAnalyze: false };
|
|
11325
|
+
}
|
|
11326
|
+
function getDeclarationLocation() {
|
|
11327
|
+
const stack = new Error().stack;
|
|
11328
|
+
const locationMatch = stack?.split(`
|
|
11329
|
+
`).find((line) => line.includes(".ts:") && !line.includes("/loops/") && !line.includes("node_modules"));
|
|
11330
|
+
return locationMatch?.trim() || "unknown location";
|
|
11331
|
+
}
|
|
11332
|
+
function warnStaticallyFalseCondition(loopType, details) {
|
|
11333
|
+
const location = getDeclarationLocation();
|
|
11334
|
+
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.
|
|
11335
|
+
` + ` at ${location}`);
|
|
11336
|
+
}
|
|
11337
|
+
var init_staticAnalysis = __esm(() => {
|
|
11338
|
+
init_score();
|
|
11339
|
+
init_and();
|
|
11340
|
+
init_or();
|
|
11341
|
+
init_not();
|
|
11342
|
+
});
|
|
11343
|
+
|
|
10710
11344
|
// src/flow/loops/for_i.ts
|
|
10711
11345
|
class ForIStatement {
|
|
10712
11346
|
sandstoneCore;
|
|
@@ -10727,43 +11361,64 @@ class ForIStatement {
|
|
|
10727
11361
|
}
|
|
10728
11362
|
var ForINode;
|
|
10729
11363
|
var init_for_i = __esm(() => {
|
|
10730
|
-
init_commands2();
|
|
10731
11364
|
init_variables();
|
|
11365
|
+
init_flow();
|
|
11366
|
+
init_if_else();
|
|
10732
11367
|
init_loop();
|
|
11368
|
+
init_staticAnalysis();
|
|
10733
11369
|
ForINode = class ForINode extends LoopNode {
|
|
10734
11370
|
constructor(sandstoneCore2, initialValue, endCondition, iterate, callback) {
|
|
10735
11371
|
const iterator = sandstoneCore2.pack.Variable(initialValue, "loop_iterator");
|
|
10736
|
-
const condition2 =
|
|
10737
|
-
const
|
|
10738
|
-
const
|
|
10739
|
-
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
11372
|
+
const condition2 = conditionToNode(endCondition(iterator));
|
|
11373
|
+
const _continue = () => sandstoneCore2.pack.commands.returnCmd.run(() => new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack)));
|
|
11374
|
+
const analysisResult = typeof initialValue === "number" ? analyzeCondition(condition2, iterator, initialValue) : { canAnalyze: false };
|
|
11375
|
+
if (analysisResult.canAnalyze) {
|
|
11376
|
+
if (analysisResult.result) {
|
|
11377
|
+
callback(iterator, _continue);
|
|
11378
|
+
iterate(iterator);
|
|
11379
|
+
} else {
|
|
11380
|
+
warnStaticallyFalseCondition("for", `initial value ${initialValue} does not satisfy condition`);
|
|
11381
|
+
}
|
|
11382
|
+
}
|
|
11383
|
+
super(sandstoneCore2, condition2, () => callback(iterator, _continue), () => {
|
|
10745
11384
|
iterate(iterator);
|
|
10746
|
-
|
|
10747
|
-
body: [new LoopArgument(sandstoneCore2.pack)]
|
|
10748
|
-
});
|
|
11385
|
+
new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack));
|
|
10749
11386
|
});
|
|
10750
11387
|
}
|
|
10751
11388
|
};
|
|
10752
11389
|
});
|
|
10753
11390
|
|
|
10754
11391
|
// src/flow/loops/for_of.ts
|
|
11392
|
+
function isMultipleVariable(iteratorType) {
|
|
11393
|
+
if (Array.isArray(iteratorType)) {
|
|
11394
|
+
return true;
|
|
11395
|
+
}
|
|
11396
|
+
return false;
|
|
11397
|
+
}
|
|
11398
|
+
function isMapIterator(iteratorType, iterable) {
|
|
11399
|
+
if (isMultipleVariable(iteratorType) && iteratorType[0] === "key") {
|
|
11400
|
+
if (iterable.iteratorType === "map") {
|
|
11401
|
+
return true;
|
|
11402
|
+
}
|
|
11403
|
+
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)');
|
|
11404
|
+
}
|
|
11405
|
+
return false;
|
|
11406
|
+
}
|
|
11407
|
+
|
|
10755
11408
|
class ForOfStatement {
|
|
10756
11409
|
sandstoneCore;
|
|
10757
11410
|
iteratorType;
|
|
11411
|
+
direction;
|
|
10758
11412
|
iterable;
|
|
10759
11413
|
callback;
|
|
10760
11414
|
node;
|
|
10761
|
-
constructor(sandstoneCore2, iteratorType, iterable, callback) {
|
|
11415
|
+
constructor(sandstoneCore2, iteratorType, direction, iterable, callback) {
|
|
10762
11416
|
this.sandstoneCore = sandstoneCore2;
|
|
10763
11417
|
this.iteratorType = iteratorType;
|
|
11418
|
+
this.direction = direction;
|
|
10764
11419
|
this.iterable = iterable;
|
|
10765
11420
|
this.callback = callback;
|
|
10766
|
-
this.node = new ForOfNode(sandstoneCore2, iteratorType, iterable, callback);
|
|
11421
|
+
this.node = new ForOfNode(sandstoneCore2, iteratorType, direction, iterable, callback);
|
|
10767
11422
|
}
|
|
10768
11423
|
getNode = () => this.node;
|
|
10769
11424
|
}
|
|
@@ -10773,35 +11428,31 @@ var init_for_of = __esm(() => {
|
|
|
10773
11428
|
init_if_else();
|
|
10774
11429
|
init_loop();
|
|
10775
11430
|
ForOfNode = class ForOfNode extends LoopNode {
|
|
10776
|
-
constructor(sandstoneCore2, iteratorType, iterable, callback) {
|
|
10777
|
-
const _iterable = iterable._toDataPoint();
|
|
10778
|
-
let startCondition;
|
|
11431
|
+
constructor(sandstoneCore2, iteratorType, direction, iterable, callback) {
|
|
10779
11432
|
let iterate;
|
|
10780
|
-
|
|
10781
|
-
|
|
10782
|
-
if (iteratorType[0] === "key") {
|
|
10783
|
-
startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
|
|
11433
|
+
if (isMultipleVariable(iteratorType)) {
|
|
11434
|
+
if (isMapIterator(iteratorType, iterable)) {
|
|
10784
11435
|
iterate = iterable.iterator((dataPoints) => {
|
|
10785
|
-
if (dataPoints.length === 1) {
|
|
10786
|
-
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)');
|
|
10787
|
-
}
|
|
10788
11436
|
callback(...[dataPoints[0], dataPoints[1]]);
|
|
10789
|
-
});
|
|
11437
|
+
}, direction);
|
|
10790
11438
|
} else {
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
11439
|
+
const _iterator = sandstoneCore2.pack.Variable(direction === "normal" ? -1 : undefined);
|
|
11440
|
+
if (direction === "reverse") {
|
|
11441
|
+
_iterator.set(iterable.size());
|
|
11442
|
+
}
|
|
10795
11443
|
iterate = iterable.iterator((dataPoints) => {
|
|
10796
|
-
|
|
11444
|
+
if (direction === "normal") {
|
|
11445
|
+
_iterator.increase();
|
|
11446
|
+
} else {
|
|
11447
|
+
_iterator.decrease();
|
|
11448
|
+
}
|
|
10797
11449
|
if (dataPoints.length === 1) {
|
|
10798
11450
|
return callback(...[_iterator, dataPoints[0]]);
|
|
10799
11451
|
}
|
|
10800
11452
|
return callback(...[_iterator, dataPoints[1]]);
|
|
10801
|
-
});
|
|
11453
|
+
}, direction);
|
|
10802
11454
|
}
|
|
10803
11455
|
} else {
|
|
10804
|
-
startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
|
|
10805
11456
|
iterate = iterable.iterator((dataPoints) => {
|
|
10806
11457
|
if (dataPoints.length === 1) {
|
|
10807
11458
|
return callback(...[dataPoints[0]]);
|
|
@@ -10809,8 +11460,8 @@ var init_for_of = __esm(() => {
|
|
|
10809
11460
|
return callback(...[dataPoints[1]]);
|
|
10810
11461
|
});
|
|
10811
11462
|
}
|
|
10812
|
-
|
|
10813
|
-
super(sandstoneCore2,
|
|
11463
|
+
const continueCondition = iterable.continue(direction);
|
|
11464
|
+
super(sandstoneCore2, continueCondition, () => iterate, () => new IfStatement(sandstoneCore2, continueCondition, () => new LoopArgument(sandstoneCore2.pack)));
|
|
10814
11465
|
}
|
|
10815
11466
|
};
|
|
10816
11467
|
});
|
|
@@ -10832,11 +11483,12 @@ var WhileNode;
|
|
|
10832
11483
|
var init_while = __esm(() => {
|
|
10833
11484
|
init_variables();
|
|
10834
11485
|
init_if_else();
|
|
11486
|
+
init_flow();
|
|
10835
11487
|
init_loop();
|
|
10836
11488
|
WhileNode = class WhileNode extends LoopNode {
|
|
10837
11489
|
constructor(sandstoneCore2, condition2, callback) {
|
|
10838
|
-
const _condition =
|
|
10839
|
-
super(sandstoneCore2,
|
|
11490
|
+
const _condition = conditionToNode(condition2);
|
|
11491
|
+
super(sandstoneCore2, _condition, callback, () => new IfStatement(sandstoneCore2, _condition, () => new LoopArgument(sandstoneCore2.pack)));
|
|
10840
11492
|
}
|
|
10841
11493
|
};
|
|
10842
11494
|
});
|
|
@@ -10850,29 +11502,77 @@ var init_loops = __esm(() => {
|
|
|
10850
11502
|
});
|
|
10851
11503
|
|
|
10852
11504
|
// src/flow/switch_case.ts
|
|
10853
|
-
|
|
11505
|
+
function isConditionCase(c) {
|
|
11506
|
+
return typeof c === "function";
|
|
11507
|
+
}
|
|
11508
|
+
function executeSwitch(sandstoneCore2, value, _cases) {
|
|
11509
|
+
let staticCaseEntries = [];
|
|
11510
|
+
let conditionCaseEntries = [];
|
|
11511
|
+
let _default;
|
|
11512
|
+
if (_cases instanceof CaseStatement) {
|
|
11513
|
+
staticCaseEntries = _cases.getStaticCases();
|
|
11514
|
+
conditionCaseEntries = _cases.getConditionCases();
|
|
11515
|
+
} else if (Array.isArray(_cases)) {
|
|
11516
|
+
for (const _case of _cases) {
|
|
11517
|
+
if (_case[0] === "default") {
|
|
11518
|
+
_default = _case;
|
|
11519
|
+
continue;
|
|
11520
|
+
}
|
|
11521
|
+
const [, condition2, callback] = _case;
|
|
11522
|
+
if (isConditionCase(condition2)) {
|
|
11523
|
+
conditionCaseEntries.push({ type: "condition", condition: condition2, callback });
|
|
11524
|
+
} else {
|
|
11525
|
+
staticCaseEntries.push({ type: "static", value: condition2, callback });
|
|
11526
|
+
}
|
|
11527
|
+
}
|
|
11528
|
+
} else {
|
|
11529
|
+
for (const _case of _cases.entries) {
|
|
11530
|
+
if (_case.type === "condition") {
|
|
11531
|
+
conditionCaseEntries.push(_case);
|
|
11532
|
+
} else {
|
|
11533
|
+
staticCaseEntries.push(_case);
|
|
11534
|
+
}
|
|
11535
|
+
}
|
|
11536
|
+
if (_cases.default) {
|
|
11537
|
+
_default = ["default", _cases.default];
|
|
11538
|
+
}
|
|
11539
|
+
}
|
|
11540
|
+
const staticCaseNodes = staticCaseEntries.map((c) => new StaticCaseNode2(sandstoneCore2, c.value, c.callback));
|
|
11541
|
+
const conditionCaseNodes = conditionCaseEntries.map((c) => new ConditionCaseNode2(sandstoneCore2, c.condition, c.callback));
|
|
11542
|
+
const defaultCaseNode = _default ? new DefaultCaseNode2(sandstoneCore2, _default[1]) : undefined;
|
|
11543
|
+
new SwitchNode2(sandstoneCore2, value, staticCaseNodes, conditionCaseNodes, defaultCaseNode);
|
|
11544
|
+
}
|
|
11545
|
+
var CASE_STATEMENT_BRAND, CaseStatement, SwitchNode2, StaticCaseNode2, ConditionCaseNode2, DefaultCaseNode2;
|
|
10854
11546
|
var init_switch_case = __esm(() => {
|
|
11547
|
+
init_core();
|
|
10855
11548
|
CASE_STATEMENT_BRAND = Symbol.for("sandstone.CaseStatement");
|
|
10856
11549
|
CaseStatement = class CaseStatement {
|
|
10857
|
-
|
|
10858
|
-
callback;
|
|
10859
|
-
previous;
|
|
11550
|
+
entries;
|
|
10860
11551
|
[CASE_STATEMENT_BRAND] = true;
|
|
10861
|
-
constructor(
|
|
10862
|
-
this.
|
|
10863
|
-
this.callback = callback;
|
|
10864
|
-
this.previous = previous;
|
|
11552
|
+
constructor(entries = []) {
|
|
11553
|
+
this.entries = entries;
|
|
10865
11554
|
}
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
11555
|
+
getStaticCases() {
|
|
11556
|
+
return this.entries.filter((e) => e.type === "static");
|
|
11557
|
+
}
|
|
11558
|
+
getConditionCases() {
|
|
11559
|
+
return this.entries.filter((e) => e.type === "condition");
|
|
10869
11560
|
}
|
|
10870
|
-
case(
|
|
10871
|
-
|
|
11561
|
+
case(valueOrCondition, callback) {
|
|
11562
|
+
if (typeof valueOrCondition === "function") {
|
|
11563
|
+
return new CaseStatement([
|
|
11564
|
+
...this.entries,
|
|
11565
|
+
{ type: "condition", condition: valueOrCondition, callback }
|
|
11566
|
+
]);
|
|
11567
|
+
}
|
|
11568
|
+
return new CaseStatement([
|
|
11569
|
+
...this.entries,
|
|
11570
|
+
{ type: "static", value: valueOrCondition, callback }
|
|
11571
|
+
]);
|
|
10872
11572
|
}
|
|
10873
11573
|
default(callback) {
|
|
10874
11574
|
return {
|
|
10875
|
-
|
|
11575
|
+
entries: this.entries,
|
|
10876
11576
|
default: callback
|
|
10877
11577
|
};
|
|
10878
11578
|
}
|
|
@@ -10880,24 +11580,83 @@ var init_switch_case = __esm(() => {
|
|
|
10880
11580
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[CASE_STATEMENT_BRAND] === true;
|
|
10881
11581
|
}
|
|
10882
11582
|
};
|
|
11583
|
+
SwitchNode2 = class SwitchNode2 extends ContainerNode {
|
|
11584
|
+
value;
|
|
11585
|
+
staticCases;
|
|
11586
|
+
conditionCases;
|
|
11587
|
+
defaultCase;
|
|
11588
|
+
parentMCFunction;
|
|
11589
|
+
constructor(sandstoneCore2, value, staticCases, conditionCases, defaultCase) {
|
|
11590
|
+
super(sandstoneCore2);
|
|
11591
|
+
this.value = value;
|
|
11592
|
+
this.staticCases = staticCases;
|
|
11593
|
+
this.conditionCases = conditionCases;
|
|
11594
|
+
this.defaultCase = defaultCase;
|
|
11595
|
+
this.parentMCFunction = sandstoneCore2.getCurrentMCFunctionOrThrow();
|
|
11596
|
+
this.parentMCFunction.enterContext(this);
|
|
11597
|
+
for (const caseNode of [...staticCases, ...conditionCases]) {
|
|
11598
|
+
this.parentMCFunction.enterContext(caseNode);
|
|
11599
|
+
caseNode.callback();
|
|
11600
|
+
this.parentMCFunction.exitContext();
|
|
11601
|
+
}
|
|
11602
|
+
if (defaultCase) {
|
|
11603
|
+
this.parentMCFunction.enterContext(defaultCase);
|
|
11604
|
+
defaultCase.callback();
|
|
11605
|
+
this.parentMCFunction.exitContext();
|
|
11606
|
+
}
|
|
11607
|
+
this.parentMCFunction.exitContext();
|
|
11608
|
+
}
|
|
11609
|
+
getValue = () => {
|
|
11610
|
+
throw new Error("SwitchNode must be transformed by SwitchTransformationVisitor");
|
|
11611
|
+
};
|
|
11612
|
+
};
|
|
11613
|
+
StaticCaseNode2 = class StaticCaseNode2 extends ContainerNode {
|
|
11614
|
+
value;
|
|
11615
|
+
callback;
|
|
11616
|
+
constructor(sandstoneCore2, value, callback) {
|
|
11617
|
+
super(sandstoneCore2);
|
|
11618
|
+
this.value = value;
|
|
11619
|
+
this.callback = callback;
|
|
11620
|
+
}
|
|
11621
|
+
getValue = () => null;
|
|
11622
|
+
};
|
|
11623
|
+
ConditionCaseNode2 = class ConditionCaseNode2 extends ContainerNode {
|
|
11624
|
+
condition;
|
|
11625
|
+
callback;
|
|
11626
|
+
constructor(sandstoneCore2, condition2, callback) {
|
|
11627
|
+
super(sandstoneCore2);
|
|
11628
|
+
this.condition = condition2;
|
|
11629
|
+
this.callback = callback;
|
|
11630
|
+
}
|
|
11631
|
+
getValue = () => null;
|
|
11632
|
+
};
|
|
11633
|
+
DefaultCaseNode2 = class DefaultCaseNode2 extends ContainerNode {
|
|
11634
|
+
callback;
|
|
11635
|
+
constructor(sandstoneCore2, callback) {
|
|
11636
|
+
super(sandstoneCore2);
|
|
11637
|
+
this.callback = callback;
|
|
11638
|
+
}
|
|
11639
|
+
getValue = () => null;
|
|
11640
|
+
};
|
|
10883
11641
|
});
|
|
10884
11642
|
|
|
10885
11643
|
// src/flow/Flow.ts
|
|
11644
|
+
function conditionToNode(condition2) {
|
|
11645
|
+
if (!(condition2 instanceof ConditionNode)) {
|
|
11646
|
+
return condition2._toMinecraftCondition();
|
|
11647
|
+
}
|
|
11648
|
+
return condition2;
|
|
11649
|
+
}
|
|
11650
|
+
|
|
10886
11651
|
class Flow {
|
|
10887
11652
|
sandstoneCore;
|
|
10888
11653
|
constructor(sandstoneCore2) {
|
|
10889
11654
|
this.sandstoneCore = sandstoneCore2;
|
|
10890
11655
|
}
|
|
10891
|
-
conditionToNode(condition2)
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
return condition2;
|
|
10896
|
-
}
|
|
10897
|
-
if = (condition2, callback) => new IfStatement(this.sandstoneCore, this.conditionToNode(condition2), callback);
|
|
10898
|
-
and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
|
|
10899
|
-
or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
|
|
10900
|
-
not = (condition2) => new NotNode(this.sandstoneCore, this.conditionToNode(condition2));
|
|
11656
|
+
if = (condition2, callback) => new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
11657
|
+
and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
|
|
11658
|
+
or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
|
|
11659
|
+
not = (condition2) => new NotNode(this.sandstoneCore, conditionToNode(condition2));
|
|
10901
11660
|
get return() {
|
|
10902
11661
|
return this.sandstoneCore.pack.commands.returnCmd;
|
|
10903
11662
|
}
|
|
@@ -10920,77 +11679,56 @@ Sandstone Pack Error:
|
|
|
10920
11679
|
if (broadcast !== false) {
|
|
10921
11680
|
tellraw2(broadcast || "@a", fullError);
|
|
10922
11681
|
}
|
|
10923
|
-
const
|
|
11682
|
+
const errorSerializable = parseJSONText(this.sandstoneCore, fullError);
|
|
10924
11683
|
if (dataPoint2 !== false) {
|
|
10925
11684
|
let point;
|
|
10926
11685
|
if (dataPoint2 === undefined) {
|
|
10927
|
-
point = DataVariable(
|
|
11686
|
+
point = DataVariable(errorSerializable.toJSON());
|
|
10928
11687
|
} else {
|
|
10929
|
-
point = dataPoint2.set(
|
|
11688
|
+
point = dataPoint2.set(errorSerializable.toJSON());
|
|
10930
11689
|
}
|
|
10931
11690
|
returnCmd.fail();
|
|
10932
11691
|
return point;
|
|
10933
11692
|
}
|
|
10934
11693
|
returnCmd.fail();
|
|
10935
|
-
return
|
|
11694
|
+
return errorSerializable;
|
|
10936
11695
|
}
|
|
10937
11696
|
while(condition2, callback) {
|
|
10938
|
-
return new WhileStatement(this.sandstoneCore,
|
|
11697
|
+
return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
10939
11698
|
}
|
|
10940
11699
|
doWhile(condition2, callback) {
|
|
10941
11700
|
callback();
|
|
10942
|
-
return new WhileStatement(this.sandstoneCore,
|
|
11701
|
+
return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
10943
11702
|
}
|
|
10944
11703
|
for(arg1, arg2, arg3, arg4) {
|
|
10945
11704
|
if (typeof arg1 === "number" || arg1 instanceof Score) {
|
|
10946
11705
|
return new ForIStatement(this.sandstoneCore, arg1, arg2, arg3, arg4);
|
|
10947
11706
|
}
|
|
10948
11707
|
if (arg1 === "entry") {
|
|
10949
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
11708
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
10950
11709
|
}
|
|
10951
11710
|
if (arg1[0] === "key") {
|
|
10952
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
11711
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
10953
11712
|
}
|
|
10954
11713
|
if (typeof arg1[0] === "number" || arg1[0] instanceof Score) {
|
|
10955
11714
|
if (arg2 === "iterate") {
|
|
10956
11715
|
return new ForIStatement(this.sandstoneCore, arg1[0], (i) => i["<="](arg1[1]), (i) => i["++"], arg3);
|
|
10957
11716
|
}
|
|
10958
|
-
return binaryFor(this, arg1[0], arg1[1], arg3, arg1[2]);
|
|
10959
11717
|
}
|
|
10960
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
11718
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
10961
11719
|
}
|
|
10962
|
-
switch(value,
|
|
10963
|
-
|
|
10964
|
-
if (_cases instanceof CaseStatement) {
|
|
10965
|
-
cases = _cases.getCases().map((c) => c.getValue());
|
|
10966
|
-
} else if (Array.isArray(_cases)) {
|
|
10967
|
-
cases = _cases;
|
|
10968
|
-
} else {
|
|
10969
|
-
cases = _cases.cases.map((c) => c.getValue());
|
|
10970
|
-
_default = ["default", _cases.default];
|
|
10971
|
-
}
|
|
10972
|
-
const { Data: Data2, initMCFunction, MCFunction, Macro: Macro2 } = this.sandstoneCore.pack;
|
|
10973
|
-
const id2 = switches++;
|
|
10974
|
-
const values = Data2("storage", `__sandstone:switch_${id2}`, "Values");
|
|
10975
|
-
initMCFunction.push(() => values.set(cases.map(([_, v, callback], i) => {
|
|
10976
|
-
MCFunction(`__sandstone:switch_${id2}_case_${i}`, [], () => callback());
|
|
10977
|
-
return { Value: v, Index: i };
|
|
10978
|
-
})));
|
|
10979
|
-
const flow = this;
|
|
10980
|
-
MCFunction(`__sandstone:switch_${id2}`, [value], () => {
|
|
10981
|
-
const index = Data2("storage", `__sandstone:switch_${id2}`, "Index");
|
|
10982
|
-
Macro2.data.modify.storage(index.currentTarget, "Index").set.from.storage(values.currentTarget, Macro2`Values[{Value:${value}}}].Index`);
|
|
10983
|
-
const _if = flow.if(index, () => {
|
|
10984
|
-
MCFunction(`__sandstone:switch_${id2}_inner`, [index], () => {
|
|
10985
|
-
Macro2.functionCmd(Macro2`__sandstone:switch_${id2}_case_${index}`);
|
|
10986
|
-
})();
|
|
10987
|
-
});
|
|
10988
|
-
if (_default)
|
|
10989
|
-
_if.else(() => _default?.[1]());
|
|
10990
|
-
})();
|
|
11720
|
+
switch(value, cases) {
|
|
11721
|
+
executeSwitch(this.sandstoneCore, value, cases);
|
|
10991
11722
|
}
|
|
10992
11723
|
case(value, callback) {
|
|
10993
|
-
|
|
11724
|
+
if (typeof value === "function") {
|
|
11725
|
+
return new CaseStatement([
|
|
11726
|
+
{ type: "condition", condition: value, callback }
|
|
11727
|
+
]);
|
|
11728
|
+
}
|
|
11729
|
+
return new CaseStatement([
|
|
11730
|
+
{ type: "static", value, callback }
|
|
11731
|
+
]);
|
|
10994
11732
|
}
|
|
10995
11733
|
biome = (coordinates, biome2) => {
|
|
10996
11734
|
return new SandstoneConditions.Biome(this.sandstoneCore, coordinates, biome2);
|
|
@@ -11032,7 +11770,6 @@ Sandstone Pack Error:
|
|
|
11032
11770
|
return new SandstoneConditions.Predicate(this.sandstoneCore, predicate3.name);
|
|
11033
11771
|
};
|
|
11034
11772
|
}
|
|
11035
|
-
var switches = 0;
|
|
11036
11773
|
var init_Flow = __esm(() => {
|
|
11037
11774
|
init_variables();
|
|
11038
11775
|
init_conditions();
|
|
@@ -11047,12 +11784,17 @@ var init_flow = __esm(() => {
|
|
|
11047
11784
|
init_Flow();
|
|
11048
11785
|
init_if_else();
|
|
11049
11786
|
init_loop();
|
|
11787
|
+
init_switch_case();
|
|
11050
11788
|
});
|
|
11051
11789
|
init_flow();
|
|
11052
11790
|
|
|
11053
11791
|
export {
|
|
11792
|
+
executeSwitch,
|
|
11793
|
+
conditionToNode,
|
|
11054
11794
|
UUIDConditionNode,
|
|
11055
11795
|
TagConditionNode,
|
|
11796
|
+
SwitchNode2 as SwitchNode,
|
|
11797
|
+
StaticCaseNode2 as StaticCaseNode,
|
|
11056
11798
|
SingleExecuteNode,
|
|
11057
11799
|
SingleConditionNode,
|
|
11058
11800
|
SelectorConditionNode,
|
|
@@ -11073,9 +11815,12 @@ export {
|
|
|
11073
11815
|
ElseStatement,
|
|
11074
11816
|
ElseNode2 as ElseNode,
|
|
11075
11817
|
DimensionConditionNode,
|
|
11818
|
+
DefaultCaseNode2 as DefaultCaseNode,
|
|
11076
11819
|
DataPointExistsConditionNode,
|
|
11077
11820
|
DataPointEqualsConditionNode,
|
|
11078
11821
|
ConditionNode,
|
|
11822
|
+
ConditionCaseNode2 as ConditionCaseNode,
|
|
11823
|
+
CaseStatement,
|
|
11079
11824
|
BlocksConditionNode,
|
|
11080
11825
|
BlockConditionNode,
|
|
11081
11826
|
BiomeConditionNode,
|