import { world, system, EquipmentSlot } from "@minecraft/server";
import * as game from "./game";
import * as utils from "./utils";
import * as effect_weapons from "./effect_weapons";
import * as armor_sets from "./armor_sets";
import * as amethyst_staff from "./special_items/amethyst_staff";
import * as book from "./book";
import * as intro from "./intro";
import * as lightning_axe from "./special_items/lightning_axe";
import * as ender_dagger from "./special_items/ender_dagger";
import * as vampire_fang from "./special_items/vampire_fang";
import * as demolition_hammer from "./special_items/demolition_hammer";
import * as fire_shield from "./special_items/fire_shield";
import * as tornado_wand from "./special_items/tornado_wand";
import * as tnt_stick from "./special_items/tnt_stick";
import * as inferno_scythe from "./special_items/inferno_scythe";
import * as dragon_staff from "./special_items/dragon_staff";
import * as custom_tools from "./custom_tools";
import * as punch_sounds from "./special_items/punch_sounds";

export async function onLoad() {
  await fire_shield.onLoad();
}

export async function onTick() {
  armor_sets.onTick();
  intro.onTick();
  fire_shield.onTick();
  await tornado_wand.onTick();
}

export async function onEntityLoad(event) {}

export async function onPlayerSpawn(event) {
  intro.onPlayerSpawn(event);
}

export async function onPlayerJoin(event) {}

export async function onEntitySpawn(event) {}

export async function onEntityHealthChanged(event) {}

export async function onEntityHurt(event) {
  await effect_weapons.onEntityHurt(event);
  await armor_sets.onEntityHurt(event);
  await lightning_axe.onEntityHurt(event);
  await fire_shield.onEntityHurt(event);
}

export async function onEntityHitEntity(event) {
  await vampire_fang.onEntityHit(event);
  await punch_sounds.onEntityHit(event);
  await demolition_hammer.onEntityHit(event);
  await ender_dagger.onEntityHit(event);
  await inferno_scythe.onEntityHit(event);
  await dragon_staff.onEntityHit(event);
  await amethyst_staff.onEntityHit(event);
  await tornado_wand.onEntityHit(event);
  await custom_tools.onEntityHit(event);
}

export async function onEntityDie(event) {
}

export async function onItemUse(event) {
  const item = event.itemStack.typeId;

  if (item == "tcs_cwp:inferno_scythe") inferno_scythe.onItemUse(event);
  if (item == "tcs_cwp:ender_dagger") ender_dagger.onItemUse(event);
  if (item == "tcs_cwp:intro") intro.onItemUse(event);
  if (item == "tcs_cwp:book") book.onItemUse(event);
  if (item == "tcs_cwp:amethyst_staff") amethyst_staff.onItemUse(event);
  if (item == "tcs_cwp:demolition_hammer")
    await demolition_hammer.onItemUse(event);
  if (item == "tcs_cwp:tornado_wand") await tornado_wand.onItemUse(event);
  if (item == "tcs_cwp:tnt_stick") await tnt_stick.onItemUse(event);
  if (item == "tcs_cwp:dragon_staff") await dragon_staff.onItemUse(event);
}

export async function onItemStartUse(event) {}

export async function onItemStopUse(event) {}

export async function onItemUseOn(event) {
}

export async function onEntityHitBlock(event) {}

export async function onPlayerBreakBlock(event) {
  if(event.itemStackBeforeBreak == undefined || event.itemStackBeforeBreak.typeId == undefined) return;

  if(event.itemStackBeforeBreak.typeId.startsWith("tcs_cwp:")) {
    custom_tools.onPlayerBreakBlock(event);
  }
}

export async function onPlayerInteractWithEntity(event) {}

export async function onScriptEventReceive(event) {
  if (event.id === "tcs_cwp:update_entity") {
    dragon_staff.onScriptEventReceive(event);
  }
}

export async function onPlayerButtonInput(event) {
  armor_sets.onPlayerButtonInput(event);
}

export async function onPlayerPlaceBlock(event) {
}

export async function onEntityRemoveAfterEvent(event) {
}

export async function onPlayerInteractWithBlock(event) {
  if(event.itemStack == undefined || event.itemStack.typeId == undefined) return;

  if(event.itemStack.typeId.startsWith("tcs_cwp:")) {
    custom_tools.onPlayerInteractWithBlock(event);
  }
}