import { getBlocksInRange, fakeBlockBreak } from '../../utils/utils.js';

class BasicBreakProcessor {
    constructor(allowedBlocks) {
        this.process = (block, entity, range) => {
            const blocksInRange = getBlocksInRange(block, range);
            let blockBroken = 0;
            for (let blocksInRangeElement of blocksInRange) {
                const blockInRange = entity.dimension.getBlock(blocksInRangeElement);
                if (!this.canProcess(blockInRange.typeId)) {
                    continue;
                }
                fakeBlockBreak(blockInRange, entity);
                blockBroken++;
            }
            return blockBroken;
        };
        this.canProcess = (blockId) => {
            return this.allowedBlocks.includes(blockId);
        };
        this.allowedBlocks = allowedBlocks;
    }
}

export { BasicBreakProcessor };
