sandstone 1.0.0-beta.2 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +315 -16
- package/bun.lock +18 -22
- package/dist/arguments/index.js +1093 -367
- package/dist/arguments/selector.d.ts +6 -6
- package/dist/commands/implementations/block/setblock.d.ts +6 -9
- package/dist/commands/implementations/entity/execute.d.ts +36 -21
- package/dist/commands/implementations/server/return.d.ts +14 -7
- package/dist/commands/implementations/world/data.d.ts +29 -32
- package/dist/commands/index.js +1102 -364
- package/dist/core/index.js +2207 -1481
- package/dist/core/resources/datapack/mcfunction.d.ts +1 -1
- package/dist/core/resources/datapack/variant.d.ts +1 -1
- package/dist/core/resources/resource.d.ts +4 -4
- package/dist/flow/Flow.d.ts +21 -22
- package/dist/flow/if_else.d.ts +8 -3
- package/dist/flow/index.d.ts +1 -0
- package/dist/flow/index.js +2196 -1451
- package/dist/flow/loop.d.ts +5 -4
- package/dist/flow/loops/for_i.d.ts +1 -1
- package/dist/flow/loops/for_of.d.ts +4 -3
- package/dist/flow/loops/staticAnalysis.d.ts +26 -0
- package/dist/flow/loops/while.d.ts +1 -1
- package/dist/flow/switch_case.d.ts +94 -12
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1093 -367
- package/dist/pack/index.js +1103 -364
- package/dist/pack/pack.d.ts +12 -12
- package/dist/pack/visitors/index.d.ts +1 -0
- package/dist/pack/visitors/loopTransformationVisitor.d.ts +13 -6
- package/dist/pack/visitors/simplifyExecuteFunction.d.ts +3 -2
- package/dist/pack/visitors/simplifyReturnRunFunction.d.ts +2 -1
- package/dist/pack/visitors/switchTransformationVisitor.d.ts +31 -0
- package/dist/pack/visitors/unifyChainedExecutes.d.ts +3 -2
- package/dist/pack/visitors/visitor.d.ts +5 -1
- package/dist/utils.d.ts +34 -3
- package/dist/variables/Data.d.ts +7 -5
- package/dist/variables/DataSets.d.ts +17 -14
- package/dist/variables/Label.d.ts +1 -0
- package/dist/variables/Loop.d.ts +10 -2
- package/dist/variables/ResolveNBT.d.ts +4 -3
- package/dist/variables/Score.d.ts +49 -3
- package/dist/variables/index.js +1066 -328
- package/package.json +1 -1
- package/src/arguments/selector.ts +12 -0
- package/src/commands/implementations/block/setblock.ts +8 -12
- package/src/commands/implementations/entity/damage.ts +2 -2
- package/src/commands/implementations/entity/execute.ts +103 -34
- package/src/commands/implementations/server/return.ts +15 -7
- package/src/commands/implementations/world/data.ts +96 -48
- package/src/core/Macro.ts +18 -1
- package/src/core/resources/datapack/advancement.ts +1 -1
- package/src/core/resources/datapack/bannerPattern.ts +1 -1
- package/src/core/resources/datapack/chatType.ts +1 -1
- package/src/core/resources/datapack/damageType.ts +1 -1
- package/src/core/resources/datapack/dialog.ts +1 -1
- package/src/core/resources/datapack/enchantment.ts +2 -2
- package/src/core/resources/datapack/gametest.ts +2 -2
- package/src/core/resources/datapack/instrument.ts +1 -1
- package/src/core/resources/datapack/itemModifier.ts +1 -1
- package/src/core/resources/datapack/jukeboxSong.ts +1 -1
- package/src/core/resources/datapack/lootTable.ts +1 -1
- package/src/core/resources/datapack/mcfunction.ts +36 -17
- package/src/core/resources/datapack/predicate.ts +1 -1
- package/src/core/resources/datapack/recipe.ts +1 -1
- package/src/core/resources/datapack/structure.ts +1 -1
- package/src/core/resources/datapack/tag.ts +4 -4
- package/src/core/resources/datapack/timeline.ts +2 -2
- package/src/core/resources/datapack/trialSpawner.ts +1 -1
- package/src/core/resources/datapack/trimMaterial.ts +1 -1
- package/src/core/resources/datapack/trimPattern.ts +1 -1
- package/src/core/resources/datapack/variant.ts +2 -2
- package/src/core/resources/datapack/villagerTrade.ts +2 -2
- package/src/core/resources/resource.ts +22 -11
- package/src/core/resources/resourcepack/atlas.ts +1 -1
- package/src/core/resources/resourcepack/blockstate.ts +1 -1
- package/src/core/resources/resourcepack/equipment.ts +1 -1
- package/src/core/resources/resourcepack/font.ts +1 -1
- package/src/core/resources/resourcepack/itemDefinition.ts +1 -1
- package/src/core/resources/resourcepack/language.ts +1 -1
- package/src/core/resources/resourcepack/model.ts +1 -1
- package/src/core/resources/resourcepack/particle.ts +1 -1
- package/src/core/resources/resourcepack/postEffect.ts +1 -1
- package/src/core/resources/resourcepack/shader.ts +1 -1
- package/src/core/resources/resourcepack/sound.ts +1 -1
- package/src/core/resources/resourcepack/waypointStyle.ts +1 -1
- package/src/core/sandstoneCore.ts +9 -1
- package/src/flow/Flow.ts +58 -94
- package/src/flow/conditions/command.ts +1 -1
- package/src/flow/conditions/variables/dataPoint.ts +2 -2
- package/src/flow/if_else.ts +14 -3
- package/src/flow/index.ts +1 -0
- package/src/flow/loop.ts +10 -6
- package/src/flow/loops/for_i.ts +21 -17
- package/src/flow/loops/for_of.ts +43 -36
- package/src/flow/loops/staticAnalysis.ts +114 -0
- package/src/flow/loops/while.ts +8 -5
- package/src/flow/switch_case.ts +214 -13
- package/src/index.ts +6 -1
- package/src/pack/pack.ts +24 -19
- package/src/pack/visitors/containerCommandsToMCFunction.ts +12 -5
- package/src/pack/visitors/ifElseTransformationVisitor.ts +44 -16
- package/src/pack/visitors/index.ts +1 -0
- package/src/pack/visitors/initConstantsVisitor.ts +13 -11
- package/src/pack/visitors/loopTransformationVisitor.ts +30 -7
- package/src/pack/visitors/simplifyExecuteFunction.ts +43 -6
- package/src/pack/visitors/simplifyReturnRunFunction.ts +40 -17
- package/src/pack/visitors/switchTransformationVisitor.ts +452 -0
- package/src/pack/visitors/unifyChainedExecutes.ts +9 -1
- package/src/pack/visitors/visitor.ts +9 -1
- package/src/utils.ts +53 -12
- package/src/variables/Data.ts +20 -4
- package/src/variables/DataSets.ts +57 -23
- package/src/variables/JSONTextComponentClass.ts +6 -1
- package/src/variables/Label.ts +0 -3
- package/src/variables/Loop.ts +30 -1
- package/src/variables/Objective.ts +0 -1
- package/src/variables/ResolveNBT.ts +5 -3
- package/src/variables/Score.ts +238 -8
- package/src/variables/Sleep.ts +2 -2
- package/src/variables/UUID.ts +8 -6
- package/src/variables/nbt/NBTs.ts +14 -0
package/dist/flow/loop.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { SandstoneCore } from "../core/index.js";
|
|
1
|
+
import type { MCFunctionNode, SandstoneCore } from "../core/index.js";
|
|
3
2
|
import { ContainerNode } from "../core/index.js";
|
|
3
|
+
import type { ConditionNode } from "./conditions/index.js";
|
|
4
4
|
export declare class LoopNode extends ContainerNode {
|
|
5
|
-
|
|
5
|
+
condition: ConditionNode;
|
|
6
6
|
callback: () => void;
|
|
7
7
|
loopback: () => void;
|
|
8
|
-
|
|
8
|
+
parentMCFunction: MCFunctionNode;
|
|
9
|
+
constructor(sandstoneCore: SandstoneCore, condition: ConditionNode, callback: () => void, loopback: () => void);
|
|
9
10
|
getValue: () => never;
|
|
10
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SandstoneCore } from "../../core/sandstoneCore.js";
|
|
2
2
|
import type { Score } from "../../variables/index.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type Condition } from '..';
|
|
4
4
|
import { LoopNode } from "../loop.js";
|
|
5
5
|
export declare class ForINode extends LoopNode {
|
|
6
6
|
constructor(sandstoneCore: SandstoneCore, initialValue: number | Score, endCondition: (iterator: Score) => Condition, iterate: (iterator: Score) => Score, callback: (iterator: number | Score, _continue: () => void) => any);
|
|
@@ -20,14 +20,15 @@ export type ForOfIterate<ITERATOR extends ForOfIterator> = ITERATOR extends 'ent
|
|
|
20
20
|
never
|
|
21
21
|
];
|
|
22
22
|
export declare class ForOfNode<ITERATOR extends ForOfIterator, ITERATE extends ForOfIterate<ForOfIterator>> extends LoopNode {
|
|
23
|
-
constructor(sandstoneCore: SandstoneCore, iteratorType: ITERATOR, iterable: IterableDataClass
|
|
23
|
+
constructor(sandstoneCore: SandstoneCore, iteratorType: ITERATOR, direction: 'normal' | 'reverse', iterable: IterableDataClass<ITERATOR extends string[] ? ITERATOR[0] extends 'key' ? 'map' : ('list' | 'map') : ('list' | 'map')>, callback: (...args: ITERATE) => any);
|
|
24
24
|
}
|
|
25
25
|
export declare class ForOfStatement<ITERATOR extends ForOfIterator, ITERATE extends ForOfIterate<ForOfIterator>> {
|
|
26
26
|
protected sandstoneCore: SandstoneCore;
|
|
27
27
|
protected iteratorType: ITERATOR;
|
|
28
|
-
protected
|
|
28
|
+
protected direction: 'normal' | 'reverse';
|
|
29
|
+
protected iterable: IterableDataClass<ITERATOR extends string[] ? ITERATOR[0] extends 'key' ? 'map' : ('list' | 'map') : ('list' | 'map')>;
|
|
29
30
|
protected callback: (...args: ITERATE) => any;
|
|
30
31
|
protected node: ForOfNode<ITERATOR, ITERATE>;
|
|
31
|
-
constructor(sandstoneCore: SandstoneCore, iteratorType: ITERATOR, iterable: IterableDataClass
|
|
32
|
+
constructor(sandstoneCore: SandstoneCore, iteratorType: ITERATOR, direction: 'normal' | 'reverse', iterable: IterableDataClass<ITERATOR extends string[] ? ITERATOR[0] extends 'key' ? 'map' : ('list' | 'map') : ('list' | 'map')>, callback: (...args: ITERATE) => any);
|
|
32
33
|
protected getNode: () => ForOfNode<ITERATOR, ITERATE>;
|
|
33
34
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ConditionNode } from '..';
|
|
2
|
+
import type { Score } from "../../variables/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Result of static condition analysis.
|
|
5
|
+
* - `{ canAnalyze: false }` - condition references other variables or can't be analyzed
|
|
6
|
+
* - `{ canAnalyze: true, result: boolean }` - condition was evaluated statically
|
|
7
|
+
*/
|
|
8
|
+
export type AnalysisResult = {
|
|
9
|
+
canAnalyze: false;
|
|
10
|
+
} | {
|
|
11
|
+
canAnalyze: true;
|
|
12
|
+
result: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Recursively analyzes a condition node to check if it only references the given score
|
|
16
|
+
* and evaluates to true/false for the given value.
|
|
17
|
+
*/
|
|
18
|
+
export declare function analyzeCondition(condition: ConditionNode, targetScore: Score, value: number, negated?: boolean): AnalysisResult;
|
|
19
|
+
/**
|
|
20
|
+
* Gets a user-friendly location string from a stack trace, filtering out internal files.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDeclarationLocation(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Warns about a statically false loop condition.
|
|
25
|
+
*/
|
|
26
|
+
export declare function warnStaticallyFalseCondition(loopType: string, details: string): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SandstoneCore } from "../../core/index.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ConditionNode } from '..';
|
|
3
3
|
import { LoopNode } from "../loop.js";
|
|
4
4
|
export declare class WhileNode extends LoopNode {
|
|
5
5
|
constructor(sandstoneCore: SandstoneCore, condition: ConditionNode, callback: () => void);
|
|
@@ -1,16 +1,98 @@
|
|
|
1
1
|
import type { NBTObject } from "../arguments/index.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { DataPointPickClass, MCFunctionNode, SandstoneCore } from "../core/index.js";
|
|
3
|
+
import { ContainerNode } from "../core/index.js";
|
|
4
|
+
import type { DataPointClass } from "../variables/index.js";
|
|
5
|
+
import { Score } from "../variables/index.js";
|
|
6
|
+
import type { Condition } from "./Flow.js";
|
|
7
|
+
/** A condition callback that receives the switch value and returns a condition */
|
|
8
|
+
export type ConditionCallback<ValueType> = (value: ValueType) => Condition;
|
|
9
|
+
/** Widen literal types to their base types for better inference */
|
|
10
|
+
type Widen<T> = T extends number ? number : T;
|
|
11
|
+
/** Static value case */
|
|
12
|
+
type StaticCaseEntry<CheckType> = {
|
|
13
|
+
type: 'static';
|
|
14
|
+
value: Widen<CheckType>;
|
|
15
|
+
callback: () => any;
|
|
16
|
+
};
|
|
17
|
+
/** Condition callback case */
|
|
18
|
+
type ConditionCaseEntry<ValueType> = {
|
|
19
|
+
type: 'condition';
|
|
20
|
+
condition: ConditionCallback<ValueType>;
|
|
21
|
+
callback: () => any;
|
|
22
|
+
};
|
|
23
|
+
/** Either a static or condition case entry */
|
|
24
|
+
type CaseEntry<ValueType, CheckType> = StaticCaseEntry<CheckType> | ConditionCaseEntry<ValueType>;
|
|
25
|
+
/** Static value case tuple */
|
|
26
|
+
export type StaticCase<CheckType> = readonly [
|
|
27
|
+
'case',
|
|
28
|
+
Widen<CheckType>,
|
|
29
|
+
() => any
|
|
30
|
+
];
|
|
31
|
+
/** Condition callback case tuple */
|
|
32
|
+
export type ConditionCase<ValueType> = readonly [
|
|
33
|
+
'case',
|
|
34
|
+
ConditionCallback<ValueType>,
|
|
35
|
+
() => any
|
|
36
|
+
];
|
|
37
|
+
/** Either a static or condition case */
|
|
38
|
+
export type SwitchCase<ValueType, CheckType> = StaticCase<CheckType> | ConditionCase<ValueType>;
|
|
39
|
+
export type DefaultType<ValueType extends number | NBTObject, SwitchValueType = unknown> = {
|
|
40
|
+
entries: CaseEntry<SwitchValueType, ValueType>[];
|
|
4
41
|
default: () => any;
|
|
5
42
|
};
|
|
6
|
-
export declare class CaseStatement<ValueType extends number | NBTObject> {
|
|
7
|
-
readonly
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
case
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
43
|
+
export declare class CaseStatement<ValueType extends number | NBTObject, SwitchValueType = unknown> {
|
|
44
|
+
readonly entries: CaseEntry<SwitchValueType, ValueType>[];
|
|
45
|
+
constructor(entries?: CaseEntry<SwitchValueType, ValueType>[]);
|
|
46
|
+
/** Add a static value case */
|
|
47
|
+
case(value: ValueType, callback: () => any): CaseStatement<ValueType, SwitchValueType>;
|
|
48
|
+
/** Add a condition case - checked after static cases fail. Use generic to specify switch value type on first condition: `.case<Score>(v => ...)` */
|
|
49
|
+
case<T = SwitchValueType>(condition: ConditionCallback<T>, callback: () => any): CaseStatement<ValueType, T>;
|
|
50
|
+
default(callback: () => any): DefaultType<ValueType, SwitchValueType>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* AST node representing a switch statement.
|
|
54
|
+
* Transformed into MCFunctions by SwitchTransformationVisitor during save().
|
|
55
|
+
*/
|
|
56
|
+
export declare class SwitchNode extends ContainerNode {
|
|
57
|
+
value: DataPointClass | DataPointPickClass | Score;
|
|
58
|
+
staticCases: StaticCaseNode[];
|
|
59
|
+
conditionCases: ConditionCaseNode[];
|
|
60
|
+
defaultCase: DefaultCaseNode | undefined;
|
|
61
|
+
parentMCFunction: MCFunctionNode;
|
|
62
|
+
constructor(sandstoneCore: SandstoneCore, value: DataPointClass | DataPointPickClass | Score, staticCases: StaticCaseNode[], conditionCases: ConditionCaseNode[], defaultCase: DefaultCaseNode | undefined);
|
|
63
|
+
getValue: () => never;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* AST node representing a static value case in a switch statement.
|
|
67
|
+
*/
|
|
68
|
+
export declare class StaticCaseNode extends ContainerNode {
|
|
69
|
+
value: number | NBTObject;
|
|
70
|
+
callback: () => any;
|
|
71
|
+
constructor(sandstoneCore: SandstoneCore, value: number | NBTObject, callback: () => any);
|
|
72
|
+
getValue: () => null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* AST node representing a condition-based case in a switch statement.
|
|
76
|
+
*/
|
|
77
|
+
export declare class ConditionCaseNode extends ContainerNode {
|
|
78
|
+
condition: ConditionCallback<any>;
|
|
79
|
+
callback: () => any;
|
|
80
|
+
constructor(sandstoneCore: SandstoneCore, condition: ConditionCallback<any>, callback: () => any);
|
|
81
|
+
getValue: () => null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* AST node representing the default case in a switch statement.
|
|
85
|
+
*/
|
|
86
|
+
export declare class DefaultCaseNode extends ContainerNode {
|
|
87
|
+
callback: () => any;
|
|
88
|
+
constructor(sandstoneCore: SandstoneCore, callback: () => any);
|
|
89
|
+
getValue: () => null;
|
|
16
90
|
}
|
|
91
|
+
export declare function executeSwitch<ValueType extends DataPointClass | DataPointPickClass | Score, CheckType extends ValueType extends Score ? number : NBTObject>(sandstoneCore: SandstoneCore, value: ValueType, _cases: SwitchCase<ValueType, CheckType>[] | [
|
|
92
|
+
...SwitchCase<ValueType, CheckType>[],
|
|
93
|
+
[
|
|
94
|
+
'default',
|
|
95
|
+
() => any
|
|
96
|
+
]
|
|
97
|
+
] | CaseStatement<CheckType, ValueType> | DefaultType<CheckType, ValueType>): void;
|
|
98
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1612,13 +1612,13 @@ export declare const RawResource: {
|
|
|
1612
1612
|
(nbt: import(".").DataPointClass, scale?: number, name?: string): import(".").Score;
|
|
1613
1613
|
}, flowVariable: import(".").Score, Trigger: (name: string, callback: import("./variables/index.js").TriggerHandler, pollingEvery?: number) => import("./variables/index.js").TriggerClass<import("./variables").TriggerHandler>, Label: (label: `${any}${string}` | `${string}:${string}`, description?: `${any}${string}`) => import("./utils.js").MakeInstanceCallable<import("./variables")._RawLabelClass>, Data: {
|
|
1614
1614
|
<T extends import("./variables/index.js").DATA_TYPES>(type: T): import("./variables/index.js").TargetlessDataClass<T>;
|
|
1615
|
-
<T extends "entity">(type: T, target: import(".").
|
|
1616
|
-
<T extends "storage">(type: T, target: import("./core/index.js").MacroArgument | string): import("./variables/index.js").DataClass<T>;
|
|
1617
|
-
<T extends "block">(type: T, target: import(".").
|
|
1615
|
+
<T extends "entity", S extends string>(type: T, target: import("./variables/index.js").TargetFor<T, S>): import("./variables/index.js").DataClass<T>;
|
|
1616
|
+
<T extends "storage">(type: T, target: import("./core/index.js").MacroArgument | import("./variables/index.js").TargetFor<T, string>): import("./variables/index.js").DataClass<T>;
|
|
1617
|
+
<T extends "block">(type: T, target: import("./variables/index.js").TargetFor<T, string>): import("./variables/index.js").DataClass<T>;
|
|
1618
1618
|
<T extends import("./variables/index.js").DATA_TYPES>(type: T, target: undefined, path: import("./core/index.js").MacroArgument | import("./variables/index.js").DATA_PATH | import("./variables/index.js").DATA_PATH[]): import("./variables/index.js").TargetlessDataPointClass<T>;
|
|
1619
|
-
<T extends "entity">(type: T, target: import(".").
|
|
1620
|
-
<T extends "storage">(type: T, target: import("./core/index.js").MacroArgument |
|
|
1621
|
-
<T extends "block">(type: T, target: import(".").
|
|
1619
|
+
<T extends "entity", S extends string>(type: T, target: import("./variables/index.js").TargetFor<T, S>, path: import("./core/index.js").MacroArgument | import("./variables/index.js").DATA_PATH | import("./variables/index.js").DATA_PATH[]): import(".").DataPointClass<T>;
|
|
1620
|
+
<T extends "storage">(type: T, target: import("./core/index.js").MacroArgument | import("./variables/index.js").TargetFor<T, string>, path: import("./core/index.js").MacroArgument | import("./variables/index.js").DATA_PATH | import("./variables/index.js").DATA_PATH[]): import(".").DataPointClass<T>;
|
|
1621
|
+
<T extends "block">(type: T, target: import("./variables/index.js").TargetFor<T, string>, path: import("./core/index.js").MacroArgument | import("./variables/index.js").DATA_PATH | import("./variables/index.js").DATA_PATH[]): import(".").DataPointClass<T>;
|
|
1622
1622
|
}, DataVariable: {
|
|
1623
1623
|
(initialValue?: import(".").NBTObject | import(".").DataPointClass<any> | import("./core/index.js").DataPointPickClass, name?: string): import(".").DataPointClass<"storage">;
|
|
1624
1624
|
(score: import(".").Score, storeType?: import("./commands/index.js").StoreType, scale?: number, name?: string): import(".").DataPointClass<"storage">;
|