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
| Member | Type | Description |
|---|---|---|
connection | Connection | The MITM connection. Inject and flow-control packets. |
events | EventEmitter<GameSessionEvents> | The high-level game events, including the input_tick and movement_tick hooks. 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 chat line on your client only. It is not sent to the server. |
sendChatMessagessession.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, andlocalPlayer.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,EntityLocalPlayerAbstractBlockLocationTrackerModuleCategory,ModuleMode,ModuleTriggerMode,FlushActionSprintIntent,SneakIntentMoveKey,moveFromKeys,keysFromMovedefineModule,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,ConfigurableBlockState,Chunk,SubChunk,BlockEntryMovementState,InputState,AudioClipConnection,PacketQueueChecker,HeldPacket, andpackets, the namespace of every packet payload type- 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 - Deprecated legacy types:
ModuleOptions,ModuleBuild,Session
Math and vector types, and many internal types, are also available under the
utils namespace.