import { isBlockId } from "./stableTriggers.js"
import * as mc from "@minecraft/server"

function setPermutation(block, stateAdd, stateValue, blockId) {
    if (block) {
        const result = block.permutation.getAllStates();
        result[stateAdd] = stateValue;
        block.setPermutation(mc.BlockPermutation.resolve(blockId, result));
    }
}
export const allBlocksId = [
    'ecbl_bc:baobab_branch',
    'ecbl_bc:baobab_log',
    'ecbl_bc:baobab_wood'
]
export function generateRemaining(block, face1, face2, face3, face4, face5, face6) {
    const Score = mc.world.scoreboard?.getObjective(`${contentType}`)?.getScore(`${block.location.x},${block.location.y},${block.location.z}`) ?? 0;
    if (Score > 0) {
        generate(block, filter, face1, face2, face3, face4, face5, face6);
    }
}


export function generate(block, filter, face1, face2, face3, face4, face5, face6) {

    let index1 = 0;
    allFaces.forEach(face => {
        index1++;
        if (face?.hasTag(`${type}_${baobab_wood}`)) {
            let states = face?.permutation?.getAllStates();
            let connectedTubes = [];
            let lastBlock;
            connectedTubes.push({ origin: block, actual: block });
            detectTubeAround(block, block, filter, face1, face2, face3, face4, face5, face6);
            function detectTubeAround(origin, actual, filter, face1, face2, face3, face4, face5, face6) {
                //console.warn(connectedTubes.length)
                if (connectedTubes.length < 90 || connectedTubes) {
                    let allFaces = [
                        actual?.north(),
                        actual?.south(),
                        actual?.west(),
                        actual?.east(),
                        actual?.above(),
                        actual?.below()
                    ];
                    if (filter == true) {
                        allFaces = [];
                        if (face1 == "north" || face2 == "north" || face3 == "north" || face4 == "north" || face5 == "north" || face6 == "north") allFaces.push(block?.north());
                        if (face1 == "south" || face2 == "south" || face3 == "south" || face4 == "south" || face5 == "south" || face6 == "south") allFaces.push(block?.south());
                        if (face1 == "east" || face2 == "east" || face3 == "east" || face4 == "east" || face5 == "east" || face6 == "east") allFaces.push(block?.east());
                        if (face1 == "west" || face2 == "west" || face3 == "west" || face4 == "west" || face5 == "west" || face6 == "west") allFaces.push(block?.west());
                        if (face1 == "above" || face2 == "above" || face3 == "above" || face4 == "above" || face5 == "above" || face6 == "above") allFaces.push(block?.above());
                        if (face1 == "below" || face2 == "below" || face3 == "below" || face4 == "below" || face5 == "below" || face6 == "below") allFaces.push(block?.below());
                    }
                }
            }
        }

    });
}