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

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:sculk_fungus_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 4) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:sculk_tree1 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 4) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:sculk_tree2 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 4) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:sculk_tree3 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:anomalous_fungus_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_tree1 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_tree2 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_tree3 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 4 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_tree4 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:soul_fungus_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 4) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:soul_tree1 ${x - 3} ${y} ${z - 3}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 4) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:soul_tree2 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 4) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:soul_tree3 ${x - 4} ${y} ${z - 4}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:withered_fungus_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 6) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_tree1 ${x - 5} ${y} ${z - 5}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 6) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_tree2 ${x - 5} ${y} ${z - 5}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 6) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_tree3 ${x - 5} ${y} ${z - 5}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 4 / 6) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_tree4 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 4 / 6) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_tree5 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                }
            }
        }
    })
})


world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:wart_fungus_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_tree1 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_tree2 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_tree3 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 4 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_tree4 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:ash_fungus_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:ash_tree1 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:ash_tree2 ${x - 2} ${y} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:ash_tree3 ${x} ${y} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 4 / 5) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:ash_tree4 ${x} ${y} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_pumpkin', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:shears') {
                block.setType('old_nether:carved_ash_pumpkin');
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_temporal_nexus', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'old_nether:luminous_stone') {
                block.setType('old_nether:temporal_nexus_active');
                player.runCommandAsync("playsound beacon.power @a [r=32]");
                player.runCommandAsync("say §aThe temporal nexus has been activated!")
                player.runCommandAsync("gamerule doDaylightCycle false");
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_beacon_inactive', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'old_nether:inferno_powder_soul') {
                block.setType('old_nether:withered_beacon_positive');
                player.runCommandAsync("playsound beacon.power @a [r=32]");
                player.runCommandAsync("playsound spirit.death @a[r=16] ~ ~ ~ 0.12 1");
                block.dimension.spawnEntity(('old_nether:wblbp_active'), block.location);
            }
            if (selectedItem?.typeId === 'old_nether:inferno_powder') {
                block.setType('old_nether:withered_beacon_negative');
                player.runCommandAsync("playsound beacon.power @a [r=32]");
                player.runCommandAsync("playsound spirit.death @a[r=16] ~ ~ ~ 0.12 1");
                block.dimension.spawnEntity(('old_nether:wblbn_active'), block.location);
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:sculk_nylium_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:sculk_roots1 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:sculk_roots2 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:sculk_roots3 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:withered_nylium_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_roots1 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_roots2 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:withered_roots3 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:wart_nylium_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_roots1 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_roots2 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:nether_wart_roots3 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:soul_nylium_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:soul_roots1 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:soul_roots2 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:soul_roots3 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:anomalous_nylium_bonemeal', {
        onPlayerInteract({ block, player }) {
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === 'minecraft:bone_meal' || selectedItem?.typeId === 'old_nether:wither_bone_powder' || selectedItem?.typeId === 'old_nether:boggy_bone_powder' || selectedItem?.typeId === 'old_nether:stray_bone_powder') {
                const chance = Math.random();
                if (chance <= 1 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_roots1 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 2 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_roots2 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
                else if (chance <= 3 / 3) {
                    const { x, y, z } = block.location
                    block.dimension.runCommand(`structure load mystructure:anomalous_roots3 ${x - 2} ${y + 1} ${z - 2}`)
                    block.dimension.playSound('item.bone_meal.use', block.location)
                    block.dimension.runCommand(`particle minecraft:crop_growth_emitter ${x} ${y + 0.5} ${z}`)
                }
            }
        }
    })
})

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_anomalous_log', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:anomalous_log_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_sculk_log', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:sculk_log_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_wart_log', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:wart_log_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_log', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:ash_log_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_soul_log', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:soul_log_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_log', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:withered_log_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_anomalous_hyphae', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:anomalous_hyphae_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_sculk_hyphae', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:sculk_hyphae_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_wart_hyphae', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:wart_hyphae_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_hyphae', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:ash_hyphae_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_soul_hyphae', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:soul_hyphae_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_hyphae', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (!selectedItem?.hasTag('minecraft:is_axe')) return;
            const blockState = block.permutation.getState("minecraft:block_face");
            if (blockState) {
                const strippedLog = BlockPermutation.resolve('old_nether:withered_hyphae_stripped', { "minecraft:block_face": blockState });
                block.setPermutation(strippedLog);
            }
            player.playSound('step.wood');
            const durability = selectedItem.getComponent('durability');
            if (durability && durability.damage < durability.maxDurability) {
                durability.damage++;
                equipment.setEquipment('Mainhand', selectedItem);
            }
            if (durability && durability.damage >= durability.maxDurability) {
                player.playSound('random.break');
                equipment.setEquipment('Mainhand', new ItemStack('minecraft:air', 1));
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_anomalous_door', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const isUpperBlock = block.permutation.getState('old_nether:upper_block_bit');
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const targetBlock = isUpperBlock ? block.below() : block.above();
            const currentOpenState = block.permutation.getState('old_nether:open_bit');
            const targetOpenState = targetBlock.permutation.getState('old_nether:open_bit');
            const newOpenState = !currentOpenState;
            const newTargetOpenState = !targetOpenState;
            const newBlockPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open_bit': newOpenState
            });
            const newTargetBlockPermutation = BlockPermutation.resolve(targetBlock.typeId, {
                ...targetBlock.permutation.getAllStates(),
                'old_nether:open_bit': newTargetOpenState
            });
            block.setPermutation(newBlockPermutation);
            targetBlock.setPermutation(newTargetBlockPermutation);
            const sound = currentOpenState ? 'close.wooden_door' : 'open.wooden_door';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:anomalous_door' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'old_nether:anomalous_door';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_sculk_door', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const isUpperBlock = block.permutation.getState('old_nether:upper_block_bit');
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const targetBlock = isUpperBlock ? block.below() : block.above();
            const currentOpenState = block.permutation.getState('old_nether:open_bit');
            const targetOpenState = targetBlock.permutation.getState('old_nether:open_bit');
            const newOpenState = !currentOpenState;
            const newTargetOpenState = !targetOpenState;
            const newBlockPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open_bit': newOpenState
            });
            const newTargetBlockPermutation = BlockPermutation.resolve(targetBlock.typeId, {
                ...targetBlock.permutation.getAllStates(),
                'old_nether:open_bit': newTargetOpenState
            });
            block.setPermutation(newBlockPermutation);
            targetBlock.setPermutation(newTargetBlockPermutation);
            const sound = currentOpenState ? 'close.wooden_door' : 'open.wooden_door';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:sculk_door' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'old_nether:sculk_door';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_soul_door', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const isUpperBlock = block.permutation.getState('old_nether:upper_block_bit');
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const targetBlock = isUpperBlock ? block.below() : block.above();
            const currentOpenState = block.permutation.getState('old_nether:open_bit');
            const targetOpenState = targetBlock.permutation.getState('old_nether:open_bit');
            const newOpenState = !currentOpenState;
            const newTargetOpenState = !targetOpenState;
            const newBlockPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open_bit': newOpenState
            });
            const newTargetBlockPermutation = BlockPermutation.resolve(targetBlock.typeId, {
                ...targetBlock.permutation.getAllStates(),
                'old_nether:open_bit': newTargetOpenState
            });
            block.setPermutation(newBlockPermutation);
            targetBlock.setPermutation(newTargetBlockPermutation);
            const sound = currentOpenState ? 'close.wooden_door' : 'open.wooden_door';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:soul_door' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'old_nether:soul_door';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_wart_door', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const isUpperBlock = block.permutation.getState('old_nether:upper_block_bit');
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const targetBlock = isUpperBlock ? block.below() : block.above();
            const currentOpenState = block.permutation.getState('old_nether:open_bit');
            const targetOpenState = targetBlock.permutation.getState('old_nether:open_bit');
            const newOpenState = !currentOpenState;
            const newTargetOpenState = !targetOpenState;
            const newBlockPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open_bit': newOpenState
            });
            const newTargetBlockPermutation = BlockPermutation.resolve(targetBlock.typeId, {
                ...targetBlock.permutation.getAllStates(),
                'old_nether:open_bit': newTargetOpenState
            });
            block.setPermutation(newBlockPermutation);
            targetBlock.setPermutation(newTargetBlockPermutation);
            const sound = currentOpenState ? 'close.wooden_door' : 'open.wooden_door';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:wart_door' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'old_nether:wart_door';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_door', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const isUpperBlock = block.permutation.getState('old_nether:upper_block_bit');
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const targetBlock = isUpperBlock ? block.below() : block.above();
            const currentOpenState = block.permutation.getState('old_nether:open_bit');
            const targetOpenState = targetBlock.permutation.getState('old_nether:open_bit');
            const newOpenState = !currentOpenState;
            const newTargetOpenState = !targetOpenState;
            const newBlockPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open_bit': newOpenState
            });
            const newTargetBlockPermutation = BlockPermutation.resolve(targetBlock.typeId, {
                ...targetBlock.permutation.getAllStates(),
                'old_nether:open_bit': newTargetOpenState
            });
            block.setPermutation(newBlockPermutation);
            targetBlock.setPermutation(newTargetBlockPermutation);
            const sound = currentOpenState ? 'close.wooden_door' : 'open.wooden_door';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:ash_door' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'old_nether:ash_door';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_door', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const isUpperBlock = block.permutation.getState('old_nether:upper_block_bit');
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const targetBlock = isUpperBlock ? block.below() : block.above();
            const currentOpenState = block.permutation.getState('old_nether:open_bit');
            const targetOpenState = targetBlock.permutation.getState('old_nether:open_bit');
            const newOpenState = !currentOpenState;
            const newTargetOpenState = !targetOpenState;
            const newBlockPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open_bit': newOpenState
            });
            const newTargetBlockPermutation = BlockPermutation.resolve(targetBlock.typeId, {
                ...targetBlock.permutation.getAllStates(),
                'old_nether:open_bit': newTargetOpenState
            });
            block.setPermutation(newBlockPermutation);
            targetBlock.setPermutation(newTargetBlockPermutation);
            const sound = currentOpenState ? 'close.wooden_door' : 'open.wooden_door';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:withered_door' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'old_nether:withered_door';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Anomalous Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_anomalous_fence_gate', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem && face === 'Up' && BlockTypes.get(selectedItem.typeId)) {
                const aboveBlock = block.above();
                if (aboveBlock.typeId === 'old_nether:anomalous_fence_gate') {
                    aboveBlock.setType(selectedItem.typeId);
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    return; // Exit the function after placing the block
                }
            }
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const sound = newOpenState ? 'open.fence_gate' : 'close.fence_gate';
            const rotationAngle = player.getRotation().y;
            const newCardinalDirection = getNewCardinalDirection(block.permutation.getState('minecraft:cardinal_direction'), rotationAngle);
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState,
                'minecraft:cardinal_direction': newCardinalDirection
            });
            block.setPermutation(newPermutation);
            block.dimension.playSound(sound, block.location);
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:anomalous_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                const aboveCurrentState = aboveBlock.permutation.getState('old_nether:open');
                if (aboveCurrentState !== newOpenState) {
                    const newAbovePermutation = BlockPermutation.resolve(aboveBlock.typeId, {
                        ...aboveBlock.permutation.getAllStates(),
                        'old_nether:open': newOpenState
                    });
                    aboveBlock.setPermutation(newAbovePermutation);
                }
            }
        }
    });
});

