HWH Scripts
===========

Put one JavaScript file (.js) in this folder for each custom module. Scripts
are discovered automatically within about two seconds; no restart is required.
The folder is config/HWH/scripts inside Minecraft's active game directory
(usually .minecraft/config/HWH/scripts). Empty files are rejected.
Each file must define a global module object:

var module = {
    name: "Script Example",
    settings: {
        report: { type: "boolean", default: true },
        interval: { type: "int", default: 200, min: 20, max: 1200 },
        style: { type: "mode", default: "Compact", options: ["Compact", "Detailed"] },
        prefix: { type: "text", default: "[HWH]" }
    },
    onEnable: function (hwh) {
        hwh.log("Script Example enabled");
    },
    onDisable: function (hwh) {
        hwh.log("Script Example disabled");
    },
    onTick: function (hwh) {
        if (!hwh.isInGame() || !hwh.getSetting("report")) {
            return;
        }

        this.ticks = (this.ticks || 0) + 1;
        if (this.ticks % hwh.getSetting("interval") === 0) {
            var player = hwh.getPlayerInfo();
            var style = hwh.getMode("style");
            var message = hwh.getSetting("prefix") + " " + player.name
                + " HP " + player.health.toFixed(1);
            if (style === "Detailed") {
                message += " at " + player.x.toFixed(1) + ", "
                    + player.y.toFixed(1) + ", " + player.z.toFixed(1);
            }
            hwh.chat(message);
        }
    },
    onUpdate: function (hwh, phase, yaw, pitch, outgoingYaw, outgoingPitch) {
        // Called before and after the player update; read-only rotation data.
    },
    onAttack: function (hwh, targetName, entityId, x, y, z, health) {
        hwh.log("Attack: " + targetName + " (" + entityId + ")");
    },
    onWorldChange: function (hwh, disconnecting) {
        hwh.log(disconnecting ? "World disconnected" : "World changed");
    }
};

Available API:
  hwh.getSetting(name)             Read a declared setting. Mode settings return
                                    their numeric option index.
  hwh.setSetting(name, value)      Change a declared setting, subject to its type
                                    and range. Returns true on success.
  hwh.getMode(name)                Read a mode/choice setting by its displayed name.
  hwh.isInGame()                   True when a world and player are available.
  hwh.getPlayerInfo()              Snapshot: name, x/y/z, health/maxHealth, food,
                                    yaw/pitch, motionX/Y/Z, onGround, sprinting.
  hwh.playerX(), playerY(), playerZ()  Read the player's current coordinates.
  hwh.getBlockInfo(x, y, z)        Snapshot: x/y/z, registry name, metadata, air,
                                    solid. Only loaded blocks within 64 blocks are
                                    queried; otherwise returns undefined.
  hwh.getTargetInfo()              Snapshot of the crosshair target (miss, block,
                                    or entity); returns undefined outside a world.
  hwh.isKeyDown(name)               Read a configured key: forward, back, left,
                                    right, jump, sneak, sprint, attack, or use.
  hwh.worldTime(), hwh.dimension() Read the current world's time and dimension.
  hwh.jump()                       Make the player jump.
  hwh.setMotion(x, y, z)           Set motion; each component is clamped to [-3, 3].
  hwh.chat(text)                   Show local client chat text (up to 256 characters).
  hwh.log(text)                    Write to the HWH client log.

Callbacks (all are optional):
  onEnable(hwh), onDisable(hwh)    Module lifecycle.
  onTick(hwh)                      PRE tick callback.
  onUpdate(hwh, phase, yaw, pitch, outgoingYaw, outgoingPitch)
                                    Player-update callback for PRE and POST.
  onAttack(hwh, targetName, entityId, x, y, z, health)
                                    Read-only attack notification. health is -1
                                    when the target is not a living entity.
  onWorldChange(hwh, disconnecting) World-load/disconnect notification.

Supported setting types: boolean, int, float, text, mode (or choice).
Integer/float settings require min/max; mode settings use an options array of
1-16 unique names and a default option name or index. Text values are limited to
128 characters. Modules start disabled and must be enabled in the GUI.
Scripts are sandboxed from direct Java class access and have a per-callback
instruction limit. Callbacks that throw an error are logged and disable that
script; toggling it off and on retries it. Only add scripts you trust.
