ForgeEvents.onEvent(
  "net.minecraftforge.event.entity.EntityTravelToDimensionEvent",
  (event) => {
    global.teleportEvent(event);
  }
);

global.teleportEvent = (event) => {
  const { entity, dimension } = event;
  if (!entity.isPlayer()) return;
  switch (dimension) {
    case "the_bumblezone:the_bumblezone": {
      bumblezoneTeleport(event);
    }
  }
};

function bumblezoneTeleport(event) {
  const { entity, dimension } = event;

  // early return if the player has the correct stage, to not check for armor
  // this stage is only given to player once they enter the bumblezone once with correct armor
  if (entity.stages.has("allow_bumblezone_teleport")) return;

  if (global.hasArmor(entity, dimension.path)) return;
  entity.tell("You need a Bee suit to enter the Bumblezone");
  event.setCanceled(true);
}

global.hasArmor = (player, dimension) => {
  let [boots, leggings, chest, head] = player.getArmorSlots();
  // console.log(boots.id, leggings.id, chest.id, head.id);
  if (!global.armorCheck[dimension].boots.includes(boots.id)) return false;
  if (!global.armorCheck[dimension].leggings.includes(leggings.id)) return false;
  if (!global.armorCheck[dimension].chest.includes(chest.id)) return false;
  if (!global.armorCheck[dimension].head.includes(head.id)) return false;
  //add a stage to allow teleporting to the bumblezone if the player has the correct armor
  player.stages.add("allow_bumblezone_teleport");

  return true;
};

global.armorCheck = {
  the_bumblezone: {
    head: [
      "the_bumblezone:stingless_bee_helmet_1",
      "the_bumblezone:stingless_bee_helmet_2",
      "thermal:beekeeper_helmet",
    ],
    chest: [
      "the_bumblezone:bumble_bee_chestplate_1",
      "the_bumblezone:bumble_bee_chestplate_2",
      "the_bumblezone:bumble_bee_chestplate__trans_1",
      "the_bumblezone:bumble_bee_chestplate_trans_2",
      "thermal:beekeeper_chestplate",
    ],
    leggings: [
      "the_bumblezone:honey_bee_leggings_1",
      "the_bumblezone:honey_bee_leggings_2",
      "thermal:beekeeper_leggings",
    ],
    boots: [
      "the_bumblezone:carpenter_bee_boots_1",
      "the_bumblezone:carpenter_bee_boots_2",
      "thermal:beekeeper_boots",
    ],
  },
};
 
