import { world, system } from "@minecraft/server";

const FOG_ID = "mid:fog_the_limbo";

// límites del área (XZ) → POSITIVOS
const MIN = 20000;
const MAX = 30000;

function isInsideZone(x, z) {
  return (
    x >= MIN && x <= MAX &&
    z >= MIN && z <= MAX
  );
}

system.runInterval(() => {
  for (const player of world.getPlayers()) {

    // Solo The End
    if (player.dimension.id !== "minecraft:the_end") {
      player.runCommandAsync("fog @s remove mid_limbo");
      continue;
    }

    const { x, z } = player.location;

    if (isInsideZone(x, z)) {
      // Aplica la niebla del Limbo
      player.runCommandAsync(
        `fog @s push ${FOG_ID} mid_limbo`
      );
    } else {
      // Quita la niebla si sale del área
      player.runCommandAsync(
        "fog @s remove mid_limbo"
      );
    }
  }
}, 20); // cada 1 segundo