import { world, system } from "@minecraft/server";
import Timer from "../timer/timerClass";

system.beforeEvents.startup.subscribe(initEvent => {
    initEvent.itemComponentRegistry.registerCustomComponent('rustic:ironberries_on_cosume', {
      onConsume: e =>  {
        const source = e.source

        let timeHolder = Timer.set(10, "seconds");
        let intervalId = system.runInterval(() => {
            let isExpired = Timer.hasExpired(timeHolder);
            source.applyKnockback(0,0,0,-1)             

            if (isExpired) system.clearRun(intervalId);
        }, 1);

        source.addEffect('weakness', 200);
        source.addEffect('mining_fatigue', 200);
        source.addEffect('slowness', 200);
        source.addEffect('resistance', 200);
        source.addEffect('fire_resistance', 200);
      }
    });
});