import type { FinalCommandOutput } from "../commands/index.js"; import type { BiomeConditionNode, BlocksConditionNode, DataPointExistsConditionNode, DimensionConditionNode, FunctionConditionNode, SelectorConditionNode, LoadedConditionNode, PredicateConditionNode } from "./conditions/index.js"; import type { Registry, Coordinates, JSONTextComponent, MultipleEntitiesArgument, MultiplePlayersArgument, NBTObject, SymbolBlock, SymbolMcdocBlockStates, TimeArgument, SingleEntityArgument } from '../arguments/index.js'; import type { ItemSlotSource } from '../commands/implementations/world/item.js'; import type { SandstoneCommands } from '../commands/index.js'; import type { ConditionClass, DataPointClass, IterableDataClass, JSONTextComponentClass, StringDataPointClass } from '../variables/index.js'; import { Score } from '../variables/index.js'; import type { AwaitNode, AwaitNodeClass, DataPointPickClass, MacroArgument, MCFunctionClass, PredicateClass, SandstoneCore } from '../core/index.js'; import type { NamespacedLiteralUnion, NamespacedString, NonEmptyString, RemoveFirst } from '../utils.js'; import { AttachClass, SleepClass, UntilClass } from './async/index.js'; import { AndNode, ConditionNode, ItemPredicateArgument, NotNode, OrNode, type BlockConditionNode, type ItemsBlockConditionNode, type ItemsEntityConditionNode, type SlotsBlockConditionNode, type SlotsEntityConditionNode } from './conditions/index.js'; import { IfStatement } from './if_else.js'; import { ForIStatement, ForOfStatement, WhileStatement } from './loops/index.js'; import { WithClass } from './macro/index.js'; import type { ConditionCallback, DefaultType, SwitchCase } from './switch_case.js'; import { CaseStatement } from './switch_case.js'; export type Condition = ConditionNode | ConditionClass; type ParseLiteral = (T extends 'true' | 'false' ? boolean : T extends `${infer N extends number}` ? N : T); type ParseBlockState = { [K in keyof T]: ParseLiteral; }; type BlockEntity = NamespacedLiteralUnion; type BlockStatic = NamespacedLiteralUnion>; export declare function conditionToNode(condition: Condition): ConditionNode; /** * Unique sentinel function used by `_.if()` (and other Flow primitives) when * the caller omits the callback. Comparing by reference lets downstream code * distinguish "no callback supplied" from "user wrote an explicit empty * callback `() => {}`" — the latter is a build error (no commands in body), * the former is the normal "user will chain `.run.` or `.return(...)`" * case. */ export declare const NO_CALLBACK_SENTINEL: () => void; export declare class Flow { sandstoneCore: SandstoneCore; constructor(sandstoneCore: SandstoneCore); if(condition: Condition, callback: () => void): IfStatement; if(condition: Condition): IfStatement; /** * Combine conditions with AND. * * Accepts either variadic conditions (`_.and(a, b, c)`) or a single array * (`_.and([a, b, c])`, useful for `Array.prototype.map` results). */ and(...conditions: Condition[]): AndNode; and(conditions: Condition[]): AndNode; /** * Combine conditions with OR. * * Accepts either variadic conditions (`_.or(a, b, c)`) or a single array * (`_.or([a, b, c])`, useful for `Array.prototype.map` results). */ or(...conditions: Condition[]): OrNode; or(conditions: Condition[]): OrNode; not: (condition: Condition) => NotNode; get return(): { run: SandstoneCommands & ((callback: () => void) => /* */FinalCommandOutput); fail: () => /* */FinalCommandOutput; } & ((value?: number | undefined) => /* */FinalCommandOutput); /** * Async-control * * 1. Methods - `_.await.sleep`, `_.await.until`, `_.await.attach`, `_.await.interrupt` * * 2. Custom - `_.await(YourAwaitNodeClass, ...args)` threads `SandstoneCore` * through for you, then forwards the remaining args to your class constructor. */ get await(): { sleep: (delay: TimeArgument, logPath?: boolean) => SleepClass; until: (condition: Condition, pollRate: TimeArgument, logPath?: boolean) => UntilClass; /** * Start awaiting another `MCFunction`'s active `AwaitNode` at run time * * @param entrypoint How to continue after the await resolves. * - `'start'` - `MCFunction` continuance begins before the target would continue (will not delay the target). \ * If your executor (asyncContext) supports `Passengers` you can use `AttachClass#execute` to run commands `as` the target. * - `'end'` - `MCFunction` continues as-is the tick after the target continues. * @param func Root `MCFunction` of the target AwaitNode. * @param branch Planned `MCFunction` pre-optimizer-visitors path relative to the root, empty if the `AwaitNode` was added at the root. * @param awaitNodeIdx `N` of the `AwaitNode` within the above branch. * @param entity `await.attach` will error if this is left unspecified when attaching to an `AwaitNode` that is a child of an `asyncContext` `MCFunction`. */ attach: (entrypoint: Entrypoint, func: MCFunctionClass | NonEmptyString, branch: string[], awaitNodeIdx: number, entity?: SingleEntityArgument) => AttachClass; /** * Cancels active `AwaitNode`'s at run time (kinda like `clearTimeout` in JS) * * Note: Only use if you need to interrupt externally, `_.return` / `returnCmd` can be used internally. * * When interrupting an `asyncContext` mcfunction: * - Current executor is an entity being tracked by the `asyncContext`? -> Interrupts only for that entity. * - Executor is missing or is not being tracked by the `asyncContext`? -> Interrupts all `AwaitNode`'s in the `MCFunction` for all entities being tracked. */ interrupt: (func: MCFunctionClass | NonEmptyString, /** * Adds command(s) to run within the target context before interrupting. * * Callback is called multiple times -> Once for each `AwaitNode` that is a direct or nested child of the root. * * Return `false` at compile time to cancel the interrupt for a given `branch`+`awaitNodeIdx` `AwaitNode` path. * * @param root Resolved `func`. * @param branch Planned `MCFunction` pre-optimizer-visitors path relative to the root `MCFunction`, empty if the `AwaitNode` was added at the root. * @param awaitNodeIdx `N` of the `AwaitNode` within the above branch. * @param node The `AwaitNode` being interrupted. */ handle?: (root: MCFunctionClass, branch: string[], awaitNodeIdx: number, node: AwaitNode) => any) => void; } & ((Ctor: C, ...args: RemoveFirst>) => AwaitNode); /** * Logs an error in data storage and chat by default and `return fail`'s from the context. * * @param error Error to log before `return`. * @param broadcast Whether to scope the broadcast of the error (from `@a`) or disable it. * * @returns DataPoint where error was stored. */ throw(error?: JSONTextComponent, broadcast?: MultiplePlayersArgument | false): DataPointClass; /** * Logs an error in data storage and chat by default and `return fail`'s from the context. * * @param error Error to log before `return`. * @param broadcast Whether to scope the broadcast of the error (from `@a`) or disable it. * @param dataPoint Disable storing to data point. * * @returns The full error text component. */ throw(error: JSONTextComponent | undefined, broadcast: MultiplePlayersArgument | false | undefined, dataPoint: false): JSONTextComponentClass; /** * Logs an error in data storage and chat by default and `return fail`'s from the context. * * @param error Error to log before `return`. * @param broadcast Whether to scope the broadcast of the error (from `@a`) or disable it. * @param dataPoint Specific point to store the error to. * * @returns DataPoint that was set. */ throw(error: JSONTextComponent | undefined, broadcast: MultiplePlayersArgument | false | undefined, dataPoint: DataPointClass): DataPointClass; while(condition: Condition, callback: () => void): WhileStatement; doWhile(condition: Condition, callback: () => void): WhileStatement; for(initial: number | Score, end: (iterator: Score) => Condition, iterate: (iterator: Score) => Score, callback: (iterator: Score | number, _continue: () => void) => any): ForIStatement; for(range: [start: number | Score, end: number | Score], type: 'iterate', callback: (iterator: Score, _continue: () => void) => any): ForIStatement; for(type: 'entry', _: 'of' | 'of-reverse', iterable: IterableDataClass<'list' | 'map'>, callback: (entry: DataPointClass) => any): ForOfStatement<'entry', [entry: DataPointClass]>; for(type: ['key', 'value'], _: 'of' | 'of-reverse', iterable: IterableDataClass<'map'>, callback: (key: StringDataPointClass, value: DataPointClass) => any): ForOfStatement<['key', 'value'], [key: StringDataPointClass, value: DataPointClass]>; for(type: ['i', 'entry'], _: 'of' | 'of-reverse', iterable: IterableDataClass<'list' | 'map'>, callback: (i: Score, entry: DataPointClass) => any): ForOfStatement<['i', 'entry'], [i: Score, entry: DataPointClass]>; switch(value: ValueType, cases: CaseStatement | DefaultType): void; switch(value: ValueType, cases: SwitchCase[] | [...SwitchCase[], ['default', () => any]]): void; case(value: (SwitchValueType extends Score ? number : NBTObject) | ConditionCallback, callback: () => any): CaseStatement; /** * Checks for a specific biome in a given position. * @param coordinates Position to test. * @param biome Biome(s) to test for (can be a tag). */ biome: (coordinates: Coordinates, biome: Registry['minecraft:worldgen/biome']) => /* */BiomeConditionNode; /** * Compares the block at a given position to a given block. * * @param position Position of a target block to test. * @param block Block to test for (can be a tag). * @param state Optional block state properties to match. * * @example * ```ts * // Simple block check * _.if(_.block(abs(0, 64, 0), 'minecraft:stone'), () => { ... }) * * // Check block with specific state * _.if(_.block(abs(0, 64, 0), 'minecraft:oak_log', { axis: 'y' }), () => { ... }) * ``` */ block(position: Coordinates, block: BLOCK, state?: BLOCK extends keyof SymbolMcdocBlockStates ? ParseBlockState> : Record): BlockConditionNode; /** * Compares the block at a given position to a given block with NBT data. * * @param position Position of a target block to test. * @param block Block to test for (must be a block entity). * @param state Optional block state properties to match. * @param nbt NBT data to match against the block entity. * * @example * ```ts * // Check chest with specific NBT * _.if(_.block(abs(0, 64, 0), 'minecraft:chest', { facing: 'north' }, { Items: [] }), () => { ... }) * * // Check command block * _.if(_.block(['~', '~', '~1'], 'minecraft:command_block', {}, { Command: 'say Hello' }), () => { ... }) * ``` */ block(position: Coordinates, block: BLOCK, state: BLOCK extends keyof SymbolMcdocBlockStates ? ParseBlockState> : Record | undefined, nbt: BLOCK extends keyof SymbolBlock ? NonNullable : SymbolBlock<'%fallback'>): BlockConditionNode; /** * Compares the blocks in two equally sized volumes. * @param start Start position of the first volume. * @param end End position of the first volume. * @param destination Start position of the second volume. * @param scan_mode Specifies whether all blocks in the source volume should be compared, or if air blocks should be masked/ignored */ blocks: (start: Coordinates, end: Coordinates, destination: Coordinates, scan_mode?: 'all' | 'masked') => /* */BlocksConditionNode; /** * Checks whether the targeted block, entity or storage has any data tag for a given path. * * You must provide a Data instance. * * ⚠️ You should prefer using the Data instance as a direct condition, as this function is only here for completeness. * * @example * _.if(_.data(Data('entity', '@s', 'myData')), () => { * // Do something if the data exists * }) * * // You should however prefer using the Data instance directly: * _.if(Data('entity', '@s', 'myData'), () => { * // Do something if the data exists * }) * * @param data Data instance to check. */ data: (data: DataPointClass) => /* */DataPointExistsConditionNode; /** * Checks if the execution is in a matching dimension. * @param dimension Dimension to check for. */ dimension: (dimension: Registry['minecraft:dimension']) => /* */DimensionConditionNode; /** * Checks a function or function tag and matches the return value(s). If a tag is given, all functions run regardless of the results of prior functions. * @param mcfunction Function to check for. */ mcfunction: (mcfunction: NamespacedString | MCFunctionClass) => /* */FunctionConditionNode; /** * Checks whether one or more entities exist. * * @example * _.if(_.entity('@a[tag=example]'), () => { * // Do something if the entity exists * }) * * // ⚠️ You can use a Selector directly to achieve the same result: * _.if(Selector('@a', {tag: 'example'}), () => { * // Do something if the entity exists * }) * * @param targets Entity targets to check for. */ entity: (targets: MultipleEntitiesArgument) => /* */SelectorConditionNode; /** * Tests for items in block entity or entity inventory slots. * * @example * ```ts * // Check if chest has any diamonds * _.if(_.items.block(abs(0, 64, 0), 'container.*', 'minecraft:diamond'), () => { ... }) * * // Check if player has any diamonds * _.if(_.items.entity('@p', 'inventory.*', 'minecraft:diamond'), () => { ... }) * * // Check for enchanted sword with builder * _.if(_.items.entity('@p', 'weapon.mainhand', * ItemPredicate('minecraft:diamond_sword').has('minecraft:enchantments') * ), () => { ... }) * ``` */ get items(): { /** * Test for items in a block entity's inventory slots. * * @param sourcePos Position of the block entity to test. * @param slotSource Slot source to test (e.g., `'container.*'`, inline slot source, or a slot source reference). * @param itemPredicate Item predicate to match against. */ block: (sourcePos: Coordinates, slotSource: ItemSlotSource, itemPredicate: ItemPredicateArgument) => ItemsBlockConditionNode; /** * Test for items in an entity's inventory slots. * * @param source Entity to test. * @param slotSource Slot source to test (e.g., `'inventory.*'`, inline slot source, or a slot source reference). * @param itemPredicate Item predicate to match against. */ entity: (source: MultipleEntitiesArgument, slotSource: ItemSlotSource, itemPredicate: ItemPredicateArgument) => ItemsEntityConditionNode; }; /** * Counts slots from a slot source that are present in a block entity or entity. * * @example * ```ts * _.if(_.slots.entity('@p', 'inventory.*'), () => { ... }) * _.if(_.slots.block(abs(0, 64, 0), { type: 'minecraft:slot_range', slots: 'armor.chest' }), () => { ... }) * ``` */ get slots(): { /** * Count slots from a slot source that are present in a block entity. * * @param sourcePos Position of the block entity to test. * @param slotSource Slot source (e.g., `'container.*'`, inline slot source, or a slot source reference). */ block: (sourcePos: Coordinates, slotSource: ItemSlotSource) => SlotsBlockConditionNode; /** * Count slots from a slot source that are present in an entity. * * @param source Entity to test. * @param slotSource Slot source (e.g., `'inventory.*'`, inline slot source, or a slot source reference). */ entity: (source: MultipleEntitiesArgument, slotSource: ItemSlotSource) => SlotsEntityConditionNode; }; /** * Checks if chunks at a given position is fully loaded. * @param position Position to check. */ chunksLoaded: (position: Coordinates) => /* */LoadedConditionNode; /** * Checks whether the predicate successes. * * @param predicate Predicate to check. */ predicate: (predicate: NamespacedString | PredicateClass) => /* */PredicateConditionNode; /** * Runs the callback inside a child macro MCFunction, with each given * `MacroArgument` bound as a macro parameter (`$(env_0)`, `$(env_1)`, ...). * * @param env Macro arguments to expose inside the macro function. * @param callback Body of the macro function. */ with(env: MacroArgument[], callback: () => any): WithClass; /** * Runs a single command inside a child macro MCFunction, with each given * `MacroArgument` bound as a macro parameter (`$(env_0)`, `$(env_1)`, ...). * * @param env Macro arguments to expose inside the macro function. * * @example * ```ts * _.with([world]).say($`Hello ${world}!`) * ``` */ with(env: MacroArgument[]): SandstoneCommands; } export {}; //# sourceMappingURL=Flow.d.ts.map