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

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_spectral_sand', {
        onPlayerDestroy({ player }) {
            player.runCommandAsync("event entity @e [type=old_nether:spectral_sand_active,r=6,c=1] despawn")
        }
    }
    ,);
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_silica_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:silica_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_volcanic_rock', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:volcanic_rock', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_cooled_magma', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:cooled_magma', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_netherrack_gold_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:netherrack_gold_ore', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_bloodstone_golden_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('minecraft:gold_ingot', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_bloodstone', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:bloodstone', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_blackstone_gold_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:blackstone_gold_ore', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_blaze_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:blaze_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_bloodstone_gold_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnEntity(('old_nether:bloodstone_gold_ore_loot'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_bloodstone_silica_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnEntity(('old_nether:bloodstone_silica_ore_loot'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_ruby_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnEntity(('old_nether:ruby_ore_loot'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_chiselled_gold_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:chiselled_gold_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_compressed_gold_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:compressed_gold_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_gold_fragment_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnEntity(('old_nether:fragment_gold_ore_loot'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_gilded_netherrack', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnEntity(('old_nether:gilded_netherrack_loot'), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_glowing_gold_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:glowing_gold_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_glowing_obsidian', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:glowing_obsidian', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_gilded_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:gilded_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_chiseled_bloodstone_bricks', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:chiseled_bloodstone_bricks', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_silica_bricks', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:silica_bricks', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_corrupted_volcanic_rock', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:corrupted_volcanic_rock', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_bloodstone_bricks', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:bloodstone_bricks', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_polished_silica', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:polished_silica', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_ruby_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:ruby_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_stray_bone_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:stray_bone_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_wither_bone_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:wither_bone_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_taaffeite_block', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:taaffeite_block', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_taaffeite_ore', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:taaffeite', 1), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
                block.dimension.spawnEntity(('minecraft:xp_orb'), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_sculk_nylium', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:sculk_nylium', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_anomalous_nylium', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:anomalous_nylium', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_wart_nylium', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:wart_nylium', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_soul_nylium', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:soul_nylium', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_withered_nylium', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:withered_nylium', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_warped_nether_bricks', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:warped_nether_bricks', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_withered_nether_bricks', {
        onPlayerDestroy({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.hasTag('minecraft:is_pickaxe')) {
                block.dimension.spawnItem(new ItemStack('old_nether:withered_nether_bricks', 1), block.location);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_temporal_nexus', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("say §cThe temporal nexus has been destroyed!")
            player.runCommandAsync("gamerule doDaylightCycle true")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_withered_beacon_negative', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync(`event entity @e[type=old_nether:withered_beacon_lightning_bolt_negative,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_negative_poison,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_negative_weakness,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_negative_wither,r=8] instant_despawn`)
            player.runCommandAsync("playsound spirit.death @a[r=16] ~ ~ ~ 0.12 1")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_withered_beacon_positive', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync(`event entity @e[type=old_nether:withered_beacon_lightning_bolt_positive,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_haste,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_health_boost,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_jump_boost,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_regeneration,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_speed,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_strength,r=8] instant_despawn`)
            player.runCommandAsync(`event entity @e[type=old_nether:wblbp_positive_resistance,r=8] instant_despawn`)
            player.runCommandAsync("playsound spirit.death @a[r=16] ~ ~ ~ 0.12 1")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_amethyst_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound break.amethyst_block @a[r=16] ~ ~ ~ 0.5 1")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_soul_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound soul.death @a[r=16] ~ ~ ~ 0.25 0.8")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_sculk_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound break.sculk @a[r=16] ~ ~ ~ 1 0.8")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_anomalous_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound dig.netherrack @a[r=16] ~ ~ ~ 0.5 0.8")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_wart_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound break.dripstone_block @a[r=16] ~ ~ ~ 0.5 1")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_ash_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound dig.basalt @a[r=16] ~ ~ ~ 0.4 1")
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_withered_sound', {
        onPlayerDestroy: e => {
            const { player } = e;
            player.runCommandAsync("playsound spirit.death @a[r=16] ~ ~ ~ 0.12 1")
        }
    });
});

//Anomalous Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_anomalous_fence_gate', {
        onPlayerDestroy(e) {
            const { block } = e;
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:anomalous_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                aboveBlock.setType('minecraft:air')
            }
        }
    });
});

//Sculk Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_sculk_fence_gate', {
        onPlayerDestroy(e) {
            const { block } = e;
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:sculk_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                aboveBlock.setType('minecraft:air')
            }
        }
    });
});

