# Mineflayer
使用强大、稳定、高级的 JavaScript ~~~~API 来开发 Minecraft 机器人,同时支持 Python。
第一次使用 node.js ?你可以先看看 ~~使用教程 。了解过 Python?这里有一些 ~~Python 实例,同时你也可以~~~~在谷歌 Colab 中运行 Mineflayer 来体验一下。
## 特点
-
*实体感知与追踪 -
*方块感知,你可以在几毫秒内查找到bot周围的任何方块 -
*物理和运动引擎 - 支持所有的碰撞箱 -
*攻击实体,使用交通工具 -
*背包管理 -
*使用工作台、箱子、酿造台、附魔台 -
*挖掘和建造 -
*各种各样的的信息接口,比如查看你的血量或是否下雨 -
*激活方块和使用物品 -
*进行聊天
### 路线图
~~~~点这里 看看目前我们有哪些实用的项目
## 安装
首先,从 ~~~~nodejs.org 安装 nodejs(版本要求 >= 18),
然后在你创建的bot项目目录中,使用命令行运行:
~~</s>npm install mineflayer<e>
##~~ 文档
| 链接 | 描述 |
|---|---|
| ~~~~使用教程 | node.js 和 mineflayer 入门 |
| ~~~~FAQ | 使用中出现问题?先看看这个文档吧 |
| ~~api、~~不稳定的api | 完整的接口参考文档 |
| ~~~~更新日志 | mineflayer 的更新日志 |
| ~~~~示例/ | 我们为你准备的 mineflayer 使用实例 |
## 参与贡献
请参阅 ~~为本项目贡献,以及~~为 Prismarine 贡献
## 如何使用
~~~~视频(Youtube)
~~~~这里 是一个解释bot基本设置过程的教程视频。
如果你想了解更多,更多的视频教程可以在 ~~这里 找到,视频的相应的源码在 ~~这里 。
~~~~
[img="https://camo.hach.chat/?proxyUrl=https://img.youtube.com/vi/ltWosy4Z0Kw/0.jpg" alt="tutorial 1" width="200"]
[img="https://camo.hach.chat/?proxyUrl=https://img.youtube.com/vi/UWGSf08wQSc/0.jpg" alt="tutorial 2" width="200"] ~~~~
[img="https://camo.hach.chat/?proxyUrl=https://img.youtube.com/vi/ssWE0kXDGJE/0.jpg" alt="tutorial 3" width="200"]
[img="https://camo.hach.chat/?proxyUrl=https://img.youtube.com/vi/walbRk20KYU/0.jpg" alt="tutorial 4" width="200"]
~~~~开始使用
如果没有指定特定版本,使用的服务器版本将自动判断并使用。
如果没有指定登录类型,默认使用 mojang 账户认证登录。
### 例子:复读机
```js
const mineflayer = require('mineflayer')
const bot = mineflayer.createBot({
host: 'localhost', // minecraft 服务器的 IP 地址
username: 'email@example.com', // minecraft 用户名
password: '12345678' // minecraft 密码, 如果你玩的是不需要正版验证的服务器,请注释掉。
// port: 25565, // 默认使用 25565,如果你的服务器端口不是这个请取消注释并填写。
// version: false, // 如果需要指定使用一个版本或快照时,请取消注释并手动填写(如:"1.8.9" 或 "1.16.5"),否则会自动设置。
// auth: 'mojang' // 如果需要使用微软账号登录时,请取消注释,然后将值设置为 'microsoft',否则会自动设置为 'mojang'。
})
bot.on('chat', (username, message) => {
if (username === bot.username) return
bot.chat(message)
})
// 记录错误和被踢出服务器的原因:
bot.on('kicked', console.log)
bot.on('error', console.log)
```
### 看看你的 bot 在做什么
感谢 ~~prismarine-viewer项目,它可以在浏览器窗口显示你的机器人正在做什么。
只需要运行 </s>npm install prismarine-viewer<e> 并将其添加到你的 bot 代码中。
</i>const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
bot.once('spawn', () => {
mineflayerViewer(bot, { port: 3007, firstPerson: true }) // port 是本地网页运行的端口 ,如果 firstPerson: false,那么将会显示鸟瞰图。
})<i>
</i><e>```</e>
然后你会得到一个看起来像这样的**~~实时视图<e>*</e>*:
<URL url="https://prismarinejs.github.io/prismarine-viewer/">~~[~~[img="https://camo.hach.chat/?proxyUrl=https://prismarinejs.github.io/prismarine-viewer/test_1.16.1.png" alt="viewer" width="500"]<e>](https://prismarinejs.github.io/prismarine-viewer/)</e></URL>
~~####~~ 更多示例
*|* 例子 *|* 描述 *|*
*|---|---|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/tree/master/examples/viewer">~~[~~viewer<e>](https://github.com/PrismarineJS/mineflayer/tree/master/examples/viewer)</e></URL> *|* 在浏览器中显示 bot 的视角 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/tree/master/examples/pathfinder">~~[~~pathfinder<e>](https://github.com/PrismarineJS/mineflayer/tree/master/examples/pathfinder)</e></URL> *|* 让你的 bot 自动前往任何地点 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/chest.js">~~[~~chest<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/chest.js)</e></URL> *|* 使用箱子、熔炉、酿造台、附魔台 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/digger.js">~~[~~digger<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/digger.js)</e></URL> *|* 学习如何创建一个能够挖掘方块的简单bot *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/discord.js">~~[~~discord<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/discord.js)</e></URL> *|* 将 discord bot 与 mineflayer bot 进行消息互通 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/jumper.js">~~[~~jumper<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/jumper.js)</e></URL> *|* 学习如何移动、跳跃、骑乘载具、攻击附近的实体 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/ansi.js">~~[~~ansi<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/ansi.js)</e></URL> *|* 使用全彩色在命令行中显示 bot 的聊天记录 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/guard.js">~~[~~guard<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/guard.js)</e></URL> *|* 让bot守卫一个指定的区域,不让附近的生物进入。 *|*
*|*<URL url="https://github.com/PrismarineJS/mineflayer/blob/master/examples/multiple_from_file.js">~~[~~multiple-from-file<e>](https://github.com/PrismarineJS/mineflayer/blob/master/examples/multiple_from_file.js)</e></URL> *|* 创建一个包含账户信息的文本文件,让它们全部同时登录 *|*
还有更多的例子在 <URL url="https://github.com/PrismarineJS/mineflayer/tree/master/examples">~~[~~examples<e>](https://github.com/PrismarineJS/mineflayer/tree/master/examples)</e></URL> 文件夹中
~~###~~ 模块
很多活跃的开发都发生在 mineflayer 所使用的小型 npm 包内
~~####~~ The Node Way & trade;
<QUOTE>*>* <FP char="“">"</FP>当你很好的编写了一个应用程序,此时它的价值仅限于这些特定的需求。你要知道,真正好的、可重复使用的优秀组件都会升华到github和npm上,在那里,每个人都可以合作来推进公共事业。<FP char="”">"</FP> — <URL url="https://gist.github.com/substack/5075355">~~[~~《 how I write modules 》 - substack<e>](https://gist.github.com/substack/5075355)</e></URL>
</QUOTE>
~~####~~ 子模块
这些是 构成 mineflayer 的主要模块:
*|* 模块 *|* 描述 *|*
*|---|---|*
*|* <URL url="https://github.com/PrismarineJS/node-minecraft-protocol">~~[~~minecraft-protocol<e>](https://github.com/PrismarineJS/node-minecraft-protocol)</e></URL> *|* 解析和序列化 minecraft 数据包,以及身份验证和加密。
*|* <URL url="https://github.com/PrismarineJS/minecraft-data">~~[~~minecraft-data<e>](https://github.com/PrismarineJS/minecraft-data)</e></URL> *|* 为 minecraft 客户端、服务器和库提供 minecraft 数据的语言独立模块。
*|* <URL url="https://github.com/PrismarineJS/prismarine-physics">~~[~~prismarine-physics<e>](https://github.com/PrismarineJS/prismarine-physics)</e></URL> *|* 为 minecraft 实体提供物理引擎
*|* <URL url="https://github.com/PrismarineJS/prismarine-chunk">~~[~~prismarine-chunk<e>](https://github.com/PrismarineJS/prismarine-chunk)</e></URL> *|* 一个为 Minecraft 保存区块数据的类
*|* <URL url="https://github.com/PrismarineJS/node-vec3">~~[~~node-vec3<e>](https://github.com/PrismarineJS/node-vec3)</e></URL> *|* 具有强大单元测试的 3d 矢量数学
*|* <URL url="https://github.com/PrismarineJS/prismarine-block">~~[~~prismarine-block<e>](https://github.com/PrismarineJS/prismarine-block)</e></URL> *|* 用相关数据表示一个 minecraft 方块
*|* <URL url="https://github.com/PrismarineJS/prismarine-chat">~~[~~prismarine-chat<e>](https://github.com/PrismarineJS/prismarine-chat)</e></URL> *|* minecraft 聊天消息解析器(从 mineflayer 中提取)
*|* <URL url="https://github.com/PrismarineJS/node-yggdrasil">~~[~~node-yggdrasil<e>](https://github.com/PrismarineJS/node-yggdrasil)</e></URL> *|* Node.js 库与 Mojang 的身份验证系统交互
*|* <URL url="https://github.com/PrismarineJS/prismarine-world">~~[~~prismarine-world<e>](https://github.com/PrismarineJS/prismarine-world)</e></URL> *|* prismarine 世界的核心实现
*|* <URL url="https://github.com/PrismarineJS/prismarine-windows">~~[~~prismarine-windows<e>](https://github.com/PrismarineJS/prismarine-windows)</e></URL> *|* 表示 minecraft 窗口
*|* <URL url="https://github.com/PrismarineJS/prismarine-item">~~[~~prismarine-item<e>](https://github.com/PrismarineJS/prismarine-item)</e></URL> *|* 用相关数据表示一个 minecraft 物品
*|* <URL url="https://github.com/PrismarineJS/prismarine-nbt">~~[~~prismarine-nbt<e>](https://github.com/PrismarineJS/prismarine-nbt)</e></URL> *|* node-minecraft-protocol 的 NBT 解析器
*|* <URL url="https://github.com/PrismarineJS/prismarine-recipe">~~[~~prismarine-recipe<e>](https://github.com/PrismarineJS/prismarine-recipe)</e></URL> *|* 展示我的世界合成表
*|* <URL url="https://github.com/PrismarineJS/prismarine-biome">~~[~~prismarine-biome<e>](https://github.com/PrismarineJS/prismarine-biome)</e></URL> *|* 用相关数据表示 minecraft 生物群落
*|* <URL url="https://github.com/PrismarineJS/prismarine-entity">~~[~~prismarine-entity<e>](https://github.com/PrismarineJS/prismarine-entity)</e></URL> *|* 表示一个 minecraft 实体
~~###~~ 调试
您可以使用 <C>~~`</s>DEBUG<e>`</e></C> 环境变量启用某些协议调试输出:
```bash</s><i>
</i>DEBUG="minecraft-protocol" node [...]<i>
</i><e>```</e>
在 windows 上:
```powershell</s><i>
</i>set DEBUG=minecraft-protocol
node your_script.js<i>
</i><e>```</e>
##~~ 第三方插件
mineflayer 支持插件;任何人都可以创建一个插件,在 mineflayer 之上添加更高级别的 API。
最新和最有用的有:
<LIST>
- ~~*~~ <URL url="https://github.com/Karang/mineflayer-pathfinder">~~[~~pathfinder<e>](https://github.com/Karang/mineflayer-pathfinder)</e></URL> - 具有许多可配置功能的高级 A* 寻路
- ~~*~~ <URL url="https://github.com/PrismarineJS/prismarine-viewer">~~[~~prismarine-viewer<e>](https://github.com/PrismarineJS/prismarine-viewer)</e></URL> - 简单的在线区块查看器
- ~~*~~ <URL url="https://github.com/ImHarvol/mineflayer-web-inventory">~~[~~web-inventory<e>](https://github.com/ImHarvol/mineflayer-web-inventory)</e></URL> - 在线背包查看器
- ~~*~~ <URL url="https://github.com/TheDudeFromCI/mineflayer-statemachine">~~[~~statemachine<e>](https://github.com/TheDudeFromCI/mineflayer-statemachine)</e></URL> - 用于更复杂机器人行为的状态机 API
- ~~*~~ <URL url="https://github.com/G07cha/MineflayerArmorManager">~~[~~Armor Manager<e>](https://github.com/G07cha/MineflayerArmorManager)</e></URL> - 自动护甲管理
- ~~*~~ <URL url="https://github.com/TheDudeFromCI/mineflayer-collectblock">~~[~~Collect Block<e>](https://github.com/TheDudeFromCI/mineflayer-collectblock)</e></URL> - 快速简单的块收集 API
- ~~*~~ <URL url="https://github.com/wvffle/mineflayer-dashboard">~~[~~Dashboard<e>](https://github.com/wvffle/mineflayer-dashboard)</e></URL> - mineflayer bot 的前端仪表板
- ~~*~~ <URL url="https://github.com/TheDudeFromCI/mineflayer-pvp">~~[~~PVP<e>](https://github.com/TheDudeFromCI/mineflayer-pvp)</e></URL> - 用于基本 PVP 和 PVE 的简单 API
- ~~*~~ <URL url="https://github.com/LINKdiscordd/mineflayer-auto-eat">~~[~~auto-eat<e>](https://github.com/LINKdiscordd/mineflayer-auto-eat)</e></URL> - 自动进食
<LIST>
- ~~*~~ <URL url="https://github.com/link-discord/mineflayer-autocrystal">~~[~~Auto Crystal<e>](https://github.com/link-discord/mineflayer-autocrystal)</e></URL> - 自动放置和破碎结
- ~~*~~ <URL url="https://github.com/TheDudeFromCI/mineflayer-tool">~~[~~Tool<e>](https://github.com/TheDudeFromCI/mineflayer-tool)</e></URL> - 一个具有高级API的工具/武器自动选择工具的工具
- ~~*~~ <URL url="https://github.com/sefirosweb/minecraftHawkEye">~~[~~Hawkeye<e>](https://github.com/sefirosweb/minecraftHawkEye)</e></URL> - 一个使用自动瞄准弓的工具
- ~~*~~ <URL url="https://github.com/firejoust/mineflayer-GUI">~~[~~GUI<e>](https://github.com/firejoust/mineflayer-GUI)</e></URL> - 简化了嵌套箱子GUI窗口的导航和管理
- ~~*~~ <URL url="https://github.com/firejoust/mineflayer-projectile">~~[~~Projectile<e>](https://github.com/firejoust/mineflayer-projectile)</e></URL> - 以投射物为基础的战斗的可配置插件</LIST></LIST>
也可以看看这些 :
<LIST>
- ~~*~~ <URL url="https://github.com/andrewrk/mineflayer-radar/">~~[~~radar<e>](https://github.com/andrewrk/mineflayer-radar/)</e></URL> - 使用 canvas 和 socket.io 的基于 Web 的雷达界面 <URL url="https://www.youtube.com/watch?v=FjDmAfcVulQ">~~[~~YouTube 演示<e>](https://www.youtube.com/watch?v=FjDmAfcVulQ)</e></URL>
- ~~*~~ <URL url="https://github.com/Darthfett/mineflayer-blockFinder">~~[~~blockfinder<e>](https://github.com/Darthfett/mineflayer-blockFinder)</e></URL> - 在 3D 世界中寻找方块
- ~~*~~ <URL url="https://github.com/andrewrk/mineflayer-scaffold">~~[~~scaffold<e>](https://github.com/andrewrk/mineflayer-scaffold)</e></URL> - 到达目标目的地,即使您必须建造或破坏块才能这样做 <URL url="http://youtu.be/jkg6psMUSE0">~~[~~YouTube 演示<e>](http://youtu.be/jkg6psMUSE0)</e></URL>
- ~~*~~ <URL url="https://github.com/G07cha/MineflayerAutoAuth">~~[~~auto-auth<e>](https://github.com/G07cha/MineflayerAutoAuth)</e></URL> - 基于聊天的bot身份验证
- ~~*~~ <URL url="https://github.com/Nixes/mineflayer-bloodhound">~~[~~Bloodhound<e>](https://github.com/Nixes/mineflayer-bloodhound)</e></URL> - 确定谁和什么对另一个实体的损害负责
- ~~*~~ <URL url="https://github.com/SiebeDW/mineflayer-tps">~~[~~tps<e>](https://github.com/SiebeDW/mineflayer-tps)</e></URL> - 获取当前的 tps(已处理的 tps)
- ~~*~~ <URL url="https://github.com/IceTank/mineflayer-panorama">~~[~~panorama<e>](https://github.com/IceTank/mineflayer-panorama)</e></URL> - 拍摄您的世界的全景图像
<LIST>
- ~~*~~ <URL url="https://github.com/tuanzisama/mineflayer-death-event">~~[~~player-death-event<e>](https://github.com/tuanzisama/mineflayer-death-event)</e></URL> - 在 Mineflayer 里监听玩家死亡事件</LIST></LIST>
~~##~~ 正在使用 mineflayer 的项目
<LIST>
- ~~*~~ <URL url="https://github.com/rom1504/rbot">~~[~~rom1504/rbot<e>](https://github.com/rom1504/rbot)</e></URL>
<LIST>
- ~~*~~ <URL url="https://www.youtube.com/watch?v=UM1ZV5200S0">~~[~~YouTube - 建造旋转楼梯<e>](https://www.youtube.com/watch?v=UM1ZV5200S0)</e></URL>
- ~~*~~ <URL url="https://www.youtube.com/watch?v=0cQxg9uDnzA">~~[~~YouTube - 复制一个建筑<e>](https://www.youtube.com/watch?v=0cQxg9uDnzA)</e></URL></LIST>
- ~~*~~ <URL url="https://github.com/Darthfett/Helperbot">~~[~~Darthfett/Helperbot<e>](https://github.com/Darthfett/Helperbot)</e></URL> - 完成一些简单指令
- ~~*~~ <URL url="https://github.com/vogonistic/mineflayer-voxel">~~[~~vogonistic/voxel<e>](https://github.com/vogonistic/mineflayer-voxel)</e></URL> - 使用 voxel.js 可视化机器人正在做什么
- ~~*~~ <URL url="https://github.com/JonnyD/Skynet">~~[~~JonnyD/Skynet<e>](https://github.com/JonnyD/Skynet)</e></URL> - 将玩家活动记录到在线 API 上
- ~~*~~ <URL url="https://github.com/rom1504/MinecraftChat">~~[~~MinecraftChat<e>](https://github.com/rom1504/MinecraftChat)</e></URL> (最后一个开源版本,由 AlexKvazos 构建)——基于 Minecraft 网络的聊天客户端 <URL url="https://minecraftchat.net/">~~<~~https://minecraftchat.net/<e>></e></URL>
- ~~*~~ <URL url="https://github.com/Minecheesecraft/Cheese-Bot">~~[~~Cheese Bot<e>](https://github.com/Minecheesecraft/Cheese-Bot)</e></URL> - 基于插件的机器人,具有干净的 GUI。使用 Node-Webkit 制作。
- ~~*~~ <URL url="https://github.com/schematical/chaoscraft">~~[~~Chaoscraft<e>](https://github.com/schematical/chaoscraft)</e></URL> - 使用遗传算法的 Minecraft 机器人,请参阅 <URL url="https://www.youtube.com/playlist?list=PLLkpLgU9B5xJ7Qy4kOyBJl5J6zsDIMceH">~~[~~Youtube<e>](https://www.youtube.com/playlist?list=PLLkpLgU9B5xJ7Qy4kOyBJl5J6zsDIMceH)</e></URL>
- ~~*~~ <URL url="https://github.com/hexatester/minetelegram">~~[~~hexatester/minetelegram<e>](https://github.com/hexatester/minetelegram)</e></URL> - Minecraft - Telegram 消息互通,基于 mineflayer & telegraf.
- ~~*~~ <URL url="https://github.com/PrismarineJS/mineflayer-builder">~~[~~PrismarineJS/mineflayer-builder<e>](https://github.com/PrismarineJS/mineflayer-builder)</e></URL> - 在生存中打印我的世界示意图,保持方向
- ~~*~~ <URL url="https://github.com/PrismarineJS/mineflayer/network/dependents">~~[~~以及数千个<e>](https://github.com/PrismarineJS/mineflayer/network/dependents)</e></URL> - github 检测到的在使用 mineflayer 的项目</LIST>
~~##~~ 测试
~~###~~ 完整测试
运行
~~```bash</s><i>
</i>npm test<i>
</i><e>```</e>
###~~ 测试指定版本
运行
~~```bash</s><i>
</i>npm mocha_test -- -g <version><i>
</i><e>```</e>
其中 <C>`</s><version><e>`</e></C> 表示 minecraft 版本号 如 <C>`</s>1.12<e>`</e></C>, <C>`</s>1.15.2<e>`</e></C><FP char="…">...</FP>
###~~ 测试指定测试脚本
运行
~~```bash</s><i>
</i>npm mocha_test -- -g <test_name><i>
</i><e>```</e>
其中 <C>`</s><test_name><e>`</e></C> 是测试名称,例如 <C>`</s>bed<e>`</e></C>, <C>`</s>useChests<e>`</e></C>, <C>`</s>rayTrace<e>`</e></C><FP char="…">...</FP>
###~~ 示例
~~```bash</s><i>
</i>npm run mocha_test -- -g "1.18.1.*BlockFinder"<i>
</i><e>```</e>
进行 1.18.1 寻路测试
##~~ 许可证
<URL url="https://raw.kkgithub.com/PrismarineJS/mineflayer/refs/heads/master/LICENSE">~~[~~MIT<e>](https://raw.kkgithub.com/PrismarineJS/mineflayer/refs/heads/master/LICENSE)</e></URL>
***
***
原文(本文有为兼容NL排版而改动):<URL url="https://raw.github.com/PrismarineJS/mineflayer/refs/heads/master/docs/zh/README_ZH_CN.md">https://raw.github.com/PrismarineJS/mineflayer/refs/heads/master/docs/zh/README_ZH_CN.md</URL>
</r>
可以共享、可以push的免费邮箱,更可使用自定义域名,完美契合您的各项需求。
1 条回复
排序