The Session
ctx.session is a GameSession — the live handle to one connection. It is
the root of the game model: entities, world, items, and the raw packet
connection all hang off it.
(ctx) => {
const session = ctx.session;
ctx.on("tick", () => {
const player = session.entityState.localPlayer;
// ...
});
};
GameSession
| Member | Type | Description |
|---|---|---|
connection | Connection | The MITM connection — inject and flow-control packets. |
events | EventEmitter<GameSessionEvents> | The high-level game events (ctx.on wraps this). |
entityState | EntityStateTracker | Entities, the player list, and the local player. |
itemState | ItemStateTracker | Inventories, containers, forms, and the item registry. |
levelState | LevelStateTracker | The world: blocks, chunks, raytrace, collision. |
sendChatMessage(message) | void | Print a client-side chat line (not sent to the server). |
Tip —
session.sendChatMessagevs. the player's.session.sendChatMessage(msg)prints a local, client-only line. To actually send chat to the server as the player, uselocalPlayer.sendChatMessage(msg).
session.events
ctx.on(event, cb) is the normal way to subscribe — it binds to the module's
enabled state and tears down automatically. The underlying emitter is exposed as
session.events for the cases ctx.on doesn't cover, e.g. a one-shot
listener:
session.events.once("post_tick", () => {
// runs on the next post_tick only
});
The event names and payloads are the GameSessionEvents
map.
The three trackers
GameSession exposes the game state as three trackers. Each has its own
reference page:
entityState—EntityStateTracker: the entity map, the player list, andlocalPlayer.levelState—LevelStateTracker: blocks, chunks, subchunks, ray-tracing, collision, and the block-state registry.itemState—ItemStateTracker: the local inventories, open containers, forms, item movement, and the item registry.
And the raw network layer:
connection—Connection: inject packets in either direction and gate/flush the packet queue.
Reaching types
The classes reachable through the session graph (Connection, ItemStack, the
inventory classes, the trackers, Scheduler, …) are fully typed — your editor
resolves session.entityState.localPlayer.inventory.hand?.definition.name end to
end. You rarely need to import those type names; you reach them by property
access.
A handful of types are exported by name because you name them directly:
- Value exports (importable, usable with
instanceof/extends):GameSession,AbstractEntity,EntityPlayer,EntityNetworkPlayer,EntityCreature,EntityItem,EntityLocalPlayer,BlockState,Chunk,SubChunk,AbstractBlockLocationTracker,Option,ModuleCategory,ModuleMode,ModuleTriggerMode,SprintIntent,FlushAction, plusdefineModule,mode,moduleManager,utils,nbt, and the combat helpers (targets,TargetConfigurable,TargetPriority,ClickSchedulerConfigurable,ClickTechnique, the rotation strategy classes,face3DToRotationFace,ROTATION_CANCEL,ROTATION_KEEP). - Type-only exports:
GameSessionEvents,FullPacketEvents,ModuleContext,ModuleMeta,Color,NumberOptionProps,NumberRange,Configurable,BlockEntry,MovementState,Connection,PacketQueueChecker,HeldPacket, the option schema types (OptionsSchema,SchemaNodeand 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,RotationTypeand its variants,RotationFace,Face3D), plus the deprecated legacy types (ModuleOptions,ModuleBuild,Session).
Math/vector types and many internal types are also available under the
utils namespace.