// Function to calculate the new cardinal direction based on the player's rotation
function getNewCardinalDirection(currentDirection, angle) {
    const direction = directionDisplay(angle);
    if (['north', 'south'].includes(currentDirection)) {
        return direction.includes('south') ? 'south' : 'north';
    } else {
        return direction.includes('west') ? 'west' : 'east';
    }
}

// Function to calculate the direction a player is looking at
function directionDisplay(angle) {
    if (Math.abs(angle) > 112.5) return 'north';
    if (Math.abs(angle) < 67.5) return 'south';
    if (angle < 157.5 && angle > 22.5) return 'west';
    if (angle > -157.5 && angle < -22.5) return 'east';
    return '';
}

//Sculk Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_sculk_fence_gate', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem && face === 'Up' && BlockTypes.get(selectedItem.typeId)) {
                const aboveBlock = block.above();
                if (aboveBlock.typeId === 'old_nether:sculk_fence_gate') {
                    aboveBlock.setType(selectedItem.typeId);
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    return; // Exit the function after placing the block
                }
            }
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const sound = newOpenState ? 'open.fence_gate' : 'close.fence_gate';
            const rotationAngle = player.getRotation().y;
            const newCardinalDirection = getNewCardinalDirection(block.permutation.getState('minecraft:cardinal_direction'), rotationAngle);
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState,
                'minecraft:cardinal_direction': newCardinalDirection
            });
            block.setPermutation(newPermutation);
            block.dimension.playSound(sound, block.location);
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:sculk_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                const aboveCurrentState = aboveBlock.permutation.getState('old_nether:open');
                if (aboveCurrentState !== newOpenState) {
                    const newAbovePermutation = BlockPermutation.resolve(aboveBlock.typeId, {
                        ...aboveBlock.permutation.getAllStates(),
                        'old_nether:open': newOpenState
                    });
                    aboveBlock.setPermutation(newAbovePermutation);
                }
            }
        }
    });
});

