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.

FieldMeaning
availablefalse when the game could not be read this frame
connectedtrue while connected to a server
singleplayertrue in a single-player world
inWorldtrue while a world is loaded
serverA 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.

FieldMeaning
apiVersionVersion of the Lua API
targetVersion"1.21.11"
loader"Fabric"
width, heightWindow size in pixels
focusedWhether the window has focus
inWorld, connected, singleplayerAs in the connection state
serverAs in the connection state
screenAs returned by mc.getScreen()
availableAs 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