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

function assertKeepInventory() {
  try {
    world.getDimension("overworld").runCommand("gamerule keepInventory true");
  } catch (e) {
    // Non-fatal — chunk-load races, etc. The next interval will retry.
  }
}

system.run(() => {
  assertKeepInventory();
  world.sendMessage("§a[Keep Inventory] §7keepInventory enforced — items stay on death.");
});

// Re-assert every 10 minutes so anything that toggles it off (manual op, world reset, etc.) gets corrected.
system.runInterval(assertKeepInventory, 12000);