//Soul Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_soul_fence_gate', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem && face === 'Up' && BlockTypes.get(selectedItem.typeId)) {
                const aboveBlock = block.above();
                if (aboveBlock.typeId === 'old_nether:soul_fence_gate') {
                    aboveBlock.setType(selectedItem.typeId);
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    return; // Exit the function after placing the block
                }
            }
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const sound = newOpenState ? 'open.fence_gate' : 'close.fence_gate';
            const rotationAngle = player.getRotation().y;
            const newCardinalDirection = getNewCardinalDirection(block.permutation.getState('minecraft:cardinal_direction'), rotationAngle);
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState,
                'minecraft:cardinal_direction': newCardinalDirection
            });
            block.setPermutation(newPermutation);
            block.dimension.playSound(sound, block.location);
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:soul_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                const aboveCurrentState = aboveBlock.permutation.getState('old_nether:open');
                if (aboveCurrentState !== newOpenState) {
                    const newAbovePermutation = BlockPermutation.resolve(aboveBlock.typeId, {
                        ...aboveBlock.permutation.getAllStates(),
                        'old_nether:open': newOpenState
                    });
                    aboveBlock.setPermutation(newAbovePermutation);
                }
            }
        }
    });
});

//Wart Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_wart_fence_gate', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem && face === 'Up' && BlockTypes.get(selectedItem.typeId)) {
                const aboveBlock = block.above();
                if (aboveBlock.typeId === 'old_nether:wart_fence_gate') {
                    aboveBlock.setType(selectedItem.typeId);
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    return; // Exit the function after placing the block
                }
            }
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const sound = newOpenState ? 'open.fence_gate' : 'close.fence_gate';
            const rotationAngle = player.getRotation().y;
            const newCardinalDirection = getNewCardinalDirection(block.permutation.getState('minecraft:cardinal_direction'), rotationAngle);
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState,
                'minecraft:cardinal_direction': newCardinalDirection
            });
            block.setPermutation(newPermutation);
            block.dimension.playSound(sound, block.location);
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:wart_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                const aboveCurrentState = aboveBlock.permutation.getState('old_nether:open');
                if (aboveCurrentState !== newOpenState) {
                    const newAbovePermutation = BlockPermutation.resolve(aboveBlock.typeId, {
                        ...aboveBlock.permutation.getAllStates(),
                        'old_nether:open': newOpenState
                    });
                    aboveBlock.setPermutation(newAbovePermutation);
                }
            }
        }
    });
});

