赞
踩
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 文件的截取内容和部分翻译
npm install mineflayer
Videos
机器人的基础设置过程
【熟肉】Mineflayer教程 ep.1 快速上手
开始上手
如果不指定版本,将自动检测服务器的版本,您可以使用版本选项设置特定版本。例如 , version:"1.8"
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 | 在浏览器里显示你的机器人的视图 |
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 包在进行活跃的开发
“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”
Mineflayer的主要组成模块 :
module | description |
---|---|
minecraft-protocol | Parse and serialize minecraft packets, plus authentication and encryption. |
minecraft-data | Language independent module providing minecraft data for minecraft clients, servers and libraries. |
prismarine-physics | Provide the physics engine for minecraft entities |
prismarine-chunk | A class to hold chunk data for Minecraft |
node-vec3 | 3d vector math with robust unit tests |
prismarine-block | Represent a minecraft block with its associated data |
prismarine-chat | A parser for a minecraft chat message (extracted from mineflayer) |
node-yggdrasil | Node.js library to interact with Mojang’s authentication system, known as Yggdrasil |
prismarine-world | The core implementation of worlds for prismarine |
prismarine-windows | Represent minecraft windows |
prismarine-item | Represent a minecraft item with its associated data |
prismarine-nbt | An NBT parser for node-minecraft-protocol |
prismarine-recipe | Represent minecraft recipes |
prismarine-biome | Represent a minecraft biome with its associated data |
prismarine-entity | Represent a minecraft entity |
你可以使用 DEBUG
环境变量来启用一些协议调试输出 :
DEBUG="minecraft-protocol" node [...]
Windows :
set DEBUG=minecraft-protocol
node your_script.js
Mineflayer 可以扩展; 任何人都可以创造插件,在Mineflayer基础上添加更高级的API
最有用、最常更新的如下 :
另见:
使用 MIT 许可证
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。