import { world ,system} from "@minecraft/server"


world.afterEvents.playerPlaceBlock.subscribe(ev => {
    //fences and stairs
    var location = { x: ev.block.location.x, y: ev.block.location.y, z: ev.block.location.z };
    var block = world.getDimension(ev.player.dimension.id).getBlock({x:location.x+1,y:location.y,z:location.z})
    if (block.hasTag('update')){
        block.setPermutation(block.permutation.withState('edx:update', true));
    }
    var block = world.getDimension(ev.player.dimension.id).getBlock({x:location.x-1,y:location.y,z:location.z})
    if (block.hasTag('update')){
        block.setPermutation(block.permutation.withState('edx:update', true));
    }
    var block = world.getDimension(ev.player.dimension.id).getBlock({x:location.x,y:location.y,z:location.z+1})
    if (block.hasTag('update')){
        block.setPermutation(block.permutation.withState('edx:update', true));
    }
    var block = world.getDimension(ev.player.dimension.id).getBlock({x:location.x,y:location.y,z:location.z-1})
    if (block.hasTag('update')){
        block.setPermutation(block.permutation.withState('edx:update', true));
    }
    //door
    var block = world.getDimension(ev.player.dimension.id).getBlock(location)
    const above = ev.block.above();
    if (block.hasTag('bottom_door') &&  !above.isAir){
    ev.dimension.runCommand(`setblock ${location.x} ${location.y} ${location.z} air[] destroy`);
        }
})