//Ash Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_fence_gate', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem && face === 'Up' && BlockTypes.get(selectedItem.typeId)) {
                const aboveBlock = block.above();
                if (aboveBlock.typeId === 'old_nether:ash_fence_gate') {
                    aboveBlock.setType(selectedItem.typeId);
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    return; // Exit the function after placing the block
                }
            }
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const sound = newOpenState ? 'open.fence_gate' : 'close.fence_gate';
            const rotationAngle = player.getRotation().y;
            const newCardinalDirection = getNewCardinalDirection(block.permutation.getState('minecraft:cardinal_direction'), rotationAngle);
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState,
                'minecraft:cardinal_direction': newCardinalDirection
            });
            block.setPermutation(newPermutation);
            block.dimension.playSound(sound, block.location);
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:ash_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                const aboveCurrentState = aboveBlock.permutation.getState('old_nether:open');
                if (aboveCurrentState !== newOpenState) {
                    const newAbovePermutation = BlockPermutation.resolve(aboveBlock.typeId, {
                        ...aboveBlock.permutation.getAllStates(),
                        'old_nether:open': newOpenState
                    });
                    aboveBlock.setPermutation(newAbovePermutation);
                }
            }
        }
    });
});

//Withered Fence Gate
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_fence_gate', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem && face === 'Up' && BlockTypes.get(selectedItem.typeId)) {
                const aboveBlock = block.above();
                if (aboveBlock.typeId === 'old_nether:withered_fence_gate') {
                    aboveBlock.setType(selectedItem.typeId);
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    return; // Exit the function after placing the block
                }
            }
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const sound = newOpenState ? 'open.fence_gate' : 'close.fence_gate';
            const rotationAngle = player.getRotation().y;
            const newCardinalDirection = getNewCardinalDirection(block.permutation.getState('minecraft:cardinal_direction'), rotationAngle);
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState,
                'minecraft:cardinal_direction': newCardinalDirection
            });
            block.setPermutation(newPermutation);
            block.dimension.playSound(sound, block.location);
            const aboveBlock = block.above();
            if (aboveBlock.typeId === 'old_nether:withered_fence_gate' && aboveBlock.permutation.getState('old_nether:invisible')) {
                const aboveCurrentState = aboveBlock.permutation.getState('old_nether:open');
                if (aboveCurrentState !== newOpenState) {
                    const newAbovePermutation = BlockPermutation.resolve(aboveBlock.typeId, {
                        ...aboveBlock.permutation.getAllStates(),
                        'old_nether:open': newOpenState
                    });
                    aboveBlock.setPermutation(newAbovePermutation);
                }
            }
        }
    });
});

