BlockEvents.rightClicked('kubejs:void_portal_block', event => {
    const { player, level, hand } = event
    
    if (hand != 'main_hand') return

    let voidDim = 'kubejs:void_dim'
    let currentDim = String(level.dimension)

    if (currentDim != voidDim) {

        player.persistentData.putDouble('overworldX', player.x)
        player.persistentData.putDouble('overworldY', player.y)
        player.persistentData.putDouble('overworldZ', player.z)
        player.persistentData.putString('overworldDim', currentDim)

        let vx = player.persistentData.getDouble('voidX')
        let vy = player.persistentData.getDouble('voidY')
        let vz = player.persistentData.getDouble('voidZ')

        if (vy != 0) {
            player.teleportTo(voidDim, vx, vy, vz, player.yaw, player.pitch)
        } else {
            player.teleportTo(voidDim, 0.5, 65.1, 0.5, 0, 0)
        }

    } else {

        player.persistentData.putDouble('voidX', player.x)
        player.persistentData.putDouble('voidY', player.y)
        player.persistentData.putDouble('voidZ', player.z)

        let rx = player.persistentData.getDouble('overworldX')
        let ry = player.persistentData.getDouble('overworldY')
        let rz = player.persistentData.getDouble('overworldZ')
        let rd = player.persistentData.getString('overworldDim')

        if (rd != "" && rd != null) {
            player.teleportTo(rd, rx, ry, rz, player.yaw, player.pitch)
        } else {
            player.teleportTo('minecraft:overworld', 0, 100, 0, 0, 0)
        }
    }
})