import { world, system } from "@minecraft/server";
import { playerJoins } from "./events/player_joins";
import { itemLore } from "./items/item_lore";
import { itemUseController } from "./items/item_use_controller";
import { entityHitEntityController } from "./entity/entity_hit_entity_controller";
import { playerInteractEntityController } from "./entity/player_interact_entity_controller";
import { showCampBoxHint } from "./entity/camp_controller";
import { itemHold } from "./items/item_hold";
import { backpackHandler } from "./utilities/backpack_handler";
import { tentHandler } from "./utilities/tent_handler";
import { diamondPoppyHandler } from "./utilities/diamond_poppy_handler";
import { ancientLanternHandler } from "./utilities/ancient_lantern_handler";
import { bellStaffHandler } from "./utilities/bell_staff_handler";
import { roofHandler } from "./utilities/roof_handler";
import { kettleHandler } from "./utilities/kettle_handler";
import { benchHandler } from "./utilities/bench_handler";
import { foodHandler } from "./utilities/food_handler";

let curTick = 0;
const INIT_TIME = 0;

new backpackHandler();
new tentHandler();
new diamondPoppyHandler();
new ancientLanternHandler();
new bellStaffHandler();
new roofHandler();
new kettleHandler();
new benchHandler();
new foodHandler();

// Subscribe to an event that calls every Minecraft tick
system.runInterval(() => {
  try {
    if (curTick > INIT_TIME) {
      const allPlayers = world.getAllPlayers();
      allPlayers.forEach((player) => {
        if (!player.isValid()) return;
        else {
          showCampBoxHint(player);
          itemLore(player);
          itemHold(player);
        }
      });
    }
    curTick++;
  } catch (e) {
    console.warn(e);
  }
}, 0);

world.afterEvents.playerInteractWithEntity.subscribe(playerInteractEntityController);
world.afterEvents.playerSpawn.subscribe(playerJoins);
// world.afterEvents.entityHitEntity.subscribe(entityHitEntityController);
// world.afterEvents.itemUse.subscribe(itemUseController);
