Files
2026-10-22 17:07:08 +08:00

26 lines
1.1 KiB
TypeScript

import type {Bot} from '@wp2508/mineflayer';
import type {BaseFunction, FunctionArgument} from '../../../types/bot/function/function.ts';
export class init implements BaseFunction<number[]> {
readonly name = 'left_click_slot';
readonly i18n = {
lang: 'zh-CN', name: '左键点击槽位', description: '在当前窗口左键点击一个物品槽位,使用原生拾取、放置或合并行为',
};
readonly args: FunctionArgument[] = [{
name: 'slot', type: 'number',
i18n: {lang: 'zh-CN', name: '物品槽位', description: '当前窗口中的槽位编号'},
}];
async run(bot: Bot, args: number[]): Promise<boolean> {
const window = bot.currentWindow ?? bot.inventory;
if (!window || !Array.isArray(args) || args.length !== 1 || !Number.isSafeInteger(args[0])
|| args[0] < 0 || args[0] >= window.slots.length) return false;
try {
await bot.clickWindow(args[0], 0, 0);
return (bot.currentWindow ?? bot.inventory) === window;
} catch {
return false;
}
}
}