26 lines
1.1 KiB
TypeScript
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 = 'right_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], 1, 0);
|
|
return (bot.currentWindow ?? bot.inventory) === window;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
}
|