import { world } from "@minecraft/server";

world.beforeEvents.itemUseOn.subscribe((data) => {
    const {block, blockFace, itemStack} = data;

    if(/^door:.*_door/.test(itemStack.typeId)) {
        const hasBlockAbove = function() {
            switch(blockFace) {
                case 'Up':
                    return !block.above(2).isAir;
                case 'Down':
                    return true;
                default:
                    return !block.above()[blockFace.toLowerCase()]().isAir;
            }
        }
        data.cancel = hasBlockAbove();
    }
});