import { world, system } from "@minecraft/server";
import { utils } from "Utils";
import { cutsceneController } from "CutsceneController";
import { particleController } from "ParticleController";
import { } from "./PortalTeleport";
import { } from "./BossSecurity";
import { } from "./Eternal/Modules/MusicController";
import { } from "./tamedNamer";
import { } from "./chop";
import { } from "./interactiveTools";
import { } from "./crops";
import { } from "./dragon_tip";

import { } from "./Eternal/fixes/142468";
import { } from './Portal'

let previousCoords = null;

// world.beforeEvents.itemUseOn.subscribe((event) => {
//   const { block, itemStack, source } = event;

//   const { x, y, z } = block.location;

//   // This event is called while using, not on click, so this line speeds up performance by not running the commands more than once on one block
//   if (previousCoords && previousCoords.x === x && previousCoords.y === y && previousCoords.z === z) {
//     return;
//   }

//   previousCoords = { x, y, z };

//   const isHoeOrAxe = itemStack.typeId.match(/eternal:.+(_hoe|_axe)/);

//   if (isHoeOrAxe) {
//     const toolType = isHoeOrAxe[1].toLowerCase();
//     source.runCommandAsync(`execute positioned ${x} ${y} ${z} run function eternal/tools/use${toolType}`);
//   }
// });
const playerJoin = world.afterEvents.playerJoin;
playerJoin.subscribe((event) => {
  system.runTimeout(() => {
    utils.serverCommand(
      `scoreboard players set @a id 0`,
      `execute as @a[scores={in_quest=1}] run titleraw @s title {"rawtext":[{"text":"eternal.quest_"},{"score":{"name":"@s","objective":"quest"}}]}`
    );
  }, 200);
});
