ServerEvents.recipes(event => {
    event.shaped('kubejs:sundial', [
        ' G ',
        'BEB',
        'GGG'
    ], {
        G: 'minecraft:gold_block',
        B: 'iceandfire:dragonbone',
        E: 'minecraft:ender_pearl'
    })
})

BlockEvents.rightClicked('kubejs:sundial', event => {
    const { player, level, server } = event
    
    // Must call () because dayTime is a getter method in your KubeJS version
    let currentAbsoluteDayTime = level.dayTime()
    let currentDayTime = currentAbsoluteDayTime % 24000
    
    if (currentDayTime < 12000 || currentDayTime > 23800) {
        player.setStatusMessage(Text.of("The Sundial only turns during the dark hours.").yellow())
        return
    }

    // Original cooldown logic restored exactly as you first sent it
    let currentTime = level.time
    let lastUse = player.persistentData.getLong('sundial_cd')
    if (currentTime < lastUse + 72000 && lastUse != 0) {
        let remainingTicks = (lastUse + 72000) - currentTime
        let remainingDays = Math.ceil(remainingTicks / 24000)
        player.setStatusMessage(Text.of(`The Sundial is cold. Wait ${remainingDays} days.`).red())
        return
    }
    
    player.persistentData.putLong('sundial_cd', currentTime)

    // Calculate ticks to add to reach dawn (1000) on the NEXT day
    let ticksToAdd = 24000 - currentDayTime + 1000
    
    // Directly advance the day cycle using the proper API (bypasses commands)
    level.setDayTime(currentAbsoluteDayTime + ticksToAdd)
    
    // Clear weather like sleeping in a bed
    server.runCommandSilent('weather clear 6000')
    
    server.runCommandSilent(`execute at ${player.uuid} run playsound minecraft:block.bell.use block @p ~ ~ ~ 1 0.5`)
    server.runCommandSilent(`execute at ${player.uuid} run particle minecraft:flash ~ ~1 ~ 0 0 0 0 1`)
    
    player.tell(Text.of("The gears of time grind forward... dawn arrives.").gold())
    player.setStatusMessage(Text.of("Dawn has arrived.").yellow())
})