> ## Documentation Index
> Fetch the complete documentation index at: https://docs.selvut.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Threading Model

> Where script callbacks run.

Most event callbacks run on Minecraft's client thread. Keep those callbacks short.

Packet callbacks can run during networking dispatch. They are marked non-blocking: client-thread APIs that would have to wait are rejected from those scopes.

```lua theme={null}
local cachedHealth = nil

Script.on("tick", function()
  cachedHealth = Player.health()
end)

Script.on("packet_receive", function(event)
  if event.type == "system_chat" and event.text ~= nil and string.find(event.text, "debug", 1, true) then
    Chat.log("cached hp: " .. tostring(cachedHealth or "?"))
  end
end)
```

Use `Script.thread` or `Async.run` for blocking waits:

```lua theme={null}
Script.thread(function()
  Time.sleepTicks(20)
  Chat.log("one second later")
end)
```

Direct raw Java calls through `Java.mc()`, `Java.type(...)`, or `Reflect` do not automatically marshal back to the client thread. Prefer the high-level APIs when possible.
