gamesense.kirkLua API

Lua scripting API

Minecraft Forge 1.20.1 / Lua API 3.1

Open the Lua editor

Build client extensions with script-owned callbacks, movement input, targeting, inventory actions, world queries, rendering, settings and storage.

Runtime and directories

TopicDetails
LuaJ 3.0.1Lua 5.2 compatible. Base, package, bit32, table, string, coroutine and math libraries are available. This is LuaJ, not LuaJIT. Native Lua 5.3 bit operators and unrestricted Java access are unavailable.
ScriptsPlace Lua files in .minecraft/kirk.sploit/scripts/. Top-level local scripts load at engine start and on Scripts reload. Server-hosted scripts are explicit entries. API version and mod version are separate.
ModulesPlace modules in scripts/modules/. require("name") loads local code with a cache per script, never an implicit remote download. io, os, luajava, debug, dofile and loadfile are removed.
local runtime = kirk.api.runtime()
local capabilities = kirk.api.capabilities()
kirk.log(runtime.engine .. " " .. runtime.version)

Lifecycle and execution

Each script has separate globals, modules and owned registrations. Most Lua callbacks run on the Minecraft client thread. on_tick fires at client tick END, usually about 20 times per second, even without a player or world. Render callbacks run in render phases. HTTP transport is on a worker and completion returns to the client thread.

kirk.on(event, fn) and kirk.register_callback(event, fn) return a cancel handle. Reload invalidates the previous instance, removes callbacks, timers, tweens, keybinds, widgets and providers, then suppresses old HTTP delivery. kirk.script.on_unload(fn) runs cleanup. Callback errors are logged and isolated.

Legacy on_pre_move(vx,vy,vz) runs at tick START and a true result zeroes local velocity. Use kirk.movement.register for mutable input after vanilla sampling. Movement providers run by ascending priority, then stable script/provider ID. Target providers run by descending priority and choose only a Java-approved candidate.

local h = kirk.on("on_tick", function()
  local player = kirk.player.state()
  if not player then return end
end)
kirk.script.on_unload(function() h.cancel() end)

Events

Legacy callbacks keep their positional arguments. Structured events take a context table. Observation events ignore returns. Inbound packet callbacks run after network handling from a snapshot on the next client tick and cannot cancel packets.

Data structures

Snapshots are ordinary Lua tables. Legacy entity proxies resolve by entity ID, UUID and dimension; they become invalid after despawn or world change. Block queries return nil for unloaded chunks without loading them. An action status of sent means locally dispatched, not server confirmed.

Function reference

FunctionDescriptionReturns

Patterns

Common mistakes

End-to-end examples

Eight scripts in the repository under scripts/examples/ cover HUD, movement, inventory, world rendering, target selection, mod settings, HTTP/JSON and module isolation. Copy one into the top-level scripts directory before reloading; keep counter.lua in scripts/modules/.

Auto jump on collision

kirk.movement.register("sample.auto_jump", 10, function(ctx)
  if ctx.forward > 0 and ctx.on_ground and ctx.horizontal_collision then
    ctx.jump = true
  end
end)

Speed HUD with a settings widget

For health based displays, require max_health > 0 before division. Entity removal is not proof of a kill.

Packets and limits

kirk.packet.names() lists known packet names. kirk.packet.describe(name) reports direction, observation, cancellation, sendability and supported construction fields. Constructible schemas: move_pos takes x/y/z, move_rot takes yaw/pitch, move_pos_rot takes both, swing takes optional main/off hand, player_command takes integer action, and set_carried_item takes slot 0..8. Movement packets are observational; inbound packets cannot be cancelled.

Use bounded world queries and avoid scanning during every render. HTTP is limited to four concurrent requests per script, 100 to 30000 ms timeouts, 256 KiB request and 512 KiB response. Block batches contain at most 256 positions; entity queries return at most 256 snapshots. LuaJ does not enforce a hard CPU or memory budget.