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

//Events when step on blocks 

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_spectral_sand', {
        onStepOn: e => {
            const { block } = e;
            block.setType('old_nether:spectral_sand_active');
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_anomalous_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.anomalous_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_wart_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.wart_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_ash_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.ash_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_withered_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.withered_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_soul_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.soul_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_spiritual_gravel', {
        onStepOn: e => {
            const { block } = e;
            block.setPermutation('old_nether:spiritual_gravel');
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_sculk_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.nether_sculk_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_step_amethyst_sound', {
        onStepOn: e => {
            const { block } = e;
            block.dimension.playSound('step.gilded_block', block.location)
        }
    });
});

//Events when they fall on the blocks

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_spectral_sand', {
        onEntityFallOn: e => {
            const { block } = e;
            block.setType('old_nether:spectral_sand_active');
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_amethyst_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('step.gilded_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_anomalous_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('step.anomalous_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_wart_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('fall.wart_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_ash_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('fall.ash_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_withered_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('fall.withered_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_soul_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('fall.soul_block', block.location)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_spiritual_gravel', {
        onEntityFallOn: e => {
            const { block } = e;
            block.setPermutation('old_nether:spiritual_gravel');
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_fall_sculk_sound', {
        onEntityFallOn: e => {
            const { block } = e;
            block.dimension.playSound('fall.nether_sculk_block', block.location)
        }
    });
});