import type { Coordinates, Rotation, SingleEntityArgumentOf } from 'sandstone/arguments' import type { Macroable } from 'sandstone/core' import { CommandNode } from 'sandstone/core/nodes' import { coordinatesParser, targetParser } from 'sandstone/variables/parsers' import { CommandArguments, type FinalCommandOutput } from '../../helpers' export class RotateCommandNode extends CommandNode { command = 'rotate' as const } /** * Changes an entity's rotation. * * @see https://minecraft.wiki/w/Commands/rotate */ export class RotateCommand extends CommandArguments { protected NodeType = RotateCommandNode /** * Sets an entity's rotation directly. * * @param rotation Yaw and pitch. Supports relative rotation. */ rotate( target: Macroable, MACRO>, rotation: Macroable, MACRO>, ): FinalCommandOutput /** * Rotates an entity to face a location or another entity. */ rotate( target: Macroable, MACRO>, ): RotateFacingArguments rotate( target: Macroable, MACRO>, rotation?: Macroable, MACRO>, ) { if (rotation !== undefined) { return this.finalCommand([targetParser(target), coordinatesParser(rotation)]) } return this.subCommand([targetParser(target)], RotateFacingArguments, false) } } export class RotateFacingArguments extends CommandArguments { /** * Rotates the entity to face a block location. */ facing = (location: Macroable, MACRO>): FinalCommandOutput => this.finalCommand(['facing', coordinatesParser(location)]) /** * Rotates the entity to face another entity. * * @param anchor Whether to face the entity's `'eyes'` or `'feet'`. Defaults to `'feet'`. */ facingEntity = ( entity: Macroable, MACRO>, anchor?: Macroable<'eyes' | 'feet', MACRO>, ): FinalCommandOutput => this.finalCommand(['facing', 'entity', targetParser(entity), anchor]) }