Skip to main content

The Session

ctx.session is a GameSession: your live handle to one connection. Everything else hangs off it — entities, the world, items, and the raw packet connection.

(ctx) => {
const session = ctx.session;
ctx.on("tick", () => {
const player = session.entityState.localPlayer;
// ...
});
};

GameSession​

MemberTypeDescription
connectionConnectionThe MITM connection. Inject and flow-control packets.
eventsEventEmitter<GameSessionEvents>The high-level game events, including the input_tick and movement_tick hooks. ctx.on wraps this.
entityStateEntityStateTrackerEntities, the player list, and the local player.
itemStateItemStateTrackerInventories, containers, forms, and the item registry.
levelStateLevelStateTrackerThe world: blocks, chunks, raytrace, collision.
sendChatMessage(message)voidPrint a chat line on your client only. It is not sent to the server.
Two different sendChatMessages

session.sendChatMessage(msg) prints a local line only you can see. To send chat to the server as the player, use localPlayer.sendChatMessage(msg).

session.events​

You normally subscribe with ctx.on(event, cb). It follows the module's enabled state and cleans up for you. For anything ctx.on doesn't cover, such as a one-shot listener, use the underlying emitter directly:

session.events.once("post_tick", () => {
// runs on the next post_tick only
});

Event names and payloads are listed in the GameSessionEvents map.

The three trackers​

The game state lives in three trackers, each with its own page:

  • entityState (EntityStateTracker): the entity map, the player list, and localPlayer.
  • levelState (LevelStateTracker): blocks, chunks, subchunks, ray-tracing, collision, and the block-state registry.
  • itemState (ItemStateTracker): your inventories, open containers, forms, item movement, and the item registry.

Plus the raw network layer:

  • connection (Connection): inject packets in either direction and gate or flush the packet queue.

Reaching types​

Everything reachable from the session (Connection, ItemStack, the inventory classes, the trackers, Scheduler, …) is fully typed. Your editor resolves session.entityState.localPlayer.inventory.hand?.definition.name end to end, so you rarely need to import these types. You reach them through properties.

Some types are exported by name, because you need to name them directly.

Value exports (importable, usable with instanceof / extends):

  • AbstractEntity, EntityPlayer, EntityNetworkPlayer, EntityCreature, EntityItem, EntityLocalPlayer
  • AbstractBlockLocationTracker
  • ModuleCategory, ModuleMode, ModuleTriggerMode, FlushAction
  • SprintIntent, SneakIntent
  • MoveKey, moveFromKeys, keysFromMove
  • defineModule, mode, moduleManager, utils, nbt
  • The combat helpers: targets, TargetConfigurable, TargetPriority, ClickSchedulerConfigurable, ClickTechnique, the rotation strategy classes, face3DToRotationFace, ROTATION_CANCEL, ROTATION_KEEP
  • registerAudio

Type-only exports. Import these with import type. They don't exist at runtime, so instanceof doesn't work on them:

  • GameSession, GameSessionEvents, FullPacketEvents, ModuleContext, ModuleMeta, Option, Color, NumberOptionProps, NumberRange, Configurable
  • BlockState, Chunk, SubChunk, BlockEntry
  • MovementState, InputState, AudioClip
  • Connection, PacketQueueChecker, HeldPacket, and packets, the namespace of every packet payload type
  • The option schema types (OptionsSchema, SchemaNode and the per-kind node interfaces, ModeSchema) and their handle types (OptionHandles, SchemaNodeHandle, ModesHandle, ModeHandle, GroupHandle, RotationHandle)
  • The combat helper types: ModuleTargets, TargetConfigurableOptions, TargetInfo, AbstractClickScheduler, RotationConfigurable, RotationType and its variants, RotationFace, Face3D
  • Deprecated legacy types: ModuleOptions, ModuleBuild, Session

Math and vector types, and many internal types, are also available under the utils namespace.