//Anomalous Trapdoor
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_anomalous_trapdoor', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState
            });
            block.setPermutation(newPermutation);
            const sound = currentState ? 'open.wooden_trapdoor' : 'close.wooden_trapdoor';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:anomalous_trapdoor' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'mystructure:trapdoor';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Sculk Trapdoor
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_sculk_trapdoor', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState
            });
            block.setPermutation(newPermutation);
            const sound = currentState ? 'open.wooden_trapdoor' : 'close.wooden_trapdoor';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:sculk_trapdoor' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'mystructure:trapdoor';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Soul Trapdoor
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_soul_trapdoor', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState
            });
            block.setPermutation(newPermutation);
            const sound = currentState ? 'open.wooden_trapdoor' : 'close.wooden_trapdoor';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:soul_trapdoor' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'mystructure:trapdoor';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Wart Trapdoor
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_wart_trapdoor', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState
            });
            block.setPermutation(newPermutation);
            const sound = currentState ? 'open.wooden_trapdoor' : 'close.wooden_trapdoor';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:wart_trapdoor' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'mystructure:trapdoor';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Ash Trapdoor
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_trapdoor', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState
            });
            block.setPermutation(newPermutation);
            const sound = currentState ? 'open.wooden_trapdoor' : 'close.wooden_trapdoor';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:ash_trapdoor' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'mystructure:trapdoor';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Withered Trapdoor
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_trapdoor', {
        onPlayerInteract(e) {
            const { block, player } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            const currentState = block.permutation.getState('old_nether:open');
            const newOpenState = !currentState;
            const newPermutation = BlockPermutation.resolve(block.typeId, {
                ...block.permutation.getAllStates(),
                'old_nether:open': newOpenState
            });
            block.setPermutation(newPermutation);
            const sound = currentState ? 'open.wooden_trapdoor' : 'close.wooden_trapdoor';
            player.playSound(sound);
            if (selectedItem?.typeId === 'minecraft:water_bucket') {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
            }
            if (block.typeId === 'old_nether:withered_trapdoor' && selectedItem?.typeId === 'minecraft:water_bucket') {
                const currentStates = block.permutation.getAllStates();
                const structureName = 'mystructure:trapdoor';
                const { x, y, z } = block.location;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
                const newBlock = e.dimension.getBlock({ x, y, z });
                const newStates = { ...newBlock.permutation.getAllStates(), ...currentStates };
                const newPermutation = BlockPermutation.resolve(newBlock.typeId, newStates);
                newBlock.setPermutation(newPermutation);
            }
        }
    });
});

