From 703bcbe5375cd525d5076f8c808330d52ba0bb24 Mon Sep 17 00:00:00 2001 From: Rin Date: Sat, 10 Jan 2026 17:24:30 +0800 Subject: [PATCH] chore(minecraft): cleanup for tick handler --- services/minecraft/src/cognitive/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/minecraft/src/cognitive/index.ts b/services/minecraft/src/cognitive/index.ts index df9f83ba8..967bcd97b 100644 --- a/services/minecraft/src/cognitive/index.ts +++ b/services/minecraft/src/cognitive/index.ts @@ -7,6 +7,7 @@ import { createAgentContainer } from './container' export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlugin { let container: ReturnType + let tickHandler: ((ctx: { delta: number }) => void) | null = null return { async created(bot) { @@ -41,9 +42,11 @@ export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlug // Initialize perception pipeline (raw events + detectors) perceptionPipeline.init(botWithAgents) - bot.onTick('tick', ({ delta }) => { + tickHandler = ({ delta }) => { perceptionPipeline.tick(delta) - }) + } + + bot.onTick('tick', tickHandler) // Set message handling via EventManager const chatHandler = new ChatMessageHandler(bot.username) @@ -102,6 +105,11 @@ export function CognitiveEngine(options: CognitiveEngineOptions): MineflayerPlug perceptionPipeline.destroy() } + if (tickHandler) { + bot.offTick('tick', tickHandler) + tickHandler = null + } + bot.bot.removeAllListeners('chat') }, }