//“修复”帕斯特之梦的一些bug

//风之旅途进度丢失bug
ItemEvents.rightClicked(event => {
    let player = event.player;
    if (!player || event.hand != 'MAIN_HAND') return;
    let item = player.getMainHandItem()
    if (item.id == 'pasterdream:dreamnotes_14') {
        player.persistentData.putBoolean("dreamnotes_14", true)
    }
})
PlayerEvents.tick(event => {
    let player = event.player;
    if (!player) return;
    if (player.age % 20 != 0) return;
    if (player.hasEffect('pasterdream:fondillusion_buff') && player.level.getDimension() == 'minecraft:overworld' && player.persistentData.getBoolean("dreamnotes_14")) {
        if (player.y > 310) {
            player.teleportTo("pasterdream:wind_journey_world", 0, 300, 0, player.yaw, player.pitch)
        }
    }
})


//阴影维度进不去bug
ItemEvents.rightClicked(event => {
    let player = event.player;
    if (!player || event.hand != 'MAIN_HAND') return;
    let item = player.getMainHandItem()
    if (item.id == 'pasterdream:dreamnotes_8' || item.id == 'pasterdream:dreamnotes_9') {
        player.persistentData.putBoolean("lamp_shadow_world", true)
    }
})
BlockEvents.rightClicked(event => {
    let player = event.player;
    let block = event.block.id
    if (!player || event.hand != 'MAIN_HAND' || block != 'pasterdream:shadow_bed') return;
    //延后检测玩家是否在阴影维度，防止传送两次
    player.getServer().scheduleInTicks(5, () => {
        if (player.persistentData.getBoolean("lamp_shadow_world") && player.level.getDimension() != "pasterdream:lamp_shadow_world") {
            player.teleportTo("pasterdream:lamp_shadow_world", 0, 100, 0, player.yaw, player.pitch)
        }
    })
})