27 lines
1.1 KiB
TypeScript
27 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 = 'drop_slot_all_item';
|
|
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 || !window.slots[args[0]]
|
|
|| window.selectedItem) return false;
|
|
try {
|
|
await bot.clickWindow(args[0], 1, 4);
|
|
return (bot.currentWindow ?? bot.inventory) === window && !window.slots[args[0]];
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
}
|