import { Block, Dimension, Direction, Player } from "@minecraft/server";
import { Vector3 } from "../vector/vector3"

/**
 * 
 * @param {Player} player 
 */
export function getBlockFace(player) {
    return player.getBlockFromViewDirection({ includeLiquidBlocks: true, includePassableBlocks: true, maxDistance: 9 })?.face
}

/**
 * 
 * @param {Vector3} origin 
 * @param {Direction} face 
 * @param {Dimension} dimension 
 */
export function getBlocksToBreak(origin, face, dimension) {
    /**
     * @type {Block[]}
     */
    let blocks = []
    switch (face) {
        case Direction.Up:
        case Direction.Down:
            for (let x = -2; x <= 2; x++) {
                for (let z = -2; z <= 2; z++) {
                    blocks.push(dimension.getBlock(new Vector3(origin.x + x, origin.y, origin.z + z)))
                }
            }
            break
        case Direction.North:
        case Direction.South:
            for (let x = -2; x <= 2; x++) {
                for (let y = -2; y <= 2; y++) {
                    blocks.push(dimension.getBlock(new Vector3(origin.x + x, origin.y + y, origin.z)))
                }
            }
            break
        case Direction.West:
        case Direction.East:
            for (let z = -2; z <= 2; z++) {
                for (let y = -2; y <= 2; y++) {
                    blocks.push(dimension.getBlock(new Vector3(origin.x, origin.y + y, origin.z + z)))
                }
            }
            break
    }

    return blocks
}