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/commands/index.js
CHANGED
|
@@ -85,6 +85,16 @@ function randomUUID() {
|
|
|
85
85
|
}
|
|
86
86
|
return array;
|
|
87
87
|
}
|
|
88
|
+
function add(obj) {
|
|
89
|
+
const filtered = {};
|
|
90
|
+
for (const key of Object.keys(obj)) {
|
|
91
|
+
const value = obj[key];
|
|
92
|
+
if (value !== undefined) {
|
|
93
|
+
filtered[key] = value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return filtered;
|
|
97
|
+
}
|
|
88
98
|
async function safeWrite(...args) {
|
|
89
99
|
if (typeof args[0] !== "string")
|
|
90
100
|
throw new Error("unimplemented");
|
|
@@ -101,6 +111,14 @@ function formatDebugString(className, args, body, currentIndent) {
|
|
|
101
111
|
argsString = args;
|
|
102
112
|
} else if (Array.isArray(args)) {
|
|
103
113
|
argsString = args.map((arg) => util.inspect(arg, options)).join(", ");
|
|
114
|
+
if (argsString.includes(`
|
|
115
|
+
`)) {
|
|
116
|
+
argsString = `
|
|
117
|
+
${nextIndent}${args.map((arg) => util.inspect(arg, options).replaceAll(`
|
|
118
|
+
`, `
|
|
119
|
+
${nextIndent}`)).join(`,
|
|
120
|
+
${nextIndent}`)}`;
|
|
121
|
+
}
|
|
104
122
|
} else if (args && typeof args === "object") {
|
|
105
123
|
argsString = Object.entries(args).map(([key, value]) => `${key}: ${util.inspect(value, options)}`).join(", ");
|
|
106
124
|
} else {
|
|
@@ -213,7 +231,17 @@ class MacroArgument {
|
|
|
213
231
|
try {
|
|
214
232
|
currentMCFunctionName = sandstoneCore.getCurrentMCFunctionOrThrow().resource.name;
|
|
215
233
|
} catch {}
|
|
216
|
-
|
|
234
|
+
let result = this.local.get(this.sandstoneCore.currentNode) || this.local.get(currentMCFunctionName);
|
|
235
|
+
if (!result) {
|
|
236
|
+
let path = this.sandstoneCore.currentNode;
|
|
237
|
+
while (path.includes("/")) {
|
|
238
|
+
path = path.substring(0, path.lastIndexOf("/"));
|
|
239
|
+
result = this.local.get(path);
|
|
240
|
+
if (result)
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return `$(${result})`;
|
|
217
245
|
};
|
|
218
246
|
}
|
|
219
247
|
}
|
|
@@ -253,6 +281,9 @@ var init_Macro = __esm(() => {
|
|
|
253
281
|
result += `${macro}`;
|
|
254
282
|
} else {
|
|
255
283
|
result += macro.toMacro();
|
|
284
|
+
if (result.endsWith("}")) {
|
|
285
|
+
console.warn("what", macro);
|
|
286
|
+
}
|
|
256
287
|
}
|
|
257
288
|
}
|
|
258
289
|
}
|
|
@@ -707,14 +738,14 @@ var init_damage = __esm(() => {
|
|
|
707
738
|
from = (cause) => this.finalCommand(["from", targetParser(cause)]);
|
|
708
739
|
};
|
|
709
740
|
DamageSourceCommand = class DamageSourceCommand extends CommandArguments {
|
|
710
|
-
by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand);
|
|
741
|
+
by = (entity) => this.subCommand(["by", targetParser(entity)], DamageCauseCommand, true);
|
|
711
742
|
at = (position) => this.finalCommand(["at", coordinatesParser(position)]);
|
|
712
743
|
};
|
|
713
744
|
DamageCommand = class DamageCommand extends CommandArguments {
|
|
714
745
|
NodeType = DamageCommandNode;
|
|
715
746
|
damage = (target, amount, damageType) => {
|
|
716
747
|
validateIntegerRange(amount, "amount", 0, 1e6);
|
|
717
|
-
return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand);
|
|
748
|
+
return this.subCommand([targetParser(target), amount, damageType], DamageSourceCommand, true);
|
|
718
749
|
};
|
|
719
750
|
};
|
|
720
751
|
});
|
|
@@ -1385,7 +1416,7 @@ function dynamicNBT(template, ...args) {
|
|
|
1385
1416
|
const result = mixedArgs.map((element) => element instanceof NBTClass ? nbtStringifier(element) : element.toString()).join("");
|
|
1386
1417
|
return parseNBT(NBT, result);
|
|
1387
1418
|
}
|
|
1388
|
-
var N_B_T_CLASS_BRAND, NBTClass, N_B_T_PRIMITIVE_BRAND, NBTPrimitive, NBTLong, NBTByte, NBTShort, NBTFloat, NBTInt, NBTDouble,
|
|
1419
|
+
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) => {
|
|
1389
1420
|
if (nbt === null || nbt === undefined) {
|
|
1390
1421
|
throw new Error("Nullish nbt values are not allowed");
|
|
1391
1422
|
}
|
|
@@ -1463,6 +1494,9 @@ var init_NBTs = __esm(() => {
|
|
|
1463
1494
|
this.value = value;
|
|
1464
1495
|
this.unit = unit;
|
|
1465
1496
|
}
|
|
1497
|
+
toJSON() {
|
|
1498
|
+
return this.value;
|
|
1499
|
+
}
|
|
1466
1500
|
[util3.inspect.custom] = () => `${this.value}${this.unit}`;
|
|
1467
1501
|
static [Symbol.hasInstance](instance) {
|
|
1468
1502
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_PRIMITIVE_BRAND] === true;
|
|
@@ -1498,9 +1532,7 @@ var init_NBTs = __esm(() => {
|
|
|
1498
1532
|
super(value, "d");
|
|
1499
1533
|
}
|
|
1500
1534
|
};
|
|
1501
|
-
N_B_T_TYPED_ARRAY_BRAND = Symbol.for("sandstone.NBTTypedArray");
|
|
1502
1535
|
NBTTypedArray = class NBTTypedArray extends NBTClass {
|
|
1503
|
-
[N_B_T_TYPED_ARRAY_BRAND] = true;
|
|
1504
1536
|
values;
|
|
1505
1537
|
unit;
|
|
1506
1538
|
constructor(values, unit) {
|
|
@@ -1508,10 +1540,10 @@ var init_NBTs = __esm(() => {
|
|
|
1508
1540
|
this.values = values;
|
|
1509
1541
|
this.unit = unit;
|
|
1510
1542
|
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[N_B_T_TYPED_ARRAY_BRAND] === true;
|
|
1543
|
+
toJSON() {
|
|
1544
|
+
return this.values;
|
|
1514
1545
|
}
|
|
1546
|
+
[util3.inspect.custom] = () => `[${this.unit};${this.values.length === 0 ? "" : this.values.join(",")}]`;
|
|
1515
1547
|
};
|
|
1516
1548
|
NBTLongArray = class NBTLongArray extends NBTTypedArray {
|
|
1517
1549
|
constructor(values) {
|
|
@@ -1615,6 +1647,9 @@ var init_Score = __esm(() => {
|
|
|
1615
1647
|
]));
|
|
1616
1648
|
unaryOperation(operation, operator, ...args) {
|
|
1617
1649
|
if (typeof args[0] === "number") {
|
|
1650
|
+
if (args[0] < 0 && operation !== "set") {
|
|
1651
|
+
return this.binaryOperation(operator, args[0]);
|
|
1652
|
+
}
|
|
1618
1653
|
this.commands.scoreboard.players[operation](this, args[0]);
|
|
1619
1654
|
} else if (args[0] instanceof Score) {
|
|
1620
1655
|
this.commands.scoreboard.players.operation(this, operator, args[0].target, args[0].objective);
|
|
@@ -1631,7 +1666,7 @@ var init_Score = __esm(() => {
|
|
|
1631
1666
|
let objective = args[1] ?? this.objective;
|
|
1632
1667
|
if (typeof args[0] === "number") {
|
|
1633
1668
|
this.sandstonePack.registerNewConstant(args[0]);
|
|
1634
|
-
objective = "
|
|
1669
|
+
objective = "__sandstone";
|
|
1635
1670
|
}
|
|
1636
1671
|
this.commands.scoreboard.players.operation(this, operator, args[0], objective);
|
|
1637
1672
|
return this;
|
|
@@ -1787,7 +1822,99 @@ Warning: Score.match() will have to create ${maximum - minimum} mcfunction files
|
|
|
1787
1822
|
}
|
|
1788
1823
|
return MCFunction(`__sandstone:score_match/${matcher}`, [score], () => Macro.returnCmd.run.functionCmd(Macro`__sandstone:score_match/${matcher}/${score}`));
|
|
1789
1824
|
};
|
|
1790
|
-
|
|
1825
|
+
getDecomposer(size, splitsOrCount, componentCount = 31, includeSign = true) {
|
|
1826
|
+
if (typeof this.target !== "string" || this.target.search(/-|@/) !== -1) {
|
|
1827
|
+
throw new Error("[Score#getDecomposer] Must use a fake-player Score for decomposition.");
|
|
1828
|
+
}
|
|
1829
|
+
const { MCFunction, _, commands } = this.sandstonePack;
|
|
1830
|
+
const { execute, returnCmd } = commands;
|
|
1831
|
+
const newScore = this.objective.ScoreHolder;
|
|
1832
|
+
const components = [];
|
|
1833
|
+
const sign = includeSign ? newScore(`${this.target}._32`) : undefined;
|
|
1834
|
+
let decompose;
|
|
1835
|
+
if (size === "bit" || size === undefined) {
|
|
1836
|
+
for (let i = 1;i <= componentCount; i++) {
|
|
1837
|
+
components.push(newScore(`${this.target}._${i}`));
|
|
1838
|
+
}
|
|
1839
|
+
decompose = MCFunction(`__sandstone:score/decompose_bits/${componentCount}_${splitsOrCount === undefined ? 0 : splitsOrCount.size}/${this.target.replaceAll(".", "/").toLowerCase()}`, () => {
|
|
1840
|
+
const resetBits = execute.store.result(components[0]);
|
|
1841
|
+
for (const component of components.slice(1, -1)) {
|
|
1842
|
+
resetBits.store.result(component);
|
|
1843
|
+
resetBits.nestedExecute(["\\\n "], false);
|
|
1844
|
+
}
|
|
1845
|
+
if (includeSign) {
|
|
1846
|
+
resetBits.store.result(components.at(-1));
|
|
1847
|
+
resetBits.nestedExecute(["\\\n "], false);
|
|
1848
|
+
resetBits.run(() => sign["="](0));
|
|
1849
|
+
} else {
|
|
1850
|
+
resetBits.run(() => components.at(-1)["="](0));
|
|
1851
|
+
}
|
|
1852
|
+
const input = newScore(`${this.target}._bf_iterator`);
|
|
1853
|
+
const splits = splitsOrCount ?? new Set;
|
|
1854
|
+
const bitExecute = (bit) => execute.store.success(components[bit - 1]);
|
|
1855
|
+
input["="](this);
|
|
1856
|
+
_.if(this["=="](0), () => {
|
|
1857
|
+
returnCmd(1);
|
|
1858
|
+
});
|
|
1859
|
+
if (includeSign) {
|
|
1860
|
+
execute.store.success(sign).if.score(input, "matches", [null, -1]).run(() => {
|
|
1861
|
+
input["*="](-1);
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
input.decomposeBits(splits, componentCount, bitExecute);
|
|
1865
|
+
}, {
|
|
1866
|
+
creator: "sandstone",
|
|
1867
|
+
onConflict: "rename",
|
|
1868
|
+
addToSandstoneCore: true
|
|
1869
|
+
});
|
|
1870
|
+
} else {
|
|
1871
|
+
throw new Error("[Score#getDecomposer(byte)] Byte decomposition is not yet supported");
|
|
1872
|
+
}
|
|
1873
|
+
const result = {
|
|
1874
|
+
components,
|
|
1875
|
+
...add({ sign })
|
|
1876
|
+
};
|
|
1877
|
+
return {
|
|
1878
|
+
...result,
|
|
1879
|
+
decompose: () => {
|
|
1880
|
+
decompose();
|
|
1881
|
+
return result;
|
|
1882
|
+
}
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
decomposeBits(splits, componentCount, bitExecute, extra) {
|
|
1886
|
+
const { _ } = this.sandstonePack;
|
|
1887
|
+
const sortedSplits = [...splits].filter((s) => s > 0 && s < componentCount).sort((a, b) => b - a);
|
|
1888
|
+
const boundaries = [componentCount, ...sortedSplits, 0];
|
|
1889
|
+
const processRange = (high, low) => {
|
|
1890
|
+
let halvedAgain = 2 ** high;
|
|
1891
|
+
for (let bit = high;bit >= low; bit--) {
|
|
1892
|
+
halvedAgain /= 2;
|
|
1893
|
+
bitExecute(bit, halvedAgain).if.score(this, "matches", [halvedAgain, null]).run(() => {
|
|
1894
|
+
this["-="](halvedAgain);
|
|
1895
|
+
extra?.(bit, halvedAgain);
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
const buildNested = (rangeIndex) => {
|
|
1900
|
+
const high = boundaries[rangeIndex];
|
|
1901
|
+
const low = boundaries[rangeIndex + 1] + 1;
|
|
1902
|
+
if (rangeIndex > 0) {
|
|
1903
|
+
const higherMinValue = 2 ** boundaries[rangeIndex];
|
|
1904
|
+
_.if(this.matches([higherMinValue, null]), () => {
|
|
1905
|
+
buildNested(rangeIndex - 1);
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
processRange(high, low);
|
|
1909
|
+
};
|
|
1910
|
+
if (splits.size === 0) {
|
|
1911
|
+
processRange(componentCount, 1);
|
|
1912
|
+
} else {
|
|
1913
|
+
const lowestRangeIndex = boundaries.length - 2;
|
|
1914
|
+
buildNested(lowestRangeIndex);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
[util4.inspect.custom](_depth, options) {
|
|
1791
1918
|
return formatDebugString(this.constructor.name, {
|
|
1792
1919
|
target: this.target,
|
|
1793
1920
|
display: this.display,
|
|
@@ -1847,7 +1974,9 @@ class TargetlessDataClass {
|
|
|
1847
1974
|
this.sandstonePack = sandstonePack;
|
|
1848
1975
|
this.type = type;
|
|
1849
1976
|
}
|
|
1850
|
-
target = (target) =>
|
|
1977
|
+
target = (target) => {
|
|
1978
|
+
return new DataClass(this.sandstonePack, this.type, target);
|
|
1979
|
+
};
|
|
1851
1980
|
select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, path);
|
|
1852
1981
|
}
|
|
1853
1982
|
|
|
@@ -1860,7 +1989,9 @@ class TargetlessDataPointClass {
|
|
|
1860
1989
|
this.type = type;
|
|
1861
1990
|
this.path = NBTpathToString(sandstonePack, path);
|
|
1862
1991
|
}
|
|
1863
|
-
target = (target) =>
|
|
1992
|
+
target = (target) => {
|
|
1993
|
+
return new DataPointClass(this.sandstonePack, this.type, target, [this.path]);
|
|
1994
|
+
};
|
|
1864
1995
|
select = (...path) => new TargetlessDataPointClass(this.sandstonePack, this.type, [this.path, ...path]);
|
|
1865
1996
|
}
|
|
1866
1997
|
|
|
@@ -1948,7 +2079,9 @@ var init_Data = __esm(() => {
|
|
|
1948
2079
|
append = (value) => this.modify((data) => data.append, value);
|
|
1949
2080
|
prepend = (value) => this.modify((data) => data.prepend, value);
|
|
1950
2081
|
insert = (value, index) => this.modify((data) => data.insert(index), value);
|
|
1951
|
-
remove = () =>
|
|
2082
|
+
remove = () => {
|
|
2083
|
+
return this.sandstonePack.commands.data.remove[this.type](this.currentTarget, this.path);
|
|
2084
|
+
};
|
|
1952
2085
|
slice = (start, end) => new StringDataPointClass(this.sandstonePack, this.type, this.currentTarget, this.path, start, end);
|
|
1953
2086
|
_toMinecraftCondition = () => new this.sandstonePack.conditions.DataPointExists(this.sandstonePack.core, this);
|
|
1954
2087
|
equals = (value) => new this.sandstonePack.conditions.DataPointEquals(this.sandstonePack.core, this, value);
|
|
@@ -2051,20 +2184,16 @@ function hasContext() {
|
|
|
2051
2184
|
var _context;
|
|
2052
2185
|
|
|
2053
2186
|
// src/core/resources/resource.ts
|
|
2054
|
-
function jsonStringify(json) {
|
|
2055
|
-
return JSON.stringify(json, (
|
|
2056
|
-
if (value
|
|
2057
|
-
return value.
|
|
2058
|
-
}
|
|
2059
|
-
if (value instanceof NBTTypedArray) {
|
|
2060
|
-
return value.values;
|
|
2187
|
+
function jsonStringify(json, resourceType) {
|
|
2188
|
+
return JSON.stringify(json, function(key, value) {
|
|
2189
|
+
if ((typeof value === "object" || typeof value === "function") && value.constructor.name !== "Object" && "toResourceJSON" in value) {
|
|
2190
|
+
return value.toResourceJSON(key, this, resourceType, json);
|
|
2061
2191
|
}
|
|
2062
2192
|
return value;
|
|
2063
2193
|
}, 2);
|
|
2064
2194
|
}
|
|
2065
2195
|
var RESOURCE_CLASS_BRAND, ResourceClass, CallableResourceClass, ResourceNodesMap;
|
|
2066
2196
|
var init_resource = __esm(() => {
|
|
2067
|
-
init_NBTs();
|
|
2068
2197
|
init_arguments();
|
|
2069
2198
|
RESOURCE_CLASS_BRAND = Symbol.for("sandstone.ResourceClass");
|
|
2070
2199
|
ResourceClass = class ResourceClass {
|
|
@@ -2101,7 +2230,7 @@ var init_resource = __esm(() => {
|
|
|
2101
2230
|
}
|
|
2102
2231
|
handleConflicts() {
|
|
2103
2232
|
const conflict = this.core.resourceNodes.get(this.node);
|
|
2104
|
-
let
|
|
2233
|
+
let add2 = false;
|
|
2105
2234
|
if (conflict) {
|
|
2106
2235
|
const oldResource = conflict.resource;
|
|
2107
2236
|
const newResource = this.node.resource;
|
|
@@ -2112,7 +2241,7 @@ var init_resource = __esm(() => {
|
|
|
2112
2241
|
case "replace":
|
|
2113
2242
|
{
|
|
2114
2243
|
this.core.resourceNodes.delete(conflict);
|
|
2115
|
-
|
|
2244
|
+
add2 = true;
|
|
2116
2245
|
}
|
|
2117
2246
|
break;
|
|
2118
2247
|
case "warn":
|
|
@@ -2124,14 +2253,14 @@ var init_resource = __esm(() => {
|
|
|
2124
2253
|
].join(`
|
|
2125
2254
|
`));
|
|
2126
2255
|
this.core.resourceNodes.delete(conflict);
|
|
2127
|
-
|
|
2256
|
+
add2 = true;
|
|
2128
2257
|
}
|
|
2129
2258
|
break;
|
|
2130
2259
|
case "rename":
|
|
2131
2260
|
{
|
|
2132
2261
|
this.path[this.path.length - 1] += oldResource.renameIndex.toString();
|
|
2133
2262
|
oldResource.renameIndex += 1;
|
|
2134
|
-
|
|
2263
|
+
add2 = true;
|
|
2135
2264
|
}
|
|
2136
2265
|
break;
|
|
2137
2266
|
case "prepend":
|
|
@@ -2148,9 +2277,9 @@ var init_resource = __esm(() => {
|
|
|
2148
2277
|
break;
|
|
2149
2278
|
}
|
|
2150
2279
|
} else {
|
|
2151
|
-
|
|
2280
|
+
add2 = true;
|
|
2152
2281
|
}
|
|
2153
|
-
if (this.addToSandstoneCore &&
|
|
2282
|
+
if (this.addToSandstoneCore && add2) {
|
|
2154
2283
|
this.core.resourceNodes.add(this.node);
|
|
2155
2284
|
}
|
|
2156
2285
|
}
|
|
@@ -2168,6 +2297,9 @@ var init_resource = __esm(() => {
|
|
|
2168
2297
|
toNBT() {
|
|
2169
2298
|
return this.name;
|
|
2170
2299
|
}
|
|
2300
|
+
toJSON() {
|
|
2301
|
+
return this.name;
|
|
2302
|
+
}
|
|
2171
2303
|
static [Symbol.hasInstance](instance) {
|
|
2172
2304
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RESOURCE_CLASS_BRAND] === true;
|
|
2173
2305
|
}
|
|
@@ -2267,7 +2399,7 @@ var init_advancement = __esm(() => {
|
|
|
2267
2399
|
super(sandstoneCore);
|
|
2268
2400
|
this.resource = resource;
|
|
2269
2401
|
}
|
|
2270
|
-
getValue = () => jsonStringify(this.resource.advancementJSON);
|
|
2402
|
+
getValue = () => jsonStringify(this.resource.advancementJSON, this.resource._resourceType);
|
|
2271
2403
|
};
|
|
2272
2404
|
ADVANCEMENT_CLASS_BRAND = Symbol.for("sandstone.AdvancementClass");
|
|
2273
2405
|
AdvancementClass = class AdvancementClass extends ResourceClass {
|
|
@@ -2325,7 +2457,7 @@ var init_bannerPattern = __esm(() => {
|
|
|
2325
2457
|
super(sandstoneCore);
|
|
2326
2458
|
this.resource = resource;
|
|
2327
2459
|
}
|
|
2328
|
-
getValue = () => jsonStringify(this.resource.bannerPatternJSON);
|
|
2460
|
+
getValue = () => jsonStringify(this.resource.bannerPatternJSON, this.resource._resourceType);
|
|
2329
2461
|
};
|
|
2330
2462
|
BannerPatternClass = class BannerPatternClass extends ResourceClass {
|
|
2331
2463
|
static resourceType = "banner_pattern";
|
|
@@ -2350,7 +2482,7 @@ var init_chatType = __esm(() => {
|
|
|
2350
2482
|
super(sandstoneCore);
|
|
2351
2483
|
this.resource = resource;
|
|
2352
2484
|
}
|
|
2353
|
-
getValue = () => jsonStringify(this.resource.chatTypeJSON);
|
|
2485
|
+
getValue = () => jsonStringify(this.resource.chatTypeJSON, this.resource._resourceType);
|
|
2354
2486
|
};
|
|
2355
2487
|
ChatTypeClass = class ChatTypeClass extends ResourceClass {
|
|
2356
2488
|
static resourceType = "chat_type";
|
|
@@ -2376,7 +2508,7 @@ var init_damageType = __esm(() => {
|
|
|
2376
2508
|
super(sandstoneCore);
|
|
2377
2509
|
this.resource = resource;
|
|
2378
2510
|
}
|
|
2379
|
-
getValue = () => jsonStringify(this.resource.damageTypeJSON);
|
|
2511
|
+
getValue = () => jsonStringify(this.resource.damageTypeJSON, this.resource._resourceType);
|
|
2380
2512
|
};
|
|
2381
2513
|
DamageTypeClass = class DamageTypeClass extends ResourceClass {
|
|
2382
2514
|
static resourceType = "damage_type";
|
|
@@ -2438,7 +2570,7 @@ var init_dialog = __esm(() => {
|
|
|
2438
2570
|
super(sandstoneCore);
|
|
2439
2571
|
this.resource = resource;
|
|
2440
2572
|
}
|
|
2441
|
-
getValue = () => jsonStringify(this.resource.dialogJSON);
|
|
2573
|
+
getValue = () => jsonStringify(this.resource.dialogJSON, this.resource._resourceType);
|
|
2442
2574
|
};
|
|
2443
2575
|
DialogClass = class DialogClass extends ResourceClass {
|
|
2444
2576
|
static resourceType = "dialog";
|
|
@@ -2463,7 +2595,7 @@ var init_enchantment = __esm(() => {
|
|
|
2463
2595
|
super(sandstoneCore);
|
|
2464
2596
|
this.resource = resource;
|
|
2465
2597
|
}
|
|
2466
|
-
getValue = () => jsonStringify(this.resource.enchantmentJSON);
|
|
2598
|
+
getValue = () => jsonStringify(this.resource.enchantmentJSON, this.resource._resourceType);
|
|
2467
2599
|
};
|
|
2468
2600
|
EnchantmentClass = class EnchantmentClass extends ResourceClass {
|
|
2469
2601
|
static resourceType = "enchantment";
|
|
@@ -2480,7 +2612,7 @@ var init_enchantment = __esm(() => {
|
|
|
2480
2612
|
super(sandstoneCore);
|
|
2481
2613
|
this.resource = resource;
|
|
2482
2614
|
}
|
|
2483
|
-
getValue = () => jsonStringify(this.resource.enchantmentProviderJSON);
|
|
2615
|
+
getValue = () => jsonStringify(this.resource.enchantmentProviderJSON, this.resource._resourceType);
|
|
2484
2616
|
};
|
|
2485
2617
|
EnchantmentProviderClass = class EnchantmentProviderClass extends ResourceClass {
|
|
2486
2618
|
static resourceType = "enchantment_provider";
|
|
@@ -2505,7 +2637,7 @@ var init_gametest = __esm(() => {
|
|
|
2505
2637
|
super(sandstoneCore);
|
|
2506
2638
|
this.resource = resource;
|
|
2507
2639
|
}
|
|
2508
|
-
getValue = () => jsonStringify(this.resource.testEnvironmentJSON);
|
|
2640
|
+
getValue = () => jsonStringify(this.resource.testEnvironmentJSON, this.resource._resourceType);
|
|
2509
2641
|
};
|
|
2510
2642
|
TestEnvironmentClass = class TestEnvironmentClass extends ResourceClass {
|
|
2511
2643
|
static resourceType = "test_environment";
|
|
@@ -2522,7 +2654,7 @@ var init_gametest = __esm(() => {
|
|
|
2522
2654
|
super(sandstoneCore);
|
|
2523
2655
|
this.resource = resource;
|
|
2524
2656
|
}
|
|
2525
|
-
getValue = () => jsonStringify(this.resource.testInstanceJSON);
|
|
2657
|
+
getValue = () => jsonStringify(this.resource.testInstanceJSON, this.resource._resourceType);
|
|
2526
2658
|
};
|
|
2527
2659
|
TestInstanceClass = class TestInstanceClass extends ResourceClass {
|
|
2528
2660
|
static resourceType = "test_instance";
|
|
@@ -2547,7 +2679,7 @@ var init_instrument = __esm(() => {
|
|
|
2547
2679
|
super(sandstoneCore);
|
|
2548
2680
|
this.resource = resource;
|
|
2549
2681
|
}
|
|
2550
|
-
getValue = () => jsonStringify(this.resource.instrumentJSON);
|
|
2682
|
+
getValue = () => jsonStringify(this.resource.instrumentJSON, this.resource._resourceType);
|
|
2551
2683
|
};
|
|
2552
2684
|
InstrumentClass = class InstrumentClass extends ResourceClass {
|
|
2553
2685
|
static resourceType = "instrument";
|
|
@@ -2573,7 +2705,7 @@ var init_itemModifier = __esm(() => {
|
|
|
2573
2705
|
super(sandstoneCore);
|
|
2574
2706
|
this.resource = resource;
|
|
2575
2707
|
}
|
|
2576
|
-
getValue = () => jsonStringify(this.resource.itemModifierJSON);
|
|
2708
|
+
getValue = () => jsonStringify(this.resource.itemModifierJSON, this.resource._resourceType);
|
|
2577
2709
|
};
|
|
2578
2710
|
ITEM_MODIFIER_CLASS_BRAND = Symbol.for("sandstone.ItemModifierClass");
|
|
2579
2711
|
ItemModifierClass = class ItemModifierClass extends ResourceClass {
|
|
@@ -2649,7 +2781,7 @@ var init_jukeboxSong = __esm(() => {
|
|
|
2649
2781
|
super(sandstoneCore);
|
|
2650
2782
|
this.resource = resource;
|
|
2651
2783
|
}
|
|
2652
|
-
getValue = () => jsonStringify(this.resource.jukeboxSongJSON);
|
|
2784
|
+
getValue = () => jsonStringify(this.resource.jukeboxSongJSON, this.resource._resourceType);
|
|
2653
2785
|
};
|
|
2654
2786
|
JukeboxSongClass = class JukeboxSongClass extends ResourceClass {
|
|
2655
2787
|
static resourceType = "jukebox_song";
|
|
@@ -2674,7 +2806,7 @@ var init_lootTable = __esm(() => {
|
|
|
2674
2806
|
super(sandstoneCore);
|
|
2675
2807
|
this.resource = resource;
|
|
2676
2808
|
}
|
|
2677
|
-
getValue = () => jsonStringify(this.resource.lootTableJSON);
|
|
2809
|
+
getValue = () => jsonStringify(this.resource.lootTableJSON, this.resource._resourceType);
|
|
2678
2810
|
};
|
|
2679
2811
|
LootTableClass = class LootTableClass extends ResourceClass {
|
|
2680
2812
|
static resourceType = "loot_table";
|
|
@@ -2906,7 +3038,7 @@ var init_mcfunction = __esm(() => {
|
|
|
2906
3038
|
return this.body.filter((node) => node.getValue() !== null).map((node) => node.getValue()).join(`
|
|
2907
3039
|
`);
|
|
2908
3040
|
};
|
|
2909
|
-
[util6.inspect.custom](
|
|
3041
|
+
[util6.inspect.custom](_depth, options) {
|
|
2910
3042
|
return formatDebugString(this.constructor.name, {
|
|
2911
3043
|
name: this.resource.name
|
|
2912
3044
|
}, this.body, options.indent);
|
|
@@ -2922,6 +3054,7 @@ var init_mcfunction = __esm(() => {
|
|
|
2922
3054
|
tags;
|
|
2923
3055
|
lazy;
|
|
2924
3056
|
env;
|
|
3057
|
+
macroPoint;
|
|
2925
3058
|
constructor(core, name, args, env) {
|
|
2926
3059
|
if (name.startsWith("./")) {
|
|
2927
3060
|
const currentMCFunctionName = core.currentMCFunction?.resource.name;
|
|
@@ -2944,11 +3077,16 @@ var init_mcfunction = __esm(() => {
|
|
|
2944
3077
|
this.lazy = !!args.lazy;
|
|
2945
3078
|
this.addToSandstoneCore = !!args.addToSandstoneCore;
|
|
2946
3079
|
this.tags = args.tags;
|
|
2947
|
-
if (env) {
|
|
3080
|
+
if (env && env.length !== 0) {
|
|
2948
3081
|
this.env = env;
|
|
2949
3082
|
}
|
|
3083
|
+
if (this.env || this.callback.length > 1) {
|
|
3084
|
+
this.macroPoint = core.pack.DataVariable();
|
|
3085
|
+
} else {
|
|
3086
|
+
this.macroPoint = undefined;
|
|
3087
|
+
}
|
|
2950
3088
|
if (args.runOnLoad) {
|
|
2951
|
-
if (env) {
|
|
3089
|
+
if (this.env) {
|
|
2952
3090
|
core.pack.loadTags.load.push(core.pack.MCFunction(`load_${this.name.split(":")[1]}`, () => {
|
|
2953
3091
|
this.__call__();
|
|
2954
3092
|
}));
|
|
@@ -3002,21 +3140,25 @@ var init_mcfunction = __esm(() => {
|
|
|
3002
3140
|
__call__ = (..._params) => {
|
|
3003
3141
|
if (this.env || _params.length !== 0) {
|
|
3004
3142
|
const args = {};
|
|
3143
|
+
if (this.env) {
|
|
3144
|
+
for (const [i, env] of this.env.entries()) {
|
|
3145
|
+
args[`env_${i}`] = ResolveNBTPart(env);
|
|
3146
|
+
env.local.set(this.name, `env_${i}`);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3005
3149
|
if (_params.length !== 0) {
|
|
3006
3150
|
for (const [i, param] of _params.entries()) {
|
|
3007
3151
|
args[`param_${i}`] = ResolveNBTPart(param);
|
|
3008
3152
|
param.local.set(this.name, `param_${i}`);
|
|
3009
3153
|
}
|
|
3010
3154
|
this.node.body = [];
|
|
3155
|
+
this.core.enterMCFunction(this);
|
|
3011
3156
|
this.core.insideContext(this.node, () => this.callback(makeCallable(this, this.__call__.bind(undefined, ..._params)), ..._params), false);
|
|
3157
|
+
this.core.exitMCFunction();
|
|
3158
|
+
} else if (this.callback.length > 1) {
|
|
3159
|
+
throw new Error(`[MCFunctionClass] Function ${this.name} expects ${this.callback.length - 1} params at the call-site`);
|
|
3012
3160
|
}
|
|
3013
|
-
|
|
3014
|
-
for (const [i, env] of this.env.entries()) {
|
|
3015
|
-
args[`env_${i}`] = ResolveNBTPart(env);
|
|
3016
|
-
env.local.set(this.name, `env_${i}`);
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args).dataPoint);
|
|
3161
|
+
return this.commands.functionCmd(this.name, "with", this.pack.ResolveNBT(args, this.macroPoint).dataPoint);
|
|
3020
3162
|
}
|
|
3021
3163
|
return this.commands.functionCmd(this.name);
|
|
3022
3164
|
};
|
|
@@ -3046,12 +3188,14 @@ var init_mcfunction = __esm(() => {
|
|
|
3046
3188
|
});
|
|
3047
3189
|
if (contents[0] instanceof _RawMCFunctionClass) {
|
|
3048
3190
|
for (const mcfunction of contents) {
|
|
3191
|
+
mcfunction.generate();
|
|
3049
3192
|
this.node.body.unshift(...mcfunction.node.body);
|
|
3050
3193
|
}
|
|
3051
3194
|
} else {
|
|
3052
3195
|
this.core.enterMCFunction(fake);
|
|
3053
3196
|
this.core.insideContext(fake.node, contents[0], false);
|
|
3054
3197
|
this.core.exitMCFunction();
|
|
3198
|
+
fake.generate();
|
|
3055
3199
|
this.node.body.unshift(...fake.node.body);
|
|
3056
3200
|
}
|
|
3057
3201
|
}
|
|
@@ -3064,12 +3208,14 @@ var init_mcfunction = __esm(() => {
|
|
|
3064
3208
|
const fullBody = [];
|
|
3065
3209
|
if (contents[0] instanceof _RawMCFunctionClass) {
|
|
3066
3210
|
for (const mcfunction of contents) {
|
|
3211
|
+
mcfunction.generate();
|
|
3067
3212
|
fullBody.push(...mcfunction.node.body);
|
|
3068
3213
|
}
|
|
3069
3214
|
} else {
|
|
3070
3215
|
this.core.enterMCFunction(fake);
|
|
3071
3216
|
this.core.insideContext(fake.node, contents[0], false);
|
|
3072
3217
|
this.core.exitMCFunction();
|
|
3218
|
+
fake.generate();
|
|
3073
3219
|
fullBody.push(...fake.node.body);
|
|
3074
3220
|
}
|
|
3075
3221
|
this.node.body.splice(start, removeItems === "auto" ? fullBody.length : removeItems, ...fullBody);
|
|
@@ -3096,7 +3242,7 @@ var init_predicate = __esm(() => {
|
|
|
3096
3242
|
super(sandstoneCore);
|
|
3097
3243
|
this.resource = resource;
|
|
3098
3244
|
}
|
|
3099
|
-
getValue = () => jsonStringify(this.resource.predicateJSON);
|
|
3245
|
+
getValue = () => jsonStringify(this.resource.predicateJSON, this.resource._resourceType);
|
|
3100
3246
|
};
|
|
3101
3247
|
PREDICATE_CLASS_BRAND = Symbol.for("sandstone.PredicateClass");
|
|
3102
3248
|
PredicateClass = class PredicateClass extends ResourceClass {
|
|
@@ -3166,7 +3312,7 @@ var init_recipe = __esm(() => {
|
|
|
3166
3312
|
super(sandstoneCore);
|
|
3167
3313
|
this.resource = resource;
|
|
3168
3314
|
}
|
|
3169
|
-
getValue = () => jsonStringify(this.resource.recipeJSON);
|
|
3315
|
+
getValue = () => jsonStringify(this.resource.recipeJSON, this.resource._resourceType);
|
|
3170
3316
|
};
|
|
3171
3317
|
RecipeClass = class RecipeClass extends ResourceClass {
|
|
3172
3318
|
static resourceType = "recipe";
|
|
@@ -3211,7 +3357,7 @@ var init_timeline = __esm(() => {
|
|
|
3211
3357
|
super(sandstoneCore);
|
|
3212
3358
|
this.resource = resource;
|
|
3213
3359
|
}
|
|
3214
|
-
getValue = () => jsonStringify(this.resource.timelineJSON);
|
|
3360
|
+
getValue = () => jsonStringify(this.resource.timelineJSON, this.resource._resourceType);
|
|
3215
3361
|
};
|
|
3216
3362
|
TimelineClass = class TimelineClass extends ResourceClass {
|
|
3217
3363
|
static resourceType = "timeline";
|
|
@@ -3228,7 +3374,7 @@ var init_timeline = __esm(() => {
|
|
|
3228
3374
|
super(sandstoneCore);
|
|
3229
3375
|
this.resource = resource;
|
|
3230
3376
|
}
|
|
3231
|
-
getValue = () => jsonStringify(this.resource.worldClockJSON);
|
|
3377
|
+
getValue = () => jsonStringify(this.resource.worldClockJSON, this.resource._resourceType);
|
|
3232
3378
|
};
|
|
3233
3379
|
WorldClockClass = class WorldClockClass extends ResourceClass {
|
|
3234
3380
|
static resourceType = "world_clock";
|
|
@@ -3256,7 +3402,7 @@ var init_trialSpawner = __esm(() => {
|
|
|
3256
3402
|
super(sandstoneCore);
|
|
3257
3403
|
this.resource = resource;
|
|
3258
3404
|
}
|
|
3259
|
-
getValue = () => jsonStringify(this.resource.trialSpawnerJSON);
|
|
3405
|
+
getValue = () => jsonStringify(this.resource.trialSpawnerJSON, this.resource._resourceType);
|
|
3260
3406
|
};
|
|
3261
3407
|
TrialSpawnerClass = class TrialSpawnerClass extends ResourceClass {
|
|
3262
3408
|
static resourceType = "trial_spawner";
|
|
@@ -3281,7 +3427,7 @@ var init_trimMaterial = __esm(() => {
|
|
|
3281
3427
|
super(sandstoneCore);
|
|
3282
3428
|
this.resource = resource;
|
|
3283
3429
|
}
|
|
3284
|
-
getValue = () => jsonStringify(this.resource.trimMaterialJSON);
|
|
3430
|
+
getValue = () => jsonStringify(this.resource.trimMaterialJSON, this.resource._resourceType);
|
|
3285
3431
|
};
|
|
3286
3432
|
TrimMaterialClass = class TrimMaterialClass extends ResourceClass {
|
|
3287
3433
|
static resourceType = "trim_material";
|
|
@@ -3309,7 +3455,7 @@ var init_trimPattern = __esm(() => {
|
|
|
3309
3455
|
super(sandstoneCore);
|
|
3310
3456
|
this.resource = resource;
|
|
3311
3457
|
}
|
|
3312
|
-
getValue = () => jsonStringify(this.resource.trimPatternJSON);
|
|
3458
|
+
getValue = () => jsonStringify(this.resource.trimPatternJSON, this.resource._resourceType);
|
|
3313
3459
|
};
|
|
3314
3460
|
TrimPatternClass = class TrimPatternClass extends ResourceClass {
|
|
3315
3461
|
static resourceType = "trim_pattern";
|
|
@@ -3333,7 +3479,7 @@ var init_variant = __esm(() => {
|
|
|
3333
3479
|
super(sandstoneCore);
|
|
3334
3480
|
this.resource = resource;
|
|
3335
3481
|
}
|
|
3336
|
-
getValue = () => jsonStringify(this.resource.variantJSON);
|
|
3482
|
+
getValue = () => jsonStringify(this.resource.variantJSON, this.resource._resourceType);
|
|
3337
3483
|
};
|
|
3338
3484
|
VariantClass = class VariantClass extends ResourceClass {
|
|
3339
3485
|
variantType;
|
|
@@ -3360,7 +3506,7 @@ var init_villagerTrade = __esm(() => {
|
|
|
3360
3506
|
super(sandstoneCore);
|
|
3361
3507
|
this.resource = resource;
|
|
3362
3508
|
}
|
|
3363
|
-
getValue = () => jsonStringify(this.resource.villagerTradeJSON);
|
|
3509
|
+
getValue = () => jsonStringify(this.resource.villagerTradeJSON, this.resource._resourceType);
|
|
3364
3510
|
};
|
|
3365
3511
|
VillagerTradeClass = class VillagerTradeClass extends ResourceClass {
|
|
3366
3512
|
static resourceType = "villager_trade";
|
|
@@ -3377,7 +3523,7 @@ var init_villagerTrade = __esm(() => {
|
|
|
3377
3523
|
super(sandstoneCore);
|
|
3378
3524
|
this.resource = resource;
|
|
3379
3525
|
}
|
|
3380
|
-
getValue = () => jsonStringify(this.resource.tradeSetJSON);
|
|
3526
|
+
getValue = () => jsonStringify(this.resource.tradeSetJSON, this.resource._resourceType);
|
|
3381
3527
|
};
|
|
3382
3528
|
TradeSetClass = class TradeSetClass extends ResourceClass {
|
|
3383
3529
|
static resourceType = "trade_set";
|
|
@@ -3428,7 +3574,7 @@ var init_atlas = __esm(() => {
|
|
|
3428
3574
|
super(sandstoneCore);
|
|
3429
3575
|
this.resource = resource;
|
|
3430
3576
|
}
|
|
3431
|
-
getValue = () => jsonStringify(this.resource.atlasJSON);
|
|
3577
|
+
getValue = () => jsonStringify(this.resource.atlasJSON, this.resource._resourceType);
|
|
3432
3578
|
};
|
|
3433
3579
|
ATLAS_CLASS_BRAND = Symbol.for("sandstone.AtlasClass");
|
|
3434
3580
|
AtlasClass = class AtlasClass extends ResourceClass {
|
|
@@ -3476,7 +3622,7 @@ var init_blockstate = __esm(() => {
|
|
|
3476
3622
|
super(sandstoneCore);
|
|
3477
3623
|
this.resource = resource;
|
|
3478
3624
|
}
|
|
3479
|
-
getValue = () => jsonStringify(this.resource.blockStateJSON);
|
|
3625
|
+
getValue = () => jsonStringify(this.resource.blockStateJSON, this.resource._resourceType);
|
|
3480
3626
|
};
|
|
3481
3627
|
BLOCK_STATE_CLASS_BRAND = Symbol.for("sandstone.BlockStateClass");
|
|
3482
3628
|
BlockStateClass = class BlockStateClass extends ResourceClass {
|
|
@@ -3557,7 +3703,7 @@ var init_equipment = __esm(() => {
|
|
|
3557
3703
|
super(sandstoneCore);
|
|
3558
3704
|
this.resource = resource;
|
|
3559
3705
|
}
|
|
3560
|
-
getValue = () => jsonStringify(this.resource.equipmentJSON);
|
|
3706
|
+
getValue = () => jsonStringify(this.resource.equipmentJSON, this.resource._resourceType);
|
|
3561
3707
|
};
|
|
3562
3708
|
EquipmentClass = class EquipmentClass extends ResourceClass {
|
|
3563
3709
|
static resourceType = "equipment";
|
|
@@ -3582,7 +3728,7 @@ var init_font = __esm(() => {
|
|
|
3582
3728
|
super(sandstoneCore);
|
|
3583
3729
|
this.resource = resource;
|
|
3584
3730
|
}
|
|
3585
|
-
getValue = () => jsonStringify(this.resource.fontJSON);
|
|
3731
|
+
getValue = () => jsonStringify(this.resource.fontJSON, this.resource._resourceType);
|
|
3586
3732
|
};
|
|
3587
3733
|
FONT_CLASS_BRAND = Symbol.for("sandstone.FontClass");
|
|
3588
3734
|
FontClass = class FontClass extends ResourceClass {
|
|
@@ -3630,7 +3776,7 @@ var init_model = __esm(() => {
|
|
|
3630
3776
|
super(sandstoneCore);
|
|
3631
3777
|
this.resource = resource;
|
|
3632
3778
|
}
|
|
3633
|
-
getValue = () => jsonStringify(this.resource.modelJSON);
|
|
3779
|
+
getValue = () => jsonStringify(this.resource.modelJSON, this.resource._resourceType);
|
|
3634
3780
|
};
|
|
3635
3781
|
MODEL_CLASS_BRAND = Symbol.for("sandstone.ModelClass");
|
|
3636
3782
|
ModelClass = class ModelClass extends ResourceClass {
|
|
@@ -3834,7 +3980,7 @@ var init_itemDefinition = __esm(() => {
|
|
|
3834
3980
|
super(sandstoneCore);
|
|
3835
3981
|
this.resource = resource;
|
|
3836
3982
|
}
|
|
3837
|
-
getValue = () => jsonStringify(this.resource.itemDefinitionJSON);
|
|
3983
|
+
getValue = () => jsonStringify(this.resource.itemDefinitionJSON, this.resource._resourceType);
|
|
3838
3984
|
};
|
|
3839
3985
|
ItemModelDefinitionClass = class ItemModelDefinitionClass extends ResourceClass {
|
|
3840
3986
|
static resourceType = "item_definition";
|
|
@@ -3873,7 +4019,7 @@ var init_language = __esm(() => {
|
|
|
3873
4019
|
super(sandstoneCore);
|
|
3874
4020
|
this.resource = resource;
|
|
3875
4021
|
}
|
|
3876
|
-
getValue = () => jsonStringify(this.resource.languageJSON);
|
|
4022
|
+
getValue = () => jsonStringify(this.resource.languageJSON, this.resource._resourceType);
|
|
3877
4023
|
};
|
|
3878
4024
|
LANGUAGE_CLASS_BRAND = Symbol.for("sandstone.LanguageClass");
|
|
3879
4025
|
LanguageClass = class LanguageClass extends ResourceClass {
|
|
@@ -3925,7 +4071,7 @@ var init_particle = __esm(() => {
|
|
|
3925
4071
|
super(sandstoneCore);
|
|
3926
4072
|
this.resource = resource;
|
|
3927
4073
|
}
|
|
3928
|
-
getValue = () => jsonStringify(this.resource.particleJSON);
|
|
4074
|
+
getValue = () => jsonStringify(this.resource.particleJSON, this.resource._resourceType);
|
|
3929
4075
|
};
|
|
3930
4076
|
ParticleClass = class ParticleClass extends ResourceClass {
|
|
3931
4077
|
static resourceType = "particle";
|
|
@@ -3950,7 +4096,7 @@ var init_postEffect = __esm(() => {
|
|
|
3950
4096
|
super(sandstoneCore);
|
|
3951
4097
|
this.resource = resource;
|
|
3952
4098
|
}
|
|
3953
|
-
getValue = () => jsonStringify(this.resource.postEffectJSON);
|
|
4099
|
+
getValue = () => jsonStringify(this.resource.postEffectJSON, this.resource._resourceType);
|
|
3954
4100
|
};
|
|
3955
4101
|
PostEffectClass = class PostEffectClass extends ResourceClass {
|
|
3956
4102
|
static resourceType = "post_effect";
|
|
@@ -3975,7 +4121,7 @@ var init_shader = __esm(() => {
|
|
|
3975
4121
|
super(sandstoneCore);
|
|
3976
4122
|
this.resource = resource;
|
|
3977
4123
|
}
|
|
3978
|
-
getValue = () => jsonStringify(this.resource.shaderJSON);
|
|
4124
|
+
getValue = () => jsonStringify(this.resource.shaderJSON, this.resource._resourceType);
|
|
3979
4125
|
};
|
|
3980
4126
|
ShaderClass = class ShaderClass extends ResourceClass {
|
|
3981
4127
|
static resourceType = "shader";
|
|
@@ -4037,7 +4183,7 @@ var init_sound = __esm(() => {
|
|
|
4037
4183
|
super(sandstoneCore);
|
|
4038
4184
|
this.resource = resource;
|
|
4039
4185
|
}
|
|
4040
|
-
getValue = () => jsonStringify(this.resource.soundsJSON);
|
|
4186
|
+
getValue = () => jsonStringify(this.resource.soundsJSON, this.resource._resourceType);
|
|
4041
4187
|
};
|
|
4042
4188
|
SOUNDS_CLASS_BRAND = Symbol.for("sandstone.SoundsClass");
|
|
4043
4189
|
SoundsClass = class SoundsClass extends ResourceClass {
|
|
@@ -4267,7 +4413,7 @@ var init_waypointStyle = __esm(() => {
|
|
|
4267
4413
|
super(sandstoneCore);
|
|
4268
4414
|
this.resource = resource;
|
|
4269
4415
|
}
|
|
4270
|
-
getValue = () => jsonStringify(this.resource.waypointStyleJSON);
|
|
4416
|
+
getValue = () => jsonStringify(this.resource.waypointStyleJSON, this.resource._resourceType);
|
|
4271
4417
|
};
|
|
4272
4418
|
WaypointStyleClass = class WaypointStyleClass extends ResourceClass {
|
|
4273
4419
|
static resourceType = "waypoint_style";
|
|
@@ -4836,7 +4982,18 @@ class SandstoneCore {
|
|
|
4836
4982
|
_path.splice(1, 0, packType.resourceSubFolder);
|
|
4837
4983
|
}
|
|
4838
4984
|
const resourcePath = path4.join(..._path);
|
|
4839
|
-
|
|
4985
|
+
let value;
|
|
4986
|
+
try {
|
|
4987
|
+
value = await node.getValue();
|
|
4988
|
+
} catch (e) {
|
|
4989
|
+
console.log(`
|
|
4990
|
+
|
|
4991
|
+
|
|
4992
|
+
|
|
4993
|
+
`);
|
|
4994
|
+
console.log(node);
|
|
4995
|
+
throw e;
|
|
4996
|
+
}
|
|
4840
4997
|
if (cliOptions.verbose) {
|
|
4841
4998
|
console.log(`Path: ${resourcePath}.${fileExtension}
|
|
4842
4999
|
|
|
@@ -5146,11 +5303,11 @@ var init_dataPoint = __esm(() => {
|
|
|
5146
5303
|
const { execute } = commands;
|
|
5147
5304
|
const anon = DataVariable(this.dataPoint);
|
|
5148
5305
|
this.conditional = Variable();
|
|
5149
|
-
execute.store.result
|
|
5306
|
+
execute.store.result(this.conditional).run(() => anon.set(this.value));
|
|
5150
5307
|
}
|
|
5151
5308
|
getValue = (negated) => (negated ? ["if", ...this.getCondition()] : ["unless", ...this.getCondition()]).join(" ");
|
|
5152
5309
|
getCondition() {
|
|
5153
|
-
return ["score", "matches", "0.."];
|
|
5310
|
+
return ["score", this.conditional, "matches", "0.."];
|
|
5154
5311
|
}
|
|
5155
5312
|
};
|
|
5156
5313
|
});
|
|
@@ -5237,7 +5394,7 @@ var init_command = __esm(() => {
|
|
|
5237
5394
|
this.result = result;
|
|
5238
5395
|
const store = sandstoneCore2.pack.commands.execute.store[type];
|
|
5239
5396
|
this.variable = sandstoneCore2.pack.Variable(undefined, "condition");
|
|
5240
|
-
command(store
|
|
5397
|
+
command(store(this.variable));
|
|
5241
5398
|
}
|
|
5242
5399
|
getCondition() {
|
|
5243
5400
|
if (this.type === "success") {
|
|
@@ -5289,11 +5446,13 @@ var init_loaded = __esm(() => {
|
|
|
5289
5446
|
});
|
|
5290
5447
|
|
|
5291
5448
|
// src/flow/conditions/variables/score.ts
|
|
5292
|
-
var ScoreConditionNode;
|
|
5449
|
+
var SCORE_CONDITION_NODE_BRAND, ScoreConditionNode;
|
|
5293
5450
|
var init_score = __esm(() => {
|
|
5294
5451
|
init_condition();
|
|
5452
|
+
SCORE_CONDITION_NODE_BRAND = Symbol.for("sandstone.ScoreConditionNode");
|
|
5295
5453
|
ScoreConditionNode = class ScoreConditionNode extends SingleConditionNode {
|
|
5296
5454
|
args;
|
|
5455
|
+
[SCORE_CONDITION_NODE_BRAND] = true;
|
|
5297
5456
|
constructor(sandstoneCore2, args) {
|
|
5298
5457
|
super(sandstoneCore2);
|
|
5299
5458
|
this.args = args;
|
|
@@ -5301,6 +5460,9 @@ var init_score = __esm(() => {
|
|
|
5301
5460
|
getCondition() {
|
|
5302
5461
|
return ["score", ...this.args];
|
|
5303
5462
|
}
|
|
5463
|
+
static [Symbol.hasInstance](instance) {
|
|
5464
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[SCORE_CONDITION_NODE_BRAND] === true;
|
|
5465
|
+
}
|
|
5304
5466
|
};
|
|
5305
5467
|
});
|
|
5306
5468
|
|
|
@@ -5403,7 +5565,7 @@ class IfStatement {
|
|
|
5403
5565
|
this.node = new IfNode(sandstoneCore2, condition2, callback);
|
|
5404
5566
|
}
|
|
5405
5567
|
elseIf = (condition2, callback) => {
|
|
5406
|
-
const statement = new IfStatement(this.sandstoneCore,
|
|
5568
|
+
const statement = new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
5407
5569
|
this.node.nextFlowNode = statement.getNode();
|
|
5408
5570
|
statement.node._isElseIf = true;
|
|
5409
5571
|
return statement;
|
|
@@ -5431,6 +5593,7 @@ var IF_NODE_BRAND, IfNode, ELSE_NODE_BRAND, ElseNode;
|
|
|
5431
5593
|
var init_if_else = __esm(() => {
|
|
5432
5594
|
init_core();
|
|
5433
5595
|
init_utils();
|
|
5596
|
+
init_Flow();
|
|
5434
5597
|
IF_NODE_BRAND = Symbol.for("sandstone.IfNode");
|
|
5435
5598
|
IfNode = class IfNode extends ContainerNode {
|
|
5436
5599
|
condition;
|
|
@@ -5438,10 +5601,14 @@ var init_if_else = __esm(() => {
|
|
|
5438
5601
|
[IF_NODE_BRAND] = true;
|
|
5439
5602
|
nextFlowNode;
|
|
5440
5603
|
_isElseIf = false;
|
|
5441
|
-
|
|
5604
|
+
parentMCFunction;
|
|
5605
|
+
givenCallbackName;
|
|
5606
|
+
resultingExecuteNode;
|
|
5607
|
+
constructor(sandstoneCore2, condition2, callback, parentMCFunction) {
|
|
5442
5608
|
super(sandstoneCore2);
|
|
5443
5609
|
this.condition = condition2;
|
|
5444
5610
|
this.callback = callback;
|
|
5611
|
+
this.parentMCFunction = parentMCFunction ?? sandstoneCore2.getCurrentMCFunctionOrThrow();
|
|
5445
5612
|
if (callback && callback.toString() !== "() => {}") {
|
|
5446
5613
|
this.sandstoneCore.insideContext(this, callback, true);
|
|
5447
5614
|
}
|
|
@@ -5483,26 +5650,6 @@ ${indent}${nextFormatting}`;
|
|
|
5483
5650
|
});
|
|
5484
5651
|
|
|
5485
5652
|
// src/flow/loops/binary_for.ts
|
|
5486
|
-
function binaryFor(flow, from, to, callback, maximum = 128) {
|
|
5487
|
-
if (typeof from === "number" && typeof to === "number") {
|
|
5488
|
-
callback(to - from);
|
|
5489
|
-
}
|
|
5490
|
-
const { Variable } = flow.sandstoneCore.pack;
|
|
5491
|
-
const realStart = from instanceof Score ? from : Variable(from);
|
|
5492
|
-
const realEnd = to instanceof Score ? to : Variable(to);
|
|
5493
|
-
const iterations = realEnd.minus(realStart);
|
|
5494
|
-
const _ = flow;
|
|
5495
|
-
_.while(iterations.lessThan(maximum), () => {
|
|
5496
|
-
callback(maximum);
|
|
5497
|
-
iterations.remove(maximum);
|
|
5498
|
-
});
|
|
5499
|
-
for (let i = 1;i < maximum; i *= 2) {
|
|
5500
|
-
_.if(iterations.moduloBy(2).equalTo(1), () => {
|
|
5501
|
-
callback(i);
|
|
5502
|
-
});
|
|
5503
|
-
iterations.dividedBy(2);
|
|
5504
|
-
}
|
|
5505
|
-
}
|
|
5506
5653
|
var init_binary_for = __esm(() => {
|
|
5507
5654
|
init_variables2();
|
|
5508
5655
|
});
|
|
@@ -5512,16 +5659,18 @@ var LoopNode;
|
|
|
5512
5659
|
var init_loop = __esm(() => {
|
|
5513
5660
|
init_core();
|
|
5514
5661
|
LoopNode = class LoopNode extends ContainerNode {
|
|
5515
|
-
|
|
5662
|
+
condition;
|
|
5516
5663
|
callback;
|
|
5517
5664
|
loopback;
|
|
5518
|
-
|
|
5665
|
+
parentMCFunction;
|
|
5666
|
+
constructor(sandstoneCore2, condition2, callback, loopback) {
|
|
5519
5667
|
super(sandstoneCore2);
|
|
5520
|
-
this.
|
|
5668
|
+
this.condition = condition2;
|
|
5521
5669
|
this.callback = callback;
|
|
5522
5670
|
this.loopback = loopback;
|
|
5671
|
+
const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
|
|
5672
|
+
this.parentMCFunction = currentNode;
|
|
5523
5673
|
if (callback.toString() !== "() => {}") {
|
|
5524
|
-
const currentNode = this.sandstoneCore.getCurrentMCFunctionOrThrow();
|
|
5525
5674
|
currentNode.enterContext(this);
|
|
5526
5675
|
this.callback();
|
|
5527
5676
|
this.loopback();
|
|
@@ -5534,6 +5683,75 @@ var init_loop = __esm(() => {
|
|
|
5534
5683
|
};
|
|
5535
5684
|
});
|
|
5536
5685
|
|
|
5686
|
+
// src/flow/loops/staticAnalysis.ts
|
|
5687
|
+
function valueMatchesRange(value, rangeStr) {
|
|
5688
|
+
if (rangeStr.includes("..")) {
|
|
5689
|
+
const [minStr, maxStr] = rangeStr.split("..");
|
|
5690
|
+
const min = minStr !== "" ? parseInt(minStr, 10) : Number.NEGATIVE_INFINITY;
|
|
5691
|
+
const max = maxStr !== "" ? parseInt(maxStr, 10) : Number.POSITIVE_INFINITY;
|
|
5692
|
+
return value >= min && value <= max;
|
|
5693
|
+
}
|
|
5694
|
+
return value === parseInt(rangeStr, 10);
|
|
5695
|
+
}
|
|
5696
|
+
function analyzeCondition(condition2, targetScore, value, negated = false) {
|
|
5697
|
+
if (condition2 instanceof ScoreConditionNode) {
|
|
5698
|
+
const args = condition2.args;
|
|
5699
|
+
if (args.length >= 4 && args[2] === "matches") {
|
|
5700
|
+
const [target, objective, , rangeStr] = args;
|
|
5701
|
+
if (target !== `${targetScore.target}` || objective !== `${targetScore.objective}`) {
|
|
5702
|
+
return { canAnalyze: false };
|
|
5703
|
+
}
|
|
5704
|
+
let result = valueMatchesRange(value, rangeStr);
|
|
5705
|
+
if (negated)
|
|
5706
|
+
result = !result;
|
|
5707
|
+
return { canAnalyze: true, result };
|
|
5708
|
+
}
|
|
5709
|
+
return { canAnalyze: false };
|
|
5710
|
+
}
|
|
5711
|
+
if (condition2 instanceof AndNode) {
|
|
5712
|
+
for (const subCondition of condition2.conditions) {
|
|
5713
|
+
const subResult = analyzeCondition(subCondition, targetScore, value, negated);
|
|
5714
|
+
if (!subResult.canAnalyze)
|
|
5715
|
+
return { canAnalyze: false };
|
|
5716
|
+
if (!subResult.result)
|
|
5717
|
+
return { canAnalyze: true, result: false };
|
|
5718
|
+
}
|
|
5719
|
+
return { canAnalyze: true, result: true };
|
|
5720
|
+
}
|
|
5721
|
+
if (condition2 instanceof OrNode) {
|
|
5722
|
+
let anyTrue = false;
|
|
5723
|
+
for (const subCondition of condition2.conditions) {
|
|
5724
|
+
const subResult = analyzeCondition(subCondition, targetScore, value, negated);
|
|
5725
|
+
if (!subResult.canAnalyze)
|
|
5726
|
+
return { canAnalyze: false };
|
|
5727
|
+
if (subResult.result)
|
|
5728
|
+
anyTrue = true;
|
|
5729
|
+
}
|
|
5730
|
+
return { canAnalyze: true, result: anyTrue };
|
|
5731
|
+
}
|
|
5732
|
+
if (condition2 instanceof NotNode) {
|
|
5733
|
+
return analyzeCondition(condition2.condition, targetScore, value, !negated);
|
|
5734
|
+
}
|
|
5735
|
+
return { canAnalyze: false };
|
|
5736
|
+
}
|
|
5737
|
+
function getDeclarationLocation() {
|
|
5738
|
+
const stack = new Error().stack;
|
|
5739
|
+
const locationMatch = stack?.split(`
|
|
5740
|
+
`).find((line) => line.includes(".ts:") && !line.includes("/loops/") && !line.includes("node_modules"));
|
|
5741
|
+
return locationMatch?.trim() || "unknown location";
|
|
5742
|
+
}
|
|
5743
|
+
function warnStaticallyFalseCondition(loopType, details) {
|
|
5744
|
+
const location = getDeclarationLocation();
|
|
5745
|
+
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.
|
|
5746
|
+
` + ` at ${location}`);
|
|
5747
|
+
}
|
|
5748
|
+
var init_staticAnalysis = __esm(() => {
|
|
5749
|
+
init_score();
|
|
5750
|
+
init_and();
|
|
5751
|
+
init_or();
|
|
5752
|
+
init_not();
|
|
5753
|
+
});
|
|
5754
|
+
|
|
5537
5755
|
// src/flow/loops/for_i.ts
|
|
5538
5756
|
class ForIStatement {
|
|
5539
5757
|
sandstoneCore;
|
|
@@ -5554,43 +5772,64 @@ class ForIStatement {
|
|
|
5554
5772
|
}
|
|
5555
5773
|
var ForINode;
|
|
5556
5774
|
var init_for_i = __esm(() => {
|
|
5557
|
-
init_commands2();
|
|
5558
5775
|
init_variables2();
|
|
5776
|
+
init_flow();
|
|
5777
|
+
init_if_else();
|
|
5559
5778
|
init_loop();
|
|
5779
|
+
init_staticAnalysis();
|
|
5560
5780
|
ForINode = class ForINode extends LoopNode {
|
|
5561
5781
|
constructor(sandstoneCore2, initialValue, endCondition, iterate, callback) {
|
|
5562
5782
|
const iterator = sandstoneCore2.pack.Variable(initialValue, "loop_iterator");
|
|
5563
|
-
const condition2 =
|
|
5564
|
-
const
|
|
5565
|
-
const
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5783
|
+
const condition2 = conditionToNode(endCondition(iterator));
|
|
5784
|
+
const _continue = () => sandstoneCore2.pack.commands.returnCmd.run(() => new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack)));
|
|
5785
|
+
const analysisResult = typeof initialValue === "number" ? analyzeCondition(condition2, iterator, initialValue) : { canAnalyze: false };
|
|
5786
|
+
if (analysisResult.canAnalyze) {
|
|
5787
|
+
if (analysisResult.result) {
|
|
5788
|
+
callback(iterator, _continue);
|
|
5789
|
+
iterate(iterator);
|
|
5790
|
+
} else {
|
|
5791
|
+
warnStaticallyFalseCondition("for", `initial value ${initialValue} does not satisfy condition`);
|
|
5792
|
+
}
|
|
5793
|
+
}
|
|
5794
|
+
super(sandstoneCore2, condition2, () => callback(iterator, _continue), () => {
|
|
5572
5795
|
iterate(iterator);
|
|
5573
|
-
|
|
5574
|
-
body: [new LoopArgument(sandstoneCore2.pack)]
|
|
5575
|
-
});
|
|
5796
|
+
new IfStatement(sandstoneCore2, condition2, () => new LoopArgument(sandstoneCore2.pack));
|
|
5576
5797
|
});
|
|
5577
5798
|
}
|
|
5578
5799
|
};
|
|
5579
5800
|
});
|
|
5580
5801
|
|
|
5581
5802
|
// src/flow/loops/for_of.ts
|
|
5803
|
+
function isMultipleVariable(iteratorType) {
|
|
5804
|
+
if (Array.isArray(iteratorType)) {
|
|
5805
|
+
return true;
|
|
5806
|
+
}
|
|
5807
|
+
return false;
|
|
5808
|
+
}
|
|
5809
|
+
function isMapIterator(iteratorType, iterable) {
|
|
5810
|
+
if (isMultipleVariable(iteratorType) && iteratorType[0] === "key") {
|
|
5811
|
+
if (iterable.iteratorType === "map") {
|
|
5812
|
+
return true;
|
|
5813
|
+
}
|
|
5814
|
+
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)');
|
|
5815
|
+
}
|
|
5816
|
+
return false;
|
|
5817
|
+
}
|
|
5818
|
+
|
|
5582
5819
|
class ForOfStatement {
|
|
5583
5820
|
sandstoneCore;
|
|
5584
5821
|
iteratorType;
|
|
5822
|
+
direction;
|
|
5585
5823
|
iterable;
|
|
5586
5824
|
callback;
|
|
5587
5825
|
node;
|
|
5588
|
-
constructor(sandstoneCore2, iteratorType, iterable, callback) {
|
|
5826
|
+
constructor(sandstoneCore2, iteratorType, direction, iterable, callback) {
|
|
5589
5827
|
this.sandstoneCore = sandstoneCore2;
|
|
5590
5828
|
this.iteratorType = iteratorType;
|
|
5829
|
+
this.direction = direction;
|
|
5591
5830
|
this.iterable = iterable;
|
|
5592
5831
|
this.callback = callback;
|
|
5593
|
-
this.node = new ForOfNode(sandstoneCore2, iteratorType, iterable, callback);
|
|
5832
|
+
this.node = new ForOfNode(sandstoneCore2, iteratorType, direction, iterable, callback);
|
|
5594
5833
|
}
|
|
5595
5834
|
getNode = () => this.node;
|
|
5596
5835
|
}
|
|
@@ -5600,35 +5839,31 @@ var init_for_of = __esm(() => {
|
|
|
5600
5839
|
init_if_else();
|
|
5601
5840
|
init_loop();
|
|
5602
5841
|
ForOfNode = class ForOfNode extends LoopNode {
|
|
5603
|
-
constructor(sandstoneCore2, iteratorType, iterable, callback) {
|
|
5604
|
-
const _iterable = iterable._toDataPoint();
|
|
5605
|
-
let startCondition;
|
|
5842
|
+
constructor(sandstoneCore2, iteratorType, direction, iterable, callback) {
|
|
5606
5843
|
let iterate;
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
if (iteratorType[0] === "key") {
|
|
5610
|
-
startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
|
|
5844
|
+
if (isMultipleVariable(iteratorType)) {
|
|
5845
|
+
if (isMapIterator(iteratorType, iterable)) {
|
|
5611
5846
|
iterate = iterable.iterator((dataPoints) => {
|
|
5612
|
-
if (dataPoints.length === 1) {
|
|
5613
|
-
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)');
|
|
5614
|
-
}
|
|
5615
5847
|
callback(...[dataPoints[0], dataPoints[1]]);
|
|
5616
|
-
});
|
|
5848
|
+
}, direction);
|
|
5617
5849
|
} else {
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5850
|
+
const _iterator = sandstoneCore2.pack.Variable(direction === "normal" ? -1 : undefined);
|
|
5851
|
+
if (direction === "reverse") {
|
|
5852
|
+
_iterator.set(iterable.size());
|
|
5853
|
+
}
|
|
5622
5854
|
iterate = iterable.iterator((dataPoints) => {
|
|
5623
|
-
|
|
5855
|
+
if (direction === "normal") {
|
|
5856
|
+
_iterator.increase();
|
|
5857
|
+
} else {
|
|
5858
|
+
_iterator.decrease();
|
|
5859
|
+
}
|
|
5624
5860
|
if (dataPoints.length === 1) {
|
|
5625
5861
|
return callback(...[_iterator, dataPoints[0]]);
|
|
5626
5862
|
}
|
|
5627
5863
|
return callback(...[_iterator, dataPoints[1]]);
|
|
5628
|
-
});
|
|
5864
|
+
}, direction);
|
|
5629
5865
|
}
|
|
5630
5866
|
} else {
|
|
5631
|
-
startCondition = ["if", "data", _iterable.type, `${_iterable.path}{}`];
|
|
5632
5867
|
iterate = iterable.iterator((dataPoints) => {
|
|
5633
5868
|
if (dataPoints.length === 1) {
|
|
5634
5869
|
return callback(...[dataPoints[0]]);
|
|
@@ -5636,8 +5871,8 @@ var init_for_of = __esm(() => {
|
|
|
5636
5871
|
return callback(...[dataPoints[1]]);
|
|
5637
5872
|
});
|
|
5638
5873
|
}
|
|
5639
|
-
|
|
5640
|
-
super(sandstoneCore2,
|
|
5874
|
+
const continueCondition = iterable.continue(direction);
|
|
5875
|
+
super(sandstoneCore2, continueCondition, () => iterate, () => new IfStatement(sandstoneCore2, continueCondition, () => new LoopArgument(sandstoneCore2.pack)));
|
|
5641
5876
|
}
|
|
5642
5877
|
};
|
|
5643
5878
|
});
|
|
@@ -5659,11 +5894,12 @@ var WhileNode;
|
|
|
5659
5894
|
var init_while = __esm(() => {
|
|
5660
5895
|
init_variables2();
|
|
5661
5896
|
init_if_else();
|
|
5897
|
+
init_flow();
|
|
5662
5898
|
init_loop();
|
|
5663
5899
|
WhileNode = class WhileNode extends LoopNode {
|
|
5664
5900
|
constructor(sandstoneCore2, condition2, callback) {
|
|
5665
|
-
const _condition =
|
|
5666
|
-
super(sandstoneCore2,
|
|
5901
|
+
const _condition = conditionToNode(condition2);
|
|
5902
|
+
super(sandstoneCore2, _condition, callback, () => new IfStatement(sandstoneCore2, _condition, () => new LoopArgument(sandstoneCore2.pack)));
|
|
5667
5903
|
}
|
|
5668
5904
|
};
|
|
5669
5905
|
});
|
|
@@ -5677,29 +5913,77 @@ var init_loops = __esm(() => {
|
|
|
5677
5913
|
});
|
|
5678
5914
|
|
|
5679
5915
|
// src/flow/switch_case.ts
|
|
5680
|
-
|
|
5916
|
+
function isConditionCase(c) {
|
|
5917
|
+
return typeof c === "function";
|
|
5918
|
+
}
|
|
5919
|
+
function executeSwitch(sandstoneCore2, value, _cases) {
|
|
5920
|
+
let staticCaseEntries = [];
|
|
5921
|
+
let conditionCaseEntries = [];
|
|
5922
|
+
let _default;
|
|
5923
|
+
if (_cases instanceof CaseStatement) {
|
|
5924
|
+
staticCaseEntries = _cases.getStaticCases();
|
|
5925
|
+
conditionCaseEntries = _cases.getConditionCases();
|
|
5926
|
+
} else if (Array.isArray(_cases)) {
|
|
5927
|
+
for (const _case of _cases) {
|
|
5928
|
+
if (_case[0] === "default") {
|
|
5929
|
+
_default = _case;
|
|
5930
|
+
continue;
|
|
5931
|
+
}
|
|
5932
|
+
const [, condition2, callback] = _case;
|
|
5933
|
+
if (isConditionCase(condition2)) {
|
|
5934
|
+
conditionCaseEntries.push({ type: "condition", condition: condition2, callback });
|
|
5935
|
+
} else {
|
|
5936
|
+
staticCaseEntries.push({ type: "static", value: condition2, callback });
|
|
5937
|
+
}
|
|
5938
|
+
}
|
|
5939
|
+
} else {
|
|
5940
|
+
for (const _case of _cases.entries) {
|
|
5941
|
+
if (_case.type === "condition") {
|
|
5942
|
+
conditionCaseEntries.push(_case);
|
|
5943
|
+
} else {
|
|
5944
|
+
staticCaseEntries.push(_case);
|
|
5945
|
+
}
|
|
5946
|
+
}
|
|
5947
|
+
if (_cases.default) {
|
|
5948
|
+
_default = ["default", _cases.default];
|
|
5949
|
+
}
|
|
5950
|
+
}
|
|
5951
|
+
const staticCaseNodes = staticCaseEntries.map((c) => new StaticCaseNode(sandstoneCore2, c.value, c.callback));
|
|
5952
|
+
const conditionCaseNodes = conditionCaseEntries.map((c) => new ConditionCaseNode(sandstoneCore2, c.condition, c.callback));
|
|
5953
|
+
const defaultCaseNode = _default ? new DefaultCaseNode(sandstoneCore2, _default[1]) : undefined;
|
|
5954
|
+
new SwitchNode(sandstoneCore2, value, staticCaseNodes, conditionCaseNodes, defaultCaseNode);
|
|
5955
|
+
}
|
|
5956
|
+
var CASE_STATEMENT_BRAND, CaseStatement, SwitchNode, StaticCaseNode, ConditionCaseNode, DefaultCaseNode;
|
|
5681
5957
|
var init_switch_case = __esm(() => {
|
|
5958
|
+
init_core();
|
|
5682
5959
|
CASE_STATEMENT_BRAND = Symbol.for("sandstone.CaseStatement");
|
|
5683
5960
|
CaseStatement = class CaseStatement {
|
|
5684
|
-
|
|
5685
|
-
callback;
|
|
5686
|
-
previous;
|
|
5961
|
+
entries;
|
|
5687
5962
|
[CASE_STATEMENT_BRAND] = true;
|
|
5688
|
-
constructor(
|
|
5689
|
-
this.
|
|
5690
|
-
this.callback = callback;
|
|
5691
|
-
this.previous = previous;
|
|
5963
|
+
constructor(entries = []) {
|
|
5964
|
+
this.entries = entries;
|
|
5692
5965
|
}
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
return ["case", this.value, this.callback];
|
|
5966
|
+
getStaticCases() {
|
|
5967
|
+
return this.entries.filter((e) => e.type === "static");
|
|
5696
5968
|
}
|
|
5697
|
-
|
|
5698
|
-
return
|
|
5969
|
+
getConditionCases() {
|
|
5970
|
+
return this.entries.filter((e) => e.type === "condition");
|
|
5971
|
+
}
|
|
5972
|
+
case(valueOrCondition, callback) {
|
|
5973
|
+
if (typeof valueOrCondition === "function") {
|
|
5974
|
+
return new CaseStatement([
|
|
5975
|
+
...this.entries,
|
|
5976
|
+
{ type: "condition", condition: valueOrCondition, callback }
|
|
5977
|
+
]);
|
|
5978
|
+
}
|
|
5979
|
+
return new CaseStatement([
|
|
5980
|
+
...this.entries,
|
|
5981
|
+
{ type: "static", value: valueOrCondition, callback }
|
|
5982
|
+
]);
|
|
5699
5983
|
}
|
|
5700
5984
|
default(callback) {
|
|
5701
5985
|
return {
|
|
5702
|
-
|
|
5986
|
+
entries: this.entries,
|
|
5703
5987
|
default: callback
|
|
5704
5988
|
};
|
|
5705
5989
|
}
|
|
@@ -5707,24 +5991,83 @@ var init_switch_case = __esm(() => {
|
|
|
5707
5991
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[CASE_STATEMENT_BRAND] === true;
|
|
5708
5992
|
}
|
|
5709
5993
|
};
|
|
5994
|
+
SwitchNode = class SwitchNode extends ContainerNode {
|
|
5995
|
+
value;
|
|
5996
|
+
staticCases;
|
|
5997
|
+
conditionCases;
|
|
5998
|
+
defaultCase;
|
|
5999
|
+
parentMCFunction;
|
|
6000
|
+
constructor(sandstoneCore2, value, staticCases, conditionCases, defaultCase) {
|
|
6001
|
+
super(sandstoneCore2);
|
|
6002
|
+
this.value = value;
|
|
6003
|
+
this.staticCases = staticCases;
|
|
6004
|
+
this.conditionCases = conditionCases;
|
|
6005
|
+
this.defaultCase = defaultCase;
|
|
6006
|
+
this.parentMCFunction = sandstoneCore2.getCurrentMCFunctionOrThrow();
|
|
6007
|
+
this.parentMCFunction.enterContext(this);
|
|
6008
|
+
for (const caseNode of [...staticCases, ...conditionCases]) {
|
|
6009
|
+
this.parentMCFunction.enterContext(caseNode);
|
|
6010
|
+
caseNode.callback();
|
|
6011
|
+
this.parentMCFunction.exitContext();
|
|
6012
|
+
}
|
|
6013
|
+
if (defaultCase) {
|
|
6014
|
+
this.parentMCFunction.enterContext(defaultCase);
|
|
6015
|
+
defaultCase.callback();
|
|
6016
|
+
this.parentMCFunction.exitContext();
|
|
6017
|
+
}
|
|
6018
|
+
this.parentMCFunction.exitContext();
|
|
6019
|
+
}
|
|
6020
|
+
getValue = () => {
|
|
6021
|
+
throw new Error("SwitchNode must be transformed by SwitchTransformationVisitor");
|
|
6022
|
+
};
|
|
6023
|
+
};
|
|
6024
|
+
StaticCaseNode = class StaticCaseNode extends ContainerNode {
|
|
6025
|
+
value;
|
|
6026
|
+
callback;
|
|
6027
|
+
constructor(sandstoneCore2, value, callback) {
|
|
6028
|
+
super(sandstoneCore2);
|
|
6029
|
+
this.value = value;
|
|
6030
|
+
this.callback = callback;
|
|
6031
|
+
}
|
|
6032
|
+
getValue = () => null;
|
|
6033
|
+
};
|
|
6034
|
+
ConditionCaseNode = class ConditionCaseNode extends ContainerNode {
|
|
6035
|
+
condition;
|
|
6036
|
+
callback;
|
|
6037
|
+
constructor(sandstoneCore2, condition2, callback) {
|
|
6038
|
+
super(sandstoneCore2);
|
|
6039
|
+
this.condition = condition2;
|
|
6040
|
+
this.callback = callback;
|
|
6041
|
+
}
|
|
6042
|
+
getValue = () => null;
|
|
6043
|
+
};
|
|
6044
|
+
DefaultCaseNode = class DefaultCaseNode extends ContainerNode {
|
|
6045
|
+
callback;
|
|
6046
|
+
constructor(sandstoneCore2, callback) {
|
|
6047
|
+
super(sandstoneCore2);
|
|
6048
|
+
this.callback = callback;
|
|
6049
|
+
}
|
|
6050
|
+
getValue = () => null;
|
|
6051
|
+
};
|
|
5710
6052
|
});
|
|
5711
6053
|
|
|
5712
6054
|
// src/flow/Flow.ts
|
|
6055
|
+
function conditionToNode(condition2) {
|
|
6056
|
+
if (!(condition2 instanceof ConditionNode)) {
|
|
6057
|
+
return condition2._toMinecraftCondition();
|
|
6058
|
+
}
|
|
6059
|
+
return condition2;
|
|
6060
|
+
}
|
|
6061
|
+
|
|
5713
6062
|
class Flow {
|
|
5714
6063
|
sandstoneCore;
|
|
5715
6064
|
constructor(sandstoneCore2) {
|
|
5716
6065
|
this.sandstoneCore = sandstoneCore2;
|
|
5717
6066
|
}
|
|
5718
|
-
conditionToNode(condition2)
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
return condition2;
|
|
5723
|
-
}
|
|
5724
|
-
if = (condition2, callback) => new IfStatement(this.sandstoneCore, this.conditionToNode(condition2), callback);
|
|
5725
|
-
and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
|
|
5726
|
-
or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => this.conditionToNode(condition2)));
|
|
5727
|
-
not = (condition2) => new NotNode(this.sandstoneCore, this.conditionToNode(condition2));
|
|
6067
|
+
if = (condition2, callback) => new IfStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
6068
|
+
and = (...conditions) => new AndNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
|
|
6069
|
+
or = (...conditions) => new OrNode(this.sandstoneCore, conditions.map((condition2) => conditionToNode(condition2)));
|
|
6070
|
+
not = (condition2) => new NotNode(this.sandstoneCore, conditionToNode(condition2));
|
|
5728
6071
|
get return() {
|
|
5729
6072
|
return this.sandstoneCore.pack.commands.returnCmd;
|
|
5730
6073
|
}
|
|
@@ -5747,77 +6090,56 @@ Sandstone Pack Error:
|
|
|
5747
6090
|
if (broadcast !== false) {
|
|
5748
6091
|
tellraw(broadcast || "@a", fullError);
|
|
5749
6092
|
}
|
|
5750
|
-
const
|
|
6093
|
+
const errorSerializable = parseJSONText(this.sandstoneCore, fullError);
|
|
5751
6094
|
if (dataPoint2 !== false) {
|
|
5752
6095
|
let point;
|
|
5753
6096
|
if (dataPoint2 === undefined) {
|
|
5754
|
-
point = DataVariable(
|
|
6097
|
+
point = DataVariable(errorSerializable.toJSON());
|
|
5755
6098
|
} else {
|
|
5756
|
-
point = dataPoint2.set(
|
|
6099
|
+
point = dataPoint2.set(errorSerializable.toJSON());
|
|
5757
6100
|
}
|
|
5758
6101
|
returnCmd.fail();
|
|
5759
6102
|
return point;
|
|
5760
6103
|
}
|
|
5761
6104
|
returnCmd.fail();
|
|
5762
|
-
return
|
|
6105
|
+
return errorSerializable;
|
|
5763
6106
|
}
|
|
5764
6107
|
while(condition2, callback) {
|
|
5765
|
-
return new WhileStatement(this.sandstoneCore,
|
|
6108
|
+
return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
5766
6109
|
}
|
|
5767
6110
|
doWhile(condition2, callback) {
|
|
5768
6111
|
callback();
|
|
5769
|
-
return new WhileStatement(this.sandstoneCore,
|
|
6112
|
+
return new WhileStatement(this.sandstoneCore, conditionToNode(condition2), callback);
|
|
5770
6113
|
}
|
|
5771
6114
|
for(arg1, arg2, arg3, arg4) {
|
|
5772
6115
|
if (typeof arg1 === "number" || arg1 instanceof Score) {
|
|
5773
6116
|
return new ForIStatement(this.sandstoneCore, arg1, arg2, arg3, arg4);
|
|
5774
6117
|
}
|
|
5775
6118
|
if (arg1 === "entry") {
|
|
5776
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
6119
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
5777
6120
|
}
|
|
5778
6121
|
if (arg1[0] === "key") {
|
|
5779
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
6122
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
5780
6123
|
}
|
|
5781
6124
|
if (typeof arg1[0] === "number" || arg1[0] instanceof Score) {
|
|
5782
6125
|
if (arg2 === "iterate") {
|
|
5783
6126
|
return new ForIStatement(this.sandstoneCore, arg1[0], (i) => i["<="](arg1[1]), (i) => i["++"], arg3);
|
|
5784
6127
|
}
|
|
5785
|
-
return binaryFor(this, arg1[0], arg1[1], arg3, arg1[2]);
|
|
5786
6128
|
}
|
|
5787
|
-
return new ForOfStatement(this.sandstoneCore, arg1, arg3, arg4);
|
|
6129
|
+
return new ForOfStatement(this.sandstoneCore, arg1, arg2 === "of-reverse" ? "reverse" : "normal", arg3, arg4);
|
|
5788
6130
|
}
|
|
5789
|
-
switch(value,
|
|
5790
|
-
|
|
5791
|
-
if (_cases instanceof CaseStatement) {
|
|
5792
|
-
cases = _cases.getCases().map((c) => c.getValue());
|
|
5793
|
-
} else if (Array.isArray(_cases)) {
|
|
5794
|
-
cases = _cases;
|
|
5795
|
-
} else {
|
|
5796
|
-
cases = _cases.cases.map((c) => c.getValue());
|
|
5797
|
-
_default = ["default", _cases.default];
|
|
5798
|
-
}
|
|
5799
|
-
const { Data, initMCFunction, MCFunction, Macro: Macro2 } = this.sandstoneCore.pack;
|
|
5800
|
-
const id2 = switches++;
|
|
5801
|
-
const values = Data("storage", `__sandstone:switch_${id2}`, "Values");
|
|
5802
|
-
initMCFunction.push(() => values.set(cases.map(([_, v, callback], i) => {
|
|
5803
|
-
MCFunction(`__sandstone:switch_${id2}_case_${i}`, [], () => callback());
|
|
5804
|
-
return { Value: v, Index: i };
|
|
5805
|
-
})));
|
|
5806
|
-
const flow = this;
|
|
5807
|
-
MCFunction(`__sandstone:switch_${id2}`, [value], () => {
|
|
5808
|
-
const index = Data("storage", `__sandstone:switch_${id2}`, "Index");
|
|
5809
|
-
Macro2.data.modify.storage(index.currentTarget, "Index").set.from.storage(values.currentTarget, Macro2`Values[{Value:${value}}}].Index`);
|
|
5810
|
-
const _if = flow.if(index, () => {
|
|
5811
|
-
MCFunction(`__sandstone:switch_${id2}_inner`, [index], () => {
|
|
5812
|
-
Macro2.functionCmd(Macro2`__sandstone:switch_${id2}_case_${index}`);
|
|
5813
|
-
})();
|
|
5814
|
-
});
|
|
5815
|
-
if (_default)
|
|
5816
|
-
_if.else(() => _default?.[1]());
|
|
5817
|
-
})();
|
|
6131
|
+
switch(value, cases) {
|
|
6132
|
+
executeSwitch(this.sandstoneCore, value, cases);
|
|
5818
6133
|
}
|
|
5819
6134
|
case(value, callback) {
|
|
5820
|
-
|
|
6135
|
+
if (typeof value === "function") {
|
|
6136
|
+
return new CaseStatement([
|
|
6137
|
+
{ type: "condition", condition: value, callback }
|
|
6138
|
+
]);
|
|
6139
|
+
}
|
|
6140
|
+
return new CaseStatement([
|
|
6141
|
+
{ type: "static", value, callback }
|
|
6142
|
+
]);
|
|
5821
6143
|
}
|
|
5822
6144
|
biome = (coordinates, biome2) => {
|
|
5823
6145
|
return new SandstoneConditions.Biome(this.sandstoneCore, coordinates, biome2);
|
|
@@ -5859,7 +6181,6 @@ Sandstone Pack Error:
|
|
|
5859
6181
|
return new SandstoneConditions.Predicate(this.sandstoneCore, predicate3.name);
|
|
5860
6182
|
};
|
|
5861
6183
|
}
|
|
5862
|
-
var switches = 0;
|
|
5863
6184
|
var init_Flow = __esm(() => {
|
|
5864
6185
|
init_variables2();
|
|
5865
6186
|
init_conditions();
|
|
@@ -5874,6 +6195,7 @@ var init_flow = __esm(() => {
|
|
|
5874
6195
|
init_Flow();
|
|
5875
6196
|
init_if_else();
|
|
5876
6197
|
init_loop();
|
|
6198
|
+
init_switch_case();
|
|
5877
6199
|
});
|
|
5878
6200
|
|
|
5879
6201
|
// src/core/visitors.ts
|
|
@@ -5956,6 +6278,10 @@ var init_visitor = __esm(() => {
|
|
|
5956
6278
|
visitIfNode;
|
|
5957
6279
|
visitElseNode;
|
|
5958
6280
|
visitLoopNode;
|
|
6281
|
+
visitSwitchNode;
|
|
6282
|
+
visitStaticCaseNode;
|
|
6283
|
+
visitConditionCaseNode;
|
|
6284
|
+
visitDefaultCaseNode;
|
|
5959
6285
|
visitLoopArgumentNode;
|
|
5960
6286
|
visitAdvancementCommandNode;
|
|
5961
6287
|
visitAttributeCommandNode;
|
|
@@ -5985,6 +6311,7 @@ var init_addAwaitBodyToMCFunctions = __esm(() => {
|
|
|
5985
6311
|
// src/pack/visitors/containerCommandsToMCFunction.ts
|
|
5986
6312
|
var ContainerCommandsToMCFunctionVisitor;
|
|
5987
6313
|
var init_containerCommandsToMCFunction = __esm(() => {
|
|
6314
|
+
init_commands2();
|
|
5988
6315
|
init_core();
|
|
5989
6316
|
init_visitor();
|
|
5990
6317
|
ContainerCommandsToMCFunctionVisitor = class ContainerCommandsToMCFunctionVisitor extends GenericSandstoneVisitor {
|
|
@@ -6004,6 +6331,14 @@ var init_containerCommandsToMCFunction = __esm(() => {
|
|
|
6004
6331
|
this.currentMCFunction = node;
|
|
6005
6332
|
this.core.currentNode = node.resource.name;
|
|
6006
6333
|
const result = this.genericVisit(node);
|
|
6334
|
+
if (node.resource.creator === "sandstone" && node.body.length > 0) {
|
|
6335
|
+
const lastNode = node.body.at(-1);
|
|
6336
|
+
if (lastNode instanceof FunctionCommandNode) {
|
|
6337
|
+
const returnRunNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
6338
|
+
returnRunNode.body = [lastNode];
|
|
6339
|
+
node.body[node.body.length - 1] = returnRunNode;
|
|
6340
|
+
}
|
|
6341
|
+
}
|
|
6007
6342
|
this.core.currentNode = prev?.resource.name ?? "";
|
|
6008
6343
|
this.currentMCFunction = prev;
|
|
6009
6344
|
return result;
|
|
@@ -6046,7 +6381,7 @@ function* flattenIfNode(node) {
|
|
|
6046
6381
|
yield next;
|
|
6047
6382
|
}
|
|
6048
6383
|
}
|
|
6049
|
-
function handleMultipleNodes(visitor, nodes2) {
|
|
6384
|
+
function handleMultipleNodes(visitor, nodes2, macroStorage) {
|
|
6050
6385
|
return nodes2.flatMap((node, i) => {
|
|
6051
6386
|
const { body } = node;
|
|
6052
6387
|
if (node instanceof IfNode) {
|
|
@@ -6057,25 +6392,32 @@ function handleMultipleNodes(visitor, nodes2) {
|
|
|
6057
6392
|
if (Array.isArray(child)) {
|
|
6058
6393
|
actualBody = child;
|
|
6059
6394
|
} else {
|
|
6060
|
-
return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6395
|
+
return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6061
6396
|
isSingleExecute: false,
|
|
6062
6397
|
givenCallbackName: callbackName,
|
|
6063
|
-
body: [i === nodes2.length - 1 ? child : new
|
|
6064
|
-
|
|
6398
|
+
body: [i === nodes2.length - 1 ? child : new ReturnRunCommandNode(visitor.pack, ["run"], {
|
|
6399
|
+
isSingleExecute: false,
|
|
6400
|
+
isFlowControl: true,
|
|
6401
|
+
body: [child]
|
|
6402
|
+
})],
|
|
6403
|
+
macroStorage
|
|
6404
|
+
}));
|
|
6065
6405
|
}
|
|
6066
6406
|
}
|
|
6067
|
-
return new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6407
|
+
return visitor.visit(new ExecuteCommandNode(visitor.pack, [[node.condition.getValue()]], {
|
|
6068
6408
|
isSingleExecute: false,
|
|
6069
6409
|
givenCallbackName: `${i}_${callbackName}`,
|
|
6070
6410
|
body: [
|
|
6071
6411
|
new ReturnRunCommandNode(visitor.pack, ["run"], {
|
|
6072
6412
|
isSingleExecute: false,
|
|
6413
|
+
isFlowControl: true,
|
|
6073
6414
|
body: actualBody
|
|
6074
6415
|
})
|
|
6075
|
-
]
|
|
6076
|
-
|
|
6416
|
+
],
|
|
6417
|
+
macroStorage
|
|
6418
|
+
}));
|
|
6077
6419
|
}
|
|
6078
|
-
return body;
|
|
6420
|
+
return body.flatMap((n) => visitor.visit(n));
|
|
6079
6421
|
});
|
|
6080
6422
|
}
|
|
6081
6423
|
var IfElseTransformationVisitor;
|
|
@@ -6089,19 +6431,30 @@ var init_ifElseTransformationVisitor = __esm(() => {
|
|
|
6089
6431
|
return [];
|
|
6090
6432
|
}
|
|
6091
6433
|
const nodes2 = Array.from(flattenIfNode(node_));
|
|
6434
|
+
const { parentMCFunction, condition: condition2, givenCallbackName, body } = node_;
|
|
6435
|
+
const callbackName = givenCallbackName ?? "if";
|
|
6436
|
+
const macroStorage = parentMCFunction.resource.macroPoint;
|
|
6092
6437
|
if (nodes2.length === 1) {
|
|
6093
|
-
|
|
6438
|
+
const executeNode = new ExecuteCommandNode(this.pack, [[condition2.getValue()]], {
|
|
6094
6439
|
isSingleExecute: false,
|
|
6095
|
-
givenCallbackName:
|
|
6096
|
-
body
|
|
6097
|
-
|
|
6440
|
+
givenCallbackName: callbackName,
|
|
6441
|
+
body,
|
|
6442
|
+
macroStorage
|
|
6443
|
+
});
|
|
6444
|
+
node_.resultingExecuteNode = executeNode;
|
|
6445
|
+
return this.visit(executeNode);
|
|
6446
|
+
}
|
|
6447
|
+
if (nodes2.at(-1) === parentMCFunction.body.at(-1)) {
|
|
6448
|
+
return handleMultipleNodes(this, nodes2, macroStorage);
|
|
6098
6449
|
}
|
|
6099
6450
|
const wrapper = new ExecuteCommandNode(this.pack, [], {
|
|
6100
6451
|
isFake: true,
|
|
6101
6452
|
isSingleExecute: false,
|
|
6102
|
-
givenCallbackName:
|
|
6103
|
-
body: handleMultipleNodes(this, nodes2)
|
|
6453
|
+
givenCallbackName: callbackName,
|
|
6454
|
+
body: handleMultipleNodes(this, nodes2, macroStorage),
|
|
6455
|
+
macroStorage
|
|
6104
6456
|
});
|
|
6457
|
+
node_.resultingExecuteNode = wrapper;
|
|
6105
6458
|
return this.visit(wrapper);
|
|
6106
6459
|
};
|
|
6107
6460
|
};
|
|
@@ -6110,19 +6463,15 @@ var init_ifElseTransformationVisitor = __esm(() => {
|
|
|
6110
6463
|
// src/pack/visitors/initConstantsVisitor.ts
|
|
6111
6464
|
var InitConstantsVisitor;
|
|
6112
6465
|
var init_initConstantsVisitor = __esm(() => {
|
|
6466
|
+
init_commands2();
|
|
6113
6467
|
init_visitor();
|
|
6114
6468
|
InitConstantsVisitor = class InitConstantsVisitor extends GenericSandstoneVisitor {
|
|
6115
6469
|
onStart = () => {
|
|
6116
6470
|
const { pack } = this;
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
pack.initMCFunction.unshift(() => {
|
|
6122
|
-
for (const constant of constants) {
|
|
6123
|
-
scoreboard.players.set(constant, pack.rootObjective, constant);
|
|
6124
|
-
}
|
|
6125
|
-
});
|
|
6471
|
+
if (pack.constants.size !== 0) {
|
|
6472
|
+
for (const constant of pack.constants) {
|
|
6473
|
+
pack.initMCFunction.node.body.push(new ScoreboardCommandNode(pack, "players", "set", constant, pack.rootObjective, constant));
|
|
6474
|
+
}
|
|
6126
6475
|
}
|
|
6127
6476
|
};
|
|
6128
6477
|
};
|
|
@@ -6198,15 +6547,24 @@ var init_inlineFunctionCallVisitor = __esm(() => {
|
|
|
6198
6547
|
// src/pack/visitors/loopTransformationVisitor.ts
|
|
6199
6548
|
var LoopTransformationVisitor;
|
|
6200
6549
|
var init_loopTransformationVisitor = __esm(() => {
|
|
6201
|
-
|
|
6550
|
+
init_flow();
|
|
6202
6551
|
init_visitor();
|
|
6203
6552
|
LoopTransformationVisitor = class LoopTransformationVisitor extends GenericSandstoneVisitor {
|
|
6553
|
+
currentLoopIfNode = null;
|
|
6204
6554
|
visitLoopNode = (node_) => {
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6555
|
+
const ifNode = new IfNode(this.core, node_.condition, undefined, node_.parentMCFunction);
|
|
6556
|
+
ifNode.givenCallbackName = "loop";
|
|
6557
|
+
const previousLoopIfNode = this.currentLoopIfNode;
|
|
6558
|
+
this.currentLoopIfNode = ifNode;
|
|
6559
|
+
ifNode.body = node_.body.flatMap((node) => this.visit(node));
|
|
6560
|
+
this.currentLoopIfNode = previousLoopIfNode;
|
|
6561
|
+
return ifNode;
|
|
6562
|
+
};
|
|
6563
|
+
visitLoopArgument = (node_) => {
|
|
6564
|
+
if (this.currentLoopIfNode) {
|
|
6565
|
+
node_.loopIfNode = this.currentLoopIfNode;
|
|
6566
|
+
}
|
|
6567
|
+
return node_;
|
|
6210
6568
|
};
|
|
6211
6569
|
visitWhileNode = this.visitLoopNode;
|
|
6212
6570
|
visitForINode = this.visitLoopNode;
|
|
@@ -6305,7 +6663,7 @@ var init_simplifyExecuteFunction = __esm(() => {
|
|
|
6305
6663
|
return this.genericVisit(node);
|
|
6306
6664
|
}
|
|
6307
6665
|
const mcFunction = functionNode.args[0];
|
|
6308
|
-
if (typeof mcFunction === "string") {
|
|
6666
|
+
if (typeof mcFunction === "string" || !mcFunction?.node) {
|
|
6309
6667
|
return this.genericVisit(node);
|
|
6310
6668
|
}
|
|
6311
6669
|
const mcFunctionNode = mcFunction.node;
|
|
@@ -6317,11 +6675,33 @@ var init_simplifyExecuteFunction = __esm(() => {
|
|
|
6317
6675
|
return this.genericVisit(node);
|
|
6318
6676
|
}
|
|
6319
6677
|
}
|
|
6678
|
+
if (command instanceof LoopArgument) {
|
|
6679
|
+
const loopExecute = command.loopIfNode?.resultingExecuteNode;
|
|
6680
|
+
const loopFunctionName = loopExecute?.createdMCFunction?.name;
|
|
6681
|
+
if (loopFunctionName) {
|
|
6682
|
+
node.body = [new FunctionCommandNode(this.pack, loopFunctionName)];
|
|
6683
|
+
if (mcFunction.creator === "sandstone") {
|
|
6684
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
6685
|
+
}
|
|
6686
|
+
return this.genericVisit(node);
|
|
6687
|
+
}
|
|
6688
|
+
return this.genericVisit(node);
|
|
6689
|
+
}
|
|
6320
6690
|
if (!(command instanceof CommandNode)) {
|
|
6321
6691
|
return this.genericVisit(node);
|
|
6322
6692
|
}
|
|
6323
|
-
if (command instanceof
|
|
6324
|
-
|
|
6693
|
+
if (command instanceof ReturnRunCommandNode) {
|
|
6694
|
+
if (mcFunction.creator === "sandstone") {
|
|
6695
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
6696
|
+
}
|
|
6697
|
+
if (command.isFlowControl) {
|
|
6698
|
+
node.body = [this.genericVisit(command)];
|
|
6699
|
+
} else {
|
|
6700
|
+
const returnCmd = this.visit(command);
|
|
6701
|
+
node.body = returnCmd.body;
|
|
6702
|
+
return this.visitExecuteCommandNode(node);
|
|
6703
|
+
}
|
|
6704
|
+
return this.genericVisit(node);
|
|
6325
6705
|
}
|
|
6326
6706
|
if (command instanceof FunctionCommandNode) {
|
|
6327
6707
|
const innerMCFunction = command.args[0];
|
|
@@ -6364,17 +6744,24 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6364
6744
|
init_nodes();
|
|
6365
6745
|
init_flow();
|
|
6366
6746
|
init_visitor();
|
|
6747
|
+
init_Macro();
|
|
6367
6748
|
SimplifyReturnRunFunctionVisitor = class SimplifyReturnRunFunctionVisitor extends GenericSandstoneVisitor {
|
|
6368
6749
|
visitReturnRunCommandNode = (node) => {
|
|
6369
6750
|
if (node.body.length === 0 || node.body.length > 1) {
|
|
6370
6751
|
return this.genericVisit(node);
|
|
6371
6752
|
}
|
|
6372
|
-
const
|
|
6373
|
-
if (!(
|
|
6753
|
+
const childNode = node.body[0];
|
|
6754
|
+
if (!(childNode instanceof FunctionCommandNode)) {
|
|
6755
|
+
if (childNode instanceof ReturnRunCommandNode) {
|
|
6756
|
+
return this.visitReturnRunCommandNode(childNode);
|
|
6757
|
+
}
|
|
6758
|
+
if (childNode instanceof ReturnCommandNode) {
|
|
6759
|
+
return this.genericVisit(childNode);
|
|
6760
|
+
}
|
|
6374
6761
|
return this.genericVisit(node);
|
|
6375
6762
|
}
|
|
6376
|
-
const mcFunction =
|
|
6377
|
-
if (typeof mcFunction === "string") {
|
|
6763
|
+
const mcFunction = childNode.args[0];
|
|
6764
|
+
if (typeof mcFunction === "string" || isMacroArgument(this.core, mcFunction)) {
|
|
6378
6765
|
return this.genericVisit(node);
|
|
6379
6766
|
}
|
|
6380
6767
|
const mcFunctionNode = mcFunction.node;
|
|
@@ -6390,10 +6777,6 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6390
6777
|
return this.genericVisit(node);
|
|
6391
6778
|
}
|
|
6392
6779
|
if (command instanceof FunctionCommandNode) {
|
|
6393
|
-
const innerMCFunction = command.args[0];
|
|
6394
|
-
if (typeof innerMCFunction === "string") {
|
|
6395
|
-
return this.genericVisit(node);
|
|
6396
|
-
}
|
|
6397
6780
|
node.body = [command];
|
|
6398
6781
|
if (mcFunction.creator === "sandstone") {
|
|
6399
6782
|
this.core.resourceNodes.delete(mcFunctionNode);
|
|
@@ -6401,7 +6784,18 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6401
6784
|
return this.genericVisit(node);
|
|
6402
6785
|
}
|
|
6403
6786
|
if (command instanceof ReturnRunCommandNode) {
|
|
6404
|
-
|
|
6787
|
+
node.body = command.body;
|
|
6788
|
+
node.isFlowControl = node.isFlowControl || command.isFlowControl;
|
|
6789
|
+
if (mcFunction.creator === "sandstone") {
|
|
6790
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
6791
|
+
}
|
|
6792
|
+
return this.visitReturnRunCommandNode(node);
|
|
6793
|
+
}
|
|
6794
|
+
if (command instanceof ReturnCommandNode) {
|
|
6795
|
+
if (mcFunction.creator === "sandstone") {
|
|
6796
|
+
this.core.resourceNodes.delete(mcFunctionNode);
|
|
6797
|
+
}
|
|
6798
|
+
return this.genericVisit(command);
|
|
6405
6799
|
}
|
|
6406
6800
|
node.body = [this.genericVisit(command)];
|
|
6407
6801
|
if (mcFunction.creator === "sandstone") {
|
|
@@ -6412,6 +6806,233 @@ var init_simplifyReturnRunFunction = __esm(() => {
|
|
|
6412
6806
|
};
|
|
6413
6807
|
});
|
|
6414
6808
|
|
|
6809
|
+
// src/pack/visitors/switchTransformationVisitor.ts
|
|
6810
|
+
var SwitchTransformationVisitor;
|
|
6811
|
+
var init_switchTransformationVisitor = __esm(() => {
|
|
6812
|
+
init_commands2();
|
|
6813
|
+
init_core();
|
|
6814
|
+
init_flow();
|
|
6815
|
+
init_variables2();
|
|
6816
|
+
init_visitor();
|
|
6817
|
+
SwitchTransformationVisitor = class SwitchTransformationVisitor extends GenericSandstoneVisitor {
|
|
6818
|
+
visitSwitchNode = (node) => {
|
|
6819
|
+
const { value, staticCases, conditionCases, defaultCase, parentMCFunction } = node;
|
|
6820
|
+
const { Data, initMCFunction, Macro: Macro2, commands } = this.pack;
|
|
6821
|
+
const { functionCmd } = commands;
|
|
6822
|
+
const parentName = parentMCFunction?.resource.name ?? "__sandstone:switch";
|
|
6823
|
+
const hasStaticCases = staticCases.length > 0;
|
|
6824
|
+
const switchMCFunction = new MCFunctionClass(this.core, `${parentName}/switch`, {
|
|
6825
|
+
addToSandstoneCore: true,
|
|
6826
|
+
creator: "sandstone",
|
|
6827
|
+
onConflict: "rename"
|
|
6828
|
+
}, hasStaticCases ? [value] : undefined);
|
|
6829
|
+
const storageKey = `__sandstone:${switchMCFunction.name.replace(/[:/]/g, "_")}`;
|
|
6830
|
+
const values = Data("storage", storageKey, "Values");
|
|
6831
|
+
if (hasStaticCases) {
|
|
6832
|
+
const isScoreSwitch = value instanceof Score;
|
|
6833
|
+
if (typeof value.local?.set === "function") {
|
|
6834
|
+
value.local.set(switchMCFunction.name, "env_0");
|
|
6835
|
+
}
|
|
6836
|
+
this.core.enterMCFunction(switchMCFunction);
|
|
6837
|
+
if (isScoreSwitch) {
|
|
6838
|
+
for (const caseNode of staticCases) {
|
|
6839
|
+
const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${caseNode.value}`, {
|
|
6840
|
+
addToSandstoneCore: true,
|
|
6841
|
+
creator: "sandstone",
|
|
6842
|
+
onConflict: "rename"
|
|
6843
|
+
});
|
|
6844
|
+
caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
|
|
6845
|
+
}
|
|
6846
|
+
const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
|
|
6847
|
+
if (hasFallback) {
|
|
6848
|
+
const tryCaseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/try_case`, {
|
|
6849
|
+
addToSandstoneCore: true,
|
|
6850
|
+
creator: "sandstone",
|
|
6851
|
+
onConflict: "rename"
|
|
6852
|
+
});
|
|
6853
|
+
this.core.enterMCFunction(tryCaseMCFunction);
|
|
6854
|
+
Macro2.returnCmd.run.functionCmd(Macro2`${switchMCFunction.name}/case_${value}`);
|
|
6855
|
+
this.core.exitMCFunction();
|
|
6856
|
+
const successScore = this.pack.rootObjective("$switch_success");
|
|
6857
|
+
const resultScore = this.pack.rootObjective("$switch_result");
|
|
6858
|
+
commands.execute.store.success(successScore).store.result(resultScore).run.functionCmd(tryCaseMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
6859
|
+
commands.execute.if.score(successScore, "matches", 1).run.returnCmd.run.scoreboard.players.get(resultScore);
|
|
6860
|
+
this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
|
|
6861
|
+
} else {
|
|
6862
|
+
const dispatchMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/dispatch`, {
|
|
6863
|
+
addToSandstoneCore: true,
|
|
6864
|
+
creator: "sandstone",
|
|
6865
|
+
onConflict: "rename"
|
|
6866
|
+
});
|
|
6867
|
+
this.core.enterMCFunction(dispatchMCFunction);
|
|
6868
|
+
Macro2.returnCmd.run.functionCmd(Macro2`${switchMCFunction.name}/case_${value}`);
|
|
6869
|
+
this.core.exitMCFunction();
|
|
6870
|
+
commands.returnCmd.run.functionCmd(dispatchMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
6871
|
+
}
|
|
6872
|
+
const macroPoint = switchMCFunction.macroPoint;
|
|
6873
|
+
const env0Point = macroPoint.select("env_0");
|
|
6874
|
+
commands.execute.store.result.storage(env0Point.currentTarget, env0Point.path, "int").run.scoreboard.players.get(value);
|
|
6875
|
+
const copyNode = switchMCFunction.node.body.pop();
|
|
6876
|
+
switchMCFunction.node.body.unshift(copyNode);
|
|
6877
|
+
const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
6878
|
+
if (canInline) {
|
|
6879
|
+
this.core.exitMCFunction();
|
|
6880
|
+
this.core.resourceNodes.delete(switchMCFunction.node);
|
|
6881
|
+
return switchMCFunction.node.body;
|
|
6882
|
+
}
|
|
6883
|
+
} else {
|
|
6884
|
+
const index = switchMCFunction.macroPoint.select("Index");
|
|
6885
|
+
index.local.set(switchMCFunction.name, "Index");
|
|
6886
|
+
index.remove();
|
|
6887
|
+
Macro2.data.modify.storage(index.currentTarget, index.path).set.from.storage(values.currentTarget, Macro2`Values[{Value:${value}}].Index`);
|
|
6888
|
+
const caseData = [];
|
|
6889
|
+
for (let i = 0;i < staticCases.length; i++) {
|
|
6890
|
+
const caseNode = staticCases[i];
|
|
6891
|
+
const caseMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/case_${i}`, {
|
|
6892
|
+
addToSandstoneCore: true,
|
|
6893
|
+
creator: "sandstone",
|
|
6894
|
+
onConflict: "rename"
|
|
6895
|
+
});
|
|
6896
|
+
caseMCFunction.node.body = caseNode.body.flatMap((n) => this.visit(n));
|
|
6897
|
+
caseData.push({
|
|
6898
|
+
Value: caseNode.value,
|
|
6899
|
+
Index: NBT.int(i)
|
|
6900
|
+
});
|
|
6901
|
+
}
|
|
6902
|
+
initMCFunction.push(() => values.set(caseData));
|
|
6903
|
+
const innerMCFunction = new MCFunctionClass(this.core, `${switchMCFunction.name}/inner`, {
|
|
6904
|
+
addToSandstoneCore: true,
|
|
6905
|
+
creator: "sandstone",
|
|
6906
|
+
onConflict: "rename"
|
|
6907
|
+
});
|
|
6908
|
+
this.core.enterMCFunction(innerMCFunction);
|
|
6909
|
+
Macro2.returnCmd.run.functionCmd(Macro2`${switchMCFunction.name}/case_${index}`);
|
|
6910
|
+
this.core.exitMCFunction();
|
|
6911
|
+
const hasFallback = conditionCases.length > 0 || defaultCase !== undefined;
|
|
6912
|
+
if (hasFallback) {
|
|
6913
|
+
const ifNode = new IfNode(this.core, index._toMinecraftCondition(), undefined, switchMCFunction.node);
|
|
6914
|
+
switchMCFunction.node.enterContext(ifNode, false);
|
|
6915
|
+
functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
6916
|
+
switchMCFunction.node.exitContext();
|
|
6917
|
+
switchMCFunction.node.body.push(ifNode);
|
|
6918
|
+
this.buildFallback(ifNode, value, conditionCases, defaultCase, switchMCFunction);
|
|
6919
|
+
} else {
|
|
6920
|
+
this.pack.commands.execute.if.data.storage(index.currentTarget, index.path).run.returnCmd.run.functionCmd(innerMCFunction.name, "with", switchMCFunction.macroPoint);
|
|
6921
|
+
}
|
|
6922
|
+
}
|
|
6923
|
+
this.core.exitMCFunction();
|
|
6924
|
+
} else {
|
|
6925
|
+
this.core.enterMCFunction(switchMCFunction);
|
|
6926
|
+
this.buildFallback(undefined, value, conditionCases, defaultCase, switchMCFunction);
|
|
6927
|
+
this.core.exitMCFunction();
|
|
6928
|
+
const canInline = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
6929
|
+
if (canInline) {
|
|
6930
|
+
this.core.resourceNodes.delete(switchMCFunction.node);
|
|
6931
|
+
for (const bodyNode of switchMCFunction.node.body) {
|
|
6932
|
+
if (bodyNode instanceof IfNode) {
|
|
6933
|
+
bodyNode.parentMCFunction = parentMCFunction;
|
|
6934
|
+
let lastIfNode = bodyNode;
|
|
6935
|
+
while (lastIfNode.nextFlowNode instanceof IfNode) {
|
|
6936
|
+
lastIfNode.nextFlowNode.parentMCFunction = parentMCFunction;
|
|
6937
|
+
lastIfNode = lastIfNode.nextFlowNode;
|
|
6938
|
+
}
|
|
6939
|
+
if (lastIfNode !== bodyNode) {
|
|
6940
|
+
switchMCFunction.node.body.push(lastIfNode);
|
|
6941
|
+
}
|
|
6942
|
+
}
|
|
6943
|
+
}
|
|
6944
|
+
return switchMCFunction.node.body;
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
const isLastNode = parentMCFunction && node === parentMCFunction.body.at(-1);
|
|
6948
|
+
if (hasStaticCases && !(value instanceof Score)) {
|
|
6949
|
+
const macroPoint = switchMCFunction.macroPoint;
|
|
6950
|
+
const resolvedValue = value instanceof DataPointPickClass ? value._toDataPoint() : value;
|
|
6951
|
+
const env0Point = macroPoint.select("env_0");
|
|
6952
|
+
const copyNode = new DataCommandNode(this.pack);
|
|
6953
|
+
copyNode.args = [
|
|
6954
|
+
"modify",
|
|
6955
|
+
"storage",
|
|
6956
|
+
env0Point.currentTarget,
|
|
6957
|
+
env0Point.path,
|
|
6958
|
+
"set",
|
|
6959
|
+
"from",
|
|
6960
|
+
resolvedValue.type,
|
|
6961
|
+
resolvedValue.currentTarget,
|
|
6962
|
+
resolvedValue.path
|
|
6963
|
+
];
|
|
6964
|
+
const funcNode2 = new FunctionCommandNode(this.pack, switchMCFunction.name);
|
|
6965
|
+
funcNode2.args.push("with", macroPoint.type, macroPoint.currentTarget, macroPoint.path);
|
|
6966
|
+
if (isLastNode) {
|
|
6967
|
+
const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
6968
|
+
callNode.body = [funcNode2];
|
|
6969
|
+
return [copyNode, callNode].flatMap((n) => this.visit(n));
|
|
6970
|
+
}
|
|
6971
|
+
return [copyNode, funcNode2].flatMap((n) => this.visit(n));
|
|
6972
|
+
}
|
|
6973
|
+
const funcNode = new FunctionCommandNode(this.pack, switchMCFunction.name);
|
|
6974
|
+
if (isLastNode) {
|
|
6975
|
+
const callNode = new ReturnRunCommandNode(this.pack, ["run"]);
|
|
6976
|
+
callNode.body = [funcNode];
|
|
6977
|
+
return this.visit(callNode);
|
|
6978
|
+
}
|
|
6979
|
+
return this.visit(funcNode);
|
|
6980
|
+
};
|
|
6981
|
+
buildFallback(_if, value, conditionCases, defaultCase, switchMCFunction, targetBody) {
|
|
6982
|
+
if (conditionCases.length === 0 && !defaultCase)
|
|
6983
|
+
return;
|
|
6984
|
+
const body = targetBody ?? switchMCFunction.node.body;
|
|
6985
|
+
if (conditionCases.length > 0) {
|
|
6986
|
+
const firstCondition = conditionCases[0].condition(value);
|
|
6987
|
+
const firstConditionNode = conditionToNode(firstCondition);
|
|
6988
|
+
let currentIfNode;
|
|
6989
|
+
if (_if === undefined) {
|
|
6990
|
+
currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
|
|
6991
|
+
currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
|
|
6992
|
+
body.push(currentIfNode);
|
|
6993
|
+
} else {
|
|
6994
|
+
currentIfNode = new IfNode(this.core, firstConditionNode, undefined, switchMCFunction.node);
|
|
6995
|
+
currentIfNode._isElseIf = true;
|
|
6996
|
+
_if.nextFlowNode = currentIfNode;
|
|
6997
|
+
currentIfNode.body = conditionCases[0].body.flatMap((n) => this.visit(n));
|
|
6998
|
+
}
|
|
6999
|
+
for (let i = 1;i < conditionCases.length; i++) {
|
|
7000
|
+
const condition2 = conditionCases[i].condition(value);
|
|
7001
|
+
const conditionNode = conditionToNode(condition2);
|
|
7002
|
+
const nextIfNode = new IfNode(this.core, conditionNode, undefined, switchMCFunction.node);
|
|
7003
|
+
nextIfNode._isElseIf = true;
|
|
7004
|
+
currentIfNode.nextFlowNode = nextIfNode;
|
|
7005
|
+
nextIfNode.body = conditionCases[i].body.flatMap((n) => this.visit(n));
|
|
7006
|
+
currentIfNode = nextIfNode;
|
|
7007
|
+
}
|
|
7008
|
+
if (defaultCase) {
|
|
7009
|
+
const elseNode = new ElseNode(this.core, () => {});
|
|
7010
|
+
elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
|
|
7011
|
+
currentIfNode.nextFlowNode = elseNode;
|
|
7012
|
+
}
|
|
7013
|
+
} else if (defaultCase) {
|
|
7014
|
+
if (_if === undefined) {
|
|
7015
|
+
const visitedNodes = defaultCase.body.flatMap((n) => this.visit(n));
|
|
7016
|
+
body.push(...visitedNodes);
|
|
7017
|
+
} else {
|
|
7018
|
+
const elseNode = new ElseNode(this.core, () => {});
|
|
7019
|
+
elseNode._body = defaultCase.body.flatMap((n) => this.visit(n));
|
|
7020
|
+
_if.nextFlowNode = elseNode;
|
|
7021
|
+
}
|
|
7022
|
+
}
|
|
7023
|
+
}
|
|
7024
|
+
visitStaticCaseNode = (_node) => {
|
|
7025
|
+
return [];
|
|
7026
|
+
};
|
|
7027
|
+
visitConditionCaseNode = (_node) => {
|
|
7028
|
+
return [];
|
|
7029
|
+
};
|
|
7030
|
+
visitDefaultCaseNode = (_node) => {
|
|
7031
|
+
return [];
|
|
7032
|
+
};
|
|
7033
|
+
};
|
|
7034
|
+
});
|
|
7035
|
+
|
|
6415
7036
|
// src/pack/visitors/unifyChainedExecutes.ts
|
|
6416
7037
|
var UnifyChainedExecutesVisitor;
|
|
6417
7038
|
var init_unifyChainedExecutes = __esm(() => {
|
|
@@ -6427,6 +7048,10 @@ var init_unifyChainedExecutes = __esm(() => {
|
|
|
6427
7048
|
node.body = chainedCommand.body;
|
|
6428
7049
|
node.args.push(...chainedCommand.args);
|
|
6429
7050
|
}
|
|
7051
|
+
const flattenedArgs = node.args.flat(1).filter((a) => a !== undefined && a !== null);
|
|
7052
|
+
if (flattenedArgs.length === 0 && node.body.length === 1) {
|
|
7053
|
+
return this.genericVisit(node.body[0]);
|
|
7054
|
+
}
|
|
6430
7055
|
return this.genericVisit(node);
|
|
6431
7056
|
};
|
|
6432
7057
|
};
|
|
@@ -6444,6 +7069,7 @@ var init_visitors2 = __esm(() => {
|
|
|
6444
7069
|
init_orTransformationVisitor();
|
|
6445
7070
|
init_simplifyExecuteFunction();
|
|
6446
7071
|
init_simplifyReturnRunFunction();
|
|
7072
|
+
init_switchTransformationVisitor();
|
|
6447
7073
|
init_unifyChainedExecutes();
|
|
6448
7074
|
});
|
|
6449
7075
|
|
|
@@ -6513,6 +7139,8 @@ class SandstonePack {
|
|
|
6513
7139
|
this.__rootObjective = undefined;
|
|
6514
7140
|
this.__initMCFunction = undefined;
|
|
6515
7141
|
this.objectives.clear();
|
|
7142
|
+
this.anonymousDataId = 0;
|
|
7143
|
+
this.anonymousScoreId = 0;
|
|
6516
7144
|
this.constants.clear();
|
|
6517
7145
|
this.tickedLoops = {};
|
|
6518
7146
|
this.dependencies.clear();
|
|
@@ -6575,7 +7203,7 @@ class SandstonePack {
|
|
|
6575
7203
|
return [namespace, ...resourceFolders, ...fullPath];
|
|
6576
7204
|
};
|
|
6577
7205
|
get _() {
|
|
6578
|
-
return
|
|
7206
|
+
return this.flow;
|
|
6579
7207
|
}
|
|
6580
7208
|
registerNewObjective = (objective) => {
|
|
6581
7209
|
this.objectives.add(objective);
|
|
@@ -6614,7 +7242,7 @@ class SandstonePack {
|
|
|
6614
7242
|
return this.Variable(undefined, name2).set(nbt, scale);
|
|
6615
7243
|
}
|
|
6616
7244
|
const [initialValue, name] = args;
|
|
6617
|
-
const anonymousScore = score2(`${name ?? "anon"}_${this.packUid}_${this.anonymousScoreId++}`);
|
|
7245
|
+
const anonymousScore = score2(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousScoreId++}` : ""}`);
|
|
6618
7246
|
if (initialValue === undefined) {
|
|
6619
7247
|
return anonymousScore;
|
|
6620
7248
|
}
|
|
@@ -6658,7 +7286,7 @@ class SandstonePack {
|
|
|
6658
7286
|
return this.DataVariable(undefined, name2).set(score2, storeType || "int", scale || 1);
|
|
6659
7287
|
}
|
|
6660
7288
|
const [initialValue, name] = args;
|
|
6661
|
-
const anonymousData = data.select(`${name ?? "anon"}_${this.packUid}_${this.anonymousDataId++}`);
|
|
7289
|
+
const anonymousData = data.select(`${name ?? "anon"}_${this.packUid}${name === undefined ? `_${this.anonymousDataId++}` : ""}`);
|
|
6662
7290
|
if (initialValue === undefined) {
|
|
6663
7291
|
return anonymousData;
|
|
6664
7292
|
}
|
|
@@ -7061,6 +7689,7 @@ class SandstonePack {
|
|
|
7061
7689
|
new InitConstantsVisitor(this),
|
|
7062
7690
|
new GenerateLazyMCFunction(this),
|
|
7063
7691
|
new LoopTransformationVisitor(this),
|
|
7692
|
+
new SwitchTransformationVisitor(this),
|
|
7064
7693
|
new OrTransformationVisitor(this),
|
|
7065
7694
|
new IfElseTransformationVisitor(this),
|
|
7066
7695
|
new ContainerCommandsToMCFunctionVisitor(this),
|
|
@@ -7111,7 +7740,7 @@ var init_pack = __esm(() => {
|
|
|
7111
7740
|
}
|
|
7112
7741
|
handleOutput = async (type, readFile, writeFile) => {
|
|
7113
7742
|
if (type === "output") {
|
|
7114
|
-
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
|
|
7743
|
+
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
|
|
7115
7744
|
}
|
|
7116
7745
|
};
|
|
7117
7746
|
};
|
|
@@ -7132,7 +7761,7 @@ var init_pack = __esm(() => {
|
|
|
7132
7761
|
}
|
|
7133
7762
|
handleOutput = async (type, readFile, writeFile) => {
|
|
7134
7763
|
if (type === "output") {
|
|
7135
|
-
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta));
|
|
7764
|
+
await writeFile("pack.mcmeta", JSON.stringify(this.packMcmeta, null, 2));
|
|
7136
7765
|
}
|
|
7137
7766
|
};
|
|
7138
7767
|
};
|
|
@@ -7207,7 +7836,11 @@ var init_src = __esm(() => {
|
|
|
7207
7836
|
return new Proxy(fn, {
|
|
7208
7837
|
get(_target, subProp) {
|
|
7209
7838
|
const method = sandstonePack[prop];
|
|
7210
|
-
|
|
7839
|
+
const value = method[subProp];
|
|
7840
|
+
if (typeof value === "function") {
|
|
7841
|
+
return value.bind(method);
|
|
7842
|
+
}
|
|
7843
|
+
return value;
|
|
7211
7844
|
},
|
|
7212
7845
|
apply(_target, _thisArg, args) {
|
|
7213
7846
|
const method = sandstonePack[prop];
|
|
@@ -7474,7 +8107,7 @@ function isTagClass(v) {
|
|
|
7474
8107
|
}
|
|
7475
8108
|
function objectToString(value) {
|
|
7476
8109
|
if (isMCFunctionClass(value)) {
|
|
7477
|
-
if (value.
|
|
8110
|
+
if (value.env && value.callback.length < 2) {
|
|
7478
8111
|
return value.node.sandstoneCore.pack.MCFunction(`${value.name}/_env`, () => value(), {
|
|
7479
8112
|
creator: "sandstone",
|
|
7480
8113
|
onConflict: "rename"
|
|
@@ -7490,7 +8123,7 @@ function objectToString(value) {
|
|
|
7490
8123
|
}
|
|
7491
8124
|
if (typeof value === "object") {
|
|
7492
8125
|
if (isMCFunctionClass(value.id)) {
|
|
7493
|
-
if (value.id.
|
|
8126
|
+
if (value.id.env && value.id.callback.length < 2) {
|
|
7494
8127
|
return {
|
|
7495
8128
|
id: value.id.node.sandstoneCore.pack.MCFunction(`${value.id.name}/_env`, () => value.id(), { creator: "sandstone", onConflict: "rename" }).name,
|
|
7496
8129
|
required: value.required
|
|
@@ -7524,7 +8157,7 @@ var init_tag2 = __esm(() => {
|
|
|
7524
8157
|
super(sandstoneCore2);
|
|
7525
8158
|
this.resource = resource2;
|
|
7526
8159
|
}
|
|
7527
|
-
getValue = () => jsonStringify(this.resource.tagJSON);
|
|
8160
|
+
getValue = () => jsonStringify(this.resource.tagJSON, this.resource._resourceType);
|
|
7528
8161
|
};
|
|
7529
8162
|
TAG_CLASS_BRAND = Symbol.for("sandstone.TagClass");
|
|
7530
8163
|
TagClass = class TagClass extends ResourceClass {
|
|
@@ -7740,7 +8373,12 @@ var init_DataSets = __esm(() => {
|
|
|
7740
8373
|
init_Data();
|
|
7741
8374
|
init_Score();
|
|
7742
8375
|
IterableDataClass = class IterableDataClass extends ConditionalDataPointPickClass {
|
|
7743
|
-
|
|
8376
|
+
iteratorType;
|
|
8377
|
+
constructor(sandstoneCore2, iteratorType) {
|
|
8378
|
+
super(sandstoneCore2);
|
|
8379
|
+
this.iteratorType = iteratorType;
|
|
8380
|
+
}
|
|
8381
|
+
iterator(_callback, _direction = "normal") {
|
|
7744
8382
|
throw new Error("Not implemented");
|
|
7745
8383
|
}
|
|
7746
8384
|
size() {
|
|
@@ -7749,24 +8387,30 @@ var init_DataSets = __esm(() => {
|
|
|
7749
8387
|
last() {
|
|
7750
8388
|
throw new Error("Not implemented");
|
|
7751
8389
|
}
|
|
7752
|
-
|
|
8390
|
+
continue(direction = "normal") {
|
|
7753
8391
|
throw new Error("Not implemented");
|
|
7754
8392
|
}
|
|
7755
8393
|
};
|
|
7756
8394
|
DataIndexMapClass = class DataIndexMapClass extends IterableDataClass {
|
|
7757
8395
|
pack;
|
|
7758
|
-
initialize;
|
|
7759
8396
|
entries = {};
|
|
7760
8397
|
dataPoint;
|
|
7761
8398
|
constructor(pack2, initialize, dataPoint2) {
|
|
7762
|
-
super(pack2.core);
|
|
8399
|
+
super(pack2.core, "map");
|
|
7763
8400
|
this.pack = pack2;
|
|
7764
|
-
this.initialize = initialize;
|
|
7765
8401
|
if (dataPoint2) {
|
|
7766
8402
|
this.dataPoint = dataPoint2;
|
|
7767
8403
|
} else {
|
|
7768
8404
|
this.dataPoint = this.pack.DataVariable(undefined, "IndexMap");
|
|
7769
8405
|
}
|
|
8406
|
+
if (pack2.core.currentMCFunction) {
|
|
8407
|
+
this.init(initialize);
|
|
8408
|
+
} else {
|
|
8409
|
+
const init = this.init;
|
|
8410
|
+
pack2.initMCFunction.push(() => init(initialize));
|
|
8411
|
+
}
|
|
8412
|
+
}
|
|
8413
|
+
init(initialize) {
|
|
7770
8414
|
for (const [i, [key, value]] of Object.entries(initialize).entries()) {
|
|
7771
8415
|
this.dataPoint.select("Index").select(key).set(i);
|
|
7772
8416
|
this.dataPoint.select("Entries").append([]);
|
|
@@ -7777,21 +8421,22 @@ var init_DataSets = __esm(() => {
|
|
|
7777
8421
|
}
|
|
7778
8422
|
}
|
|
7779
8423
|
__entryIterator;
|
|
7780
|
-
|
|
8424
|
+
entryIterator(direction) {
|
|
7781
8425
|
if (!this.__entryIterator) {
|
|
7782
|
-
this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select("
|
|
8426
|
+
this.__entryIterator = this.pack.DataVariable(this.dataPoint.select("Entries")).select(`[${direction === "normal" ? 0 : -1}]`);
|
|
7783
8427
|
}
|
|
7784
8428
|
return this.__entryIterator;
|
|
7785
8429
|
}
|
|
7786
|
-
iterator(callback) {
|
|
8430
|
+
iterator(callback, direction = "normal") {
|
|
7787
8431
|
this.__entryIterator = undefined;
|
|
8432
|
+
const entryIterator = this.entryIterator(direction);
|
|
7788
8433
|
return () => {
|
|
7789
|
-
callback([
|
|
7790
|
-
|
|
8434
|
+
callback([entryIterator.select("[0]").slice(0), entryIterator.select("[1]")]);
|
|
8435
|
+
entryIterator.remove();
|
|
7791
8436
|
};
|
|
7792
8437
|
}
|
|
7793
|
-
|
|
7794
|
-
return this.entryIterator._toMinecraftCondition();
|
|
8438
|
+
continue(direction = "normal") {
|
|
8439
|
+
return this.entryIterator(direction)._toMinecraftCondition();
|
|
7795
8440
|
}
|
|
7796
8441
|
size = () => this.dataPoint.select("Entries");
|
|
7797
8442
|
last = () => [this.dataPoint.select("Entries[-1][0]").slice(0), this.dataPoint.select("Entries[-1][1]")];
|
|
@@ -7900,33 +8545,42 @@ var init_DataSets = __esm(() => {
|
|
|
7900
8545
|
pack;
|
|
7901
8546
|
dataPoint;
|
|
7902
8547
|
constructor(pack2, initialize, dataPoint2) {
|
|
7903
|
-
super(pack2.core);
|
|
8548
|
+
super(pack2.core, "list");
|
|
7904
8549
|
this.pack = pack2;
|
|
7905
8550
|
if (dataPoint2) {
|
|
7906
8551
|
this.dataPoint = dataPoint2;
|
|
7907
8552
|
} else {
|
|
7908
8553
|
this.dataPoint = this.pack.DataVariable([], "Array");
|
|
7909
8554
|
}
|
|
8555
|
+
if (pack2.core.currentMCFunction) {
|
|
8556
|
+
this.init(initialize);
|
|
8557
|
+
} else {
|
|
8558
|
+
const init = this.init;
|
|
8559
|
+
pack2.initMCFunction.push(() => init(initialize));
|
|
8560
|
+
}
|
|
8561
|
+
}
|
|
8562
|
+
init(initialize) {
|
|
7910
8563
|
for (const entry of initialize) {
|
|
7911
8564
|
this.dataPoint.append(entry);
|
|
7912
8565
|
}
|
|
7913
8566
|
}
|
|
7914
8567
|
__entryIterator;
|
|
7915
|
-
|
|
8568
|
+
entryIterator(direction) {
|
|
7916
8569
|
if (!this.__entryIterator) {
|
|
7917
|
-
this.__entryIterator = this.pack.DataVariable(this.dataPoint).select("
|
|
8570
|
+
this.__entryIterator = this.pack.DataVariable(this.dataPoint).select(`[${direction === "normal" ? 0 : -1}]`);
|
|
7918
8571
|
}
|
|
7919
8572
|
return this.__entryIterator;
|
|
7920
8573
|
}
|
|
7921
|
-
iterator(callback) {
|
|
8574
|
+
iterator(callback, direction = "normal") {
|
|
7922
8575
|
this.__entryIterator = undefined;
|
|
8576
|
+
const entryIterator = this.entryIterator(direction);
|
|
7923
8577
|
return () => {
|
|
7924
|
-
callback([
|
|
7925
|
-
|
|
8578
|
+
callback([entryIterator]);
|
|
8579
|
+
entryIterator.remove();
|
|
7926
8580
|
};
|
|
7927
8581
|
}
|
|
7928
|
-
|
|
7929
|
-
return this.entryIterator._toMinecraftCondition();
|
|
8582
|
+
continue(direction = "normal") {
|
|
8583
|
+
return this.entryIterator(direction)._toMinecraftCondition();
|
|
7930
8584
|
}
|
|
7931
8585
|
size = () => this.dataPoint;
|
|
7932
8586
|
last = () => this.dataPoint.select("[-1]");
|
|
@@ -8008,7 +8662,11 @@ var init_JSONTextComponentClass = __esm(() => {
|
|
|
8008
8662
|
this.jsonTextComponent = jsonTextComponent2;
|
|
8009
8663
|
}
|
|
8010
8664
|
toString() {
|
|
8011
|
-
|
|
8665
|
+
const component = toComponent(this.jsonTextComponent);
|
|
8666
|
+
if (typeof component === "string") {
|
|
8667
|
+
return `"${component}"`;
|
|
8668
|
+
}
|
|
8669
|
+
return JSON.stringify(component, function(key, value) {
|
|
8012
8670
|
if (Array.isArray(this)) {
|
|
8013
8671
|
const realValue = this[Number.parseInt(key, 10)];
|
|
8014
8672
|
return toComponent(realValue);
|
|
@@ -8223,14 +8881,52 @@ var init_Label = __esm(() => {
|
|
|
8223
8881
|
LabelClass = makeClassCallable(_RawLabelClass);
|
|
8224
8882
|
});
|
|
8225
8883
|
|
|
8884
|
+
// src/commands/implementations/server/function.ts
|
|
8885
|
+
var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
|
|
8886
|
+
var init_function2 = __esm(() => {
|
|
8887
|
+
init_nodes();
|
|
8888
|
+
init_tag2();
|
|
8889
|
+
init_NBTs();
|
|
8890
|
+
FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
|
|
8891
|
+
FunctionCommandNode = class FunctionCommandNode extends CommandNode {
|
|
8892
|
+
[FUNCTION_COMMAND_NODE_BRAND] = true;
|
|
8893
|
+
command = "function";
|
|
8894
|
+
static [Symbol.hasInstance](instance) {
|
|
8895
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
|
|
8896
|
+
}
|
|
8897
|
+
};
|
|
8898
|
+
FunctionCommand = class FunctionCommand extends CommandArguments {
|
|
8899
|
+
NodeType = FunctionCommandNode;
|
|
8900
|
+
function(mcFunction, params, pointOrType, target, path5) {
|
|
8901
|
+
const args = [];
|
|
8902
|
+
if (params) {
|
|
8903
|
+
if (params === "with" && pointOrType) {
|
|
8904
|
+
args.push("with");
|
|
8905
|
+
if (typeof pointOrType === "string") {
|
|
8906
|
+
args.push(pointOrType, target, path5 ?? "{}");
|
|
8907
|
+
} else {
|
|
8908
|
+
const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
|
|
8909
|
+
args.push(point.type, point.currentTarget, point.path);
|
|
8910
|
+
}
|
|
8911
|
+
} else {
|
|
8912
|
+
args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
|
|
8913
|
+
}
|
|
8914
|
+
}
|
|
8915
|
+
return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
|
|
8916
|
+
}
|
|
8917
|
+
};
|
|
8918
|
+
});
|
|
8919
|
+
|
|
8226
8920
|
// src/variables/Loop.ts
|
|
8227
8921
|
var LOOP_ARGUMENT_BRAND, LoopArgument;
|
|
8228
8922
|
var init_Loop = __esm(() => {
|
|
8923
|
+
init_function2();
|
|
8229
8924
|
init_nodes();
|
|
8230
8925
|
LOOP_ARGUMENT_BRAND = Symbol.for("sandstone.LoopArgument");
|
|
8231
8926
|
LoopArgument = class LoopArgument extends Node {
|
|
8232
8927
|
pack;
|
|
8233
8928
|
[LOOP_ARGUMENT_BRAND] = true;
|
|
8929
|
+
loopIfNode = null;
|
|
8234
8930
|
constructor(pack2) {
|
|
8235
8931
|
super(pack2.core);
|
|
8236
8932
|
this.pack = pack2;
|
|
@@ -8240,7 +8936,15 @@ var init_Loop = __esm(() => {
|
|
|
8240
8936
|
return this.toLoop();
|
|
8241
8937
|
}
|
|
8242
8938
|
toLoop() {
|
|
8243
|
-
|
|
8939
|
+
const loopExecute = this.loopIfNode?.resultingExecuteNode;
|
|
8940
|
+
if (loopExecute?.createdMCFunction) {
|
|
8941
|
+
const funcNode = new FunctionCommandNode(this.pack, loopExecute.createdMCFunction.name);
|
|
8942
|
+
if (loopExecute.macroStorage) {
|
|
8943
|
+
funcNode.args.push("with", "storage", loopExecute.macroStorage.currentTarget, loopExecute.macroStorage.path);
|
|
8944
|
+
}
|
|
8945
|
+
return funcNode.getValue();
|
|
8946
|
+
}
|
|
8947
|
+
return new FunctionCommandNode(this.pack, this.pack.core.currentNode);
|
|
8244
8948
|
}
|
|
8245
8949
|
static [Symbol.hasInstance](instance) {
|
|
8246
8950
|
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[LOOP_ARGUMENT_BRAND] === true;
|
|
@@ -8280,7 +8984,6 @@ var init_Objective = __esm(() => {
|
|
|
8280
8984
|
return formatDebugString(this.constructor.name, {
|
|
8281
8985
|
name: this.name,
|
|
8282
8986
|
criteria: this.criteria,
|
|
8283
|
-
display: this.display,
|
|
8284
8987
|
creator: this.creator
|
|
8285
8988
|
}, undefined, options.indent);
|
|
8286
8989
|
}
|
|
@@ -8336,13 +9039,13 @@ var init_Sleep = __esm(() => {
|
|
|
8336
9039
|
const { execute } = commands;
|
|
8337
9040
|
const name = `__sandstone:asyncTimer.${currentFunction.resource.name.replace(/[:/]/g, ".")}`;
|
|
8338
9041
|
const timer = new ObjectiveClass(core.pack, name.replace(":", "."), "dummy", undefined, { creator: "sandstone" });
|
|
8339
|
-
execute.store.result
|
|
9042
|
+
execute.store.result(timer("@s")).run.time.query("gametime");
|
|
8340
9043
|
timer("@s").add(Duration);
|
|
8341
9044
|
const label2 = Label(name);
|
|
8342
9045
|
label2("@s").add();
|
|
8343
9046
|
this.mcfunction.unshift(() => label2("@s").remove());
|
|
8344
9047
|
schedule = MCFunction(`${this.mcfunction.name}/_context`, () => {
|
|
8345
|
-
execute.store.result
|
|
9048
|
+
execute.store.result(timer("#current")).run.time.query("gametime");
|
|
8346
9049
|
execute.as(Selector("@e", { tag: label2.fullName })).if.score(timer("@s"), "=", timer("#current")).at("@s").run.functionCmd(this.mcfunction);
|
|
8347
9050
|
}, {
|
|
8348
9051
|
packType: currentFunction.resource.packType
|
|
@@ -8407,42 +9110,6 @@ var init_Trigger = __esm(() => {
|
|
|
8407
9110
|
checkTriggers = {};
|
|
8408
9111
|
});
|
|
8409
9112
|
|
|
8410
|
-
// src/commands/implementations/server/function.ts
|
|
8411
|
-
var FUNCTION_COMMAND_NODE_BRAND, FunctionCommandNode, FunctionCommand;
|
|
8412
|
-
var init_function2 = __esm(() => {
|
|
8413
|
-
init_nodes();
|
|
8414
|
-
init_tag2();
|
|
8415
|
-
init_NBTs();
|
|
8416
|
-
FUNCTION_COMMAND_NODE_BRAND = Symbol.for("sandstone.FunctionCommandNode");
|
|
8417
|
-
FunctionCommandNode = class FunctionCommandNode extends CommandNode {
|
|
8418
|
-
[FUNCTION_COMMAND_NODE_BRAND] = true;
|
|
8419
|
-
command = "function";
|
|
8420
|
-
static [Symbol.hasInstance](instance) {
|
|
8421
|
-
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[FUNCTION_COMMAND_NODE_BRAND] === true;
|
|
8422
|
-
}
|
|
8423
|
-
};
|
|
8424
|
-
FunctionCommand = class FunctionCommand extends CommandArguments {
|
|
8425
|
-
NodeType = FunctionCommandNode;
|
|
8426
|
-
function(mcFunction, params, pointOrType, target, path5) {
|
|
8427
|
-
const args = [];
|
|
8428
|
-
if (params) {
|
|
8429
|
-
if (params === "with" && pointOrType) {
|
|
8430
|
-
args.push("with");
|
|
8431
|
-
if (typeof pointOrType === "string") {
|
|
8432
|
-
args.push(pointOrType, target, path5 ?? "{}");
|
|
8433
|
-
} else {
|
|
8434
|
-
const point = Object.hasOwn(pointOrType, "_toDataPoint") ? pointOrType._toDataPoint : pointOrType;
|
|
8435
|
-
args.push(point.type, point.currentTarget, point.path);
|
|
8436
|
-
}
|
|
8437
|
-
} else {
|
|
8438
|
-
args.push(typeof params === "object" && params.toMacro ? params : nbtStringifier(params));
|
|
8439
|
-
}
|
|
8440
|
-
}
|
|
8441
|
-
return this.finalCommand([mcFunction instanceof TagClass ? `#${mcFunction}` : mcFunction, ...args]);
|
|
8442
|
-
}
|
|
8443
|
-
};
|
|
8444
|
-
});
|
|
8445
|
-
|
|
8446
9113
|
// src/commands/implementations/entity/execute.ts
|
|
8447
9114
|
function createDeferredMacroExecute(pack2, executeChain, options) {
|
|
8448
9115
|
const { childFunctionName, prependArgs } = options;
|
|
@@ -8465,7 +9132,7 @@ function createDeferredMacroExecute(pack2, executeChain, options) {
|
|
|
8465
9132
|
childFunctionNode = childFunction.node;
|
|
8466
9133
|
} else {
|
|
8467
9134
|
const childFunction = pack2.MCFunction(`${currentFunction.resource.name}/${childFunctionName}`, () => {}, { creator: "sandstone", onConflict: "rename" });
|
|
8468
|
-
pack2.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage);
|
|
9135
|
+
pack2.commands.functionCmd(childFunction.name, "with", "storage", options.macroStorage.currentTarget, options.macroStorage.path);
|
|
8469
9136
|
childFunctionNode = childFunction.node;
|
|
8470
9137
|
}
|
|
8471
9138
|
childFunctionNode.body.push(macroNode);
|
|
@@ -8549,15 +9216,15 @@ var init_execute = __esm(() => {
|
|
|
8549
9216
|
isSingleExecute;
|
|
8550
9217
|
givenCallbackName;
|
|
8551
9218
|
macroStorage;
|
|
8552
|
-
|
|
9219
|
+
pendingCommit;
|
|
9220
|
+
createdMCFunction = null;
|
|
9221
|
+
constructor(sandstonePack2, args = [], { isFake = false, isSingleExecute = true, givenCallbackName = undefined, body = [], macroStorage = undefined, pendingCommit = false } = {}) {
|
|
8553
9222
|
super(sandstonePack2, ...args);
|
|
8554
9223
|
this.givenCallbackName = givenCallbackName;
|
|
8555
9224
|
this.isSingleExecute = isSingleExecute;
|
|
8556
9225
|
this.isFake = isFake;
|
|
8557
9226
|
this.macroStorage = macroStorage;
|
|
8558
|
-
|
|
8559
|
-
this.isMacro = true;
|
|
8560
|
-
}
|
|
9227
|
+
this.pendingCommit = pendingCommit;
|
|
8561
9228
|
this.append(...body);
|
|
8562
9229
|
}
|
|
8563
9230
|
get callbackName() {
|
|
@@ -8568,6 +9235,9 @@ var init_execute = __esm(() => {
|
|
|
8568
9235
|
this.body.push(node);
|
|
8569
9236
|
if (this.isSingleExecute) {
|
|
8570
9237
|
this.sandstoneCore.getCurrentMCFunctionOrThrow().exitContext();
|
|
9238
|
+
if (this.pendingCommit && !this.commited) {
|
|
9239
|
+
this.commit();
|
|
9240
|
+
}
|
|
8571
9241
|
}
|
|
8572
9242
|
}
|
|
8573
9243
|
return nodes2.length === 1 ? nodes2[0] : nodes2;
|
|
@@ -8616,9 +9286,10 @@ var init_execute = __esm(() => {
|
|
|
8616
9286
|
});
|
|
8617
9287
|
const mcFunctionNode = mcFunction.node;
|
|
8618
9288
|
mcFunctionNode.body = this.body;
|
|
9289
|
+
this.createdMCFunction = mcFunction;
|
|
8619
9290
|
const mcFunctionCall = new FunctionCommandNode(this.sandstonePack, mcFunction);
|
|
8620
9291
|
if (this.macroStorage) {
|
|
8621
|
-
mcFunctionCall.args.push("with", "storage", this.macroStorage,
|
|
9292
|
+
mcFunctionCall.args.push("with", "storage", this.macroStorage.currentTarget, this.macroStorage.path);
|
|
8622
9293
|
}
|
|
8623
9294
|
this.body = [mcFunctionCall];
|
|
8624
9295
|
return { node: this, mcFunction: mcFunctionNode };
|
|
@@ -8631,20 +9302,30 @@ var init_execute = __esm(() => {
|
|
|
8631
9302
|
block = (targetPos, path5, type, scale) => this.nestedExecute(["block", coordinatesParser(targetPos), path5, type, scale]);
|
|
8632
9303
|
bossbar = (id2, type) => this.nestedExecute(["bossbar", id2, type]);
|
|
8633
9304
|
entity = (target, path5, type, scale) => this.nestedExecute(["entity", targetParser(target), path5, type, scale]);
|
|
8634
|
-
score(
|
|
8635
|
-
if (isScore(args[0])) {
|
|
8636
|
-
return this.nestedExecute(["score", args[0]]);
|
|
8637
|
-
}
|
|
8638
|
-
return this.nestedExecute(["score", targetParser(args[0]), args[1]]);
|
|
8639
|
-
}
|
|
9305
|
+
score = (targets, objective2) => this.nestedExecute(["score", targetParser(targets), objective2]);
|
|
8640
9306
|
storage = (target, path5, type, scale = 1) => this.nestedExecute(["storage", target, path5, type, scale]);
|
|
8641
9307
|
};
|
|
8642
9308
|
ExecuteStoreCommand = class ExecuteStoreCommand extends ExecuteCommandPart {
|
|
9309
|
+
_storeCallable(cmd, target, type, scale) {
|
|
9310
|
+
if (isScore(target)) {
|
|
9311
|
+
return cmd.score(target.target, target.objective);
|
|
9312
|
+
}
|
|
9313
|
+
const resolvedType = type ?? "int";
|
|
9314
|
+
if (target.type === "block") {
|
|
9315
|
+
return cmd.block(coordinatesParser(target.currentTarget), target.path, resolvedType, scale);
|
|
9316
|
+
}
|
|
9317
|
+
if (target.type === "entity") {
|
|
9318
|
+
return cmd.entity(target.currentTarget, target.path, resolvedType, scale);
|
|
9319
|
+
}
|
|
9320
|
+
return cmd.storage(target.currentTarget, target.path, resolvedType, scale);
|
|
9321
|
+
}
|
|
8643
9322
|
get result() {
|
|
8644
|
-
|
|
9323
|
+
const cmd = this.subCommand([["result"]], ExecuteStoreArgsCommand, false);
|
|
9324
|
+
return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
|
|
8645
9325
|
}
|
|
8646
9326
|
get success() {
|
|
8647
|
-
|
|
9327
|
+
const cmd = this.subCommand([["success"]], ExecuteStoreArgsCommand, false);
|
|
9328
|
+
return makeCallable(cmd, (target, type, scale) => this._storeCallable(cmd, target, type, scale), true);
|
|
8648
9329
|
}
|
|
8649
9330
|
};
|
|
8650
9331
|
ExecuteDataArgsCommand = class ExecuteDataArgsCommand extends ExecuteCommandPart {
|
|
@@ -8769,6 +9450,9 @@ var init_execute = __esm(() => {
|
|
|
8769
9450
|
const node = this.getNode();
|
|
8770
9451
|
const commands = new Proxy(this.sandstonePack.commands, {
|
|
8771
9452
|
get: (_t, p, _r) => {
|
|
9453
|
+
if (!node.commited) {
|
|
9454
|
+
node.pendingCommit = true;
|
|
9455
|
+
}
|
|
8772
9456
|
this.sandstoneCore.getCurrentMCFunctionOrThrow().enterContext(node, false);
|
|
8773
9457
|
return this.sandstonePack.commands[p];
|
|
8774
9458
|
}
|
|
@@ -8779,7 +9463,7 @@ var init_execute = __esm(() => {
|
|
|
8779
9463
|
node.givenCallbackName = args[0];
|
|
8780
9464
|
}
|
|
8781
9465
|
node.isSingleExecute = false;
|
|
8782
|
-
this.sandstoneCore.insideContext(node, callback,
|
|
9466
|
+
this.sandstoneCore.insideContext(node, callback, !node.commited);
|
|
8783
9467
|
return new FinalCommandOutput(node);
|
|
8784
9468
|
}, true);
|
|
8785
9469
|
}
|
|
@@ -8999,7 +9683,7 @@ class UUIDClass {
|
|
|
8999
9683
|
}
|
|
9000
9684
|
if (this.data || this.scores) {
|
|
9001
9685
|
const pack2 = this.core.pack;
|
|
9002
|
-
const { MCFunction, getTempStorage, commands: commands2 } = pack2;
|
|
9686
|
+
const { MCFunction, getTempStorage, commands: commands2, Macro: Macro2, Data } = pack2;
|
|
9003
9687
|
const { data } = commands2;
|
|
9004
9688
|
let sourceData = this.data;
|
|
9005
9689
|
if (!sourceData && this.scores) {
|
|
@@ -9013,15 +9697,15 @@ class UUIDClass {
|
|
|
9013
9697
|
tempUUID.set(sourceData);
|
|
9014
9698
|
const cacheKeyVar = this.primarySource === "scores" && this.scores ? this.scores[0] : tempUUID;
|
|
9015
9699
|
const currentFunction = this.core.getCurrentMCFunctionOrThrow();
|
|
9016
|
-
const
|
|
9017
|
-
|
|
9018
|
-
|
|
9019
|
-
|
|
9700
|
+
const uuidLookup = Data("storage", "__sandstone:temp", "uuid_lookup");
|
|
9701
|
+
MCFunction(`${currentFunction.resource.name}/__uuid_lookup`, [cacheKeyVar], () => {
|
|
9702
|
+
Macro2.data.modify(uuidLookup.select("uuid_string")).set.from.storage(UUID_CACHE.STORAGE, Macro2`"${cacheKeyVar}"`);
|
|
9703
|
+
}, { creator: "sandstone", onConflict: "rename" })();
|
|
9020
9704
|
const deferredExecute = new ExecuteCommand(pack2, undefined, false);
|
|
9021
9705
|
return createDeferredMacroExecute(pack2, deferredExecute, {
|
|
9022
9706
|
childFunctionName: "__uuid_execute",
|
|
9023
9707
|
prependArgs: () => [["as", "$(uuid_string)"]],
|
|
9024
|
-
macroStorage:
|
|
9708
|
+
macroStorage: uuidLookup
|
|
9025
9709
|
});
|
|
9026
9710
|
}
|
|
9027
9711
|
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.");
|
|
@@ -10046,7 +10730,7 @@ var init_reload = __esm(() => {
|
|
|
10046
10730
|
});
|
|
10047
10731
|
|
|
10048
10732
|
// src/commands/implementations/server/return.ts
|
|
10049
|
-
var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, ReturnCommandNode, ReturnCommand;
|
|
10733
|
+
var RETURN_RUN_COMMAND_NODE_BRAND, ReturnRunCommandNode, ReturnArgumentsCommand, RETURN_COMMAND_NODE_BRAND, ReturnCommandNode, ReturnCommand;
|
|
10050
10734
|
var init_return = __esm(() => {
|
|
10051
10735
|
init_nodes();
|
|
10052
10736
|
init_utils();
|
|
@@ -10056,9 +10740,11 @@ var init_return = __esm(() => {
|
|
|
10056
10740
|
[RETURN_RUN_COMMAND_NODE_BRAND] = true;
|
|
10057
10741
|
command = "return";
|
|
10058
10742
|
isSingleExecute;
|
|
10059
|
-
|
|
10743
|
+
isFlowControl;
|
|
10744
|
+
constructor(sandstonePack2, args = [], { isSingleExecute = true, body = [], isFlowControl = false } = {}) {
|
|
10060
10745
|
super(sandstonePack2, ...args);
|
|
10061
10746
|
this.isSingleExecute = isSingleExecute;
|
|
10747
|
+
this.isFlowControl = isFlowControl;
|
|
10062
10748
|
this.append(...body);
|
|
10063
10749
|
}
|
|
10064
10750
|
getValue = () => {
|
|
@@ -10118,8 +10804,13 @@ var init_return = __esm(() => {
|
|
|
10118
10804
|
}, true);
|
|
10119
10805
|
}
|
|
10120
10806
|
};
|
|
10807
|
+
RETURN_COMMAND_NODE_BRAND = Symbol.for("sandstone.ReturnCommandNode");
|
|
10121
10808
|
ReturnCommandNode = class ReturnCommandNode extends CommandNode {
|
|
10809
|
+
[RETURN_COMMAND_NODE_BRAND] = true;
|
|
10122
10810
|
command = "return";
|
|
10811
|
+
static [Symbol.hasInstance](instance) {
|
|
10812
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && instance[RETURN_COMMAND_NODE_BRAND] === true;
|
|
10813
|
+
}
|
|
10123
10814
|
};
|
|
10124
10815
|
ReturnCommand = class ReturnCommand extends CommandArguments {
|
|
10125
10816
|
NodeType = ReturnCommandNode;
|
|
@@ -10301,8 +10992,8 @@ var init_version = __esm(() => {
|
|
|
10301
10992
|
// src/commands/implementations/world/data.ts
|
|
10302
10993
|
var DataCommandNode, DataCommand, DataGetCommand, DataMergeCommand, DataModifyFromCommand, DataModifyValuesCommand, DataModifyTypeCommand, DataModifyCommand, DataRemoveCommand;
|
|
10303
10994
|
var init_data = __esm(() => {
|
|
10304
|
-
init_core();
|
|
10305
10995
|
init_nodes();
|
|
10996
|
+
init_utils();
|
|
10306
10997
|
init_NBTs();
|
|
10307
10998
|
init_parsers();
|
|
10308
10999
|
DataCommandNode = class DataCommandNode extends CommandNode {
|
|
@@ -10311,22 +11002,55 @@ var init_data = __esm(() => {
|
|
|
10311
11002
|
DataCommand = class DataCommand extends CommandArguments {
|
|
10312
11003
|
NodeType = DataCommandNode;
|
|
10313
11004
|
get get() {
|
|
10314
|
-
|
|
11005
|
+
const cmd = this.subCommand(["get"], DataGetCommand, false);
|
|
11006
|
+
return makeCallable(cmd, (dataPoint2, scale) => {
|
|
11007
|
+
if (dataPoint2.type === "block") {
|
|
11008
|
+
return cmd.block(coordinatesParser(dataPoint2.currentTarget), dataPoint2.path, scale);
|
|
11009
|
+
}
|
|
11010
|
+
if (dataPoint2.type === "entity") {
|
|
11011
|
+
return cmd.entity(dataPoint2.currentTarget, dataPoint2.path, scale);
|
|
11012
|
+
}
|
|
11013
|
+
return cmd.storage(dataPoint2.currentTarget, dataPoint2.path, scale);
|
|
11014
|
+
});
|
|
10315
11015
|
}
|
|
10316
11016
|
get merge() {
|
|
10317
11017
|
return this.subCommand(["merge"], DataMergeCommand, false);
|
|
10318
11018
|
}
|
|
10319
11019
|
get modify() {
|
|
10320
|
-
|
|
11020
|
+
const cmd = this.subCommand(["modify"], DataModifyCommand, false);
|
|
11021
|
+
return makeCallable(cmd, (dataPoint2) => {
|
|
11022
|
+
if (dataPoint2.type === "block") {
|
|
11023
|
+
return cmd.block(coordinatesParser(dataPoint2.currentTarget), dataPoint2.path);
|
|
11024
|
+
}
|
|
11025
|
+
if (dataPoint2.type === "entity") {
|
|
11026
|
+
return cmd.entity(dataPoint2.currentTarget, dataPoint2.path);
|
|
11027
|
+
}
|
|
11028
|
+
return cmd.storage(dataPoint2.currentTarget, dataPoint2.path);
|
|
11029
|
+
});
|
|
10321
11030
|
}
|
|
10322
11031
|
get remove() {
|
|
10323
|
-
|
|
11032
|
+
const cmd = this.subCommand(["remove"], DataRemoveCommand, false);
|
|
11033
|
+
return makeCallable(cmd, (dataPoint2) => {
|
|
11034
|
+
if (dataPoint2.type === "block") {
|
|
11035
|
+
return cmd.block(coordinatesParser(dataPoint2.currentTarget), dataPoint2.path);
|
|
11036
|
+
}
|
|
11037
|
+
if (dataPoint2.type === "entity") {
|
|
11038
|
+
return cmd.entity(dataPoint2.currentTarget, dataPoint2.path);
|
|
11039
|
+
}
|
|
11040
|
+
return cmd.storage(dataPoint2.currentTarget, dataPoint2.path);
|
|
11041
|
+
});
|
|
10324
11042
|
}
|
|
10325
11043
|
};
|
|
10326
11044
|
DataGetCommand = class DataGetCommand extends CommandArguments {
|
|
10327
|
-
block = (targetPos, path5, scale) =>
|
|
10328
|
-
|
|
10329
|
-
|
|
11045
|
+
block = (targetPos, path5, scale) => {
|
|
11046
|
+
return this.finalCommand(["block", coordinatesParser(targetPos), path5, scale]);
|
|
11047
|
+
};
|
|
11048
|
+
entity = (target, path5, scale) => {
|
|
11049
|
+
return this.finalCommand(["entity", targetParser(target), path5, scale]);
|
|
11050
|
+
};
|
|
11051
|
+
storage = (target, path5, scale) => {
|
|
11052
|
+
return this.finalCommand(["storage", target, path5, scale]);
|
|
11053
|
+
};
|
|
10330
11054
|
};
|
|
10331
11055
|
DataMergeCommand = class DataMergeCommand extends CommandArguments {
|
|
10332
11056
|
block = (targetPos, nbt3) => this.finalCommand(["block", coordinatesParser(targetPos), nbtStringifier(nbt3)]);
|
|
@@ -10336,20 +11060,22 @@ var init_data = __esm(() => {
|
|
|
10336
11060
|
DataModifyFromCommand = class DataModifyFromCommand extends CommandArguments {
|
|
10337
11061
|
block = (sourcePosition, sourcePath) => this.finalCommand(["block", coordinatesParser(sourcePosition), sourcePath]);
|
|
10338
11062
|
entity = (source, sourcePath) => this.finalCommand(["entity", targetParser(source), sourcePath]);
|
|
10339
|
-
storage(source, sourcePath) {
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
storageArg = source;
|
|
10343
|
-
} else {
|
|
10344
|
-
const dataPoint2 = source;
|
|
10345
|
-
storageArg = `${dataPoint2.currentTarget} ${dataPoint2.path}`;
|
|
10346
|
-
}
|
|
10347
|
-
return this.finalCommand(["storage", storageArg, sourcePath]);
|
|
10348
|
-
}
|
|
11063
|
+
storage = (source, sourcePath) => {
|
|
11064
|
+
return this.finalCommand(["storage", source, sourcePath]);
|
|
11065
|
+
};
|
|
10349
11066
|
};
|
|
10350
11067
|
DataModifyValuesCommand = class DataModifyValuesCommand extends CommandArguments {
|
|
10351
11068
|
get from() {
|
|
10352
|
-
|
|
11069
|
+
const cmd = this.subCommand(["from"], DataModifyFromCommand, false);
|
|
11070
|
+
return makeCallable(cmd, (dataPoint2) => {
|
|
11071
|
+
if (dataPoint2.type === "block") {
|
|
11072
|
+
return cmd.block(coordinatesParser(dataPoint2.currentTarget), dataPoint2.path);
|
|
11073
|
+
}
|
|
11074
|
+
if (dataPoint2.type === "entity") {
|
|
11075
|
+
return cmd.entity(dataPoint2.currentTarget, dataPoint2.path);
|
|
11076
|
+
}
|
|
11077
|
+
return cmd.storage(dataPoint2.currentTarget, dataPoint2.path);
|
|
11078
|
+
});
|
|
10353
11079
|
}
|
|
10354
11080
|
string = {
|
|
10355
11081
|
block: (sourcePosition, sourcePath, start, end) => {
|
|
@@ -10408,14 +11134,26 @@ var init_data = __esm(() => {
|
|
|
10408
11134
|
}
|
|
10409
11135
|
};
|
|
10410
11136
|
DataModifyCommand = class DataModifyCommand extends CommandArguments {
|
|
10411
|
-
block = (targetPos, targetPath) =>
|
|
10412
|
-
|
|
10413
|
-
|
|
11137
|
+
block = (targetPos, targetPath) => {
|
|
11138
|
+
return this.subCommand(["block", coordinatesParser(targetPos), targetPath], DataModifyTypeCommand, false);
|
|
11139
|
+
};
|
|
11140
|
+
entity = (target, targetPath) => {
|
|
11141
|
+
return this.subCommand(["entity", targetParser(target), targetPath], DataModifyTypeCommand, false);
|
|
11142
|
+
};
|
|
11143
|
+
storage = (target, targetPath) => {
|
|
11144
|
+
return this.subCommand(["storage", target, targetPath], DataModifyTypeCommand, false);
|
|
11145
|
+
};
|
|
10414
11146
|
};
|
|
10415
11147
|
DataRemoveCommand = class DataRemoveCommand extends CommandArguments {
|
|
10416
|
-
block = (targetPos, targetPath) =>
|
|
10417
|
-
|
|
10418
|
-
|
|
11148
|
+
block = (targetPos, targetPath) => {
|
|
11149
|
+
return this.finalCommand(["block", coordinatesParser(targetPos), targetPath]);
|
|
11150
|
+
};
|
|
11151
|
+
entity = (target, targetPath) => {
|
|
11152
|
+
return this.finalCommand(["entity", targetParser(target), targetPath]);
|
|
11153
|
+
};
|
|
11154
|
+
storage = (target, targetPath) => {
|
|
11155
|
+
return this.finalCommand(["storage", target, targetPath]);
|
|
11156
|
+
};
|
|
10419
11157
|
};
|
|
10420
11158
|
});
|
|
10421
11159
|
|