console.warn("main.js loaded");

import { world, system } from "@minecraft/server";
import * as general from "./systems/general.js";
import "./systems/general.js";
import "./systems/scriptevent.js";
import "./systems/titles.js";
import "./systems/movement.js";
import "./systems/forms.js";
import "./systems/blocks.js";


general.tick1((player) => {

  if (player.hasTag(`humungousaur`) && !player.hasTag(`no_camera`)) {
    player.runCommandAsync(`execute as @s positioned ~~4~ run camera @s set minecraft:free ease 0.2 linear pos ^^^-7 rot ~~`);
  } else if (player.hasTag(`humungousaur_full`) && !player.hasTag(`no_camera`)) {
    player.runCommandAsync(`execute as @s positioned ~~6~ run camera @s set minecraft:free ease 0.2 linear pos ^^^-9 rot ~~`);
  } else if (player.hasTag(`humungousaur_ultimate`) && !player.hasTag(`no_camera`)) {
    player.runCommandAsync(`execute as @s positioned ~~6~ run camera @s set minecraft:free ease 0.2 linear pos ^^^-8 rot ~~`);
  } else if (player.hasTag(`no_camera`)) {
    player.runCommandAsync(`camera @s clear`);
  }

});

system.runInterval(() => {
  for (const player of world.getPlayers()) {
    if (player.hasTag("no_camera")) {
      system.runTimeout(() => {
        player.removeTag("no_camera");
      }, 2);
    }
    if (player.hasTag("cant_select")) {
      system.runTimeout(() => {
        player.runCommandAsync(`execute as @s at @s run execute unless entity @e[type=yog:alien_x_domain,r=14] run tag @s remove cant_select`);
      }, 4);
    }
  }
}, 1);