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/arguments/index.js
CHANGED
|
@@ -154,17 +154,15 @@ function randomUUID() {
|
|
|
154
154
|
}
|
|
155
155
|
return array;
|
|
156
156
|
}
|
|
157
|
-
function add(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const output = {};
|
|
162
|
-
for (const [key, value] of object.entries()) {
|
|
157
|
+
function add(obj) {
|
|
158
|
+
const filtered = {};
|
|
159
|
+
for (const key of Object.keys(obj)) {
|
|
160
|
+
const value = obj[key];
|
|
163
161
|
if (value !== undefined) {
|
|
164
|
-
|
|
162
|
+
filtered[key] = value;
|
|
165
163
|
}
|
|
166
164
|
}
|
|
167
|
-
return
|
|
165
|
+
return filtered;
|
|
168
166
|
}
|
|
169
167
|
async function safeWrite(...args) {
|
|
170
168
|
if (typeof args[0] !== "string")
|
|
@@ -182,6 +180,14 @@ function formatDebugString(className, args, body, currentIndent) {
|
|
|
182
180
|
argsString = args;
|
|
183
181
|
} else if (Array.isArray(args)) {
|
|
184
182
|
argsString = args.map((arg) => util.inspect(arg, options)).join(", ");
|
|
183
|
+
if (argsString.includes(`
|
|
184
|
+
`)) {
|
|
185
|
+
argsString = `
|
|
186
|
+
${nextIndent}${args.map((arg) => util.inspect(arg, options).replaceAll(`
|
|
187
|
+
`, `
|
|
188
|
+
${nextIndent}`)).join(`,
|
|
189
|
+
${nextIndent}`)}`;
|
|
190
|
+
}
|
|
185
191
|
} else if (args && typeof args === "object") {
|
|
186
192
|
argsString = Object.entries(args).map(([key, value]) => `${key}: ${util.inspect(value, options)}`).join(", ");
|
|
187
193
|
} else {
|
|
@@ -294,7 +300,17 @@ class MacroArgument {
|
|
|
294
300
|
try {
|
|
295
301
|
currentMCFunctionName = sandstoneCore.getCurrentMCFunctionOrThrow().resource.name;
|
|
296
302
|
} catch {}
|
|
297
|
-
|
|
303
|
+
let result = this.local.get(this.sandstoneCore.currentNode) || this.local.get(currentMCFunctionName);
|
|
304
|
+
if (!result) {
|
|
305
|
+
let path = this.sandstoneCore.currentNode;
|
|
306
|
+
while (path.includes("/")) {
|
|
307
|
+
path = path.substring(0, path.lastIndexOf("/"));
|
|
308
|
+
result = this.local.get(path);
|
|
309
|
+
if (result)
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return `$(${result})`;
|
|
298
314
|
};
|
|
299
315
|
}
|
|
300
316
|
}
|
|
@@ -334,6 +350,9 @@ var init_Macro = __esm(() => {
|
|
|
334
350
|
result += `${macro}`;
|
|
335
351
|
} else {
|
|
336
352
|
result += macro.toMacro();
|
|
353
|
+
if (result.endsWith("}")) {
|
|
354
|
+
console.warn("what", macro);
|
|
355
|
+
}
|
|
337
356
|
}
|
|
338
357
|
}
|
|
339
358
|
}
|
|
@@ -797,14 +816,14 @@ var init_damage = __esm(() => {
|
|
|
797
816
|
from = (cause) => this.finalCommand(["from", targetParser(cause)]);
|
|
798
817
|
};
|
|
799
818
|
DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
|
|
800
|
-
by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand);
|
|
819
|
+
by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand, true);
|
|
801
820
|
at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
|
|
802
821
|
};
|
|
803
822
|
DamageCommand = class DamageCommand extends CommandArguments {
|
|
804
823
|
NodeType = DamageCommandNode;
|
|
805
824
|
damage = (target, amount, damageType) => {
|
|
806
825
|
validateIntegerRange(amount, "amount", 0, 1e6);
|
|
807
|
-
return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand);
|
|
826
|
+
return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand, true);
|
|
808
827
|
};
|
|
809
828
|
};
|
|
810
829
|
});
|
|
@@ -1484,7 +1503,7 @@ function dynamicNBT(template, ...args) {
|
|
|
1484
1503
|
const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtStringifier(element) : element.toString()).join("");
|
|
1485
1504
|
return parseNBT(NBT, result);
|
|
1486
1505
|
}
|
|
1487
|
-
var N_B_T_CLASS_BRAND, NBTClass, N_B_T_PRIMITIVE_BRAND, NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble,
|
|
1506
|
+
var N_B_T_CLASS_BRAND, NBTClass, N_B_T_PRIMITIVE_BRAND, NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble, NBTTypedArray, NBTLongArray, NBTByteArray, NBTIntArray, NotNBT, NBTAnyValue, NBT, nbtStringifier = (nbt) => {
|
|
1488
1507
|
if (nbt === null || nbt === undefined) {
|
|
1489
1508
|
throw new Error("Nullish nbt values are not allowed");
|
|
1490
1509
|
}
|
|
@@ -1562,6 +1581,9 @@ var init_NBTs = __esm(() => {
|
|
|
1562
1581
|
this.value = value;
|
|
1563
1582
|
this.unit = unit;
|
|
1564
1583
|
}
|
|
1584
|
+
toJSON() {
|
|
1585
|
+
return this.value;
|
|
1586
|
+
}
|
|
1565
1587
|
[util3.inspect.custom] = () => `${this.value}${this.unit}`;
|
|
1566
1588
|
static [Symbol.hasInstance](instance) {
|
|
1567
1589
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_PRIMITIVE_BRAND] === true;
|
|
@@ -1597,9 +1619,7 @@ var init_NBTs = __esm(() => {
|
|
|
1597
1619
|
super(value, "d");
|
|
1598
1620
|
}
|
|
1599
1621
|
};
|
|
1600
|
-
N_B_T_TYPED_ARRAY_BRAND = Symbol.for("sandstone.NBTTypedArray");
|
|
1601
1622
|
NBTTypedArray = class NBTTypedArray extends NBTClass {
|
|
1602
|
-
[N_B_T_TYPED_ARRAY_BRAND] = true;
|
|
1603
1623
|
values;
|
|
1604
1624
|
unit;
|
|
1605
1625
|
constructor(values, unit) {
|
|
@@ -1607,10 +1627,10 @@ var init_NBTs = __esm(() => {
|
|
|
1607
1627
|
this.values = values;
|
|
1608
1628
|
this.unit = unit;
|
|
1609
1629
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_TYPED_ARRAY_BRAND] === true;
|
|
1630
|
+
toJSON() {
|
|
1631
|
+
return this.values;
|
|
1613
1632
|
}
|
|
1633
|
+
[util3.inspect.custom] = () => `[${this.unit};${this.values.length === 0 ? "" : this.values.join(",")}]`;
|
|
1614
1634
|
};
|
|
1615
1635
|
NBTLongArray = class NBTLongArray extends NBTTypedArray {
|
|
1616
1636
|
constructor(values) {
|
|
@@ -1714,6 +1734,9 @@ var init_Score = __esm(() => {
|
|
|
1714
1734
|
]));
|
|
1715
1735
|
unaryOperation(operation, operator, ...args) {
|
|
1716
1736
|
if (typeof args[0] === "number") {
|
|
1737
|
+
if (args[0] < 0 && operation !== "set") {
|
|
1738
|
+
return this.binaryOperation(operator, args[0]);
|
|
1739
|
+
}
|
|
1717
1740
|
this.commands.scoreboard.players[operation](this, args[0]);
|
|
1718
1741
|
} else if (args[0] instanceof Score) {
|
|
1719
1742
|
this.commands.scoreboard.players.operation(this, operator, args[0].target, args[0].objective);
|
|
@@ -1730,7 +1753,7 @@ var init_Score = __esm(() => {
|
|
|
1730
1753
|
let objective = args[1] ?? this.objective;
|
|
1731
1754
|
if (typeof args[0] === "number") {
|
|
1732
1755
|
this.sandstonePack.registerNewConstant(args[0]);
|
|
1733
|
-
objective = "
|
|
1756
|
+
objective = "__sandstone";
|
|
1734
1757
|
}
|
|
1735
1758
|
this.commands.scoreboard.players.operation(this, operator, args[0], objective);
|
|
1736
1759
|
return this;
|
|
@@ -1886,7 +1909,99 @@ Warning: Score.match() will have to create ${maximum - minimum} mcfunction files
|
|
|
1886
1909
|
}
|
|
1887
1910
|
return MCFunction(`__sandstone:score_match/${matcher}`, [score], () => Macro.returnCmd.run.functionCmd(Macro`__sandstone:score_match/${matcher}/${score}`));
|
|
1888
1911
|
};
|
|
1889
|
-
|
|
1912
|
+
getDecomposer(size, splitsOrCount, componentCount = 31, includeSign = true) {
|
|
1913
|
+
if (typeof this.target !== "string" || this.target.search(/-|@/) !== -1) {
|
|
1914
|
+
throw new Error("[Score#getDecomposer] Must use a fake-player Score for decomposition.");
|
|
1915
|
+
}
|
|
1916
|
+
const { MCFunction, _, commands } = this.sandstonePack;
|
|
1917
|
+
const { execute, returnCmd } = commands;
|
|
1918
|
+
const newScore = this.objective.ScoreHolder;
|
|
1919
|
+
const components = [];
|
|
1920
|
+
const sign = includeSign ? newScore(`${this.target}._32`) : undefined;
|
|
1921
|
+
let decompose;
|
|
1922
|
+
if (size === "bit" || size === undefined) {
|
|
1923
|
+
for (let i = 1;i <= componentCount; i++) {
|
|
1924
|
+
components.push(newScore(`${this.target}._${i}`));
|
|
1925
|
+
}
|
|
1926
|
+
decompose = MCFunction(`__sandstone:score/decompose_bits/${componentCount}_${splitsOrCount === undefined ? 0 : splitsOrCount.size}/${this.target.replaceAll(".", "/").toLowerCase()}`, () => {
|
|
1927
|
+
const resetBits = execute.store.result(components[0]);
|
|
1928
|
+
for (const component of components.slice(1, -1)) {
|
|
1929
|
+
resetBits.store.result(component);
|
|
1930
|
+
resetBits.nestedExecute(["\\\n "], false);
|
|
1931
|
+
}
|
|
1932
|
+
if (includeSign) {
|
|
1933
|
+
resetBits.store.result(components.at(-1));
|
|
1934
|
+
resetBits.nestedExecute(["\\\n "], false);
|
|
1935
|
+
resetBits.run(() => sign["="](0));
|
|
1936
|
+
} else {
|
|
1937
|
+
resetBits.run(() => components.at(-1)["="](0));
|
|
1938
|
+
}
|
|
1939
|
+
const input = newScore(`${this.target}._bf_iterator`);
|
|
1940
|
+
const splits = splitsOrCount ?? new Set;
|
|
1941
|
+
const bitExecute = (bit) => execute.store.success(components[bit - 1]);
|
|
1942
|
+
input["="](this);
|
|
1943
|
+
_.if(this["=="](0), () => {
|
|
1944
|
+
returnCmd(1);
|
|
1945
|
+
});
|
|
1946
|
+
if (includeSign) {
|
|
1947
|
+
execute.store.success(sign).if.score(input, "matches", [null, -1]).run(() => {
|
|
1948
|
+
input["*="](-1);
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
input.decomposeBits(splits, componentCount, bitExecute);
|
|
1952
|
+
}, {
|
|
1953
|
+
creator: "sandstone",
|
|
1954
|
+
onConflict: "rename",
|
|
1955
|
+
addToSandstoneCore: true
|
|
1956
|
+
});
|
|
1957
|
+
} else {
|
|
1958
|
+
throw new Error("[Score#getDecomposer(byte)] Byte decomposition is not yet supported");
|
|
1959
|
+
}
|
|
1960
|
+
const result = {
|
|
1961
|
+
components,
|
|
1962
|
+
...add({ sign })
|
|
1963
|
+
};
|
|
1964
|
+
return {
|
|
1965
|
+
...result,
|
|
1966
|
+
decompose: () => {
|
|
1967
|
+
decompose();
|
|
1968
|
+
return result;
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
decomposeBits(splits, componentCount, bitExecute, extra) {
|
|
1973
|
+
const { _ } = this.sandstonePack;
|
|
1974
|
+
const sortedSplits = [...splits].filter((s) => s > 0 && s < componentCount).sort((a, b) => b - a);
|
|
1975
|
+
const boundaries = [componentCount, ...sortedSplits, 0];
|
|
1976
|
+
const processRange = (high, low) => {
|
|
1977
|
+
let halvedAgain = 2 ** high;
|
|
1978
|
+
for (let bit = high;bit >= low; bit--) {
|
|
1979
|
+
halvedAgain /= 2;
|
|
1980
|
+
bitExecute(bit, halvedAgain).if.score(this, "matches", [halvedAgain, null]).run(() => {
|
|
1981
|
+
this["-="](halvedAgain);
|
|
1982
|
+
extra?.(bit, halvedAgain);
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
};
|
|
1986
|
+
const buildNested = (rangeIndex) => {
|
|
1987
|
+
const high = boundaries[rangeIndex];
|
|
1988
|
+
const low = boundaries[rangeIndex + 1] + 1;
|
|
1989
|
+
if (rangeIndex > 0) {
|
|
1990
|
+
const higherMinValue = 2 ** boundaries[rangeIndex];
|
|
1991
|
+
_.if(this.matches([higherMinValue, null]), () => {
|
|
1992
|
+
buildNested(rangeIndex - 1);
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
processRange(high, low);
|
|
1996
|
+
};
|
|
1997
|
+
if (splits.size === 0) {
|
|
1998
|
+
processRange(componentCount, 1);
|
|
1999
|
+
} else {
|
|
2000
|
+
const lowestRangeIndex = boundaries.length - 2;
|
|
2001
|
+
buildNested(lowestRangeIndex);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
[util4.inspect.custom](_depth, options) {
|
|
1890
2005
|
return formatDebugString(this.constructor.name, {
|
|
1891
2006
|
target: this.target,
|
|
1892
2007
|
display: this.display,
|
|
@@ -1946,7 +2061,9 @@ class TargetlessDataClass {
|
|
|
1946
2061
|
this.sandstonePack = sandstonePack;
|
|
1947
2062
|
this.type = type;
|
|
1948
2063
|
}
|
|
1949
|
-
target = (target) =>
|
|
2064
|
+
target = (target) => {
|
|
2065
|
+
return new DataClass(this.sandstonePack, this.type, target);
|
|
2066
|
+
};
|
|
1950
2067
|
select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, path);
|
|
1951
2068
|
}
|
|
1952
2069
|
|
|
@@ -1959,7 +2076,9 @@ class TargetlessDataPointClass {
|
|
|
1959
2076
|
this.type = type;
|
|
1960
2077
|
this.path = NBTpathToString(sandstonePack, path);
|
|
1961
2078
|
}
|
|
1962
|
-
target = (target) =>
|
|
2079
|
+
target = (target) => {
|
|
2080
|
+
return new DataPointClass(this.sandstonePack, this.type, target, [this.path]);
|
|
2081
|
+
};
|
|
1963
2082
|
select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, [this.path, ...path]);
|
|
1964
2083
|
}
|
|
1965
2084
|
|
|
@@ -2047,7 +2166,9 @@ var init_Data = __esm(() => {
|
|
|
2047
2166
|
append = (value) => this.modify((data) => data.append, value);
|
|
2048
2167
|
prepend = (value) => this.modify((data) => data.prepend, value);
|
|
2049
2168
|
insert = (value, index) => this.modify((data) => data.insert(index), value);
|
|
2050
|
-
remove = () =>
|
|
2169
|
+
remove = () => {
|
|
2170
|
+
return this.sandstonePack.commands.data.remove[this.type](this.currentTarget, this.path);
|
|
2171
|
+
};
|
|
2051
2172
|
slice = (start, end) => new StringDataPointClass(this.sandstonePack, this.type, this.currentTarget, this.path, start, end);
|
|
2052
2173
|
_toMinecraftCondition = () => new this.sandstonePack.conditions.DataPointExists(this.sandstonePack.core, this);
|
|
2053
2174
|
equals = (value) => new this.sandstonePack.conditions.DataPointEquals(this.sandstonePack.core, this, value);
|
|
@@ -2093,20 +2214,16 @@ function hasContext() {
|
|
|
2093
2214
|
var _context;
|
|
2094
2215
|
|
|
2095
2216
|
// src/core/resources/resource.ts
|
|
2096
|
-
function jsonStringify(json) {
|
|
2097
|
-
return JSON.stringify(json, (
|
|
2098
|
-
if (value
|
|
2099
|
-
return value.
|
|
2100
|
-
}
|
|
2101
|
-
if (value instanceof NBTTypedArray) {
|
|
2102
|
-
return value.values;
|
|
2217
|
+
function jsonStringify(json, resourceType) {
|
|
2218
|
+
return JSON.stringify(json, function(key, value) {
|
|
2219
|
+
if ((typeof value === "object" || typeof value === "function") && value.constructor.name !== "Object" && "toResourceJSON" in value) {
|
|
2220
|
+
return value.toResourceJSON(key, this, resourceType, json);
|
|
2103
2221
|
}
|
|
2104
2222
|
return value;
|
|
2105
2223
|
}, 2);
|
|
2106
2224
|
}
|
|
2107
2225
|
var RESOURCE_CLASS_BRAND, ResourceClass, CallableResourceClass, ResourceNodesMap;
|
|
2108
2226
|
var init_resource = __esm(() => {
|
|
2109
|
-
init_NBTs();
|
|
2110
2227
|
init_arguments();
|
|
2111
2228
|
RESOURCE_CLASS_BRAND = Symbol.for("sandstone.ResourceClass");
|
|
2112
2229
|
ResourceClass = class ResourceClass {
|
|
@@ -2210,6 +2327,9 @@ var init_resource = __esm(() => {
|
|
|
2210
2327
|
toNBT() {
|
|
2211
2328
|
return this.name;
|
|
2212
2329
|
}
|
|
2330
|
+
toJSON() {
|
|
2331
|
+
return this.name;
|
|
2332
|
+
}
|
|
2213
2333
|
static [Symbol.hasInstance](instance) {
|
|
2214
2334
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RESOURCE_CLASS_BRAND] === true;
|
|
2215
2335
|
}
|
|
@@ -2272,7 +2392,7 @@ function isTagClass(v) {
|
|
|
2272
2392
|
}
|
|
2273
2393
|
function objectToString(value) {
|
|
2274
2394
|
if (isMCFunctionClass(value)) {
|
|
2275
|
-
if (value.
|
|
2395
|
+
if (value.env && value.callback.length < 2) {
|
|
2276
2396
|
return value.node.sandstoneCore.pack.MCFunction(`${value.name}/_env`, () => value(), {
|
|
2277
2397
|
creator: "sandstone",
|
|
2278
2398
|
onConflict: "rename"
|
|
@@ -2288,7 +2408,7 @@ function objectToString(value) {
|
|
|
2288
2408
|
}
|
|
2289
2409
|
if (typeof value === "object") {
|
|
2290
2410
|
if (isMCFunctionClass(value.id)) {
|
|
2291
|
-
if (value.id.
|
|
2411
|
+
if (value.id.env && value.id.callback.length < 2) {
|
|
2292
2412
|
return {
|
|
2293
2413
|
id: value.id.node.sandstoneCore.pack.MCFunction(`${value.id.name}/_env`, () => value.id(), { creator: "sandstone", onConflict: "rename" }).name,
|
|
2294
2414
|
required: value.required
|
|
@@ -2322,7 +2442,7 @@ var init_tag = __esm(() => {
|
|
|
2322
2442
|
super(sandstoneCore);
|
|
2323
2443
|
this.resource = resource;
|
|
2324
2444
|
}
|
|
2325
|
-
getValue = () => jsonStringify(this.resource.tagJSON);
|
|
2445
|
+
getValue = () => jsonStringify(this.resource.tagJSON, this.resource._resourceType);
|
|
2326
2446
|
};
|
|
2327
2447
|
TAG_CLASS_BRAND = Symbol.for("sandstone.TagClass");
|
|
2328
2448
|
TagClass = class TagClass extends ResourceClass {
|
|
@@ -2415,7 +2535,7 @@ var init_model = __esm(() => {
|
|
|
2415
2535
|
super(sandstoneCore);
|
|
2416
2536
|
this.resource = resource;
|
|
2417
2537
|
}
|
|
2418
|
-
getValue = () => jsonStringify(this.resource.modelJSON);
|
|
2538
|
+
getValue = () => jsonStringify(this.resource.modelJSON, this.resource._resourceType);
|
|
2419
2539
|
};
|
|
2420
2540
|
MODEL_CLASS_BRAND = Symbol.for("sandstone.ModelClass");
|
|
2421
2541
|
ModelClass = class ModelClass extends ResourceClass {
|
|
@@ -2619,7 +2739,7 @@ var init_itemDefinition = __esm(() => {
|
|
|
2619
2739
|
super(sandstoneCore);
|
|
2620
2740
|
this.resource = resource;
|
|
2621
2741
|
}
|
|
2622
|
-
getValue = () => jsonStringify(this.resource.itemDefinitionJSON);
|
|
2742
|
+
getValue = () => jsonStringify(this.resource.itemDefinitionJSON, this.resource._resourceType);
|
|
2623
2743
|
};
|
|
2624
2744
|
ItemModelDefinitionClass = class ItemModelDefinitionClass extends ResourceClass {
|
|
2625
2745
|
static resourceType = "item_definition";
|
|
@@ -2787,7 +2907,12 @@ var init_DataSets = __esm(() => {
|
|
|
2787
2907
|
init_Data();
|
|
2788
2908
|
init_Score();
|
|
2789
2909
|
IterableDataClass = class IterableDataClass extends ConditionalDataPointPickClass {
|
|
2790
|
-
|
|
2910
|
+
iteratorType;
|
|
2911
|
+
constructor(sandstoneCore, iteratorType) {
|
|
2912
|
+
super(sandstoneCore);
|
|
2913
|
+
this.iteratorType = iteratorType;
|
|
2914
|
+
}
|
|
2915
|
+
iterator(_callback, _direction = "normal") {
|
|
2791
2916
|
throw new Error("Not implemented");
|
|
2792
2917
|
}
|
|
2793
2918
|
size() {
|
|
@@ -2796,24 +2921,30 @@ var init_DataSets = __esm(() => {
|
|
|
2796
2921
|
last() {
|
|
2797
2922
|
throw new Error("Not implemented");
|
|
2798
2923
|
}
|
|
2799
|
-
|
|
2924
|
+
continue(direction = "normal") {
|
|
2800
2925
|
throw new Error("Not implemented");
|
|
2801
2926
|
}
|
|
2802
2927
|
};
|
|
2803
2928
|
DataIndexMapClass = class DataIndexMapClass extends IterableDataClass {
|
|
2804
2929
|
pack;
|
|
2805
|
-
initialize;
|
|
2806
2930
|
entries = {};
|
|
2807
2931
|
dataPoint;
|
|
2808
2932
|
constructor(pack, initialize, dataPoint) {
|
|
2809
|
-
super(pack.core);
|
|
2933
|
+
super(pack.core, "map");
|
|
2810
2934
|
this.pack = pack;
|
|
2811
|
-
this.initialize = initialize;
|
|
2812
2935
|
if (dataPoint) {
|
|
2813
2936
|
this.dataPoint = dataPoint;
|
|
2814
2937
|
} else {
|
|
2815
2938
|
this.dataPoint = this.pack.DataVariable(undefined, "IndexMap");
|
|
2816
2939
|
}
|
|
2940
|
+
if (pack.core.currentMCFunction) {
|
|
2941
|
+
this.init(initialize);
|
|
2942
|
+
} else {
|
|
2943
|
+
const init = this.init;
|
|
2944
|
+
pack.initMCFunction.push(() => init(initialize));
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
init(initialize) {
|
|
2817
2948
|
for (const [i, [key, value]] of Object.entries(initialize).entries()) {
|
|
2818
2949
|
this.dataPoint.select("Index").select(key).set(i);
|
|
2819
2950
|
this.dataPoint.select("Entries").append([]);
|
|
@@ -2824,21 +2955,22 @@ var init_DataSets = __esm(() => {
|
|
|
2824
2955
|
}
|
|
2825
2956
|
}
|
|
2826
2957
|
__entryIterator;
|
|
2827
|
-
|
|
2958
|
+
entryIterator(direction) {
|
|
2828
2959
|
if (!this.__entryIterator) {
|
|
2829
|
-
this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select("
|
|
2960
|
+
this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select(`[${direction === "normal" ? 0 : -1}]`);
|
|
2830
2961
|
}
|
|
2831
2962
|
return this.__entryIterator;
|
|
2832
2963
|
}
|
|
2833
|
-
iterator(callback) {
|
|
2964
|
+
iterator(callback, direction = "normal") {
|
|
2834
2965
|
this.__entryIterator = undefined;
|
|
2966
|
+
const entryIterator = this.entryIterator(direction);
|
|
2835
2967
|
return () => {
|
|
2836
|
-
callback([
|
|
2837
|
-
|
|
2968
|
+
callback([entryIterator.select("[0]").slice(0), entryIterator.select("[1]")]);
|
|
2969
|
+
entryIterator.remove();
|
|
2838
2970
|
};
|
|
2839
2971
|
}
|
|
2840
|
-
|
|
2841
|
-
return this.entryIterator._toMinecraftCondition();
|
|
2972
|
+
continue(direction = "normal") {
|
|
2973
|
+
return this.entryIterator(direction)._toMinecraftCondition();
|
|
2842
2974
|
}
|
|
2843
2975
|
size = () => this.dataPoint.select("Entries");
|
|
2844
2976
|
last = () => [this.dataPoint.select("Entries[-1][0]").slice(0), this.dataPoint.select("Entries[-1][1]")];
|
|
@@ -2947,33 +3079,42 @@ var init_DataSets = __esm(() => {
|
|
|
2947
3079
|
pack;
|
|
2948
3080
|
dataPoint;
|
|
2949
3081
|
constructor(pack, initialize, dataPoint) {
|
|
2950
|
-
super(pack.core);
|
|
3082
|
+
super(pack.core, "list");
|
|
2951
3083
|
this.pack = pack;
|
|
2952
3084
|
if (dataPoint) {
|
|
2953
3085
|
this.dataPoint = dataPoint;
|
|
2954
3086
|
} else {
|
|
2955
3087
|
this.dataPoint = this.pack.DataVariable([], "Array");
|
|
2956
3088
|
}
|
|
3089
|
+
if (pack.core.currentMCFunction) {
|
|
3090
|
+
this.init(initialize);
|
|
3091
|
+
} else {
|
|
3092
|
+
const init = this.init;
|
|
3093
|
+
pack.initMCFunction.push(() => init(initialize));
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
init(initialize) {
|
|
2957
3097
|
for (const entry of initialize) {
|
|
2958
3098
|
this.dataPoint.append(entry);
|
|
2959
3099
|
}
|
|
2960
3100
|
}
|
|
2961
3101
|
__entryIterator;
|
|
2962
|
-
|
|
3102
|
+
entryIterator(direction) {
|
|
2963
3103
|
if (!this.__entryIterator) {
|
|
2964
|
-
this.__entryIterator = this.pack.DataVariable(this.dataPoint).select("
|
|
3104
|
+
this.__entryIterator = this.pack.DataVariable(this.dataPoint).select(`[${direction === "normal" ? 0 : -1}]`);
|
|
2965
3105
|
}
|
|
2966
3106
|
return this.__entryIterator;
|
|
2967
3107
|
}
|
|
2968
|
-
iterator(callback) {
|
|
3108
|
+
iterator(callback, direction = "normal") {
|
|
2969
3109
|
this.__entryIterator = undefined;
|
|
3110
|
+
const entryIterator = this.entryIterator(direction);
|
|
2970
3111
|
return () => {
|
|
2971
|
-
callback([
|
|
2972
|
-
|
|
3112
|
+
callback([entryIterator]);
|
|
3113
|
+
entryIterator.remove();
|
|
2973
3114
|
};
|
|
2974
3115
|
}
|
|
2975
|
-
|
|
2976
|
-
return this.entryIterator._toMinecraftCondition();
|
|
3116
|
+
continue(direction = "normal") {
|
|
3117
|
+
return this.entryIterator(direction)._toMinecraftCondition();
|
|
2977
3118
|
}
|
|
2978
3119
|
size = () => this.dataPoint;
|
|
2979
3120
|
last = () => this.dataPoint.select("[-1]");
|
|
@@ -3081,7 +3222,7 @@ var init_advancement = __esm(() => {
|
|
|
3081
3222
|
super(sandstoneCore);
|
|
3082
3223
|
this.resource = resource;
|
|
3083
3224
|
}
|
|
3084
|
-
getValue = () => jsonStringify(this.resource.advancementJSON);
|
|
3225
|
+
getValue = () => jsonStringify(this.resource.advancementJSON, this.resource._resourceType);
|
|
3085
3226
|
};
|
|
3086
3227
|
ADVANCEMENT_CLASS_BRAND = Symbol.for("sandstone.AdvancementClass");
|
|
3087
3228
|
AdvancementClass = class AdvancementClass extends ResourceClass {
|
|
@@ -3139,7 +3280,7 @@ var init_bannerPattern = __esm(() => {
|
|
|
3139
3280
|
super(sandstoneCore);
|
|
3140
3281
|
this.resource = resource;
|
|
3141
3282
|
}
|
|
3142
|
-
getValue = () => jsonStringify(this.resource.bannerPatternJSON);
|
|
3283
|
+
getValue = () => jsonStringify(this.resource.bannerPatternJSON, this.resource._resourceType);
|
|
3143
3284
|
};
|
|
3144
3285
|
BannerPatternClass = class BannerPatternClass extends ResourceClass {
|
|
3145
3286
|
static resourceType = "banner_pattern";
|
|
@@ -3164,7 +3305,7 @@ var init_chatType = __esm(() => {
|
|
|
3164
3305
|
super(sandstoneCore);
|
|
3165
3306
|
this.resource = resource;
|
|
3166
3307
|
}
|
|
3167
|
-
getValue = () => jsonStringify(this.resource.chatTypeJSON);
|
|
3308
|
+
getValue = () => jsonStringify(this.resource.chatTypeJSON, this.resource._resourceType);
|
|
3168
3309
|
};
|
|
3169
3310
|
ChatTypeClass = class ChatTypeClass extends ResourceClass {
|
|
3170
3311
|
static resourceType = "chat_type";
|
|
@@ -3190,7 +3331,7 @@ var init_damageType = __esm(() => {
|
|
|
3190
3331
|
super(sandstoneCore);
|
|
3191
3332
|
this.resource = resource;
|
|
3192
3333
|
}
|
|
3193
|
-
getValue = () => jsonStringify(this.resource.damageTypeJSON);
|
|
3334
|
+
getValue = () => jsonStringify(this.resource.damageTypeJSON, this.resource._resourceType);
|
|
3194
3335
|
};
|
|
3195
3336
|
DamageTypeClass = class DamageTypeClass extends ResourceClass {
|
|
3196
3337
|
static resourceType = "damage_type";
|
|
@@ -3252,7 +3393,7 @@ var init_dialog = __esm(() => {
|
|
|
3252
3393
|
super(sandstoneCore);
|
|
3253
3394
|
this.resource = resource;
|
|
3254
3395
|
}
|
|
3255
|
-
getValue = () => jsonStringify(this.resource.dialogJSON);
|
|
3396
|
+
getValue = () => jsonStringify(this.resource.dialogJSON, this.resource._resourceType);
|
|
3256
3397
|
};
|
|
3257
3398
|
DialogClass = class DialogClass extends ResourceClass {
|
|
3258
3399
|
static resourceType = "dialog";
|
|
@@ -3277,7 +3418,7 @@ var init_enchantment = __esm(() => {
|
|
|
3277
3418
|
super(sandstoneCore);
|
|
3278
3419
|
this.resource = resource;
|
|
3279
3420
|
}
|
|
3280
|
-
getValue = () => jsonStringify(this.resource.enchantmentJSON);
|
|
3421
|
+
getValue = () => jsonStringify(this.resource.enchantmentJSON, this.resource._resourceType);
|
|
3281
3422
|
};
|
|
3282
3423
|
EnchantmentClass = class EnchantmentClass extends ResourceClass {
|
|
3283
3424
|
static resourceType = "enchantment";
|
|
@@ -3294,7 +3435,7 @@ var init_enchantment = __esm(() => {
|
|
|
3294
3435
|
super(sandstoneCore);
|
|
3295
3436
|
this.resource = resource;
|
|
3296
3437
|
}
|
|
3297
|
-
getValue = () => jsonStringify(this.resource.enchantmentProviderJSON);
|
|
3438
|
+
getValue = () => jsonStringify(this.resource.enchantmentProviderJSON, this.resource._resourceType);
|
|
3298
3439
|
};
|
|
3299
3440
|
EnchantmentProviderClass = class EnchantmentProviderClass extends ResourceClass {
|
|
3300
3441
|
static resourceType = "enchantment_provider";
|
|
@@ -3319,7 +3460,7 @@ var init_gametest = __esm(() => {
|
|
|
3319
3460
|
super(sandstoneCore);
|
|
3320
3461
|
this.resource = resource;
|
|
3321
3462
|
}
|
|
3322
|
-
getValue = () => jsonStringify(this.resource.testEnvironmentJSON);
|
|
3463
|
+
getValue = () => jsonStringify(this.resource.testEnvironmentJSON, this.resource._resourceType);
|
|
3323
3464
|
};
|
|
3324
3465
|
TestEnvironmentClass = class TestEnvironmentClass extends ResourceClass {
|
|
3325
3466
|
static resourceType = "test_environment";
|
|
@@ -3336,7 +3477,7 @@ var init_gametest = __esm(() => {
|
|
|
3336
3477
|
super(sandstoneCore);
|
|
3337
3478
|
this.resource = resource;
|
|
3338
3479
|
}
|
|
3339
|
-
getValue = () => jsonStringify(this.resource.testInstanceJSON);
|
|
3480
|
+
getValue = () => jsonStringify(this.resource.testInstanceJSON, this.resource._resourceType);
|
|
3340
3481
|
};
|
|
3341
3482
|
TestInstanceClass = class TestInstanceClass extends ResourceClass {
|
|
3342
3483
|
static resourceType = "test_instance";
|
|
@@ -3361,7 +3502,7 @@ var init_instrument = __esm(() => {
|
|
|
3361
3502
|
super(sandstoneCore);
|
|
3362
3503
|
this.resource = resource;
|
|
3363
3504
|
}
|
|
3364
|
-
getValue = () => jsonStringify(this.resource.instrumentJSON);
|
|
3505
|
+
getValue = () => jsonStringify(this.resource.instrumentJSON, this.resource._resourceType);
|
|
3365
3506
|
};
|
|
3366
3507
|
InstrumentClass = class InstrumentClass extends ResourceClass {
|
|
3367
3508
|
static resourceType = "instrument";
|
|
@@ -3387,7 +3528,7 @@ var init_itemModifier = __esm(() => {
|
|
|
3387
3528
|
super(sandstoneCore);
|
|
3388
3529
|
this.resource = resource;
|
|
3389
3530
|
}
|
|
3390
|
-
getValue = () => jsonStringify(this.resource.itemModifierJSON);
|
|
3531
|
+
getValue = () => jsonStringify(this.resource.itemModifierJSON, this.resource._resourceType);
|
|
3391
3532
|
};
|
|
3392
3533
|
ITEM_MODIFIER_CLASS_BRAND = Symbol.for("sandstone.ItemModifierClass");
|
|
3393
3534
|
ItemModifierClass = class ItemModifierClass extends ResourceClass {
|
|
@@ -3463,7 +3604,7 @@ var init_jukeboxSong = __esm(() => {
|
|
|
3463
3604
|
super(sandstoneCore);
|
|
3464
3605
|
this.resource = resource;
|
|
3465
3606
|
}
|
|
3466
|
-
getValue = () => jsonStringify(this.resource.jukeboxSongJSON);
|
|
3607
|
+
getValue = () => jsonStringify(this.resource.jukeboxSongJSON, this.resource._resourceType);
|
|
3467
3608
|
};
|
|
3468
3609
|
JukeboxSongClass = class JukeboxSongClass extends ResourceClass {
|
|
3469
3610
|
static resourceType = "jukebox_song";
|
|
@@ -3488,7 +3629,7 @@ var init_lootTable = __esm(() => {
|
|
|
3488
3629
|
super(sandstoneCore);
|
|
3489
3630
|
this.resource = resource;
|
|
3490
3631
|
}
|
|
3491
|
-
getValue = () => jsonStringify(this.resource.lootTableJSON);
|
|
3632
|
+
getValue = () => jsonStringify(this.resource.lootTableJSON, this.resource._resourceType);
|
|
3492
3633
|
};
|
|
3493
3634
|
LootTableClass = class LootTableClass extends ResourceClass {
|
|
3494
3635
|
static resourceType = "loot_table";
|
|
@@ -3714,7 +3855,7 @@ var init_mcfunction = __esm(() => {
|
|
|
3714
3855
|
return this.body.filter((node) => node.getValue() !== null).map((node) => node.getValue()).join(`
|
|
3715
3856
|
`);
|
|
3716
3857
|
};
|
|
3717
|
-
[util7.inspect.custom](
|
|
3858
|
+
[util7.inspect.custom](_depth, options) {
|
|
3718
3859
|
return formatDebugString(this.constructor.name, {
|
|
3719
3860
|
name: this.resource.name
|
|
3720
3861
|
}, this.body, options.indent);
|
|
@@ -3730,6 +3871,7 @@ var init_mcfunction = __esm(() => {
|
|
|
3730
3871
|
tags;
|
|
3731
3872
|
lazy;
|
|
3732
3873
|
env;
|
|
3874
|
+
macroPoint;
|
|
3733
3875
|
constructor(core, name, args, env) {
|
|
3734
3876
|
if (name.startsWith("./")) {
|
|
3735
3877
|
const currentMCFunctionName = core.currentMCFunction?.resource.name;
|
|
@@ -3752,11 +3894,16 @@ var init_mcfunction = __esm(() => {
|
|
|
3752
3894
|
this.lazy = !!args.lazy;
|
|
3753
3895
|
this.addToSandstoneCore = !!args.addToSandstoneCore;
|
|
3754
3896
|
this.tags = args.tags;
|
|
3755
|
-
if (env) {
|
|
3897
|
+
if (env && env.length !== 0) {
|
|
3756
3898
|
this.env = env;
|
|
3757
3899
|
}
|
|
3900
|
+
if (this.env || this.callback.length > 1) {
|
|
3901
|
+
this.macroPoint = core.pack.DataVariable();
|
|
3902
|
+
} else {
|
|
3903
|
+
this.macroPoint = undefined;
|
|
3904
|
+
}
|
|
3758
3905
|
if (args.runOnLoad) {
|
|
3759
|
-
if (env) {
|
|
3906
|
+
if (this.env) {
|
|
3760
3907
|
core.pack.loadTags.load.push(core.pack.MCFunction(`load_${this.name.split(":")[1]}`, () => {
|
|
3761
3908
|
this.__call__();
|
|
3762
3909
|
}));
|
|
@@ -3810,21 +3957,25 @@ var init_mcfunction = __esm(() => {
|
|
|
3810
3957
|
__call__ = (..._params) => {
|
|
3811
3958
|
if (this.env || _params.length !== 0) {
|
|
3812
3959
|
const args = {};
|
|
3960
|
+
if (this.env) {
|
|
3961
|
+
for (const [i, env] of this.env.entries()) {
|
|
3962
|
+
args[`env_${i}`] = ResolveNBTPart(env);
|
|
3963
|
+
env.local.set(this.name, `env_${i}`);
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3813
3966
|
if (_params.length !== 0) {
|
|
3814
3967
|
for (const [i, param] of _params.entries()) {
|
|
3815
3968
|
args[`param_${i}`] = ResolveNBTPart(param);
|
|
3816
3969
|
param.local.set(this.name, `param_${i}`);
|
|
3817
3970
|
}
|
|
3818
3971
|
this.node.body = [];
|
|
3972
|
+
this.core.enterMCFunction(this);
|
|
3819
3973
|
this.core.insideContext(this.node, () => this.callback(makeCallable(this, this.__call__.bind(undefined, ..._params)), ..._params), false);
|
|
3974
|
+
this.core.exitMCFunction();
|
|
3975
|
+
} else if (this.callback.length > 1) {
|
|
3976
|
+
throw new Error(`[MCFunctionClass] Function ${this.name} expects ${this.callback.length - 1} params at the call-site`);
|
|
3820
3977
|
}
|
|
3821
|
-
|
|
3822
|
-
for (const [i, env] of this.env.entries()) {
|
|
3823
|
-
args[`env_${i}`] = ResolveNBTPart(env);
|
|
3824
|
-
env.local.set(this.name, `env_${i}`);
|
|
3825
|
-
}
|
|
3826
|
-
}
|
|
3827
|
-
return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args).dataPoint);
|
|
3978
|
+
return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args, this.macroPoint).dataPoint);
|
|
3828
3979
|
}
|
|
3829
3980
|
return this.commands.functionCmd(this.name);
|
|
3830
3981
|
};
|
|
@@ -3854,12 +4005,14 @@ var init_mcfunction = __esm(() => {
|
|
|
3854
4005
|
});
|
|
3855
4006
|
if (contents[0] instanceof _RawMCFunctionClass) {
|
|
3856
4007
|
for (const mcfunction of contents) {
|
|
4008
|
+
mcfunction.generate();
|
|
3857
4009
|
this.node.body.unshift(...mcfunction.node.body);
|
|
3858
4010
|
}
|
|
3859
4011
|
} else {
|
|
3860
4012
|
this.core.enterMCFunction(fake);
|
|
3861
4013
|
this.core.insideContext(fake.node, contents[0], false);
|
|
3862
4014
|
this.core.exitMCFunction();
|
|
4015
|
+
fake.generate();
|
|
3863
4016
|
this.node.body.unshift(...fake.node.body);
|
|
3864
4017
|
}
|
|
3865
4018
|
}
|
|
@@ -3872,12 +4025,14 @@ var init_mcfunction = __esm(() => {
|
|
|
3872
4025
|
const fullBody = [];
|
|
3873
4026
|
if (contents[0] instanceof _RawMCFunctionClass) {
|
|
3874
4027
|
for (const mcfunction of contents) {
|
|
4028
|
+
mcfunction.generate();
|
|
3875
4029
|
fullBody.push(...mcfunction.node.body);
|
|
3876
4030
|
}
|
|
3877
4031
|
} else {
|
|
3878
4032
|
this.core.enterMCFunction(fake);
|
|
3879
4033
|
this.core.insideContext(fake.node, contents[0], false);
|
|
3880
4034
|
this.core.exitMCFunction();
|
|
4035
|
+
fake.generate();
|
|
3881
4036
|
fullBody.push(...fake.node.body);
|
|
3882
4037
|
}
|
|
3883
4038
|
this.node.body.splice(start, removeItems === "auto" ? fullBody.length : removeItems, ...fullBody);
|
|
@@ -3904,7 +4059,7 @@ var init_predicate = __esm(() => {
|
|
|
3904
4059
|
super(sandstoneCore);
|
|
3905
4060
|
this.resource = resource;
|
|
3906
4061
|
}
|
|
3907
|
-
getValue = () => jsonStringify(this.resource.predicateJSON);
|
|
4062
|
+
getValue = () => jsonStringify(this.resource.predicateJSON, this.resource._resourceType);
|
|
3908
4063
|
};
|
|
3909
4064
|
PREDICATE_CLASS_BRAND = Symbol.for("sandstone.PredicateClass");
|
|
3910
4065
|
PredicateClass = class PredicateClass extends ResourceClass {
|
|
@@ -3974,7 +4129,7 @@ var init_recipe = __esm(() => {
|
|
|
3974
4129
|
super(sandstoneCore);
|
|
3975
4130
|
this.resource = resource;
|
|
3976
4131
|
}
|
|
3977
|
-
getValue = () => jsonStringify(this.resource.recipeJSON);
|
|
4132
|
+
getValue = () => jsonStringify(this.resource.recipeJSON, this.resource._resourceType);
|
|
3978
4133
|
};
|
|
3979
4134
|
RecipeClass = class RecipeClass extends ResourceClass {
|
|
3980
4135
|
static resourceType = "recipe";
|
|
@@ -4212,7 +4367,7 @@ var init_structure = __esm(() => {
|
|
|
4212
4367
|
blockPos: [layer[0], row[0], entry[0]],
|
|
4213
4368
|
nbt: {
|
|
4214
4369
|
id: entity.id,
|
|
4215
|
-
...add(entity.nbt)
|
|
4370
|
+
...add({ ...entity.nbt })
|
|
4216
4371
|
}
|
|
4217
4372
|
});
|
|
4218
4373
|
}
|
|
@@ -4292,7 +4447,7 @@ var init_timeline = __esm(() => {
|
|
|
4292
4447
|
super(sandstoneCore);
|
|
4293
4448
|
this.resource = resource;
|
|
4294
4449
|
}
|
|
4295
|
-
getValue = () => jsonStringify(this.resource.timelineJSON);
|
|
4450
|
+
getValue = () => jsonStringify(this.resource.timelineJSON, this.resource._resourceType);
|
|
4296
4451
|
};
|
|
4297
4452
|
TimelineClass = class TimelineClass extends ResourceClass {
|
|
4298
4453
|
static resourceType = "timeline";
|
|
@@ -4309,7 +4464,7 @@ var init_timeline = __esm(() => {
|
|
|
4309
4464
|
super(sandstoneCore);
|
|
4310
4465
|
this.resource = resource;
|
|
4311
4466
|
}
|
|
4312
|
-
getValue = () => jsonStringify(this.resource.worldClockJSON);
|
|
4467
|
+
getValue = () => jsonStringify(this.resource.worldClockJSON, this.resource._resourceType);
|
|
4313
4468
|
};
|
|
4314
4469
|
WorldClockClass = class WorldClockClass extends ResourceClass {
|
|
4315
4470
|
static resourceType = "world_clock";
|
|
@@ -4337,7 +4492,7 @@ var init_trialSpawner = __esm(() => {
|
|
|
4337
4492
|
super(sandstoneCore);
|
|
4338
4493
|
this.resource = resource;
|
|
4339
4494
|
}
|
|
4340
|
-
getValue = () => jsonStringify(this.resource.trialSpawnerJSON);
|
|
4495
|
+
getValue = () => jsonStringify(this.resource.trialSpawnerJSON, this.resource._resourceType);
|
|
4341
4496
|
};
|
|
4342
4497
|
TrialSpawnerClass = class TrialSpawnerClass extends ResourceClass {
|
|
4343
4498
|
static resourceType = "trial_spawner";
|
|
@@ -4362,7 +4517,7 @@ var init_trimMaterial = __esm(() => {
|
|
|
4362
4517
|
super(sandstoneCore);
|
|
4363
4518
|
this.resource = resource;
|
|
4364
4519
|
}
|
|
4365
|
-
getValue = () => jsonStringify(this.resource.trimMaterialJSON);
|
|
4520
|
+
getValue = () => jsonStringify(this.resource.trimMaterialJSON, this.resource._resourceType);
|
|
4366
4521
|
};
|
|
4367
4522
|
TrimMaterialClass = class TrimMaterialClass extends ResourceClass {
|
|
4368
4523
|
static resourceType = "trim_material";
|
|
@@ -4390,7 +4545,7 @@ var init_trimPattern = __esm(() => {
|
|
|
4390
4545
|
super(sandstoneCore);
|
|
4391
4546
|
this.resource = resource;
|
|
4392
4547
|
}
|
|
4393
|
-
getValue = () => jsonStringify(this.resource.trimPatternJSON);
|
|
4548
|
+
getValue = () => jsonStringify(this.resource.trimPatternJSON, this.resource._resourceType);
|
|
4394
4549
|
};
|
|
4395
4550
|
TrimPatternClass = class TrimPatternClass extends ResourceClass {
|
|
4396
4551
|
static resourceType = "trim_pattern";
|
|
@@ -4414,7 +4569,7 @@ var init_variant = __esm(() => {
|
|
|
4414
4569
|
super(sandstoneCore);
|
|
4415
4570
|
this.resource = resource;
|
|
4416
4571
|
}
|
|
4417
|
-
getValue = () => jsonStringify(this.resource.variantJSON);
|
|
4572
|
+
getValue = () => jsonStringify(this.resource.variantJSON, this.resource._resourceType);
|
|
4418
4573
|
};
|
|
4419
4574
|
VariantClass = class VariantClass extends ResourceClass {
|
|
4420
4575
|
variantType;
|
|
@@ -4441,7 +4596,7 @@ var init_villagerTrade = __esm(() => {
|
|
|
4441
4596
|
super(sandstoneCore);
|
|
4442
4597
|
this.resource = resource;
|
|
4443
4598
|
}
|
|
4444
|
-
getValue = () => jsonStringify(this.resource.villagerTradeJSON);
|
|
4599
|
+
getValue = () => jsonStringify(this.resource.villagerTradeJSON, this.resource._resourceType);
|
|
4445
4600
|
};
|
|
4446
4601
|
VillagerTradeClass = class VillagerTradeClass extends ResourceClass {
|
|
4447
4602
|
static resourceType = "villager_trade";
|
|
@@ -4458,7 +4613,7 @@ var init_villagerTrade = __esm(() => {
|
|
|
4458
4613
|
super(sandstoneCore);
|
|
4459
4614
|
this.resource = resource;
|
|
4460
4615
|
}
|
|
4461
|
-
getValue = () => jsonStringify(this.resource.tradeSetJSON);
|
|
4616
|
+
getValue = () => jsonStringify(this.resource.tradeSetJSON, this.resource._resourceType);
|
|
4462
4617
|
};
|
|
4463
4618
|
TradeSetClass = class TradeSetClass extends ResourceClass {
|
|
4464
4619
|
static resourceType = "trade_set";
|
|
@@ -4509,7 +4664,7 @@ var init_atlas = __esm(() => {
|
|
|
4509
4664
|
super(sandstoneCore);
|
|
4510
4665
|
this.resource = resource;
|
|
4511
4666
|
}
|
|
4512
|
-
getValue = () => jsonStringify(this.resource.atlasJSON);
|
|
4667
|
+
getValue = () => jsonStringify(this.resource.atlasJSON, this.resource._resourceType);
|
|
4513
4668
|
};
|
|
4514
4669
|
ATLAS_CLASS_BRAND = Symbol.for("sandstone.AtlasClass");
|
|
4515
4670
|
AtlasClass = class AtlasClass extends ResourceClass {
|
|
@@ -4557,7 +4712,7 @@ var init_blockstate = __esm(() => {
|
|
|
4557
4712
|
super(sandstoneCore);
|
|
4558
4713
|
this.resource = resource;
|
|
4559
4714
|
}
|
|
4560
|
-
getValue = () => jsonStringify(this.resource.blockStateJSON);
|
|
4715
|
+
getValue = () => jsonStringify(this.resource.blockStateJSON, this.resource._resourceType);
|
|
4561
4716
|
};
|
|
4562
4717
|
BLOCK_STATE_CLASS_BRAND = Symbol.for("sandstone.BlockStateClass");
|
|
4563
4718
|
BlockStateClass = class BlockStateClass extends ResourceClass {
|
|
@@ -4638,7 +4793,7 @@ var init_equipment = __esm(() => {
|
|
|
4638
4793
|
super(sandstoneCore);
|
|
4639
4794
|
this.resource = resource;
|
|
4640
4795
|
}
|
|
4641
|
-
getValue = () => jsonStringify(this.resource.equipmentJSON);
|
|
4796
|
+
getValue = () => jsonStringify(this.resource.equipmentJSON, this.resource._resourceType);
|
|
4642
4797
|
};
|
|
4643
4798
|
EquipmentClass = class EquipmentClass extends ResourceClass {
|
|
4644
4799
|
static resourceType = "equipment";
|
|
@@ -4663,7 +4818,7 @@ var init_font = __esm(() => {
|
|
|
4663
4818
|
super(sandstoneCore);
|
|
4664
4819
|
this.resource = resource;
|
|
4665
4820
|
}
|
|
4666
|
-
getValue = () => jsonStringify(this.resource.fontJSON);
|
|
4821
|
+
getValue = () => jsonStringify(this.resource.fontJSON, this.resource._resourceType);
|
|
4667
4822
|
};
|
|
4668
4823
|
FONT_CLASS_BRAND = Symbol.for("sandstone.FontClass");
|
|
4669
4824
|
FontClass = class FontClass extends ResourceClass {
|
|
@@ -4711,7 +4866,7 @@ var init_language = __esm(() => {
|
|
|
4711
4866
|
super(sandstoneCore);
|
|
4712
4867
|
this.resource = resource;
|
|
4713
4868
|
}
|
|
4714
|
-
getValue = () => jsonStringify(this.resource.languageJSON);
|
|
4869
|
+
getValue = () => jsonStringify(this.resource.languageJSON, this.resource._resourceType);
|
|
4715
4870
|
};
|
|
4716
4871
|
LANGUAGE_CLASS_BRAND = Symbol.for("sandstone.LanguageClass");
|
|
4717
4872
|
LanguageClass = class LanguageClass extends ResourceClass {
|
|
@@ -4763,7 +4918,7 @@ var init_particle = __esm(() => {
|
|
|
4763
4918
|
super(sandstoneCore);
|
|
4764
4919
|
this.resource = resource;
|
|
4765
4920
|
}
|
|
4766
|
-
getValue = () => jsonStringify(this.resource.particleJSON);
|
|
4921
|
+
getValue = () => jsonStringify(this.resource.particleJSON, this.resource._resourceType);
|
|
4767
4922
|
};
|
|
4768
4923
|
ParticleClass = class ParticleClass extends ResourceClass {
|
|
4769
4924
|
static resourceType = "particle";
|
|
@@ -4788,7 +4943,7 @@ var init_postEffect = __esm(() => {
|
|
|
4788
4943
|
super(sandstoneCore);
|
|
4789
4944
|
this.resource = resource;
|
|
4790
4945
|
}
|
|
4791
|
-
getValue = () => jsonStringify(this.resource.postEffectJSON);
|
|
4946
|
+
getValue = () => jsonStringify(this.resource.postEffectJSON, this.resource._resourceType);
|
|
4792
4947
|
};
|
|
4793
4948
|
PostEffectClass = class PostEffectClass extends ResourceClass {
|
|
4794
4949
|
static resourceType = "post_effect";
|
|
@@ -4813,7 +4968,7 @@ var init_shader = __esm(() => {
|
|
|
4813
4968
|
super(sandstoneCore);
|
|
4814
4969
|
this.resource = resource;
|
|
4815
4970
|
}
|
|
4816
|
-
getValue = () => jsonStringify(this.resource.shaderJSON);
|
|
4971
|
+
getValue = () => jsonStringify(this.resource.shaderJSON, this.resource._resourceType);
|
|
4817
4972
|
};
|
|
4818
4973
|
ShaderClass = class ShaderClass extends ResourceClass {
|
|
4819
4974
|
static resourceType = "shader";
|
|
@@ -4875,7 +5030,7 @@ var init_sound = __esm(() => {
|
|
|
4875
5030
|
super(sandstoneCore);
|
|
4876
5031
|
this.resource = resource;
|
|
4877
5032
|
}
|
|
4878
|
-
getValue = () => jsonStringify(this.resource.soundsJSON);
|
|
5033
|
+
getValue = () => jsonStringify(this.resource.soundsJSON, this.resource._resourceType);
|
|
4879
5034
|
};
|
|
4880
5035
|
SOUNDS_CLASS_BRAND = Symbol.for("sandstone.SoundsClass");
|
|
4881
5036
|
SoundsClass = class SoundsClass extends ResourceClass {
|
|
@@ -5105,7 +5260,7 @@ var init_waypointStyle = __esm(() => {
|
|
|
5105
5260
|
super(sandstoneCore);
|
|
5106
5261
|
this.resource = resource;
|
|
5107
5262
|
}
|
|
5108
|
-
getValue = () => jsonStringify(this.resource.waypointStyleJSON);
|
|
5263
|
+
getValue = () => jsonStringify(this.resource.waypointStyleJSON, this.resource._resourceType);
|
|
5109
5264
|
};
|
|
5110
5265
|
WaypointStyleClass = class WaypointStyleClass extends ResourceClass {
|
|
5111
5266
|
static resourceType = "waypoint_style";
|
|
@@ -5674,7 +5829,18 @@ class SandstoneCore {
|
|
|
5674
5829
|
_path.splice(1, 0, packType.resourceSubFolder);
|
|
5675
5830
|
}
|
|
5676
5831
|
const resourcePath = path4.join(..._path);
|
|
5677
|
-
|
|
5832
|
+
let value;
|
|
5833
|
+
try {
|
|
5834
|
+
value = await node.getValue();
|
|
5835
|
+
} catch (e) {
|
|
5836
|
+
console.log(`
|
|
5837
|
+
|
|
5838
|
+
|
|
5839
|
+
|
|
5840
|
+
`);
|
|
5841
|
+
console.log(node);
|
|
5842
|
+
throw e;
|
|
5843
|
+
}
|
|
5678
5844
|
if (cliOptions.verbose) {
|
|
5679
5845
|
console.log(`Path: ${resourcePath}.${fileExtension}
|
|
5680
5846
|
|
|
@@ -5723,7 +5889,11 @@ var init_JSONTextComponentClass = __esm(() => {
|
|
|
5723
5889
|
this.jsonTextComponent = jsonTextComponent;
|
|
5724
5890
|
}
|
|
5725
5891
|
toString() {
|
|
5726
|
-
|
|
5892
|
+
const component = toComponent(this.jsonTextComponent);
|
|
5893
|
+
if (typeof component === "string") {
|
|
5894
|
+
return `"${component}"`;
|
|
5895
|
+
}
|
|
5896
|
+
return JSON.stringify(component, function(key, value) {
|
|
5727
5897
|
if (Array.isArray(this)) {
|
|
5728
5898
|
const realValue = this[Number.parseInt(key, 10)];
|
|
5729
5899
|
return toComponent(realValue);
|
|
@@ -5938,14 +6108,52 @@ var init_Label = __esm(() => {
|
|
|
5938
6108
|
LabelClass = makeClassCallable(_RawLabelClass);
|
|
5939
6109
|
});
|
|
5940
6110
|
|
|
6111
|
+
// src/commands/implementations/server/function.ts
|
|
6112
|
+
var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
|
|
6113
|
+
var init_function = __esm(() => {
|
|
6114
|
+
init_nodes();
|
|
6115
|
+
init_tag();
|
|
6116
|
+
init_NBTs();
|
|
6117
|
+
FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
|
|
6118
|
+
FunctionCommandNode = class FunctionCommandNode extends CommandNode {
|
|
6119
|
+
[FUNCTION_COMMAND_NODE_BRAND] = true;
|
|
6120
|
+
command = "function";
|
|
6121
|
+
static [Symbol.hasInstance](instance) {
|
|
6122
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
|
|
6123
|
+
}
|
|
6124
|
+
};
|
|
6125
|
+
FunctionCommand = class FunctionCommand extends CommandArguments {
|
|
6126
|
+
NodeType = FunctionCommandNode;
|
|
6127
|
+
function(mcFunction, params, pointOrType, target, path5) {
|
|
6128
|
+
const args = [];
|
|
6129
|
+
if (params) {
|
|
6130
|
+
if (params === "with" && pointOrType) {
|
|
6131
|
+
args.push("with");
|
|
6132
|
+
if (typeof pointOrType === "string") {
|
|
6133
|
+
args.push(pointOrType, target, path5 ?? "{}");
|
|
6134
|
+
} else {
|
|
6135
|
+
const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
|
|
6136
|
+
args.push(point.type, point.currentTarget, point.path);
|
|
6137
|
+
}
|
|
6138
|
+
} else {
|
|
6139
|
+
args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
|
|
6140
|
+
}
|
|
6141
|
+
}
|
|
6142
|
+
return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
|
|
6143
|
+
}
|
|
6144
|
+
};
|
|
6145
|
+
});
|
|
6146
|
+
|
|
5941
6147
|
// src/variables/Loop.ts
|
|
5942
6148
|
var LOOP_ARGUMENT_BRAND, LoopArgument;
|
|
5943
6149
|
var init_Loop = __esm(() => {
|
|
6150
|
+
init_function();
|
|
5944
6151
|
init_nodes();
|
|
5945
6152
|
LOOP_ARGUMENT_BRAND = Symbol.for("sandstone.LoopArgument");
|
|
5946
6153
|
LoopArgument = class LoopArgument extends Node {
|
|
5947
6154
|
pack;
|
|
5948
6155
|
[LOOP_ARGUMENT_BRAND] = true;
|
|
6156
|
+
loopIfNode = null;
|
|
5949
6157
|
constructor(pack) {
|
|
5950
6158
|
super(pack.core);
|
|
5951
6159
|
this.pack = pack;
|
|
@@ -5955,7 +6163,15 @@ var init_Loop = __esm(() => {
|
|
|
5955
6163
|
return this.toLoop();
|
|
5956
6164
|
}
|
|
5957
6165
|
toLoop() {
|
|
5958
|
-
|
|
6166
|
+
const loopExecute = this.loopIfNode?.resultingExecuteNode;
|
|
6167
|
+
if (loopExecute?.createdMCFunction) {
|
|
6168
|
+
const funcNode = new FunctionCommandNode(this.pack, loopExecute.createdMCFunction.name);
|
|
6169
|
+
if (loopExecute.macroStorage) {
|
|
6170
|
+
funcNode.args.push("with", "storage", loopExecute.macroStorage.currentTarget, loopExecute.macroStorage.path);
|
|
6171
|
+
}
|
|
6172
|
+
return funcNode.getValue();
|
|
6173
|
+
}
|
|
6174
|
+
return new FunctionCommandNode(this.pack, this.pack.core.currentNode);
|
|
5959
6175
|
}
|
|
5960
6176
|
static [Symbol.hasInstance](instance) {
|
|
5961
6177
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[LOOP_ARGUMENT_BRAND] === true;
|
|
@@ -5995,7 +6211,6 @@ var init_Objective = __esm(() => {
|
|
|
5995
6211
|
return formatDebugString(this.constructor.name, {
|
|
5996
6212
|
name: this.name,
|
|
5997
6213
|
criteria: this.criteria,
|
|
5998
|
-
display: this.display,
|
|
5999
6214
|
creator: this.creator
|
|
6000
6215
|
}, undefined, options.indent);
|
|
6001
6216
|
}
|
|
@@ -6051,13 +6266,13 @@ var init_Sleep = __esm(() => {
|
|
|
6051
6266
|
const { execute } = commands;
|
|
6052
6267
|
const name = `__sandstone:asyncTimer.${currentFunction.resource.name.replace(/[:/]/g, ".")}`;
|
|
6053
6268
|
const timer = new ObjectiveClass(core.pack, name.replace(":", "."), "dummy", undefined, { creator: "sandstone" });
|
|
6054
|
-
execute.store.result
|
|
6269
|
+
execute.store.result(timer("@s")).run.time.query("gametime");
|
|
6055
6270
|
timer("@s").add(Duration);
|
|
6056
6271
|
const label = Label(name);
|
|
6057
6272
|
label("@s").add();
|
|
6058
6273
|
this.mcfunction.unshift(() => label("@s").remove());
|
|
6059
6274
|
schedule = MCFunction(`${this.mcfunction.name}/_context`, () => {
|
|
6060
|
-
execute.store.result
|
|
6275
|
+
execute.store.result(timer("#current")).run.time.query("gametime");
|
|
6061
6276
|
execute.as(Selector("@e", { tag: label.fullName })).if.score(timer("@s"), "=", timer("#current")).at("@s").run.functionCmd(this.mcfunction);
|
|
6062
6277
|
}, {
|
|
6063
6278
|
packType: currentFunction.resource.packType
|
|
@@ -6151,42 +6366,6 @@ var init_setblock = __esm(() => {
|
|
|
6151
6366
|
};
|
|
6152
6367
|
});
|
|
6153
6368
|
|
|
6154
|
-
// src/commands/implementations/server/function.ts
|
|
6155
|
-
var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
|
|
6156
|
-
var init_function = __esm(() => {
|
|
6157
|
-
init_nodes();
|
|
6158
|
-
init_tag();
|
|
6159
|
-
init_NBTs();
|
|
6160
|
-
FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
|
|
6161
|
-
FunctionCommandNode = class FunctionCommandNode extends CommandNode {
|
|
6162
|
-
[FUNCTION_COMMAND_NODE_BRAND] = true;
|
|
6163
|
-
command = "function";
|
|
6164
|
-
static [Symbol.hasInstance](instance) {
|
|
6165
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
|
|
6166
|
-
}
|
|
6167
|
-
};
|
|
6168
|
-
FunctionCommand = class FunctionCommand extends CommandArguments {
|
|
6169
|
-
NodeType = FunctionCommandNode;
|
|
6170
|
-
function(mcFunction, params, pointOrType, target, path5) {
|
|
6171
|
-
const args = [];
|
|
6172
|
-
if (params) {
|
|
6173
|
-
if (params === "with" && pointOrType) {
|
|
6174
|
-
args.push("with");
|
|
6175
|
-
if (typeof pointOrType === "string") {
|
|
6176
|
-
args.push(pointOrType, target, path5 ?? "{}");
|
|
6177
|
-
} else {
|
|
6178
|
-
const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
|
|
6179
|
-
args.push(point.type, point.currentTarget, point.path);
|
|
6180
|
-
}
|
|
6181
|
-
} else {
|
|
6182
|
-
args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
|
|
6183
|
-
}
|
|
6184
|
-
}
|
|
6185
|
-
return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
|
|
6186
|
-
}
|
|
6187
|
-
};
|
|
6188
|
-
});
|
|
6189
|
-
|
|
6190
6369
|
// src/commands/implementations/entity/execute.ts
|
|
6191
6370
|
function createDeferredMacroExecute(pack, executeChain, options) {
|
|
6192
6371
|
const { childFunctionName, prependArgs } = options;
|
|
@@ -6209,7 +6388,7 @@ function createDeferredMacroExecute(pack, executeChain, options) {
|
|
|
6209
6388
|
childFunctionNode = childFunction.node;
|
|
6210
6389
|
} else {
|
|
6211
6390
|
const childFunction = pack.MCFunction(`${currentFunction.resource.name}/${childFunctionName}`, () => {}, { creator: "sandstone", onConflict: "rename" });
|
|
6212
|
-
pack.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage);
|
|
6391
|
+
pack.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage.currentTarget, options.macroStorage.path);
|
|
6213
6392
|
childFunctionNode = childFunction.node;
|
|
6214
6393
|
}
|
|
6215
6394
|
childFunctionNode.body.push(macroNode);
|
|
@@ -6293,15 +6472,15 @@ var init_execute = __esm(() => {
|
|
|
6293
6472
|
isSingleExecute;
|
|
6294
6473
|
givenCallbackName;
|
|
6295
6474
|
macroStorage;
|
|
6296
|
-
|
|
6475
|
+
pendingCommit;
|
|
6476
|
+
createdMCFunction = null;
|
|
6477
|
+
constructor(sandstonePack, args = [], { isFake = false, isSingleExecute = true, givenCallbackName = undefined, body = [], macroStorage = undefined, pendingCommit = false } = {}) {
|
|
6297
6478
|
super(sandstonePack, ...args);
|
|
6298
6479
|
this.givenCallbackName = givenCallbackName;
|
|
6299
6480
|
this.isSingleExecute = isSingleExecute;
|
|
6300
6481
|
this.isFake = isFake;
|
|
6301
6482
|
this.macroStorage = macroStorage;
|
|
6302
|
-
|
|
6303
|
-
this.isMacro = true;
|
|
6304
|
-
}
|
|
6483
|
+
this.pendingCommit = pendingCommit;
|
|
6305
6484
|
this.append(...body);
|
|
6306
6485
|
}
|
|
6307
6486
|
get callbackName() {
|
|
@@ -6312,6 +6491,9 @@ var init_execute = __esm(() => {
|
|
|
6312
6491
|
this.body.push(node);
|
|
6313
6492
|
if (this.isSingleExecute) {
|
|
6314
6493
|
this.sandstoneCore.getCurrentMCFunctionOrThrow().exitContext();
|
|
6494
|
+
if (this.pendingCommit && !this.commited) {
|
|
6495
|
+
this.commit();
|
|
6496
|
+
}
|
|
6315
6497
|
}
|
|
6316
6498
|
}
|
|
6317
6499
|
return nodes2.length === 1 ? nodes2[0] : nodes2;
|
|
@@ -6360,9 +6542,10 @@ var init_execute = __esm(() => {
|
|
|
6360
6542
|
});
|
|
6361
6543
|
const mcFunctionNode = mcFunction.node;
|
|
6362
6544
|
mcFunctionNode.body = this.body;
|
|
6545
|
+
this.createdMCFunction = mcFunction;
|
|
6363
6546
|
const mcFunctionCall = new FunctionCommandNode(this.sandstonePack, mcFunction);
|
|
6364
6547
|
if (this.macroStorage) {
|
|
6365
|
-
mcFunctionCall.args.push("with", "storage", this.macroStorage,
|
|
6548
|
+
mcFunctionCall.args.push("with", "storage", this.macroStorage.currentTarget, this.macroStorage.path);
|
|
6366
6549
|
}
|
|
6367
6550
|
this.body = [mcFunctionCall];
|
|
6368
6551
|
return { node: this, mcFunction: mcFunctionNode };
|
|
@@ -6375,20 +6558,30 @@ var init_execute = __esm(() => {
|
|
|
6375
6558
|
block = (targetPos, path5, type, scale) => this.nestedExecute(["block", coordinatesParser(targetPos), path5, type, scale]);
|
|
6376
6559
|
bossbar = (id2, type) => this.nestedExecute(["bossbar", id2, type]);
|
|
6377
6560
|
entity = (target, path5, type, scale) => this.nestedExecute(["entity", targetParser(target), path5, type, scale]);
|
|
6378
|
-
score(
|
|
6379
|
-
if (isScore(args[0])) {
|
|
6380
|
-
return this.nestedExecute(["score", args[0]]);
|
|
6381
|
-
}
|
|
6382
|
-
return this.nestedExecute(["score", targetParser(args[0]), args[1]]);
|
|
6383
|
-
}
|
|
6561
|
+
score = (targets, objective) => this.nestedExecute(["score", targetParser(targets), objective]);
|
|
6384
6562
|
storage = (target, path5, type, scale = 1) => this.nestedExecute(["storage", target, path5, type, scale]);
|
|
6385
6563
|
};
|
|
6386
6564
|
ExecuteStoreCommand = class ExecuteStoreCommand extends ExecuteCommandPart {
|
|
6565
|
+
_storeCallable(cmd, target, type, scale) {
|
|
6566
|
+
if (isScore(target)) {
|
|
6567
|
+
return cmd.score(target.target, target.objective);
|
|
6568
|
+
}
|
|
6569
|
+
const resolvedType = type ?? "int";
|
|
6570
|
+
if (target.type === "block") {
|
|
6571
|
+
return cmd.block(coordinatesParser(target.currentTarget), target.path, resolvedType, scale);
|
|
6572
|
+
}
|
|
6573
|
+
if (target.type === "entity") {
|
|
6574
|
+
return cmd.entity(target.currentTarget, target.path, resolvedType, scale);
|
|
6575
|
+
}
|
|
6576
|
+
return cmd.storage(target.currentTarget, target.path, resolvedType, scale);
|
|
6577
|
+
}
|
|
6387
6578
|
get result() {
|
|
6388
|
-
|
|
6579
|
+
const cmd = this.subCommand([["result"]], ExecuteStoreArgsCommand, false);
|
|
6580
|
+
return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
|
|
6389
6581
|
}
|
|
6390
6582
|
get success() {
|
|
6391
|
-
|
|
6583
|
+
const cmd = this.subCommand([["success"]], ExecuteStoreArgsCommand, false);
|
|
6584
|
+
return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
|
|
6392
6585
|
}
|
|
6393
6586
|
};
|
|
6394
6587
|
ExecuteDataArgsCommand = class ExecuteDataArgsCommand extends ExecuteCommandPart {
|
|
@@ -6513,6 +6706,9 @@ var init_execute = __esm(() => {
|
|
|
6513
6706
|
const node = this.getNode();
|
|
6514
6707
|
const commands = new Proxy(this.sandstonePack.commands, {
|
|
6515
6708
|
get: (_t, p, _r) => {
|
|
6709
|
+
if (!node.commited) {
|
|
6710
|
+
node.pendingCommit = true;
|
|
6711
|
+
}
|
|
6516
6712
|
this.sandstoneCore.getCurrentMCFunctionOrThrow().enterContext(node, false);
|
|
6517
6713
|
return this.sandstonePack.commands[p];
|
|
6518
6714
|
}
|
|
@@ -6523,7 +6719,7 @@ var init_execute = __esm(() => {
|
|
|
6523
6719
|
node.givenCallbackName = args[0];
|
|
6524
6720
|
}
|
|
6525
6721
|
node.isSingleExecute = false;
|
|
6526
|
-
this.sandstoneCore.insideContext(node, callback,
|
|
6722
|
+
this.sandstoneCore.insideContext(node, callback, !node.commited);
|
|
6527
6723
|
return new FinalCommandOutput(node);
|
|
6528
6724
|
}, true);
|
|
6529
6725
|
}
|
|
@@ -6743,7 +6939,7 @@ class UUIDClass {
|
|
|
6743
6939
|
}
|
|
6744
6940
|
if (this.data || this.scores) {
|
|
6745
6941
|
const pack = this.core.pack;
|
|
6746
|
-
const { MCFunction, getTempStorage, commands: commands2 } = pack;
|
|
6942
|
+
const { MCFunction, getTempStorage, commands: commands2, Macro: Macro2, Data } = pack;
|
|
6747
6943
|
const { data } = commands2;
|
|
6748
6944
|
let sourceData = this.data;
|
|
6749
6945
|
if (!sourceData && this.scores) {
|
|
@@ -6757,15 +6953,15 @@ class UUIDClass {
|
|
|
6757
6953
|
tempUUID.set(sourceData);
|
|
6758
6954
|
const cacheKeyVar = this.primarySource === "scores" && this.scores ? this.scores[0] : tempUUID;
|
|
6759
6955
|
const currentFunction = this.core.getCurrentMCFunctionOrThrow();
|
|
6760
|
-
const
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6956
|
+
const uuidLookup = Data("storage", "__sandstone:temp", "uuid_lookup");
|
|
6957
|
+
MCFunction(`${currentFunction.resource.name}/__uuid_lookup`, [cacheKeyVar], () => {
|
|
6958
|
+
Macro2.data.modify(uuidLookup.select("uuid_string")).set.from.storage(UUID_CACHE.STORAGE, Macro2`"${cacheKeyVar}"`);
|
|
6959
|
+
}, { creator: "sandstone", onConflict: "rename" })();
|
|
6764
6960
|
const deferredExecute = new ExecuteCommand(pack, undefined, false);
|
|
6765
6961
|
return createDeferredMacroExecute(pack, deferredExecute, {
|
|
6766
6962
|
childFunctionName: "__uuid_execute",
|
|
6767
6963
|
prependArgs: () => [["as", "$(uuid_string)"]],
|
|
6768
|
-
macroStorage:
|
|
6964
|
+
macroStorage: uuidLookup
|
|
6769
6965
|
});
|
|
6770
6966
|
}
|
|
6771
6967
|
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.");
|
|
@@ -7790,7 +7986,7 @@ var init_reload = __esm(() => {
|
|
|
7790
7986
|
});
|
|
7791
7987
|
|
|
7792
7988
|
// src/commands/implementations/server/return.ts
|
|
7793
|
-
var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, ReturnCommandNode, ReturnCommand;
|
|
7989
|
+
var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, RETURN_COMMAND_NODE_BRAND, ReturnCommandNode, ReturnCommand;
|
|
7794
7990
|
var init_return = __esm(() => {
|
|
7795
7991
|
init_nodes();
|
|
7796
7992
|
init_utils();
|
|
@@ -7800,9 +7996,11 @@ var init_return = __esm(() => {
|
|
|
7800
7996
|
[RETURN_RUN_COMMAND_NODE_BRAND] = true;
|
|
7801
7997
|
command = "return";
|
|
7802
7998
|
isSingleExecute;
|
|
7803
|
-
|
|
7999
|
+
isFlowControl;
|
|
8000
|
+
constructor(sandstonePack, args = [], { isSingleExecute = true, body = [], isFlowControl = false } = {}) {
|
|
7804
8001
|
super(sandstonePack, ...args);
|
|
7805
8002
|
this.isSingleExecute = isSingleExecute;
|
|
8003
|
+
this.isFlowControl = isFlowControl;
|
|
7806
8004
|
this.append(...body);
|
|
7807
8005
|
}
|
|
7808
8006
|
getValue = () => {
|
|
@@ -7862,8 +8060,13 @@ var init_return = __esm(() => {
|
|
|
7862
8060
|
}, true);
|
|
7863
8061
|
}
|
|
7864
8062
|
};
|
|
8063
|
+
RETURN_COMMAND_NODE_BRAND = Symbol.for("sandstone.ReturnCommandNode");
|
|
7865
8064
|
ReturnCommandNode = class ReturnCommandNode extends CommandNode {
|
|
8065
|
+
[RETURN_COMMAND_NODE_BRAND] = true;
|
|
7866
8066
|
command = "return";
|
|
8067
|
+
static [Symbol.hasInstance](instance) {
|
|
8068
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RETURN_COMMAND_NODE_BRAND] === true;
|
|
8069
|
+
}
|
|
7867
8070
|
};
|
|
7868
8071
|
ReturnCommand = class ReturnCommand extends CommandArguments {
|
|
7869
8072
|
NodeType = ReturnCommandNode;
|
|
@@ -8045,8 +8248,8 @@ var init_version = __esm(() => {
|
|
|
8045
8248
|
// src/commands/implementations/world/data.ts
|
|
8046
8249
|
var DataCommandNode, DataCommand, DataGetCommand, DataMergeCommand, DataModifyFromCommand, DataModifyValuesCommand, DataModifyTypeCommand, DataModifyCommand, DataRemoveCommand;
|
|
8047
8250
|
var init_data = __esm(() => {
|
|
8048
|
-
init_core();
|
|
8049
8251
|
init_nodes();
|
|
8252
|
+
init_utils();
|
|
8050
8253
|
init_NBTs();
|
|
8051
8254
|
init_parsers();
|
|
8052
8255
|
DataCommandNode = class DataCommandNode extends CommandNode {
|
|
@@ -8055,22 +8258,55 @@ var init_data = __esm(() => {
|
|
|
8055
8258
|
DataCommand = class DataCommand extends CommandArguments {
|
|
8056
8259
|
NodeType = DataCommandNode;
|
|
8057
8260
|
get get() {
|
|
8058
|
-
|
|
8261
|
+
const cmd = this.subCommand(["get"], DataGetCommand, false);
|
|
8262
|
+
return makeCallable(cmd, (dataPoint, scale) => {
|
|
8263
|
+
if (dataPoint.type === "block") {
|
|
8264
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path, scale);
|
|
8265
|
+
}
|
|
8266
|
+
if (dataPoint.type === "entity") {
|
|
8267
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path, scale);
|
|
8268
|
+
}
|
|
8269
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path, scale);
|
|
8270
|
+
});
|
|
8059
8271
|
}
|
|
8060
8272
|
get merge() {
|
|
8061
8273
|
return this.subCommand(["merge"], DataMergeCommand, false);
|
|
8062
8274
|
}
|
|
8063
8275
|
get modify() {
|
|
8064
|
-
|
|
8276
|
+
const cmd = this.subCommand(["modify"], DataModifyCommand, false);
|
|
8277
|
+
return makeCallable(cmd, (dataPoint) => {
|
|
8278
|
+
if (dataPoint.type === "block") {
|
|
8279
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
|
|
8280
|
+
}
|
|
8281
|
+
if (dataPoint.type === "entity") {
|
|
8282
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path);
|
|
8283
|
+
}
|
|
8284
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path);
|
|
8285
|
+
});
|
|
8065
8286
|
}
|
|
8066
8287
|
get remove() {
|
|
8067
|
-
|
|
8288
|
+
const cmd = this.subCommand(["remove"], DataRemoveCommand, false);
|
|
8289
|
+
return makeCallable(cmd, (dataPoint) => {
|
|
8290
|
+
if (dataPoint.type === "block") {
|
|
8291
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
|
|
8292
|
+
}
|
|
8293
|
+
if (dataPoint.type === "entity") {
|
|
8294
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path);
|
|
8295
|
+
}
|
|
8296
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path);
|
|
8297
|
+
});
|
|
8068
8298
|
}
|
|
8069
8299
|
};
|
|
8070
8300
|
DataGetCommand = class DataGetCommand extends CommandArguments {
|
|
8071
|
-
block = (targetPos, path5, scale) =>
|
|
8072
|
-
|
|
8073
|
-
|
|
8301
|
+
block = (targetPos, path5, scale) => {
|
|
8302
|
+
return this.finalCommand(["block", coordinatesParser(targetPos), path5, scale]);
|
|
8303
|
+
};
|
|
8304
|
+
entity = (target, path5, scale) => {
|
|
8305
|
+
return this.finalCommand(["entity", targetParser(target), path5, scale]);
|
|
8306
|
+
};
|
|
8307
|
+
storage = (target, path5, scale) => {
|
|
8308
|
+
return this.finalCommand(["storage", target, path5, scale]);
|
|
8309
|
+
};
|
|
8074
8310
|
};
|
|
8075
8311
|
DataMergeCommand = class DataMergeCommand extends CommandArguments {
|
|
8076
8312
|
block = (targetPos, nbt2) => this.finalCommand(["block", coordinatesParser(targetPos), nbtStringifier(nbt2)]);
|
|
@@ -8080,20 +8316,22 @@ var init_data = __esm(() => {
|
|
|
8080
8316
|
DataModifyFromCommand = class DataModifyFromCommand extends CommandArguments {
|
|
8081
8317
|
block = (sourcePosition, sourcePath) => this.finalCommand(["block", coordinatesParser(sourcePosition), sourcePath]);
|
|
8082
8318
|
entity = (source, sourcePath) => this.finalCommand(["entity", targetParser(source), sourcePath]);
|
|
8083
|
-
storage(source, sourcePath) {
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
storageArg = source;
|
|
8087
|
-
} else {
|
|
8088
|
-
const dataPoint = source;
|
|
8089
|
-
storageArg = `${dataPoint.currentTarget} ${dataPoint.path}`;
|
|
8090
|
-
}
|
|
8091
|
-
return this.finalCommand(["storage", storageArg, sourcePath]);
|
|
8092
|
-
}
|
|
8319
|
+
storage = (source, sourcePath) => {
|
|
8320
|
+
return this.finalCommand(["storage", source, sourcePath]);
|
|
8321
|
+
};
|
|
8093
8322
|
};
|
|
8094
8323
|
DataModifyValuesCommand = class DataModifyValuesCommand extends CommandArguments {
|
|
8095
8324
|
get from() {
|
|
8096
|
-
|
|
8325
|
+
const cmd = this.subCommand(["from"], DataModifyFromCommand, false);
|
|
8326
|
+
return makeCallable(cmd, (dataPoint) => {
|
|
8327
|
+
if (dataPoint.type === "block") {
|
|
8328
|
+
return cmd.block(coordinatesParser(dataPoint.currentTarget), dataPoint.path);
|
|
8329
|
+
}
|
|
8330
|
+
if (dataPoint.type === "entity") {
|
|
8331
|
+
return cmd.entity(dataPoint.currentTarget, dataPoint.path);
|
|
8332
|
+
}
|
|
8333
|
+
return cmd.storage(dataPoint.currentTarget, dataPoint.path);
|
|
8334
|
+
});
|
|
8097
8335
|
}
|
|
8098
8336
|
string = {
|
|
8099
8337
|
block: (sourcePosition, sourcePath, start, end) => {
|
|
@@ -8152,14 +8390,26 @@ var init_data = __esm(() => {
|
|
|
8152
8390
|
}
|
|
8153
8391
|
};
|
|
8154
8392
|
DataModifyCommand = class DataModifyCommand extends CommandArguments {
|
|
8155
|
-
block = (targetPos, targetPath) =>
|
|
8156
|
-
|
|
8157
|
-
|
|
8393
|
+
block = (targetPos, targetPath) => {
|
|
8394
|
+
return this.subCommand(["block", coordinatesParser(targetPos), targetPath], DataModifyTypeCommand, false);
|
|
8395
|
+
};
|
|
8396
|
+
entity = (target, targetPath) => {
|
|
8397
|
+
return this.subCommand(["entity", targetParser(target), targetPath], DataModifyTypeCommand, false);
|
|
8398
|
+
};
|
|
8399
|
+
storage = (target, targetPath) => {
|
|
8400
|
+
return this.subCommand(["storage", target, targetPath], DataModifyTypeCommand, false);
|
|
8401
|
+
};
|
|
8158
8402
|
};
|
|
8159
8403
|
DataRemoveCommand = class DataRemoveCommand extends CommandArguments {
|
|
8160
|
-
block = (targetPos, targetPath) =>
|
|
8161
|
-
|
|
8162
|
-
|
|
8404
|
+
block = (targetPos, targetPath) => {
|
|
8405
|
+
return this.finalCommand(["block", coordinatesParser(targetPos), targetPath]);
|
|
8406
|
+
};
|
|
8407
|
+
entity = (target, targetPath) => {
|
|
8408
|
+
return this.finalCommand(["entity", targetParser(target), targetPath]);
|
|
8409
|
+
};
|
|
8410
|
+
storage = (target, targetPath) => {
|
|
8411
|
+
return this.finalCommand(["storage", target, targetPath]);
|
|
8412
|
+
};
|
|
8163
8413
|
};
|
|
8164
8414
|
});
|
|
8165
8415
|
|
|
@@ -9045,11 +9295,11 @@ var init_dataPoint = __esm(() => {
|
|
|
9045
9295
|
const { execute: execute2 } = commands2;
|
|
9046
9296
|
const anon = DataVariable(this.dataPoint);
|
|
9047
9297
|
this.conditional = Variable();
|
|
9048
|
-
execute2.store.result
|
|
9298
|
+
execute2.store.result(this.conditional).run(() => anon.set(this.value));
|
|
9049
9299
|
}
|
|
9050
9300
|
getValue = (negated) => (negated ? ["if", ...this.getCondition()] : ["unless", ...this.getCondition()]).join(" ");
|
|
9051
9301
|
getCondition() {
|
|
9052
|
-
return ["score", "matches", "0.."];
|
|
9302
|
+
return ["score", this.conditional, "matches", "0.."];
|
|
9053
9303
|
}
|
|
9054
9304
|
};
|
|
9055
9305
|
});
|
|
@@ -9136,7 +9386,7 @@ var init_command = __esm(() => {
|
|
|
9136
9386
|
this.result = result;
|
|
9137
9387
|
const store = sandstoneCore2.pack.commands.execute.store[type];
|
|
9138
9388
|
this.variable = sandstoneCore2.pack.Variable(undefined, "condition");
|
|
9139
|
-
command(store
|
|
9389
|
+
command(store(this.variable));
|
|
9140
9390
|
}
|
|
9141
9391
|
getCondition() {
|
|
9142
9392
|
if (this.type === "success") {
|
|
@@ -9188,11 +9438,13 @@ var init_loaded = __esm(() => {
|
|
|
9188
9438
|
});
|
|
9189
9439
|
|
|
9190
9440
|
// src/flow/conditions/variables/score.ts
|
|
9191
|
-
var ScoreConditionNode;
|
|
9441
|
+
var SCORE_CONDITION_NODE_BRAND, ScoreConditionNode;
|
|
9192
9442
|
var init_score = __esm(() => {
|
|
9193
9443
|
init_condition();
|
|
9444
|
+
SCORE_CONDITION_NODE_BRAND = Symbol.for("sandstone.ScoreConditionNode");
|
|
9194
9445
|
ScoreConditionNode = class ScoreConditionNode extends SingleConditionNode {
|
|
9195
9446
|
args;
|
|
9447
|
+
[SCORE_CONDITION_NODE_BRAND] = true;
|
|
9196
9448
|
constructor(sandstoneCore2, args) {
|
|
9197
9449
|
super(sandstoneCore2);
|
|
9198
9450
|
this.args = args;
|
|
@@ -9200,6 +9452,9 @@ var init_score = __esm(() => {
|
|
|
9200
9452
|
getCondition() {
|
|
9201
9453
|
return ["score", ...this.args];
|
|
9202
9454
|
}
|
|
9455
|
+
static [Symbol.hasInstance](instance) {
|
|
9456
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SCORE_CONDITION_NODE_BRAND] === true;
|
|
9457
|
+
}
|
|
9203
9458
|
};
|
|
9204
9459
|
});
|
|
9205
9460
|
|
|
@@ -9302,7 +9557,7 @@ class IfStatement {
|
|
|
9302
9557
|
this.node = new IfNode(sandstoneCore2, condition2, callback);
|
|
9303
9558
|
}
|
|
9304
9559
|
elseIf = (condition2, callback) => {
|
|
9305
|
-
const statement = new IfStatement(this.sandstoneCore,
|
|
9560
|
+
const statement = new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
9306
9561
|
this.node.nextFlowNode = statement.getNode();
|
|
9307
9562
|
statement.node._isElseIf = true;
|
|
9308
9563
|
return statement;
|
|
@@ -9330,6 +9585,7 @@ var IF_NODE_BRAND, IfNode, ELSE_NODE_BRAND, ElseNode;
|
|
|
9330
9585
|
var init_if_else = __esm(() => {
|
|
9331
9586
|
init_core();
|
|
9332
9587
|
init_utils();
|
|
9588
|
+
init_Flow();
|
|
9333
9589
|
IF_NODE_BRAND = Symbol.for("sandstone.IfNode");
|
|
9334
9590
|
IfNode = class IfNode extends ContainerNode {
|
|
9335
9591
|
condition;
|
|
@@ -9337,10 +9593,14 @@ var init_if_else = __esm(() => {
|
|
|
9337
9593
|
[IF_NODE_BRAND] = true;
|
|
9338
9594
|
nextFlowNode;
|
|
9339
9595
|
_isElseIf = false;
|
|
9340
|
-
|
|
9596
|
+
parentMCFunction;
|
|
9597
|
+
givenCallbackName;
|
|
9598
|
+
resultingExecuteNode;
|
|
9599
|
+
constructor(sandstoneCore2, condition2, callback, parentMCFunction) {
|
|
9341
9600
|
super(sandstoneCore2);
|
|
9342
9601
|
this.condition = condition2;
|
|
9343
9602
|
this.callback = callback;
|
|
9603
|
+
this.parentMCFunction = parentMCFunction ?? sandstoneCore2.getCurrentMCFunctionOrThrow();
|
|
9344
9604
|
if (callback && callback.toString() !== "() => {}") {
|
|
9345
9605
|
this.sandstoneCore.insideContext(this, callback, true);
|
|
9346
9606
|
}
|
|
@@ -9382,26 +9642,6 @@ ${indent}${nextFormatting}`;
|
|
|
9382
9642
|
});
|
|
9383
9643
|
|
|
9384
9644
|
// src/flow/loops/binary_for.ts
|
|
9385
|
-
function binaryFor(flow, from, to, callback, maximum = 128) {
|
|
9386
|
-
if (typeof from === "number" && typeof to === "number") {
|
|
9387
|
-
callback(to - from);
|
|
9388
|
-
}
|
|
9389
|
-
const { Variable } = flow.sandstoneCore.pack;
|
|
9390
|
-
const realStart = from instanceof Score ? from : Variable(from);
|
|
9391
|
-
const realEnd = to instanceof Score ? to : Variable(to);
|
|
9392
|
-
const iterations = realEnd.minus(realStart);
|
|
9393
|
-
const _ = flow;
|
|
9394
|
-
_.while(iterations.lessThan(maximum), () => {
|
|
9395
|
-
callback(maximum);
|
|
9396
|
-
iterations.remove(maximum);
|
|
9397
|
-
});
|
|
9398
|
-
for (let i = 1;i < maximum; i *= 2) {
|
|
9399
|
-
_.if(iterations.moduloBy(2).equalTo(1), () => {
|
|
9400
|
-
callback(i);
|
|
9401
|
-
});
|
|
9402
|
-
iterations.dividedBy(2);
|
|
9403
|
-
}
|
|
9404
|
-
}
|
|
9405
9645
|
var init_binary_for = __esm(() => {
|
|
9406
9646
|
init_variables();
|
|
9407
9647
|
});
|
|
@@ -9411,16 +9651,18 @@ var LoopNode;
|
|
|
9411
9651
|
var init_loop = __esm(() => {
|
|
9412
9652
|
init_core();
|
|
9413
9653
|
LoopNode = class LoopNode extends ContainerNode {
|
|
9414
|
-
|
|
9654
|
+
condition;
|
|
9415
9655
|
callback;
|
|
9416
9656
|
loopback;
|
|
9417
|
-
|
|
9657
|
+
parentMCFunction;
|
|
9658
|
+
constructor(sandstoneCore2, condition2, callback, loopback) {
|
|
9418
9659
|
super(sandstoneCore2);
|
|
9419
|
-
this.
|
|
9660
|
+
this.condition = condition2;
|
|
9420
9661
|
this.callback = callback;
|
|
9421
9662
|
this.loopback = loopback;
|
|
9663
|
+
const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
|
|
9664
|
+
this.parentMCFunction = currentNode;
|
|
9422
9665
|
if (callback.toString() !== "() => {}") {
|
|
9423
|
-
const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
|
|
9424
9666
|
currentNode.enterContext(this);
|
|
9425
9667
|
this.callback();
|
|
9426
9668
|
this.loopback();
|
|
@@ -9433,6 +9675,75 @@ var init_loop = __esm(() => {
|
|
|
9433
9675
|
};
|
|
9434
9676
|
});
|
|
9435
9677
|
|
|
9678
|
+
// src/flow/loops/staticAnalysis.ts
|
|
9679
|
+
function valueMatchesRange(value, rangeStr) {
|
|
9680
|
+
if (rangeStr.includes("..")) {
|
|
9681
|
+
const [minStr, maxStr] = rangeStr.split("..");
|
|
9682
|
+
const min = minStr !== "" ? parseInt(minStr, 10) : Number.NEGATIVE_INFINITY;
|
|
9683
|
+
const max = maxStr !== "" ? parseInt(maxStr, 10) : Number.POSITIVE_INFINITY;
|
|
9684
|
+
return value >= min && value <= max;
|
|
9685
|
+
}
|
|
9686
|
+
return value === parseInt(rangeStr, 10);
|
|
9687
|
+
}
|
|
9688
|
+
function analyzeCondition(condition2, targetScore, value, negated = false) {
|
|
9689
|
+
if (condition2 instanceof ScoreConditionNode) {
|
|
9690
|
+
const args = condition2.args;
|
|
9691
|
+
if (args.length >= 4 && args[2] === "matches") {
|
|
9692
|
+
const [target, objective, , rangeStr] = args;
|
|
9693
|
+
if (target !== `${targetScore.target}` || objective !== `${targetScore.objective}`) {
|
|
9694
|
+
return { canAnalyze: false };
|
|
9695
|
+
}
|
|
9696
|
+
let result = valueMatchesRange(value, rangeStr);
|
|
9697
|
+
if (negated)
|
|
9698
|
+
result = !result;
|
|
9699
|
+
return { canAnalyze: true, result };
|
|
9700
|
+
}
|
|
9701
|
+
return { canAnalyze: false };
|
|
9702
|
+
}
|
|
9703
|
+
if (condition2 instanceof AndNode) {
|
|
9704
|
+
for (const subCondition of condition2.conditions) {
|
|
9705
|
+
const subResult = analyzeCondition(subCondition, targetScore, value, negated);
|
|
9706
|
+
if (!subResult.canAnalyze)
|
|
9707
|
+
return { canAnalyze: false };
|
|
9708
|
+
if (!subResult.result)
|
|
9709
|
+
return { canAnalyze: true, result: false };
|
|
9710
|
+
}
|
|
9711
|
+
return { canAnalyze: true, result: true };
|
|
9712
|
+
}
|
|
9713
|
+
if (condition2 instanceof OrNode) {
|
|
9714
|
+
let anyTrue = false;
|
|
9715
|
+
for (const subCondition of condition2.conditions) {
|
|
9716
|
+
const subResult = analyzeCondition(subCondition, targetScore, value, negated);
|
|
9717
|
+
if (!subResult.canAnalyze)
|
|
9718
|
+
return { canAnalyze: false };
|
|
9719
|
+
if (subResult.result)
|
|
9720
|
+
anyTrue = true;
|
|
9721
|
+
}
|
|
9722
|
+
return { canAnalyze: true, result: anyTrue };
|
|
9723
|
+
}
|
|
9724
|
+
if (condition2 instanceof NotNode) {
|
|
9725
|
+
return analyzeCondition(condition2.condition, targetScore, value, !negated);
|
|
9726
|
+
}
|
|
9727
|
+
return { canAnalyze: false };
|
|
9728
|
+
}
|
|
9729
|
+
function getDeclarationLocation() {
|
|
9730
|
+
const stack = new Error().stack;
|
|
9731
|
+
const locationMatch = stack?.split(`
|
|
9732
|
+
`).find((line) => line.includes(".ts:") && !line.includes("/loops/") && !line.includes("node_modules"));
|
|
9733
|
+
return locationMatch?.trim() || "unknown location";
|
|
9734
|
+
}
|
|
9735
|
+
function warnStaticallyFalseCondition(loopType, details) {
|
|
9736
|
+
const location = getDeclarationLocation();
|
|
9737
|
+
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.
|
|
9738
|
+
` + ` at ${location}`);
|
|
9739
|
+
}
|
|
9740
|
+
var init_staticAnalysis = __esm(() => {
|
|
9741
|
+
init_score();
|
|
9742
|
+
init_and();
|
|
9743
|
+
init_or();
|
|
9744
|
+
init_not();
|
|
9745
|
+
});
|
|
9746
|
+
|
|
9436
9747
|
// src/flow/loops/for_i.ts
|
|
9437
9748
|
class ForIStatement {
|
|
9438
9749
|
sandstoneCore;
|
|
@@ -9453,43 +9764,64 @@ class ForIStatement {
|
|
|
9453
9764
|
}
|
|
9454
9765
|
var ForINode;
|
|
9455
9766
|
var init_for_i = __esm(() => {
|
|
9456
|
-
init_commands2();
|
|
9457
9767
|
init_variables();
|
|
9768
|
+
init_flow();
|
|
9769
|
+
init_if_else();
|
|
9458
9770
|
init_loop();
|
|
9771
|
+
init_staticAnalysis();
|
|
9459
9772
|
ForINode = class ForINode extends LoopNode {
|
|
9460
9773
|
constructor(sandstoneCore2, initialValue, endCondition, iterate, callback) {
|
|
9461
9774
|
const iterator = sandstoneCore2.pack.Variable(initialValue, "loop_iterator");
|
|
9462
|
-
const condition2 =
|
|
9463
|
-
const
|
|
9464
|
-
const
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9775
|
+
const condition2 = conditionToNode(endCondition(iterator));
|
|
9776
|
+
const _continue = () => sandstoneCore2.pack.commands.returnCmd.run(() => new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack)));
|
|
9777
|
+
const analysisResult = typeof initialValue === "number" ? analyzeCondition(condition2, iterator, initialValue) : { canAnalyze: false };
|
|
9778
|
+
if (analysisResult.canAnalyze) {
|
|
9779
|
+
if (analysisResult.result) {
|
|
9780
|
+
callback(iterator, _continue);
|
|
9781
|
+
iterate(iterator);
|
|
9782
|
+
} else {
|
|
9783
|
+
warnStaticallyFalseCondition("for", `initial value ${initialValue} does not satisfy condition`);
|
|
9784
|
+
}
|
|
9785
|
+
}
|
|
9786
|
+
super(sandstoneCore2, condition2, () => callback(iterator, _continue), () => {
|
|
9471
9787
|
iterate(iterator);
|
|
9472
|
-
|
|
9473
|
-
body: [new LoopArgument(sandstoneCore2.pack)]
|
|
9474
|
-
});
|
|
9788
|
+
new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack));
|
|
9475
9789
|
});
|
|
9476
9790
|
}
|
|
9477
9791
|
};
|
|
9478
9792
|
});
|
|
9479
9793
|
|
|
9480
9794
|
// src/flow/loops/for_of.ts
|
|
9795
|
+
function isMultipleVariable(iteratorType) {
|
|
9796
|
+
if (Array.isArray(iteratorType)) {
|
|
9797
|
+
return true;
|
|
9798
|
+
}
|
|
9799
|
+
return false;
|
|
9800
|
+
}
|
|
9801
|
+
function isMapIterator(iteratorType, iterable) {
|
|
9802
|
+
if (isMultipleVariable(iteratorType) && iteratorType[0] === "key") {
|
|
9803
|
+
if (iterable.iteratorType === "map") {
|
|
9804
|
+
return true;
|
|
9805
|
+
}
|
|
9806
|
+
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)');
|
|
9807
|
+
}
|
|
9808
|
+
return false;
|
|
9809
|
+
}
|
|
9810
|
+
|
|
9481
9811
|
class ForOfStatement {
|
|
9482
9812
|
sandstoneCore;
|
|
9483
9813
|
iteratorType;
|
|
9814
|
+
direction;
|
|
9484
9815
|
iterable;
|
|
9485
9816
|
callback;
|
|
9486
9817
|
node;
|
|
9487
|
-
constructor(sandstoneCore2, iteratorType, iterable, callback) {
|
|
9818
|
+
constructor(sandstoneCore2, iteratorType, direction, iterable, callback) {
|
|
9488
9819
|
this.sandstoneCore = sandstoneCore2;
|
|
9489
9820
|
this.iteratorType = iteratorType;
|
|
9821
|
+
this.direction = direction;
|
|
9490
9822
|
this.iterable = iterable;
|
|
9491
9823
|
this.callback = callback;
|
|
9492
|
-
this.node = new ForOfNode(sandstoneCore2, iteratorType, iterable, callback);
|
|
9824
|
+
this.node = new ForOfNode(sandstoneCore2, iteratorType, direction, iterable, callback);
|
|
9493
9825
|
}
|
|
9494
9826
|
getNode = () => this.node;
|
|
9495
9827
|
}
|
|
@@ -9499,35 +9831,31 @@ var init_for_of = __esm(() => {
|
|
|
9499
9831
|
init_if_else();
|
|
9500
9832
|
init_loop();
|
|
9501
9833
|
ForOfNode = class ForOfNode extends LoopNode {
|
|
9502
|
-
constructor(sandstoneCore2, iteratorType, iterable, callback) {
|
|
9503
|
-
const _iterable = iterable._toDataPoint();
|
|
9504
|
-
let startCondition;
|
|
9834
|
+
constructor(sandstoneCore2, iteratorType, direction, iterable, callback) {
|
|
9505
9835
|
let iterate;
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
if (iteratorType[0] === "key") {
|
|
9509
|
-
startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
|
|
9836
|
+
if (isMultipleVariable(iteratorType)) {
|
|
9837
|
+
if (isMapIterator(iteratorType, iterable)) {
|
|
9510
9838
|
iterate = iterable.iterator((dataPoints) => {
|
|
9511
|
-
if (dataPoints.length === 1) {
|
|
9512
|
-
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)');
|
|
9513
|
-
}
|
|
9514
9839
|
callback(...[dataPoints[0], dataPoints[1]]);
|
|
9515
|
-
});
|
|
9840
|
+
}, direction);
|
|
9516
9841
|
} else {
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9842
|
+
const _iterator = sandstoneCore2.pack.Variable(direction === "normal" ? -1 : undefined);
|
|
9843
|
+
if (direction === "reverse") {
|
|
9844
|
+
_iterator.set(iterable.size());
|
|
9845
|
+
}
|
|
9521
9846
|
iterate = iterable.iterator((dataPoints) => {
|
|
9522
|
-
|
|
9847
|
+
if (direction === "normal") {
|
|
9848
|
+
_iterator.increase();
|
|
9849
|
+
} else {
|
|
9850
|
+
_iterator.decrease();
|
|
9851
|
+
}
|
|
9523
9852
|
if (dataPoints.length === 1) {
|
|
9524
9853
|
return callback(...[_iterator, dataPoints[0]]);
|
|
9525
9854
|
}
|
|
9526
9855
|
return callback(...[_iterator, dataPoints[1]]);
|
|
9527
|
-
});
|
|
9856
|
+
}, direction);
|
|
9528
9857
|
}
|
|
9529
9858
|
} else {
|
|
9530
|
-
startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
|
|
9531
9859
|
iterate = iterable.iterator((dataPoints) => {
|
|
9532
9860
|
if (dataPoints.length === 1) {
|
|
9533
9861
|
return callback(...[dataPoints[0]]);
|
|
@@ -9535,8 +9863,8 @@ var init_for_of = __esm(() => {
|
|
|
9535
9863
|
return callback(...[dataPoints[1]]);
|
|
9536
9864
|
});
|
|
9537
9865
|
}
|
|
9538
|
-
|
|
9539
|
-
super(sandstoneCore2,
|
|
9866
|
+
const continueCondition = iterable.continue(direction);
|
|
9867
|
+
super(sandstoneCore2, continueCondition, () => iterate, () => new IfStatement(sandstoneCore2, continueCondition, () => new LoopArgument(sandstoneCore2.pack)));
|
|
9540
9868
|
}
|
|
9541
9869
|
};
|
|
9542
9870
|
});
|
|
@@ -9558,11 +9886,12 @@ var WhileNode;
|
|
|
9558
9886
|
var init_while = __esm(() => {
|
|
9559
9887
|
init_variables();
|
|
9560
9888
|
init_if_else();
|
|
9889
|
+
init_flow();
|
|
9561
9890
|
init_loop();
|
|
9562
9891
|
WhileNode = class WhileNode extends LoopNode {
|
|
9563
9892
|
constructor(sandstoneCore2, condition2, callback) {
|
|
9564
|
-
const _condition =
|
|
9565
|
-
super(sandstoneCore2,
|
|
9893
|
+
const _condition = conditionToNode(condition2);
|
|
9894
|
+
super(sandstoneCore2, _condition, callback, () => new IfStatement(sandstoneCore2, _condition, () => new LoopArgument(sandstoneCore2.pack)));
|
|
9566
9895
|
}
|
|
9567
9896
|
};
|
|
9568
9897
|
});
|
|
@@ -9576,29 +9905,77 @@ var init_loops = __esm(() => {
|
|
|
9576
9905
|
});
|
|
9577
9906
|
|
|
9578
9907
|
// src/flow/switch_case.ts
|
|
9579
|
-
|
|
9908
|
+
function isConditionCase(c) {
|
|
9909
|
+
return typeof c === "function";
|
|
9910
|
+
}
|
|
9911
|
+
function executeSwitch(sandstoneCore2, value, _cases) {
|
|
9912
|
+
let staticCaseEntries = [];
|
|
9913
|
+
let conditionCaseEntries = [];
|
|
9914
|
+
let _default;
|
|
9915
|
+
if (_cases instanceof CaseStatement) {
|
|
9916
|
+
staticCaseEntries = _cases.getStaticCases();
|
|
9917
|
+
conditionCaseEntries = _cases.getConditionCases();
|
|
9918
|
+
} else if (Array.isArray(_cases)) {
|
|
9919
|
+
for (const _case of _cases) {
|
|
9920
|
+
if (_case[0] === "default") {
|
|
9921
|
+
_default = _case;
|
|
9922
|
+
continue;
|
|
9923
|
+
}
|
|
9924
|
+
const [, condition2, callback] = _case;
|
|
9925
|
+
if (isConditionCase(condition2)) {
|
|
9926
|
+
conditionCaseEntries.push({ type: "condition", condition: condition2, callback });
|
|
9927
|
+
} else {
|
|
9928
|
+
staticCaseEntries.push({ type: "static", value: condition2, callback });
|
|
9929
|
+
}
|
|
9930
|
+
}
|
|
9931
|
+
} else {
|
|
9932
|
+
for (const _case of _cases.entries) {
|
|
9933
|
+
if (_case.type === "condition") {
|
|
9934
|
+
conditionCaseEntries.push(_case);
|
|
9935
|
+
} else {
|
|
9936
|
+
staticCaseEntries.push(_case);
|
|
9937
|
+
}
|
|
9938
|
+
}
|
|
9939
|
+
if (_cases.default) {
|
|
9940
|
+
_default = ["default", _cases.default];
|
|
9941
|
+
}
|
|
9942
|
+
}
|
|
9943
|
+
const staticCaseNodes = staticCaseEntries.map((c) => new StaticCaseNode(sandstoneCore2, c.value, c.callback));
|
|
9944
|
+
const conditionCaseNodes = conditionCaseEntries.map((c) => new ConditionCaseNode(sandstoneCore2, c.condition, c.callback));
|
|
9945
|
+
const defaultCaseNode = _default ? new DefaultCaseNode(sandstoneCore2, _default[1]) : undefined;
|
|
9946
|
+
new SwitchNode(sandstoneCore2, value, staticCaseNodes, conditionCaseNodes, defaultCaseNode);
|
|
9947
|
+
}
|
|
9948
|
+
var CASE_STATEMENT_BRAND, CaseStatement, SwitchNode, StaticCaseNode, ConditionCaseNode, DefaultCaseNode;
|
|
9580
9949
|
var init_switch_case = __esm(() => {
|
|
9950
|
+
init_core();
|
|
9581
9951
|
CASE_STATEMENT_BRAND = Symbol.for("sandstone.CaseStatement");
|
|
9582
9952
|
CaseStatement = class CaseStatement {
|
|
9583
|
-
|
|
9584
|
-
callback;
|
|
9585
|
-
previous;
|
|
9953
|
+
entries;
|
|
9586
9954
|
[CASE_STATEMENT_BRAND] = true;
|
|
9587
|
-
constructor(
|
|
9588
|
-
this.
|
|
9589
|
-
this.callback = callback;
|
|
9590
|
-
this.previous = previous;
|
|
9955
|
+
constructor(entries = []) {
|
|
9956
|
+
this.entries = entries;
|
|
9591
9957
|
}
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9958
|
+
getStaticCases() {
|
|
9959
|
+
return this.entries.filter((e) => e.type === "static");
|
|
9960
|
+
}
|
|
9961
|
+
getConditionCases() {
|
|
9962
|
+
return this.entries.filter((e) => e.type === "condition");
|
|
9595
9963
|
}
|
|
9596
|
-
case(
|
|
9597
|
-
|
|
9964
|
+
case(valueOrCondition, callback) {
|
|
9965
|
+
if (typeof valueOrCondition === "function") {
|
|
9966
|
+
return new CaseStatement([
|
|
9967
|
+
...this.entries,
|
|
9968
|
+
{ type: "condition", condition: valueOrCondition, callback }
|
|
9969
|
+
]);
|
|
9970
|
+
}
|
|
9971
|
+
return new CaseStatement([
|
|
9972
|
+
...this.entries,
|
|
9973
|
+
{ type: "static", value: valueOrCondition, callback }
|
|
9974
|
+
]);
|
|
9598
9975
|
}
|
|
9599
9976
|
default(callback) {
|
|
9600
9977
|
return {
|
|
9601
|
-
|
|
9978
|
+
entries: this.entries,
|
|
9602
9979
|
default: callback
|
|
9603
9980
|
};
|
|
9604
9981
|
}
|
|
@@ -9606,24 +9983,83 @@ var init_switch_case = __esm(() => {
|
|
|
9606
9983
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[CASE_STATEMENT_BRAND] === true;
|
|
9607
9984
|
}
|
|
9608
9985
|
};
|
|
9986
|
+
SwitchNode = class SwitchNode extends ContainerNode {
|
|
9987
|
+
value;
|
|
9988
|
+
staticCases;
|
|
9989
|
+
conditionCases;
|
|
9990
|
+
defaultCase;
|
|
9991
|
+
parentMCFunction;
|
|
9992
|
+
constructor(sandstoneCore2, value, staticCases, conditionCases, defaultCase) {
|
|
9993
|
+
super(sandstoneCore2);
|
|
9994
|
+
this.value = value;
|
|
9995
|
+
this.staticCases = staticCases;
|
|
9996
|
+
this.conditionCases = conditionCases;
|
|
9997
|
+
this.defaultCase = defaultCase;
|
|
9998
|
+
this.parentMCFunction = sandstoneCore2.getCurrentMCFunctionOrThrow();
|
|
9999
|
+
this.parentMCFunction.enterContext(this);
|
|
10000
|
+
for (const caseNode of [...staticCases, ...conditionCases]) {
|
|
10001
|
+
this.parentMCFunction.enterContext(caseNode);
|
|
10002
|
+
caseNode.callback();
|
|
10003
|
+
this.parentMCFunction.exitContext();
|
|
10004
|
+
}
|
|
10005
|
+
if (defaultCase) {
|
|
10006
|
+
this.parentMCFunction.enterContext(defaultCase);
|
|
10007
|
+
defaultCase.callback();
|
|
10008
|
+
this.parentMCFunction.exitContext();
|
|
10009
|
+
}
|
|
10010
|
+
this.parentMCFunction.exitContext();
|
|
10011
|
+
}
|
|
10012
|
+
getValue = () => {
|
|
10013
|
+
throw new Error("SwitchNode must be transformed by SwitchTransformationVisitor");
|
|
10014
|
+
};
|
|
10015
|
+
};
|
|
10016
|
+
StaticCaseNode = class StaticCaseNode extends ContainerNode {
|
|
10017
|
+
value;
|
|
10018
|
+
callback;
|
|
10019
|
+
constructor(sandstoneCore2, value, callback) {
|
|
10020
|
+
super(sandstoneCore2);
|
|
10021
|
+
this.value = value;
|
|
10022
|
+
this.callback = callback;
|
|
10023
|
+
}
|
|
10024
|
+
getValue = () => null;
|
|
10025
|
+
};
|
|
10026
|
+
ConditionCaseNode = class ConditionCaseNode extends ContainerNode {
|
|
10027
|
+
condition;
|
|
10028
|
+
callback;
|
|
10029
|
+
constructor(sandstoneCore2, condition2, callback) {
|
|
10030
|
+
super(sandstoneCore2);
|
|
10031
|
+
this.condition = condition2;
|
|
10032
|
+
this.callback = callback;
|
|
10033
|
+
}
|
|
10034
|
+
getValue = () => null;
|
|
10035
|
+
};
|
|
10036
|
+
DefaultCaseNode = class DefaultCaseNode extends ContainerNode {
|
|
10037
|
+
callback;
|
|
10038
|
+
constructor(sandstoneCore2, callback) {
|
|
10039
|
+
super(sandstoneCore2);
|
|
10040
|
+
this.callback = callback;
|
|
10041
|
+
}
|
|
10042
|
+
getValue = () => null;
|
|
10043
|
+
};
|
|
9609
10044
|
});
|
|
9610
10045
|
|
|
9611
10046
|
// src/flow/Flow.ts
|
|
10047
|
+
function conditionToNode(condition2) {
|
|
10048
|
+
if (!(condition2 instanceof ConditionNode)) {
|
|
10049
|
+
return condition2._toMinecraftCondition();
|
|
10050
|
+
}
|
|
10051
|
+
return condition2;
|
|
10052
|
+
}
|
|
10053
|
+
|
|
9612
10054
|
class Flow {
|
|
9613
10055
|
sandstoneCore;
|
|
9614
10056
|
constructor(sandstoneCore2) {
|
|
9615
10057
|
this.sandstoneCore = sandstoneCore2;
|
|
9616
10058
|
}
|
|
9617
|
-
conditionToNode(condition2)
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
return condition2;
|
|
9622
|
-
}
|
|
9623
|
-
if = (condition2, callback) => new IfStatement(this.sandstoneCore, this.conditionToNode(condition2), callback);
|
|
9624
|
-
and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
|
|
9625
|
-
or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
|
|
9626
|
-
not = (condition2) => new NotNode(this.sandstoneCore, this.conditionToNode(condition2));
|
|
10059
|
+
if = (condition2, callback) => new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
10060
|
+
and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
|
|
10061
|
+
or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
|
|
10062
|
+
not = (condition2) => new NotNode(this.sandstoneCore, conditionToNode(condition2));
|
|
9627
10063
|
get return() {
|
|
9628
10064
|
return this.sandstoneCore.pack.commands.returnCmd;
|
|
9629
10065
|
}
|
|
@@ -9646,77 +10082,56 @@ Sandstone Pack Error:
|
|
|
9646
10082
|
if (broadcast !== false) {
|
|
9647
10083
|
tellraw2(broadcast || "@a", fullError);
|
|
9648
10084
|
}
|
|
9649
|
-
const
|
|
10085
|
+
const errorSerializable = parseJSONText(this.sandstoneCore, fullError);
|
|
9650
10086
|
if (dataPoint2 !== false) {
|
|
9651
10087
|
let point;
|
|
9652
10088
|
if (dataPoint2 === undefined) {
|
|
9653
|
-
point = DataVariable(
|
|
10089
|
+
point = DataVariable(errorSerializable.toJSON());
|
|
9654
10090
|
} else {
|
|
9655
|
-
point = dataPoint2.set(
|
|
10091
|
+
point = dataPoint2.set(errorSerializable.toJSON());
|
|
9656
10092
|
}
|
|
9657
10093
|
returnCmd.fail();
|
|
9658
10094
|
return point;
|
|
9659
10095
|
}
|
|
9660
10096
|
returnCmd.fail();
|
|
9661
|
-
return
|
|
10097
|
+
return errorSerializable;
|
|
9662
10098
|
}
|
|
9663
10099
|
while(condition2, callback) {
|
|
9664
|
-
return new WhileStatement(this.sandstoneCore,
|
|
10100
|
+
return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
9665
10101
|
}
|
|
9666
10102
|
doWhile(condition2, callback) {
|
|
9667
10103
|
callback();
|
|
9668
|
-
return new WhileStatement(this.sandstoneCore,
|
|
10104
|
+
return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
9669
10105
|
}
|
|
9670
10106
|
for(arg1, arg2, arg3, arg4) {
|
|
9671
10107
|
if (typeof arg1 === "number" || arg1 instanceof Score) {
|
|
9672
10108
|
return new ForIStatement(this.sandstoneCore, arg1, arg2, arg3, arg4);
|
|
9673
10109
|
}
|
|
9674
10110
|
if (arg1 === "entry") {
|
|
9675
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
10111
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
9676
10112
|
}
|
|
9677
10113
|
if (arg1[0] === "key") {
|
|
9678
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
10114
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
9679
10115
|
}
|
|
9680
10116
|
if (typeof arg1[0] === "number" || arg1[0] instanceof Score) {
|
|
9681
10117
|
if (arg2 === "iterate") {
|
|
9682
10118
|
return new ForIStatement(this.sandstoneCore, arg1[0], (i) => i["<="](arg1[1]), (i) => i["++"], arg3);
|
|
9683
10119
|
}
|
|
9684
|
-
return binaryFor(this, arg1[0], arg1[1], arg3, arg1[2]);
|
|
9685
10120
|
}
|
|
9686
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
10121
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
9687
10122
|
}
|
|
9688
|
-
switch(value,
|
|
9689
|
-
|
|
9690
|
-
if (_cases instanceof CaseStatement) {
|
|
9691
|
-
cases = _cases.getCases().map((c) => c.getValue());
|
|
9692
|
-
} else if (Array.isArray(_cases)) {
|
|
9693
|
-
cases = _cases;
|
|
9694
|
-
} else {
|
|
9695
|
-
cases = _cases.cases.map((c) => c.getValue());
|
|
9696
|
-
_default = ["default", _cases.default];
|
|
9697
|
-
}
|
|
9698
|
-
const { Data: Data2, initMCFunction, MCFunction, Macro: Macro2 } = this.sandstoneCore.pack;
|
|
9699
|
-
const id2 = switches++;
|
|
9700
|
-
const values = Data2("storage", `__sandstone:switch_${id2}`, "Values");
|
|
9701
|
-
initMCFunction.push(() => values.set(cases.map(([_, v, callback], i) => {
|
|
9702
|
-
MCFunction(`__sandstone:switch_${id2}_case_${i}`, [], () => callback());
|
|
9703
|
-
return { Value: v, Index: i };
|
|
9704
|
-
})));
|
|
9705
|
-
const flow = this;
|
|
9706
|
-
MCFunction(`__sandstone:switch_${id2}`, [value], () => {
|
|
9707
|
-
const index = Data2("storage", `__sandstone:switch_${id2}`, "Index");
|
|
9708
|
-
Macro2.data.modify.storage(index.currentTarget, "Index").set.from.storage(values.currentTarget, Macro2`Values[{Value:${value}}}].Index`);
|
|
9709
|
-
const _if = flow.if(index, () => {
|
|
9710
|
-
MCFunction(`__sandstone:switch_${id2}_inner`, [index], () => {
|
|
9711
|
-
Macro2.functionCmd(Macro2`__sandstone:switch_${id2}_case_${index}`);
|
|
9712
|
-
})();
|
|
9713
|
-
});
|
|
9714
|
-
if (_default)
|
|
9715
|
-
_if.else(() => _default?.[1]());
|
|
9716
|
-
})();
|
|
10123
|
+
switch(value, cases) {
|
|
10124
|
+
executeSwitch(this.sandstoneCore, value, cases);
|
|
9717
10125
|
}
|
|
9718
10126
|
case(value, callback) {
|
|
9719
|
-
|
|
10127
|
+
if (typeof value === "function") {
|
|
10128
|
+
return new CaseStatement([
|
|
10129
|
+
{ type: "condition", condition: value, callback }
|
|
10130
|
+
]);
|
|
10131
|
+
}
|
|
10132
|
+
return new CaseStatement([
|
|
10133
|
+
{ type: "static", value, callback }
|
|
10134
|
+
]);
|
|
9720
10135
|
}
|
|
9721
10136
|
biome = (coordinates, biome2) => {
|
|
9722
10137
|
return new SandstoneConditions.Biome(this.sandstoneCore, coordinates, biome2);
|
|
@@ -9758,7 +10173,6 @@ Sandstone Pack Error:
|
|
|
9758
10173
|
return new SandstoneConditions.Predicate(this.sandstoneCore, predicate3.name);
|
|
9759
10174
|
};
|
|
9760
10175
|
}
|
|
9761
|
-
var switches = 0;
|
|
9762
10176
|
var init_Flow = __esm(() => {
|
|
9763
10177
|
init_variables();
|
|
9764
10178
|
init_conditions();
|
|
@@ -9773,6 +10187,7 @@ var init_flow = __esm(() => {
|
|
|
9773
10187
|
init_Flow();
|
|
9774
10188
|
init_if_else();
|
|
9775
10189
|
init_loop();
|
|
10190
|
+
init_switch_case();
|
|
9776
10191
|
});
|
|
9777
10192
|
|
|
9778
10193
|
// src/core/visitors.ts
|
|
@@ -9855,6 +10270,10 @@ var init_visitor = __esm(() => {
|
|
|
9855
10270
|
visitIfNode;
|
|
9856
10271
|
visitElseNode;
|
|
9857
10272
|
visitLoopNode;
|
|
10273
|
+
visitSwitchNode;
|
|
10274
|
+
visitStaticCaseNode;
|
|
10275
|
+
visitConditionCaseNode;
|
|
10276
|
+
visitDefaultCaseNode;
|
|
9858
10277
|
visitLoopArgumentNode;
|
|
9859
10278
|
visitAdvancementCommandNode;
|
|
9860
10279
|
visitAttributeCommandNode;
|
|
@@ -9884,6 +10303,7 @@ var init_addAwaitBodyToMCFunctions = __esm(() => {
|
|
|
9884
10303
|
// src/pack/visitors/containerCommandsToMCFunction.ts
|
|
9885
10304
|
var ContainerCommandsToMCFunctionVisitor;
|
|
9886
10305
|
var init_containerCommandsToMCFunction = __esm(() => {
|
|
10306
|
+
init_commands2();
|
|
9887
10307
|
init_core();
|
|
9888
10308
|
init_visitor();
|
|
9889
10309
|
ContainerCommandsToMCFunctionVisitor = class ContainerCommandsToMCFunctionVisitor extends GenericSandstoneVisitor {
|
|
@@ -9903,6 +10323,14 @@ var init_containerCommandsToMCFunction = __esm(() => {
|
|
|
9903
10323
|
this.currentMCFunction = node;
|
|
9904
10324
|
this.core.currentNode = node.resource.name;
|
|
9905
10325
|
const result = this.genericVisit(node);
|
|
10326
|
+
if (node.resource.creator === "sandstone" && node.body.length > 0) {
|
|
10327
|
+
const lastNode = node.body.at(-1);
|
|
10328
|
+
if (lastNode instanceof FunctionCommandNode) {
|
|
10329
|
+
const returnRunNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
10330
|
+
returnRunNode.body = [lastNode];
|
|
10331
|
+
node.body[node.body.length - 1] = returnRunNode;
|
|
10332
|
+
}
|
|
10333
|
+
}
|
|
9906
10334
|
this.core.currentNode = prev?.resource.name ?? "";
|
|
9907
10335
|
this.currentMCFunction = prev;
|
|
9908
10336
|
return result;
|
|
@@ -9945,7 +10373,7 @@ function* flattenIfNode(node) {
|
|
|
9945
10373
|
yield next;
|
|
9946
10374
|
}
|
|
9947
10375
|
}
|
|
9948
|
-
function handleMultipleNodes(visitor, nodes2) {
|
|
10376
|
+
function handleMultipleNodes(visitor, nodes2, macroStorage) {
|
|
9949
10377
|
return nodes2.flatMap((node, i) => {
|
|
9950
10378
|
const { body } = node;
|
|
9951
10379
|
if (node instanceof IfNode) {
|
|
@@ -9956,25 +10384,32 @@ function handleMultipleNodes(visitor, nodes2) {
|
|
|
9956
10384
|
if (Array.isArray(child)) {
|
|
9957
10385
|
actualBody = child;
|
|
9958
10386
|
} else {
|
|
9959
|
-
return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
10387
|
+
return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
9960
10388
|
isSingleExecute: false,
|
|
9961
10389
|
givenCallbackName: callbackName,
|
|
9962
|
-
body: [i === nodes2.length - 1 ? child : new
|
|
9963
|
-
|
|
10390
|
+
body: [i === nodes2.length - 1 ? child : new ReturnRunCommandNode(visitor.pack, ["run"], {
|
|
10391
|
+
isSingleExecute: false,
|
|
10392
|
+
isFlowControl: true,
|
|
10393
|
+
body: [child]
|
|
10394
|
+
})],
|
|
10395
|
+
macroStorage
|
|
10396
|
+
}));
|
|
9964
10397
|
}
|
|
9965
10398
|
}
|
|
9966
|
-
return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
10399
|
+
return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
9967
10400
|
isSingleExecute: false,
|
|
9968
10401
|
givenCallbackName: `${i}_${callbackName}`,
|
|
9969
10402
|
body: [
|
|
9970
10403
|
new ReturnRunCommandNode(visitor.pack, ["run"], {
|
|
9971
10404
|
isSingleExecute: false,
|
|
10405
|
+
isFlowControl: true,
|
|
9972
10406
|
body: actualBody
|
|
9973
10407
|
})
|
|
9974
|
-
]
|
|
9975
|
-
|
|
10408
|
+
],
|
|
10409
|
+
macroStorage
|
|
10410
|
+
}));
|
|
9976
10411
|
}
|
|
9977
|
-
return body;
|
|
10412
|
+
return body.flatMap((n) => visitor.visit(n));
|
|
9978
10413
|
});
|
|
9979
10414
|
}
|
|
9980
10415
|
var IfElseTransformationVisitor;
|
|
@@ -9988,19 +10423,30 @@ var init_ifElseTransformationVisitor = __esm(() => {
|
|
|
9988
10423
|
return [];
|
|
9989
10424
|
}
|
|
9990
10425
|
const nodes2 = Array.from(flattenIfNode(node_));
|
|
10426
|
+
const { parentMCFunction, condition: condition2, givenCallbackName, body } = node_;
|
|
10427
|
+
const callbackName = givenCallbackName ?? "if";
|
|
10428
|
+
const macroStorage = parentMCFunction.resource.macroPoint;
|
|
9991
10429
|
if (nodes2.length === 1) {
|
|
9992
|
-
|
|
10430
|
+
const executeNode = new ExecuteCommandNode(this.pack, [[condition2.getValue()]], {
|
|
9993
10431
|
isSingleExecute: false,
|
|
9994
|
-
givenCallbackName:
|
|
9995
|
-
body
|
|
9996
|
-
|
|
10432
|
+
givenCallbackName: callbackName,
|
|
10433
|
+
body,
|
|
10434
|
+
macroStorage
|
|
10435
|
+
});
|
|
10436
|
+
node_.resultingExecuteNode = executeNode;
|
|
10437
|
+
return this.visit(executeNode);
|
|
10438
|
+
}
|
|
10439
|
+
if (nodes2.at(-1) === parentMCFunction.body.at(-1)) {
|
|
10440
|
+
return handleMultipleNodes(this, nodes2, macroStorage);
|
|
9997
10441
|
}
|
|
9998
10442
|
const wrapper = new ExecuteCommandNode(this.pack, [], {
|
|
9999
10443
|
isFake: true,
|
|
10000
10444
|
isSingleExecute: false,
|
|
10001
|
-
givenCallbackName:
|
|
10002
|
-
body: handleMultipleNodes(this, nodes2)
|
|
10445
|
+
givenCallbackName: callbackName,
|
|
10446
|
+
body: handleMultipleNodes(this, nodes2, macroStorage),
|
|
10447
|
+
macroStorage
|
|
10003
10448
|
});
|
|
10449
|
+
node_.resultingExecuteNode = wrapper;
|
|
10004
10450
|
return this.visit(wrapper);
|
|
10005
10451
|
};
|
|
10006
10452
|
};
|
|
@@ -10009,19 +10455,15 @@ var init_ifElseTransformationVisitor = __esm(() => {
|
|
|
10009
10455
|
// src/pack/visitors/initConstantsVisitor.ts
|
|
10010
10456
|
var InitConstantsVisitor;
|
|
10011
10457
|
var init_initConstantsVisitor = __esm(() => {
|
|
10458
|
+
init_commands2();
|
|
10012
10459
|
init_visitor();
|
|
10013
10460
|
InitConstantsVisitor = class InitConstantsVisitor extends GenericSandstoneVisitor {
|
|
10014
10461
|
onStart = () => {
|
|
10015
10462
|
const { pack } = this;
|
|
10016
|
-
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
pack.initMCFunction.unshift(() => {
|
|
10021
|
-
for (const constant of constants) {
|
|
10022
|
-
scoreboard2.players.set(constant, pack.rootObjective, constant);
|
|
10023
|
-
}
|
|
10024
|
-
});
|
|
10463
|
+
if (pack.constants.size !== 0) {
|
|
10464
|
+
for (const constant of pack.constants) {
|
|
10465
|
+
pack.initMCFunction.node.body.push(new ScoreboardCommandNode(pack, "players", "set", constant, pack.rootObjective, constant));
|
|
10466
|
+
}
|
|
10025
10467
|
}
|
|
10026
10468
|
};
|
|
10027
10469
|
};
|
|
@@ -10097,15 +10539,24 @@ var init_inlineFunctionCallVisitor = __esm(() => {
|
|
|
10097
10539
|
// src/pack/visitors/loopTransformationVisitor.ts
|
|
10098
10540
|
var LoopTransformationVisitor;
|
|
10099
10541
|
var init_loopTransformationVisitor = __esm(() => {
|
|
10100
|
-
|
|
10542
|
+
init_flow();
|
|
10101
10543
|
init_visitor();
|
|
10102
10544
|
LoopTransformationVisitor = class LoopTransformationVisitor extends GenericSandstoneVisitor {
|
|
10545
|
+
currentLoopIfNode = null;
|
|
10103
10546
|
visitLoopNode = (node_) => {
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10547
|
+
const ifNode = new IfNode(this.core, node_.condition, undefined, node_.parentMCFunction);
|
|
10548
|
+
ifNode.givenCallbackName = "loop";
|
|
10549
|
+
const previousLoopIfNode = this.currentLoopIfNode;
|
|
10550
|
+
this.currentLoopIfNode = ifNode;
|
|
10551
|
+
ifNode.body = node_.body.flatMap((node) => this.visit(node));
|
|
10552
|
+
this.currentLoopIfNode = previousLoopIfNode;
|
|
10553
|
+
return ifNode;
|
|
10554
|
+
};
|
|
10555
|
+
visitLoopArgument = (node_) => {
|
|
10556
|
+
if (this.currentLoopIfNode) {
|
|
10557
|
+
node_.loopIfNode = this.currentLoopIfNode;
|
|
10558
|
+
}
|
|
10559
|
+
return node_;
|
|
10109
10560
|
};
|
|
10110
10561
|
visitWhileNode = this.visitLoopNode;
|
|
10111
10562
|
visitForINode = this.visitLoopNode;
|
|
@@ -10204,7 +10655,7 @@ var init_simplifyExecuteFunction = __esm(() => {
|
|
|
10204
10655
|
return this.genericVisit(node);
|
|
10205
10656
|
}
|
|
10206
10657
|
const mcFunction = functionNode.args[0];
|
|
10207
|
-
if (typeof mcFunction === "string") {
|
|
10658
|
+
if (typeof mcFunction === "string" || !mcFunction?.node) {
|
|
10208
10659
|
return this.genericVisit(node);
|
|
10209
10660
|
}
|
|
10210
10661
|
const mcFunctionNode = mcFunction.node;
|
|
@@ -10216,11 +10667,33 @@ var init_simplifyExecuteFunction = __esm(() => {
|
|
|
10216
10667
|
return this.genericVisit(node);
|
|
10217
10668
|
}
|
|
10218
10669
|
}
|
|
10670
|
+
if (command instanceof LoopArgument) {
|
|
10671
|
+
const loopExecute = command.loopIfNode?.resultingExecuteNode;
|
|
10672
|
+
const loopFunctionName = loopExecute?.createdMCFunction?.name;
|
|
10673
|
+
if (loopFunctionName) {
|
|
10674
|
+
node.body = [new FunctionCommandNode(this.pack, loopFunctionName)];
|
|
10675
|
+
if (mcFunction.creator === "sandstone") {
|
|
10676
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
10677
|
+
}
|
|
10678
|
+
return this.genericVisit(node);
|
|
10679
|
+
}
|
|
10680
|
+
return this.genericVisit(node);
|
|
10681
|
+
}
|
|
10219
10682
|
if (!(command instanceof CommandNode)) {
|
|
10220
10683
|
return this.genericVisit(node);
|
|
10221
10684
|
}
|
|
10222
|
-
if (command instanceof
|
|
10223
|
-
|
|
10685
|
+
if (command instanceof ReturnRunCommandNode) {
|
|
10686
|
+
if (mcFunction.creator === "sandstone") {
|
|
10687
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
10688
|
+
}
|
|
10689
|
+
if (command.isFlowControl) {
|
|
10690
|
+
node.body = [this.genericVisit(command)];
|
|
10691
|
+
} else {
|
|
10692
|
+
const returnCmd = this.visit(command);
|
|
10693
|
+
node.body = returnCmd.body;
|
|
10694
|
+
return this.visitExecuteCommandNode(node);
|
|
10695
|
+
}
|
|
10696
|
+
return this.genericVisit(node);
|
|
10224
10697
|
}
|
|
10225
10698
|
if (command instanceof FunctionCommandNode) {
|
|
10226
10699
|
const innerMCFunction = command.args[0];
|
|
@@ -10263,17 +10736,24 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
10263
10736
|
init_nodes();
|
|
10264
10737
|
init_flow();
|
|
10265
10738
|
init_visitor();
|
|
10739
|
+
init_Macro();
|
|
10266
10740
|
SimplifyReturnRunFunctionVisitor = class SimplifyReturnRunFunctionVisitor extends GenericSandstoneVisitor {
|
|
10267
10741
|
visitReturnRunCommandNode = (node) => {
|
|
10268
10742
|
if (node.body.length === 0 || node.body.length > 1) {
|
|
10269
10743
|
return this.genericVisit(node);
|
|
10270
10744
|
}
|
|
10271
|
-
const
|
|
10272
|
-
if (!(
|
|
10745
|
+
const childNode = node.body[0];
|
|
10746
|
+
if (!(childNode instanceof FunctionCommandNode)) {
|
|
10747
|
+
if (childNode instanceof ReturnRunCommandNode) {
|
|
10748
|
+
return this.visitReturnRunCommandNode(childNode);
|
|
10749
|
+
}
|
|
10750
|
+
if (childNode instanceof ReturnCommandNode) {
|
|
10751
|
+
return this.genericVisit(childNode);
|
|
10752
|
+
}
|
|
10273
10753
|
return this.genericVisit(node);
|
|
10274
10754
|
}
|
|
10275
|
-
const mcFunction =
|
|
10276
|
-
if (typeof mcFunction === "string") {
|
|
10755
|
+
const mcFunction = childNode.args[0];
|
|
10756
|
+
if (typeof mcFunction === "string" || isMacroArgument(this.core, mcFunction)) {
|
|
10277
10757
|
return this.genericVisit(node);
|
|
10278
10758
|
}
|
|
10279
10759
|
const mcFunctionNode = mcFunction.node;
|
|
@@ -10289,10 +10769,6 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
10289
10769
|
return this.genericVisit(node);
|
|
10290
10770
|
}
|
|
10291
10771
|
if (command instanceof FunctionCommandNode) {
|
|
10292
|
-
const innerMCFunction = command.args[0];
|
|
10293
|
-
if (typeof innerMCFunction === "string") {
|
|
10294
|
-
return this.genericVisit(node);
|
|
10295
|
-
}
|
|
10296
10772
|
node.body = [command];
|
|
10297
10773
|
if (mcFunction.creator === "sandstone") {
|
|
10298
10774
|
this.core.resourceNodes.delete(mcFunctionNode);
|
|
@@ -10300,7 +10776,18 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
10300
10776
|
return this.genericVisit(node);
|
|
10301
10777
|
}
|
|
10302
10778
|
if (command instanceof ReturnRunCommandNode) {
|
|
10303
|
-
|
|
10779
|
+
node.body = command.body;
|
|
10780
|
+
node.isFlowControl = node.isFlowControl || command.isFlowControl;
|
|
10781
|
+
if (mcFunction.creator === "sandstone") {
|
|
10782
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
10783
|
+
}
|
|
10784
|
+
return this.visitReturnRunCommandNode(node);
|
|
10785
|
+
}
|
|
10786
|
+
if (command instanceof ReturnCommandNode) {
|
|
10787
|
+
if (mcFunction.creator === "sandstone") {
|
|
10788
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
10789
|
+
}
|
|
10790
|
+
return this.genericVisit(command);
|
|
10304
10791
|
}
|
|
10305
10792
|
node.body = [this.genericVisit(command)];
|
|
10306
10793
|
if (mcFunction.creator === "sandstone") {
|
|
@@ -10311,6 +10798,233 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
10311
10798
|
};
|
|
10312
10799
|
});
|
|
10313
10800
|
|
|
10801
|
+
// src/pack/visitors/switchTransformationVisitor.ts
|
|
10802
|
+
var SwitchTransformationVisitor;
|
|
10803
|
+
var init_switchTransformationVisitor = __esm(() => {
|
|
10804
|
+
init_commands2();
|
|
10805
|
+
init_core();
|
|
10806
|
+
init_flow();
|
|
10807
|
+
init_variables();
|
|
10808
|
+
init_visitor();
|
|
10809
|
+
SwitchTransformationVisitor = class SwitchTransformationVisitor extends GenericSandstoneVisitor {
|
|
10810
|
+
visitSwitchNode = (node) => {
|
|
10811
|
+
const { value, staticCases, conditionCases, defaultCase, parentMCFunction } = node;
|
|
10812
|
+
const { Data: Data2, initMCFunction, Macro: Macro2, commands: commands2 } = this.pack;
|
|
10813
|
+
const { functionCmd } = commands2;
|
|
10814
|
+
const parentName = parentMCFunction?.resource.name ?? "__sandstone:switch";
|
|
10815
|
+
const hasStaticCases = staticCases.length > 0;
|
|
10816
|
+
const switchMCFunction = new MCFunctionClass(this.core, `${parentName}/switch`, {
|
|
10817
|
+
addToSandstoneCore: true,
|
|
10818
|
+
creator: "sandstone",
|
|
10819
|
+
onConflict: "rename"
|
|
10820
|
+
}, hasStaticCases ? [value] : undefined);
|
|
10821
|
+
const storageKey = `__sandstone:${switchMCFunction.name.replace(/[:/]/g, "_")}`;
|
|
10822
|
+
const values = Data2("storage", storageKey, "Values");
|
|
10823
|
+
if (hasStaticCases) {
|
|
10824
|
+
const isScoreSwitch = value instanceof Score;
|
|
10825
|
+
if (typeof value.local?.set === "function") {
|
|
10826
|
+
value.local.set(switchMCFunction.name, "env_0");
|
|
10827
|
+
}
|
|
10828
|
+
this.core.enterMCFunction(switchMCFunction);
|
|
10829
|
+
if (isScoreSwitch) {
|
|
10830
|
+
for (const caseNode of staticCases) {
|
|
10831
|
+
const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${caseNode.value}`, {
|
|
10832
|
+
addToSandstoneCore: true,
|
|
10833
|
+
creator: "sandstone",
|
|
10834
|
+
onConflict: "rename"
|
|
10835
|
+
});
|
|
10836
|
+
caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
|
|
10837
|
+
}
|
|
10838
|
+
const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
|
|
10839
|
+
if (hasFallback) {
|
|
10840
|
+
const tryCaseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/try_case`, {
|
|
10841
|
+
addToSandstoneCore: true,
|
|
10842
|
+
creator: "sandstone",
|
|
10843
|
+
onConflict: "rename"
|
|
10844
|
+
});
|
|
10845
|
+
this.core.enterMCFunction(tryCaseMCFunction);
|
|
10846
|
+
Macro2.returnCmd.run.functionCmd(Macro2`${switchMCFunction.name}/case_${value}`);
|
|
10847
|
+
this.core.exitMCFunction();
|
|
10848
|
+
const successScore = this.pack.rootObjective("$switch_success");
|
|
10849
|
+
const resultScore = this.pack.rootObjective("$switch_result");
|
|
10850
|
+
commands2.execute.store.success(successScore).store.result(resultScore).run.functionCmd(tryCaseMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
10851
|
+
commands2.execute.if.score(successScore, "matches", 1).run.returnCmd.run.scoreboard.players.get(resultScore);
|
|
10852
|
+
this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
|
|
10853
|
+
} else {
|
|
10854
|
+
const dispatchMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/dispatch`, {
|
|
10855
|
+
addToSandstoneCore: true,
|
|
10856
|
+
creator: "sandstone",
|
|
10857
|
+
onConflict: "rename"
|
|
10858
|
+
});
|
|
10859
|
+
this.core.enterMCFunction(dispatchMCFunction);
|
|
10860
|
+
Macro2.returnCmd.run.functionCmd(Macro2`${switchMCFunction.name}/case_${value}`);
|
|
10861
|
+
this.core.exitMCFunction();
|
|
10862
|
+
commands2.returnCmd.run.functionCmd(dispatchMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
10863
|
+
}
|
|
10864
|
+
const macroPoint = switchMCFunction.macroPoint;
|
|
10865
|
+
const env0Point = macroPoint.select("env_0");
|
|
10866
|
+
commands2.execute.store.result.storage(env0Point.currentTarget, env0Point.path, "int").run.scoreboard.players.get(value);
|
|
10867
|
+
const copyNode = switchMCFunction.node.body.pop();
|
|
10868
|
+
switchMCFunction.node.body.unshift(copyNode);
|
|
10869
|
+
const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
10870
|
+
if (canInline) {
|
|
10871
|
+
this.core.exitMCFunction();
|
|
10872
|
+
this.core.resourceNodes.delete(switchMCFunction.node);
|
|
10873
|
+
return switchMCFunction.node.body;
|
|
10874
|
+
}
|
|
10875
|
+
} else {
|
|
10876
|
+
const index = switchMCFunction.macroPoint.select("Index");
|
|
10877
|
+
index.local.set(switchMCFunction.name, "Index");
|
|
10878
|
+
index.remove();
|
|
10879
|
+
Macro2.data.modify.storage(index.currentTarget, index.path).set.from.storage(values.currentTarget, Macro2`Values[{Value:${value}}].Index`);
|
|
10880
|
+
const caseData = [];
|
|
10881
|
+
for (let i = 0;i < staticCases.length; i++) {
|
|
10882
|
+
const caseNode = staticCases[i];
|
|
10883
|
+
const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${i}`, {
|
|
10884
|
+
addToSandstoneCore: true,
|
|
10885
|
+
creator: "sandstone",
|
|
10886
|
+
onConflict: "rename"
|
|
10887
|
+
});
|
|
10888
|
+
caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
|
|
10889
|
+
caseData.push({
|
|
10890
|
+
Value: caseNode.value,
|
|
10891
|
+
Index: NBT.int(i)
|
|
10892
|
+
});
|
|
10893
|
+
}
|
|
10894
|
+
initMCFunction.push(() => values.set(caseData));
|
|
10895
|
+
const innerMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/inner`, {
|
|
10896
|
+
addToSandstoneCore: true,
|
|
10897
|
+
creator: "sandstone",
|
|
10898
|
+
onConflict: "rename"
|
|
10899
|
+
});
|
|
10900
|
+
this.core.enterMCFunction(innerMCFunction);
|
|
10901
|
+
Macro2.returnCmd.run.functionCmd(Macro2`${switchMCFunction.name}/case_${index}`);
|
|
10902
|
+
this.core.exitMCFunction();
|
|
10903
|
+
const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
|
|
10904
|
+
if (hasFallback) {
|
|
10905
|
+
const ifNode = new IfNode(this.core, index._toMinecraftCondition(), undefined, switchMCFunction.node);
|
|
10906
|
+
switchMCFunction.node.enterContext(ifNode, false);
|
|
10907
|
+
functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
10908
|
+
switchMCFunction.node.exitContext();
|
|
10909
|
+
switchMCFunction.node.body.push(ifNode);
|
|
10910
|
+
this.buildFallback(ifNode, value, conditionCases, defaultCase, switchMCFunction);
|
|
10911
|
+
} else {
|
|
10912
|
+
this.pack.commands.execute.if.data.storage(index.currentTarget, index.path).run.returnCmd.run.functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
10913
|
+
}
|
|
10914
|
+
}
|
|
10915
|
+
this.core.exitMCFunction();
|
|
10916
|
+
} else {
|
|
10917
|
+
this.core.enterMCFunction(switchMCFunction);
|
|
10918
|
+
this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
|
|
10919
|
+
this.core.exitMCFunction();
|
|
10920
|
+
const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
10921
|
+
if (canInline) {
|
|
10922
|
+
this.core.resourceNodes.delete(switchMCFunction.node);
|
|
10923
|
+
for (const bodyNode of switchMCFunction.node.body) {
|
|
10924
|
+
if (bodyNode instanceof IfNode) {
|
|
10925
|
+
bodyNode.parentMCFunction = parentMCFunction;
|
|
10926
|
+
let lastIfNode = bodyNode;
|
|
10927
|
+
while (lastIfNode.nextFlowNode instanceof IfNode) {
|
|
10928
|
+
lastIfNode.nextFlowNode.parentMCFunction = parentMCFunction;
|
|
10929
|
+
lastIfNode = lastIfNode.nextFlowNode;
|
|
10930
|
+
}
|
|
10931
|
+
if (lastIfNode !== bodyNode) {
|
|
10932
|
+
switchMCFunction.node.body.push(lastIfNode);
|
|
10933
|
+
}
|
|
10934
|
+
}
|
|
10935
|
+
}
|
|
10936
|
+
return switchMCFunction.node.body;
|
|
10937
|
+
}
|
|
10938
|
+
}
|
|
10939
|
+
const isLastNode = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
10940
|
+
if (hasStaticCases && !(value instanceof Score)) {
|
|
10941
|
+
const macroPoint = switchMCFunction.macroPoint;
|
|
10942
|
+
const resolvedValue = value instanceof DataPointPickClass ? value._toDataPoint() : value;
|
|
10943
|
+
const env0Point = macroPoint.select("env_0");
|
|
10944
|
+
const copyNode = new DataCommandNode(this.pack);
|
|
10945
|
+
copyNode.args = [
|
|
10946
|
+
"modify",
|
|
10947
|
+
"storage",
|
|
10948
|
+
env0Point.currentTarget,
|
|
10949
|
+
env0Point.path,
|
|
10950
|
+
"set",
|
|
10951
|
+
"from",
|
|
10952
|
+
resolvedValue.type,
|
|
10953
|
+
resolvedValue.currentTarget,
|
|
10954
|
+
resolvedValue.path
|
|
10955
|
+
];
|
|
10956
|
+
const funcNode2 = new FunctionCommandNode(this.pack, switchMCFunction.name);
|
|
10957
|
+
funcNode2.args.push("with", macroPoint.type, macroPoint.currentTarget, macroPoint.path);
|
|
10958
|
+
if (isLastNode) {
|
|
10959
|
+
const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
10960
|
+
callNode.body = [funcNode2];
|
|
10961
|
+
return [copyNode, callNode].flatMap((n) => this.visit(n));
|
|
10962
|
+
}
|
|
10963
|
+
return [copyNode, funcNode2].flatMap((n) => this.visit(n));
|
|
10964
|
+
}
|
|
10965
|
+
const funcNode = new FunctionCommandNode(this.pack, switchMCFunction.name);
|
|
10966
|
+
if (isLastNode) {
|
|
10967
|
+
const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
10968
|
+
callNode.body = [funcNode];
|
|
10969
|
+
return this.visit(callNode);
|
|
10970
|
+
}
|
|
10971
|
+
return this.visit(funcNode);
|
|
10972
|
+
};
|
|
10973
|
+
buildFallback(_if, value, conditionCases, defaultCase, switchMCFunction, targetBody) {
|
|
10974
|
+
if (conditionCases.length === 0 && !defaultCase)
|
|
10975
|
+
return;
|
|
10976
|
+
const body = targetBody ?? switchMCFunction.node.body;
|
|
10977
|
+
if (conditionCases.length > 0) {
|
|
10978
|
+
const firstCondition = conditionCases[0].condition(value);
|
|
10979
|
+
const firstConditionNode = conditionToNode(firstCondition);
|
|
10980
|
+
let currentIfNode;
|
|
10981
|
+
if (_if === undefined) {
|
|
10982
|
+
currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
|
|
10983
|
+
currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
|
|
10984
|
+
body.push(currentIfNode);
|
|
10985
|
+
} else {
|
|
10986
|
+
currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
|
|
10987
|
+
currentIfNode._isElseIf = true;
|
|
10988
|
+
_if.nextFlowNode = currentIfNode;
|
|
10989
|
+
currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
|
|
10990
|
+
}
|
|
10991
|
+
for (let i = 1;i < conditionCases.length; i++) {
|
|
10992
|
+
const condition2 = conditionCases[i].condition(value);
|
|
10993
|
+
const conditionNode = conditionToNode(condition2);
|
|
10994
|
+
const nextIfNode = new IfNode(this.core, conditionNode, undefined, switchMCFunction.node);
|
|
10995
|
+
nextIfNode._isElseIf = true;
|
|
10996
|
+
currentIfNode.nextFlowNode = nextIfNode;
|
|
10997
|
+
nextIfNode.body = conditionCases[i].body.flatMap((n) => this.visit(n));
|
|
10998
|
+
currentIfNode = nextIfNode;
|
|
10999
|
+
}
|
|
11000
|
+
if (defaultCase) {
|
|
11001
|
+
const elseNode = new ElseNode(this.core, () => {});
|
|
11002
|
+
elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
|
|
11003
|
+
currentIfNode.nextFlowNode = elseNode;
|
|
11004
|
+
}
|
|
11005
|
+
} else if (defaultCase) {
|
|
11006
|
+
if (_if === undefined) {
|
|
11007
|
+
const visitedNodes = defaultCase.body.flatMap((n) => this.visit(n));
|
|
11008
|
+
body.push(...visitedNodes);
|
|
11009
|
+
} else {
|
|
11010
|
+
const elseNode = new ElseNode(this.core, () => {});
|
|
11011
|
+
elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
|
|
11012
|
+
_if.nextFlowNode = elseNode;
|
|
11013
|
+
}
|
|
11014
|
+
}
|
|
11015
|
+
}
|
|
11016
|
+
visitStaticCaseNode = (_node) => {
|
|
11017
|
+
return [];
|
|
11018
|
+
};
|
|
11019
|
+
visitConditionCaseNode = (_node) => {
|
|
11020
|
+
return [];
|
|
11021
|
+
};
|
|
11022
|
+
visitDefaultCaseNode = (_node) => {
|
|
11023
|
+
return [];
|
|
11024
|
+
};
|
|
11025
|
+
};
|
|
11026
|
+
});
|
|
11027
|
+
|
|
10314
11028
|
// src/pack/visitors/unifyChainedExecutes.ts
|
|
10315
11029
|
var UnifyChainedExecutesVisitor;
|
|
10316
11030
|
var init_unifyChainedExecutes = __esm(() => {
|
|
@@ -10326,6 +11040,10 @@ var init_unifyChainedExecutes = __esm(() => {
|
|
|
10326
11040
|
node.body = chainedCommand.body;
|
|
10327
11041
|
node.args.push(...chainedCommand.args);
|
|
10328
11042
|
}
|
|
11043
|
+
const flattenedArgs = node.args.flat(1).filter((a) => a !== undefined && a !== null);
|
|
11044
|
+
if (flattenedArgs.length === 0 && node.body.length === 1) {
|
|
11045
|
+
return this.genericVisit(node.body[0]);
|
|
11046
|
+
}
|
|
10329
11047
|
return this.genericVisit(node);
|
|
10330
11048
|
};
|
|
10331
11049
|
};
|
|
@@ -10343,6 +11061,7 @@ var init_visitors2 = __esm(() => {
|
|
|
10343
11061
|
init_orTransformationVisitor();
|
|
10344
11062
|
init_simplifyExecuteFunction();
|
|
10345
11063
|
init_simplifyReturnRunFunction();
|
|
11064
|
+
init_switchTransformationVisitor();
|
|
10346
11065
|
init_unifyChainedExecutes();
|
|
10347
11066
|
});
|
|
10348
11067
|
|
|
@@ -10412,6 +11131,8 @@ class SandstonePack {
|
|
|
10412
11131
|
this.__rootObjective = undefined;
|
|
10413
11132
|
this.__initMCFunction = undefined;
|
|
10414
11133
|
this.objectives.clear();
|
|
11134
|
+
this.anonymousDataId = 0;
|
|
11135
|
+
this.anonymousScoreId = 0;
|
|
10415
11136
|
this.constants.clear();
|
|
10416
11137
|
this.tickedLoops = {};
|
|
10417
11138
|
this.dependencies.clear();
|
|
@@ -10474,7 +11195,7 @@ class SandstonePack {
|
|
|
10474
11195
|
return [namespace, ...resourceFolders, ...fullPath];
|
|
10475
11196
|
};
|
|
10476
11197
|
get _() {
|
|
10477
|
-
return
|
|
11198
|
+
return this.flow;
|
|
10478
11199
|
}
|
|
10479
11200
|
registerNewObjective = (objective) => {
|
|
10480
11201
|
this.objectives.add(objective);
|
|
@@ -10513,7 +11234,7 @@ class SandstonePack {
|
|
|
10513
11234
|
return this.Variable(undefined, name2).set(nbt2, scale);
|
|
10514
11235
|
}
|
|
10515
11236
|
const [initialValue, name] = args;
|
|
10516
|
-
const anonymousScore = score2(`${name ?? "anon"}_${this.packUid}_${this.anonymousScoreId++}`);
|
|
11237
|
+
const anonymousScore = score2(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousScoreId++}` : ""}`);
|
|
10517
11238
|
if (initialValue === undefined) {
|
|
10518
11239
|
return anonymousScore;
|
|
10519
11240
|
}
|
|
@@ -10557,7 +11278,7 @@ class SandstonePack {
|
|
|
10557
11278
|
return this.DataVariable(undefined, name2).set(score2, storeType || "int", scale || 1);
|
|
10558
11279
|
}
|
|
10559
11280
|
const [initialValue, name] = args;
|
|
10560
|
-
const anonymousData = data2.select(`${name ?? "anon"}_${this.packUid}_${this.anonymousDataId++}`);
|
|
11281
|
+
const anonymousData = data2.select(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousDataId++}` : ""}`);
|
|
10561
11282
|
if (initialValue === undefined) {
|
|
10562
11283
|
return anonymousData;
|
|
10563
11284
|
}
|
|
@@ -10960,6 +11681,7 @@ class SandstonePack {
|
|
|
10960
11681
|
new InitConstantsVisitor(this),
|
|
10961
11682
|
new GenerateLazyMCFunction(this),
|
|
10962
11683
|
new LoopTransformationVisitor(this),
|
|
11684
|
+
new SwitchTransformationVisitor(this),
|
|
10963
11685
|
new OrTransformationVisitor(this),
|
|
10964
11686
|
new IfElseTransformationVisitor(this),
|
|
10965
11687
|
new ContainerCommandsToMCFunctionVisitor(this),
|
|
@@ -11010,7 +11732,7 @@ var init_pack = __esm(() => {
|
|
|
11010
11732
|
}
|
|
11011
11733
|
handleOutput = async (type, readFile, writeFile) => {
|
|
11012
11734
|
if (type === "output") {
|
|
11013
|
-
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
|
|
11735
|
+
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
|
|
11014
11736
|
}
|
|
11015
11737
|
};
|
|
11016
11738
|
};
|
|
@@ -11031,7 +11753,7 @@ var init_pack = __esm(() => {
|
|
|
11031
11753
|
}
|
|
11032
11754
|
handleOutput = async (type, readFile, writeFile) => {
|
|
11033
11755
|
if (type === "output") {
|
|
11034
|
-
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
|
|
11756
|
+
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
|
|
11035
11757
|
}
|
|
11036
11758
|
};
|
|
11037
11759
|
};
|
|
@@ -11106,7 +11828,11 @@ var init_src = __esm(() => {
|
|
|
11106
11828
|
return new Proxy(fn, {
|
|
11107
11829
|
get(_target, subProp) {
|
|
11108
11830
|
const method = sandstonePack[prop];
|
|
11109
|
-
|
|
11831
|
+
const value = method[subProp];
|
|
11832
|
+
if (typeof value === "function") {
|
|
11833
|
+
return value.bind(method);
|
|
11834
|
+
}
|
|
11835
|
+
return value;
|
|
11110
11836
|
},
|
|
11111
11837
|
apply(_target, _thisArg, args) {
|
|
11112
11838
|
const method = sandstonePack[prop];
|