import { world, ItemStack, MolangVariableMap, StructureAnimationMode, StructureRotation, StructureSaveMode } from "@minecraft/server";
import { generateUUID } from "../utilities/uuid";

// export function saveStructureAndSaveOnEntity(backpack, campSize) {
//   let structureUUID = "hb_cb:" + backpack.id.toString() + "OldTerrain";

//   // system.waitTicks(30).then(() => {
//   world.structureManager.delete(structureUUID);
//   // });
//   //////////world.sendMessage("SAVE OLD TERRAIN STRUCTURE");
//   let pos1 = { x: backpack.location.x + campSize, y: backpack.location.y - 1, z: backpack.location.z + campSize };
//   let pos2 = { x: backpack.location.x - campSize, y: backpack.location.y + campSize * 2, z: backpack.location.z - campSize };
//   world.structureManager.createFromWorld(structureUUID, backpack.dimension, pos1, pos2, { saveMode: StructureSaveMode.World, includeEntities: false });
//   backpack.setDynamicProperty("hb_cb_old_terrain", structureUUID);
// }

export function showCampBoxHint(player) {
  let nearbyEntities = world.getDimension(player.dimension.id).getEntities({
    families: ["hb_cb_backpack"],
    location: player.location,
    tags: ["hb_cb:show_camp_box_hint"],
    minDistance: 0,
    maxDistance: 10,
  });
  if (nearbyEntities.length === 0 || nearbyEntities[0] == undefined) return;
  else {
    nearbyEntities.forEach((nearbyEntity) => {
      if (nearbyEntity.typeId == undefined || nearbyEntity.typeId.includes("minecraft:item") || nearbyEntity.typeId.includes("minecraft:falling_block") || nearbyEntity.typeId.includes("minecraft:xp_orb") || nearbyEntity.typeId.includes("minecraft:arrow")) {
        return;
      } else {
        // //////////world.sendMessage("CAMP OPEN " + nearbyEntity.getProperty("hb_cb:camp_state"));
        // //////////world.sendMessage("CAMP structure " + nearbyEntity.getDynamicProperty("hb_cb_structure_name"));
      }
    });
  }
}