//Bloodstone Bricks Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_bloodstone_bricks_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.stone');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Anomalous Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_anomalous_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.wood');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Sculk Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_sculk_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.wood');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Soul Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_soul_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.wood');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Wart Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_wart_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.wood');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Ash Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ash_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.wood');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Withered Slab
world.beforeEvents.worldInitialize.subscribe(eventData => {
    eventData.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_withered_slab', {
        onPlayerInteract(e) {
            const { block, player, face } = e;
            const equipment = player.getComponent('equippable');
            const selectedItem = equipment.getEquipment('Mainhand');
            if (selectedItem?.typeId === block.typeId && !block.permutation.getState('old_nether:double')) {
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const isBottomUp = verticalHalf === 'bottom' && face === 'Up';
                const isTopDown = verticalHalf === 'top' && face === 'Down';
                if (isBottomUp || isTopDown) {
                    if (player.getGameMode() !== "creative") {
                        if (selectedItem.amount > 1) {
                            selectedItem.amount -= 1;
                            equipment.setEquipment('Mainhand', selectedItem);
                        } else if (selectedItem.amount === 1) {
                            equipment.setEquipment('Mainhand', undefined); // Clear the slot if only 1 item left
                        }
                    }
                    block.setPermutation(block.permutation.withState('old_nether:double', true));
                    block.setWaterlogged(false);
                    player.playSound('use.wood');
                }
            }
            if (selectedItem?.typeId === 'minecraft:water_bucket' && !block.permutation.getState('old_nether:waterlogged') && !block.permutation.getState('old_nether:double')) {
                player.playSound('bucket.empty_water');
                if (player.getGameMode() !== "creative") {
                    equipment.setEquipment('Mainhand', new ItemStack('minecraft:bucket', 1));
                }
                block.setPermutation(block.permutation.withState('old_nether:waterlogged', true));
                const verticalHalf = block.permutation.getState('minecraft:vertical_half');
                const slabType = block.typeId.split(':')[1];
                const structureName = (verticalHalf === 'bottom') ? `mystructure:${slabType}_bottomSlab` : `mystructure:${slabType}_topSlab`;
                const { x, y, z } = block;
                world.structureManager.place(structureName, e.dimension, { x, y, z });
            }
        }
    });
});

//Nether Reactor Core Function

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_nether_reactor_core', {
        onPlayerInteract({ block, player }) {
            const { x, y, z } = block;
            player.runCommandAsync("say §aActive")
            player.runCommandAsync("time set 13000")
            player.runCommandAsync("playsound reactor.activate @a[r=16]")
            block.dimension.runCommand(`structure load mystructure:netherrack_spire ${x - 8} ${y - 2} ${z - 8}`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ruby_reactor_core', {
        onPlayerInteract({ block, player }) {
            const { x, y, z } = block;
            player.runCommandAsync("say §aActive")
            player.runCommandAsync("time set 13000")
            player.runCommandAsync("playsound reactor.activate @a[r=16]")
            block.dimension.runCommand(`structure load mystructure:bloodstone_spire ${x - 8} ${y - 2} ${z - 8}`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_iron_reactor_core', {
        onPlayerInteract({ block, player }) {
            const { x, y, z } = block;
            player.runCommandAsync("say §aActive")
            player.runCommandAsync("time set 13000")
            player.runCommandAsync("playsound reactor.activate @a[r=16]")
            block.dimension.runCommand(`structure load mystructure:obsidian_spire ${x - 8} ${y - 2} ${z - 8}`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_ruby_iron_reactor_core', {
        onPlayerInteract({ block, player }) {
            const { x, y, z } = block;
            player.runCommandAsync("say §aActive")
            player.runCommandAsync("time set 13000")
            player.runCommandAsync("playsound reactor.activate @a[r=16]")
            block.dimension.runCommand(`structure load mystructure:volcanic_rock_spire ${x - 8} ${y - 2} ${z - 8}`)
        }
    });
});

world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('old_nether:on_interact_inferno_reactor_core', {
        onPlayerInteract({ block, player }) {
            const { x, y, z } = block;
            player.runCommandAsync("say §aActive")
            player.runCommandAsync("time set 13000")
            player.runCommandAsync("weather clear")
            player.runCommandAsync("playsound reactor.activate @a[r=16]")
            block.dimension.runCommand(`structure load mystructure:inferno_spire ${x - 8} ${y - 2} ${z - 8}`)
        }
    });
});