//Soul Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_soul_fence_gate', {
        onPlayerDestroy(e) {
            const { block } = e;
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:soul_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                aboveBlock.setType('minecraft:air')
            }
        }
    });
});

//Wart Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_wart_fence_gate', {
        onPlayerDestroy(e) {
            const { block } = e;
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:wart_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                aboveBlock.setType('minecraft:air')
            }
        }
    });
});

//Ash Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_ash_fence_gate', {
        onPlayerDestroy(e) {
            const { block } = e;
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:ash_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                aboveBlock.setType('minecraft:air')
            }
        }
    });
});

//Withered Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_withered_fence_gate', {
        onPlayerDestroy(e) {
            const { block } = e;
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:withered_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                aboveBlock.setType('minecraft:air')
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_volcano_block', {
        onPlayerDestroy: e => {
            const { block } = e;
            block.setType('flowing_lava');
        }
    });
});

//Nether Reactor Core Function Second Phase

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_reactor2', {
        onPlayerDestroy: e => {
            const { block } = e;
            const { x, y, z } = block.location
            block.dimension.runCommand(`setblock ${x} ${y + 37} ${z} old_nether:netherrack_reactor_function_disable`)
            block.dimension.runCommand(`setblock ${x + 4} ${y - 2} ${z} netherrack`)
            block.dimension.runCommand(`setblock ${x - 4} ${y - 2} ${z} netherrack`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z + 4} netherrack`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z - 4} netherrack`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z - 5} netherrack`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z - 5} netherrack`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z + 5} netherrack`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z + 5} netherrack`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 2} netherrack`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 2} netherrack`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 2} netherrack`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 2} netherrack`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 5} netherrack`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 5} netherrack`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 5} netherrack`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 5} netherrack`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_reactor2_obsidian', {
        onPlayerDestroy: e => {
            const { block } = e;
            const { x, y, z } = block.location
            block.dimension.runCommand(`setblock ${x} ${y + 37} ${z} old_nether:obsidian_reactor_function_disable`)
            block.dimension.runCommand(`setblock ${x + 4} ${y - 2} ${z} obsidian`)
            block.dimension.runCommand(`setblock ${x - 4} ${y - 2} ${z} obsidian`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z + 4} obsidian`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z - 4} obsidian`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z - 5} obsidian`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z - 5} obsidian`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z + 5} obsidian`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z + 5} obsidian`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 2} obsidian`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 2} obsidian`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 2} obsidian`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 2} obsidian`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 5} obsidian`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 5} obsidian`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 5} obsidian`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 5} obsidian`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_reactor2_obsidian_ruby', {
        onPlayerDestroy: e => {
            const { block } = e;
            const { x, y, z } = block.location
            block.dimension.runCommand(`setblock ${x} ${y + 37} ${z} old_nether:volcanic_rock_reactor_function_disable`)
            block.dimension.runCommand(`setblock ${x + 4} ${y - 2} ${z} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 4} ${y - 2} ${z} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z + 4} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z - 4} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z - 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z - 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z + 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z + 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 2} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 2} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 2} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 2} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 5} old_nether:volcanic_rock`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 5} old_nether:volcanic_rock`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_reactor2_ruby', {
        onPlayerDestroy: e => {
            const { block } = e;
            const { x, y, z } = block.location
            block.dimension.runCommand(`setblock ${x} ${y + 37} ${z} old_nether:bloodstone_reactor_function_disable`)
            block.dimension.runCommand(`setblock ${x + 4} ${y - 2} ${z} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 4} ${y - 2} ${z} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z + 4} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z - 4} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z - 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z - 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z + 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z + 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 2} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 2} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 2} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 2} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 5} old_nether:bloodstone`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 5} old_nether:bloodstone`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_destroy_reactor2_inferno', {
        onPlayerDestroy: e => {
            const { block } = e;
            const { x, y, z } = block.location
            block.dimension.runCommand(`setblock ${x} ${y + 37} ${z} old_nether:inferno_reactor_function_disable`)
            block.dimension.runCommand(`setblock ${x + 4} ${y - 2} ${z} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 4} ${y - 2} ${z} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z + 4} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x} ${y - 2} ${z - 4} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z - 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z - 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x + 2} ${y - 2} ${z + 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 2} ${y - 2} ${z + 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 2} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 2} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 2} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 2} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z - 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x - 5} ${y - 2} ${z + 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z - 5} old_nether:bloodstone_bricks`)
            block.dimension.runCommand(`setblock ${x + 5} ${y - 2} ${z + 5} old_nether:bloodstone_bricks`)
        }
    });
});