import { world, system } from '@minecraft/server';

// handles removing the light from the fire
world.beforeEvents.entityRemove.subscribe((e) => {
    if (e.removedEntity.typeId === 'plank_waao:soul_fire') {
        const entity = e.removedEntity;
        const dimension = entity.dimension;
        const location = entity.location;

        system.run(() => {
            if (dimension.getBlock(location)?.typeId === 'minecraft:light_block_15')
                dimension.setBlockType(location, 'minecraft:air');
            dimension.playSound('random.fizz', location, { pitch: Math.random() * 0.6 + 1.8, volume: 0.5 });
        });

    }
})
