chore: initial commit

This commit is contained in:
2026-10-22 17:07:08 +08:00
commit 0acef64f48
200 changed files with 35546 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
import {base_define} from "../../../types/bot/plugins/plugin.ts";
export const define: base_define = {
path: "item",
i18n: [
{
lang: "zh-CN",
name: "物品操作",
description: "Bot 物品操作, 提供物品相关功能"
}
]
}
+26
View File
@@ -0,0 +1,26 @@
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;
}
}
}
@@ -0,0 +1,44 @@
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_item_number';
readonly i18n = {
lang: 'zh-CN', name: '丢弃指定数量物品', description: '逐个丢弃指定槽位的物品,数量不超过槽位现有数量',
};
readonly args: FunctionArgument[] = [
{name: 'slot', type: 'number', i18n: {lang: 'zh-CN', name: '物品槽位', description: '当前窗口中的槽位编号'}},
{name: 'count', type: 'number', i18n: {lang: 'zh-CN', name: '丢弃数量', description: '大于零的整数,超过现有数量时丢弃全部'}},
];
async run(bot: Bot, args: number[]): Promise<boolean> {
if (!Array.isArray(args) || args.length !== 2 || !args.every(Number.isSafeInteger)) return false;
const [slot, count] = args;
const window = bot.currentWindow ?? bot.inventory;
if (!window || slot < 0 || slot >= window.slots.length || count <= 0 || window.selectedItem) return false;
const item = window.slots[slot];
if (!item) return false;
const drop_count = Math.min(count, item.count);
const initial_count = item.count;
const type = item.type;
const metadata = item.metadata;
try {
for (let index = 0; index < drop_count; index++) {
const current = window.slots[slot];
if ((bot.currentWindow ?? bot.inventory) !== window || window.selectedItem
|| !current || current.type !== type || current.metadata !== metadata
|| current.count !== initial_count - index) return false;
await bot.clickWindow(slot, 0, 4);
if ((bot.currentWindow ?? bot.inventory) !== window || window.selectedItem) return false;
const remaining = window.slots[slot];
const expected = initial_count - index - 1;
if (expected === 0 ? remaining !== null && remaining !== undefined
: !remaining || remaining.type !== type || remaining.metadata !== metadata
|| remaining.count !== expected) return false;
}
return true;
} catch {
return false;
}
}
}
+27
View File
@@ -0,0 +1,27 @@
import type {Bot} from '@wp2508/mineflayer';
import type {BaseFunction, FunctionArgument} from '../../../types/bot/function/function.ts';
export class init implements BaseFunction<boolean[]> {
readonly name = 'use_item';
readonly i18n = {
lang: 'zh-CN', name: '使用手持物品', description: '发起主手或副手物品的使用,不等待使用完成,也不自动停止持续使用',
};
readonly args: FunctionArgument[] = [{
name: 'off_hand', type: 'boolean',
i18n: {lang: 'zh-CN', name: '使用副手', description: 'false 使用主手,true 使用副手'},
}];
async run(bot: Bot, args: boolean[]): Promise<boolean> {
if (!Array.isArray(args) || args.length !== 1 || typeof args[0] !== 'boolean') return false;
try {
const off_hand = args[0];
if (off_hand) {
if (bot.supportFeature('doesntHaveOffHandSlot') || !bot.inventory?.slots[45]) return false;
} else if (!bot.heldItem) return false;
bot.activateItem(off_hand);
return true;
} catch {
return false;
}
}
}