[index] Improve README.md

This commit is contained in:
方而静 2023-11-03 14:29:37 +08:00
parent 604d437272
commit 09cede647f
Signed by: szTom
GPG Key ID: 072D999D60C6473C
2 changed files with 28 additions and 2 deletions

View File

@ -2,10 +2,11 @@
## 安装 ## 安装
运行下面命令安装 Node.JS 的依赖包: 运行下面命令安装 Node.JS 的依赖包并应用补丁
```sh ```sh
npm i npm i
npx patch-package
``` ```
## 配置认证数据 ## 配置认证数据
@ -32,3 +33,28 @@ npm i
```sh ```sh
node index.mjs profile@host:port node index.mjs profile@host:port
``` ```
命令行选项:
+ `--offline`:使用离线模式启动
+ `--credentials-lib <file>`:指定登录凭据文件(默认值:`credentials.json`
+ `--no-repl`:禁用终端内 REPL
+ `--protocal`:指定服务器版本(不指定时自动检测)
+ `--owner`: 指定 REPL 上下文内 `owner()` 函数返回的玩家
## REPL
REPL 上下文内预先定义了如下变量/函数/类型:
+ `bot`:机器人对象
+ `Vec3`3 维向量类型
+ `debug`:调试日志模块
+ `mineflayer`: mineflayer 模块默认导出
+ `lib.utils`: compass-utils 模块导出
+ `lib.control`: mineflayer-control 模块导出
+ `lib.flyctl`: mineflayer-fly-control 模块导出
+ `sc.pos()`: 缩写,返回 `bot.entity.position`
+ `sc.debug_mfc()`:缩写,等价于 `debug.enable('mineflayer-control')`
+ `sc.debug_mff()`:缩写,等价于 `debug.enable('mineflayer-fly-control')`
+ `sc.sleep`:缩写,等价于 `lib.utils.asyncSleep`
+ `sc.tossHeld`:缩写,等价于 `bot.tossStack(bot.heldItem)`

View File

@ -65,6 +65,7 @@ async function main() {
context.lib = { context.lib = {
utils: await import('compass-utils'), utils: await import('compass-utils'),
control: await import('mineflayer-control'), control: await import('mineflayer-control'),
flyctl: await import('mineflayer-fly-control'),
}; };
context.bot = bot; context.bot = bot;
context.Vec3 = (await import('vec3')).Vec3; context.Vec3 = (await import('vec3')).Vec3;
@ -79,7 +80,6 @@ async function main() {
context.sc.pos = () => bot.entity.position; context.sc.pos = () => bot.entity.position;
context.sc.debug_mfc = () => debug.enable('mineflayer-control'); context.sc.debug_mfc = () => debug.enable('mineflayer-control');
context.sc.debug_mff = () => debug.enable('mineflayer-fly-control'); context.sc.debug_mff = () => debug.enable('mineflayer-fly-control');
context.sc.q = () => bot.quit();
context.sc.sleep = asyncSleep; context.sc.sleep = asyncSleep;
context.sc.tossHeld = () => bot.tossStack(bot.heldItem); context.sc.tossHeld = () => bot.tossStack(bot.heldItem);
} }