import { world, system } from '@minecraft/server';
import { fo } from './utilities/fo_constants.js';


export function initNoSleep() {

    function disableDaylightCycle() {
        world.gameRules.doDayLightCycle = false;
        

        system.runTimeout(() => {
            world.gameRules.doDayLightCycle = true;
            
        }, 102);
    }

    world.afterEvents.playerInteractWithBlock.subscribe((event) => {
        if (event.block?.typeId === "minecraft:bed" && fo.forebodingScore >= fo.scoreChapter5) {
            const time = world.getTimeOfDay();

            
            if ((time >= 12542 && time < 23992)) {
                
                disableDaylightCycle();
            } else {
                
            }
        }
    });

}