Minecraft (mc)
State
Connection, server, world, screen, target and client information.
The exact tables below are built by the native side of the client. This page lists the fields the built-in code reads or creates. Check other fields with rconsole.dump(value).
mc.getConnectionState()
Returns a frozen table describing the connection.
| Field | Meaning |
|---|---|
available | false when the game could not be read this frame |
connected | true while connected to a server |
singleplayer | true in a single-player world |
inWorld | true while a world is loaded |
server | A frozen table with at least address, or nil |
mc.getServer()
Returns just the server table, or nil.
mc.getServerAddress()
Returns the server address string, or nil.
mc.isConnected()
Returns true when connected to a server.
mc.isSingleplayer()
Returns true in a single-player world.
mc.isInWorld()
Returns true while a world is loaded.
mc.getWorld()
Returns a table with the state of the world, or nil.
mc.getScreen()
Returns a table describing the screen that is open (inventory, chat, menu, ...).
mc.getTarget()
Returns a table describing what your crosshair is pointing at (a block, an entity, or nothing).
mc.getClientInfo()
Returns a table about the client and the game window.
| Field | Meaning |
|---|---|
apiVersion | Version of the Lua API |
targetVersion | "1.21.11" |
loader | "Fabric" |
width, height | Window size in pixels |
focused | Whether the window has focus |
inWorld, connected, singleplayer | As in the connection state |
server | As in the connection state |
screen | As returned by mc.getScreen() |
available | As in the connection state |
mc.screenSize()
Returns the window size as a Vector2.
mc.isActive()
Returns whether the game window has focus. Same as the global isgameactive().
if mc.isInWorld() and mc.isActive() then
print("playing on", mc.getServerAddress() or "singleplayer")
end