-
-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and revise simplified Chinese language documents (#2374)
* 翻译简体中文语言文件 * fix lint Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
- Loading branch information
Showing
9 changed files
with
4,096 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# 贡献 | ||
|
||
Mineflayer 最初主要是由 [andrewrk](http://github.com/andrewrk) 制作的 | ||
但自那以后,许多[贡献者](https://github.com/andrewrk/mineflayer/graphs/contributors)对其进行了改进和修复 | ||
所以知道如何为mineflayer做出贡献的最佳方式很重要 | ||
|
||
## Issue organization | ||
|
||
我们有3个阶段标签来尝试组织Issue: | ||
|
||
* Stage 1: 只是由项目新手创建的,我们还不知道它是否值得实现/修复 | ||
* Stage 2: 有希望的想法,但在实施前需要更多思考 | ||
* Stage 3: 想法被精确地指定了,就剩写代码了 | ||
|
||
链接如 https://github.com/PrismarineJS/mineflayer/issues?q=is%3Aopen+is%3Aissue+-label%3AStage1 can be used to filter out stage 1 if you're looking for things that are ready for contribution | ||
|
||
## 创建测试 | ||
Mineflayer 有两种测试 : | ||
|
||
* [internal tests](test/internalTest.js) : 针对使用node-minecraft-protocol创建的简单服务器进行的测试 | ||
* [external tests](test/externalTests/) : 针对原版服务器进行的测试 | ||
|
||
The objective of these tests is to know automatically what works and what doesn't in mineflayer, so it's easier to make mineflayer work. | ||
|
||
### 创建外部测试 | ||
|
||
In order to add an external test now you only need to create a file in [test/externalTests](test/externalTests) | ||
|
||
一个例子 : [test/externalTests/digAndBuild.js](https://github.com/PrismarineJS/mineflayer/blob/master/test/externalTests/digAndBuild.js) | ||
|
||
That file needs to export a function returning a function or an array of function taking as parameter the bot object and a done callback, | ||
it should contain asserts to test if the tested functionality failed. | ||
|
||
|
||
## 创建第三方插件 | ||
Mineflayer 是可扩展的插件化的; 任何人都可以创建一个插件,在 Mineflayer 之上添加更高级别的 API。 | ||
|
||
已经开发了几个这样的第三方插件 [查看](https://github.com/andrewrk/mineflayer#third-party-plugins) | ||
|
||
为了创建一个新的,您需要 : | ||
|
||
1. 创建一个新的 repo | ||
2. 在你的 index.js 文件中, 导出一个接受参数 mineflayer 的 init 函数 ([查看例子](https://github.com/andrewrk/mineflayer-navigate/blob/e24cb6a868ce64ae43bea2d035832c15ed01d301/index.js#L18)) | ||
3. that function returns a inject function taking in argument the bot object ([example](https://github.com/andrewrk/mineflayer-navigate/blob/e24cb6a868ce64ae43bea2d035832c15ed01d301/index.js#L23)) | ||
4. that inject function add functionalities to the bot object ([example](https://github.com/andrewrk/mineflayer-navigate/blob/e24cb6a868ce64ae43bea2d035832c15ed01d301/index.js#L32)) | ||
|
||
Since the mineflayer object is passed in parameter, that new package doesn't need to depend on mineflayer (no mineflayer dependency in the package.json) | ||
|
||
参考 [全部示例](https://github.com/andrewrk/mineflayer-navigate/tree/e24cb6a868ce64ae43bea2d035832c15ed01d301) | ||
|
||
## 反馈Bug | ||
Mineflayer 在大多数情况下都能很好地工作,但有时仍然存在bug. | ||
|
||
找到一个问题时,最好报告一个提供这些信息的问题 : | ||
|
||
* 你想做什么 (英语目标) | ||
* 你尝试过什么 (代码) | ||
* 发生了什么事 | ||
* 你期望会发生什么 | ||
|
||
## Mineflayer 代码 | ||
提交请求或提交提交时需要考虑的一些事情 : | ||
|
||
### 错误处理 | ||
在大多数情况下,mineflayer不会让机器人崩溃。即使有些东西失败了,机器人也可以选择另一条路线来达到它的目标。 | ||
|
||
这意味着我们不应该使用 `throw(new Error("error"))` 而是使用node.js约定在回调中传递错误。 | ||
|
||
例如 : | ||
|
||
```js | ||
function myfunction (param1, callback) { | ||
// do stuff | ||
let toDo = 1 | ||
toDo = 2 | ||
if (toDo === 2) { // 一切正常 | ||
callback() | ||
} else { | ||
callback(new Error('什么东西出错了')) | ||
} | ||
} | ||
``` | ||
|
||
请参考另一个例子 [mineflayer code](https://github.com/andrewrk/mineflayer/blob/a8736c4ea473cf1a609c5a29046c0cdad006d429/lib/plugins/bed.js#L10) | ||
|
||
### 更新文档 | ||
docs/api.md 的内容是用doctoc制作的。更新该文件后,应运行 `doctoc docs/api.md` 以更新目录。 | ||
|
||
没有doctoc命令使用下面的命令安装 | ||
|
||
``` | ||
npm install -g doctoc | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
## FAQ | ||
|
||
本文档旨在帮助人们解决常见问题 | ||
|
||
### 如何隐藏报错 ? | ||
|
||
在createBot选项中使用`hideErrors:true` | ||
您也可以选择添加这些监听事件: | ||
|
||
```js | ||
client.on('error', () => {}) | ||
client.on('end', () => {}) | ||
``` | ||
|
||
### 我无法在自定义服务器上获取聊天事件,如何解决? | ||
|
||
Spigot 服务器, 特别是一些插件, 使用的是自定义聊天格式,您需要使用自定义正则表达式/解析器对其进行解析。 | ||
阅读并改编[chat_parsing.js](https://github.com/PrismarineJS/mineflayer/blob/master/examples/chat_parsing.js)使其适用于您的特定聊天插件. 或者阅读 http://mineflayer.prismarine.js.org/#/tutorial?id=custom-chat | ||
|
||
### 如何用自定义插件在聊天中收集信息 ? | ||
|
||
大多数定制的Minecraft服务器都有插件支持,很多插件会在聊天中说一些事情. 如果只是一条信息, 最好使用上述解决方案中讨论的解决方案, 但是当这些消息被分成许多小消息时, 另一个选择是使用 `"messagestr"` 事件 因为它允许轻松解析多行消息. | ||
|
||
**例子:** | ||
|
||
聊天栏中的信息看起来像: | ||
``` | ||
(!) U9G has won the /jackpot and received | ||
$26,418,402,450! They purchased 2,350,000 (76.32%) ticket(s) out of the | ||
3,079,185 ticket(s) sold! | ||
``` | ||
```js | ||
const regex = { | ||
first: /\(!\) (.+) has won the \/jackpot and received +/, | ||
second: /\$(.+)! They purchased (.+) \((.+)%\) ticket\(s\) out of the /, | ||
third: /(.+) ticket\(s\) sold!/ | ||
} | ||
|
||
let jackpot = {} | ||
bot.on('messagestr', msg => { | ||
if (regex.first.test(msg)) { | ||
const username = msg.match(regex.first)[1] | ||
jackpot.username = username | ||
} else if (regex.second.test(msg)) { | ||
const [, moneyWon, boughtTickets, winPercent] = msg.match(regex.second) | ||
jackpot.moneyWon = parseInt(moneyWon.replace(/,/g, '')) | ||
jackpot.boughtTickets = parseInt(boughtTickets.replace(/,/g, '')) | ||
jackpot.winPercent = parseFloat(winPercent) | ||
} else if (regex.third.test(msg)) { | ||
const totalTickets = msg.match(regex.third)[1] | ||
jackpot.totalTickets = parseInt(totalTickets.replace(/,/g, '')) | ||
onDone(jackpot) | ||
jackpot = {} | ||
} | ||
}) | ||
``` | ||
### 如何发送命令 ? | ||
|
||
使用 `bot.chat()`. | ||
|
||
**例子:** | ||
|
||
```js | ||
bot.chat('/give @p minecraft:diamond_sword') | ||
``` | ||
|
||
### 是否可以使用bot = mineflayer.createbot登录多个帐户 同时分别控制它们 ? | ||
|
||
通过调用createBot创建不同的bot实例,然后为每个实例执行不同的操作,请参考 multiple.js | ||
|
||
### 如何让机器人丢出它的全部背包物品? | ||
|
||
bot.inventory.items() 返回机器人的物品数组. 您可以使用递归函数循环遍历它们,并使用 `bot.toss()`. [点这里](https://gist.github.com/dada513/3d88f772be4224b40f9e5d1787bd63e9) 查看例子 | ||
|
||
### 如何检查发送/接收的数据包 ? | ||
|
||
启用调试模式 https://github.com/PrismarineJS/mineflayer#debug | ||
|
||
### 我希望即使在服务器有延迟的情况下也能避免断开连接,如何实现这一点 ? | ||
|
||
一种方法是增加 [checkTimeoutInterval](https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/docs/API.md#mccreateclientoptions) 选项的值(在createBot中设置) (例如 `300*1000` 这是5分钟,而不是默认的30秒). 如果仍然断开连接,可以使用类似于此示例的方法自动重新连接 https://github.com/PrismarineJS/mineflayer/blob/master/examples/reconnector.js | ||
|
||
### 如何获取物品的 lore / text? | ||
|
||
你可以使用 `item.nbt` 属性. 此外建议使用 `prismarine-nbt` 库. `nbt.simplify()` 方法可能有用 | ||
|
||
**例子:** | ||
|
||
```js | ||
function getLore (item) { | ||
let message = '' | ||
if (item.nbt == null) return message | ||
|
||
const nbt = require('prismarine-nbt') | ||
const ChatMessage = require('prismarine-chat')(bot.version) | ||
|
||
const data = nbt.simplify(item.nbt) | ||
const display = data.display | ||
if (display == null) return message | ||
|
||
const lore = display.Lore | ||
if (lore == null) return message | ||
for (const line of lore) { | ||
message += new ChatMessage(line).toString() | ||
message += '\n' | ||
} | ||
|
||
return message | ||
} | ||
``` | ||
|
||
### 如何从控制台发送消息到服务器? | ||
|
||
您可以使用类似`repl`的库来读取控制台输入的内容并用`bot.chat()`发送它。 你可以在这查看例子 [点这里](https://github.com/PrismarineJS/mineflayer/blob/master/examples/repl.js) | ||
|
||
### 创建插件时,如何将另一个插件指定为依赖项? | ||
|
||
在插件的`inject()`函数中,您可以安全地调用`bot.loadPlugin(anotherPlugin)`确保已加载该插件。如果插件之前已经加载,则不会发生任何事情。 | ||
|
||
请注意,加载插件的顺序是动态的, 因此,永远不要在`inject()`函数中调用其他插件. | ||
|
||
### 如何使用socks5代理? | ||
|
||
在对象的选项中 `mineflayer.createBot(options)`,从选项对象中删除你的 `host` 选项,声明以下变量 `PROXY_IP, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD, MC_SERVER_IP, MC_SERVER_PORT` 并将其添加到选项对象中: | ||
```js | ||
connect: (client) => { | ||
socks.createConnection({ | ||
proxy: { | ||
host: PROXY_IP, | ||
port: PROXY_PORT, | ||
type: 5, | ||
userId: PROXY_USERNAME, | ||
password: PROXY_PASSWORD | ||
}, | ||
command: 'connect', | ||
destination: { | ||
host: MC_SERVER_IP, | ||
port: MC_SERVER_PORT | ||
} | ||
}, (err, info) => { | ||
if (err) { | ||
console.log(err) | ||
return | ||
} | ||
client.setSocket(info.socket) | ||
client.emit('connect') | ||
}) | ||
} | ||
``` | ||
`socks` 用 `const socks = require('socks').SocksClient` 声明 使用的是[这个](https://www.npmjs.com/package/socks) 包. | ||
|
||
# 常见错误 | ||
|
||
### `UnhandledPromiseRejectionWarning: Error: Failed to read asymmetric key` | ||
|
||
当你给 mineflayer 设定了错误的服务器版本,或者 mineflayer 检测到错误的服务器版本时会发生这种情况 | ||
|
||
### `TypeError: Cannot read property '?' of undefined` | ||
|
||
您可能正在尝试在 bot 对象上使用尚不存在的内容,请尝试在 `spawn` 事件之后调用该语句 | ||
|
||
### `SyntaxError: Unexpected token '?'` | ||
|
||
更新node版本 | ||
|
||
### The bot can't break/place blocks or open chests | ||
|
||
检查出生点保护是否阻止了机器人的操作 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- 入门手册 | ||
- [介绍](/) | ||
- [API](api.md) | ||
- [FAQ](FAQ.md) | ||
- [演示](demos.md) | ||
- [教程](tutorial.md) | ||
- [不稳定的API](unstable_api.md) | ||
- [贡献](CONTRIBUTING.md) | ||
- [更新历史](history.md) |
Oops, something went wrong.