Mineflayer简介——Minecraft机器人

Mineflayer是PrismarineJS社区的开源项目,用于创建Minecraft机器人。它支持多个Minecraft版本,提供实体和方块信息、物理运动、背包管理等功能。通过模块化设计,开发者可以轻松扩展其功能。教程和示例代码帮助初学者入门,包括实时查看机器人行为和A*寻路等高级功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简介

Mineflayer是 PrismarineJS community 创建的开源项目.
Mineflayer Github: https://github.com/PrismarineJS/mineflayer
PrismarineJS Organization Github: https://github.com/PrismarineJS
使用强大、稳定、高级 JavaScript API 创建 Minecraft机器人。

我是在 YouTube 上偶然看到TheDudeFromCI的视频的,我这几年一直想找类似的API但是居然没找到(可见国内这项目有多凉)
我就很兴奋地搬了几个教程,但是貌似国内并没有什么人知道。
我希望能起到抛砖引玉之效,让大家多了解一下这个有用的项目
如果你看得懂英文,推荐去官方手册看看https://mineflayer.prismarine.js.org

以下为 README 文件的截取内容和部分翻译

Features

  • 支持 Minecraft 1.8、 1.9、 1.10、 1.11、 1.12、 1.13、 1.14、 1.15 和 1.16。
  • 实体信息和跟踪。
  • 方块信息。你可以查询你周围的世界。在毫秒内查找任何方块。
  • 物理和运动 - 处理所有碰撞箱
  • 攻击实体和使用车辆。
  • 背包管理。
  • 合成,箱子,发射器,附魔台。
  • 挖掘和放置方块。
  • 其他的东西,如知道你的血量,是否下雨。
  • 激活方块和使用物品。
  • 聊天。

安装

npm install mineflayer

使用

Videos

机器人的基础设置过程

【熟肉】Mineflayer教程 ep.1 快速上手

想进一步学习,这里有更多教程
这里是对应的源代码

开始上手

如果不指定版本,将自动检测服务器的版本,您可以使用版本选项设置特定版本。例如 , version:"1.8"

Echo 例子

const mineflayer = require('mineflayer')
const bot = mineflayer.createBot({
  host: 'localhost', // optional
  port: 25565,       // optional
  username: 'email@example.com', // email and password are required only for
  password: '12345678',          // online-mode=true servers
  version: false                 // false corresponds to auto version detection (that's the default), put for example "1.8.8" if you need a specific version
})
bot.on('chat', function (username, message) {
  if (username === bot.username) return
  bot.chat(message)
})
// Log errors and kick reasons:
bot.on('kicked', (reason, loggedIn) => console.log(reason, loggedIn))
bot.on('error', err => console.log(err))

看看机器人在做什么

得益于prismarine-viewer 项目,你可以在浏览器窗口中显示您的机器人正在做什么。只需运行并将此添加到您的机器人:npm install prismarine-viewer

const mineflayerViewer = require('prismarine-viewer').mineflayer
bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3007, firstPerson: true })
})

你会得到一个像这样的 实时 视图

viewer

更多例子
例子介绍
viewer在浏览器里显示你的机器人的视图
pathfinder让机器人自动前往某个地方
chest使用箱子、熔炉、发射器、附魔台
digger学习怎样创造一个能挖方块的机器人
discord用Mineflayer机器人链接Discord机器人
jumper学习怎样移动、跳跃、使用载具、攻击附近实体

还有 例子目录 下的许多个

模块

A lot of the active development is happening inside of small npm packages which are used by mineflayer.
Mineflayer使用的许多小 npm 包在进行活跃的开发

The Node Way™

“When applications are done well, they are just the really application-specific, brackish residue that can’t be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons.” — substack from “how I write modules”

Modules

Mineflayer的主要组成模块 :

moduledescription
minecraft-protocolParse and serialize minecraft packets, plus authentication and encryption.
minecraft-dataLanguage independent module providing minecraft data for minecraft clients, servers and libraries.
prismarine-physicsProvide the physics engine for minecraft entities
prismarine-chunkA class to hold chunk data for Minecraft
node-vec33d vector math with robust unit tests
prismarine-blockRepresent a minecraft block with its associated data
prismarine-chatA parser for a minecraft chat message (extracted from mineflayer)
node-yggdrasilNode.js library to interact with Mojang’s authentication system, known as Yggdrasil
prismarine-worldThe core implementation of worlds for prismarine
prismarine-windowsRepresent minecraft windows
prismarine-itemRepresent a minecraft item with its associated data
prismarine-nbtAn NBT parser for node-minecraft-protocol
prismarine-recipeRepresent minecraft recipes
prismarine-biomeRepresent a minecraft biome with its associated data
prismarine-entityRepresent a minecraft entity

Debug

你可以使用 DEBUG 环境变量来启用一些协议调试输出 :

DEBUG="minecraft-protocol" node [...]

Windows :

set DEBUG=minecraft-protocol
node your_script.js

第三方插件

Mineflayer 可以扩展; 任何人都可以创造插件,在Mineflayer基础上添加更高级的API

最有用、最常更新的如下 :

另见:

Projects Using Mineflayer

使用 MIT 许可证

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值