mineflayer 4.13.0 → 4.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +23 -21
- package/README.md +2 -2
- package/docs/README.md +2 -2
- package/docs/api.md +27 -2
- package/docs/br/CONTRIBUTING_BR.md +84 -0
- package/docs/br/FAQ_BR.md +169 -0
- package/docs/br/README_BR.md +228 -0
- package/docs/br/api_br.md +2038 -0
- package/docs/br/unstable_api_br.md +20 -0
- package/docs/es/README_ES.md +2 -2
- package/docs/es/api_es.md +1 -1
- package/docs/fr/README_FR.md +2 -2
- package/docs/history.md +18 -0
- package/docs/mineflayer.ipynb +21 -18
- package/docs/ru/CONTRIBUTING_RU.md +86 -0
- package/docs/ru/FAQ_RU.md +107 -17
- package/docs/ru/README_RU.md +99 -100
- package/docs/ru/_sidebar.md +9 -0
- package/docs/ru/api_ru.md +1287 -654
- package/docs/ru/demos_ru.md +18 -0
- package/docs/ru/index.html +38 -0
- package/docs/ru/tutorial_ru.md +668 -0
- package/docs/ru/unstable_api_ru.md +1 -5
- package/docs/tr/README_TR.md +2 -2
- package/docs/zh/README_ZH_CN.md +3 -2
- package/docs/zh/_sidebar.md +7 -7
- package/docs/zh/api.md +7 -1
- package/examples/elytra.js +66 -0
- package/index.d.ts +8 -1
- package/lib/plugins/entities.js +102 -9
- package/lib/plugins/explosion.js +3 -3
- package/lib/plugins/inventory.js +35 -8
- package/lib/plugins/physics.js +38 -0
- package/lib/plugins/scoreboard.js +4 -0
- package/lib/plugins/villager.js +22 -37
- package/lib/version.js +1 -1
- package/package.json +3 -3
package/.github/workflows/ci.yml
CHANGED
|
@@ -17,42 +17,44 @@ jobs:
|
|
|
17
17
|
with:
|
|
18
18
|
node-version: 18.x
|
|
19
19
|
- run: npm i && npm run lint
|
|
20
|
+
|
|
21
|
+
PrepareSupportedVersions:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
outputs:
|
|
24
|
+
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v2
|
|
28
|
+
- name: Use Node.js 18.x
|
|
29
|
+
uses: actions/setup-node@v1.4.4
|
|
30
|
+
with:
|
|
31
|
+
node-version: 18.x
|
|
32
|
+
- id: set-matrix
|
|
33
|
+
run: |
|
|
34
|
+
node -e "
|
|
35
|
+
const testedVersions = require('./lib/version').testedVersions;
|
|
36
|
+
console.log('matrix='+JSON.stringify({'include': testedVersions.map(mcVersion => ({mcVersion}))}))
|
|
37
|
+
" >> $GITHUB_OUTPUT
|
|
20
38
|
|
|
21
39
|
MinecraftServer:
|
|
40
|
+
needs: PrepareSupportedVersions
|
|
22
41
|
runs-on: ubuntu-latest
|
|
23
42
|
strategy:
|
|
24
|
-
matrix:
|
|
25
|
-
javaVersion: [1.8]
|
|
26
|
-
mcVersion: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5']
|
|
27
|
-
include:
|
|
28
|
-
- javaVersion: 16
|
|
29
|
-
mcVersion: '1.17.1'
|
|
30
|
-
- javaVersion: 17
|
|
31
|
-
mcVersion: '1.18.2'
|
|
32
|
-
- javaVersion: 17
|
|
33
|
-
mcVersion: '1.19'
|
|
34
|
-
- javaVersion: 17
|
|
35
|
-
mcVersion: '1.19.2'
|
|
36
|
-
- javaVersion: 17
|
|
37
|
-
mcVersion: '1.19.3'
|
|
38
|
-
- javaVersion: 17
|
|
39
|
-
mcVersion: '1.19.4'
|
|
40
|
-
- javaVersion: 17
|
|
41
|
-
mcVersion: '1.20.1'
|
|
43
|
+
matrix: ${{fromJson(needs.PrepareSupportedVersions.outputs.matrix)}}
|
|
42
44
|
fail-fast: false
|
|
43
45
|
|
|
44
46
|
steps:
|
|
45
47
|
- uses: actions/checkout@v2
|
|
46
|
-
- name: Use Node.js
|
|
48
|
+
- name: Use Node.js 18.x
|
|
47
49
|
uses: actions/setup-node@v1.4.4
|
|
48
50
|
with:
|
|
49
51
|
node-version: 18.x
|
|
50
52
|
- name: Setup Java JDK
|
|
51
53
|
uses: actions/setup-java@v1.4.3
|
|
52
54
|
with:
|
|
53
|
-
java-version:
|
|
55
|
+
java-version: 17
|
|
54
56
|
java-package: jre
|
|
55
57
|
- name: Install Dependencies
|
|
56
58
|
run: npm install
|
|
57
59
|
- name: Start Tests
|
|
58
|
-
run: npm run mocha_test -- -g ${{ matrix.mcVersion }}
|
|
60
|
+
run: npm run mocha_test -- -g ${{ matrix.mcVersion }}v
|
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://discord.gg/GsEFRM8)
|
|
10
10
|
|
|
11
|
-
| <sub>EN</sub> [English](README.md) | <sub>RU</sub> [русский](ru/README_RU.md) | <sub>ES</sub> [Español](es/README_ES.md) | <sub>FR</sub> [Français](fr/README_FR.md) | <sub>TR</sub> [Türkçe](tr/README_TR.md) | <sub>ZH</sub> [中文](zh/README_ZH_CN.md) |
|
|
12
|
-
|
|
11
|
+
| <sub>EN</sub> [English](README.md) | <sub>RU</sub> [русский](ru/README_RU.md) | <sub>ES</sub> [Español](es/README_ES.md) | <sub>FR</sub> [Français](fr/README_FR.md) | <sub>TR</sub> [Türkçe](tr/README_TR.md) | <sub>ZH</sub> [中文](zh/README_ZH_CN.md) | <sub>BR</sub> [Português](br/README_BR.md) |
|
|
12
|
+
|-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|-------------------------|--------------------|
|
|
13
13
|
|
|
14
14
|
Create Minecraft bots with a powerful, stable, and high level JavaScript [API](api.md), also usable from Python.
|
|
15
15
|
|
package/docs/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
[](https://discord.gg/GsEFRM8)
|
|
10
10
|
|
|
11
|
-
| <sub>EN</sub> [English](README.md) | <sub>RU</sub> [русский](ru/README_RU.md) | <sub>ES</sub> [Español](es/README_ES.md) | <sub>FR</sub> [Français](fr/README_FR.md) | <sub>TR</sub> [Türkçe](tr/README_TR.md) | <sub>ZH</sub> [中文](zh/README_ZH_CN.md) |
|
|
12
|
-
|
|
11
|
+
| <sub>EN</sub> [English](README.md) | <sub>RU</sub> [русский](ru/README_RU.md) | <sub>ES</sub> [Español](es/README_ES.md) | <sub>FR</sub> [Français](fr/README_FR.md) | <sub>TR</sub> [Türkçe](tr/README_TR.md) | <sub>ZH</sub> [中文](zh/README_ZH_CN.md) | <sub>BR</sub> [Português](br/README_BR.md) |
|
|
12
|
+
|-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|-------------------------|--------------------|
|
|
13
13
|
|
|
14
14
|
Create Minecraft bots with a powerful, stable, and high level JavaScript [API](api.md), also usable from Python.
|
|
15
15
|
|
package/docs/api.md
CHANGED
|
@@ -136,6 +136,7 @@
|
|
|
136
136
|
- [bot.foodSaturation](#botfoodsaturation)
|
|
137
137
|
- [bot.oxygenLevel](#botoxygenlevel)
|
|
138
138
|
- [bot.physics](#botphysics)
|
|
139
|
+
- [bot.fireworkRocketDuration](#botfireworkrocketduration)
|
|
139
140
|
- [bot.simpleClick.leftMouse (slot)](#botsimpleclickleftmouse-slot)
|
|
140
141
|
- [bot.simpleClick.rightMouse (slot)](#botsimpleclickrightmouse-slot)
|
|
141
142
|
- [bot.time.doDaylightCycle](#bottimedodaylightcycle)
|
|
@@ -197,6 +198,7 @@
|
|
|
197
198
|
- ["entityEquip" (entity)](#entityequip-entity)
|
|
198
199
|
- ["entitySleep" (entity)](#entitysleep-entity)
|
|
199
200
|
- ["entitySpawn" (entity)](#entityspawn-entity)
|
|
201
|
+
- ["entityElytraFlew" (entity)](#entityelytraflew-entity)
|
|
200
202
|
- ["itemDrop" (entity)](#itemdrop-entity)
|
|
201
203
|
- ["playerCollect" (collector, collected)](#playercollect-collector-collected)
|
|
202
204
|
- ["entityGone" (entity)](#entitygone-entity)
|
|
@@ -223,6 +225,7 @@
|
|
|
223
225
|
- ["blockBreakProgressEnd" (block, entity)](#blockbreakprogressend-block-entity)
|
|
224
226
|
- ["diggingCompleted" (block)](#diggingcompleted-block)
|
|
225
227
|
- ["diggingAborted" (block)](#diggingaborted-block)
|
|
228
|
+
- ["usedFirework"](#usedfirework)
|
|
226
229
|
- ["move"](#move)
|
|
227
230
|
- ["forcedMove"](#forcedmove)
|
|
228
231
|
- ["mount"](#mount)
|
|
@@ -293,6 +296,7 @@
|
|
|
293
296
|
- [bot.unequip(destination)](#botunequipdestination)
|
|
294
297
|
- [bot.tossStack(item)](#bottossstackitem)
|
|
295
298
|
- [bot.toss(itemType, metadata, count)](#bottossitemtype-metadata-count)
|
|
299
|
+
- [bot.elytraFly()](#botelytrafly)
|
|
296
300
|
- [bot.dig(block, [forceLook = true], [digFace])](#botdigblock-forcelook--true-digface)
|
|
297
301
|
- [bot.stopDigging()](#botstopdigging)
|
|
298
302
|
- [bot.digTime(block)](#botdigtimeblock)
|
|
@@ -1037,6 +1041,10 @@ Number in the range [0, 20] respresenting the number of water-icons known as oxy
|
|
|
1037
1041
|
Edit these numbers to tweak gravity, jump speed, terminal velocity, etc.
|
|
1038
1042
|
Do this at your own risk.
|
|
1039
1043
|
|
|
1044
|
+
#### bot.fireworkRocketDuration
|
|
1045
|
+
|
|
1046
|
+
How many physics ticks worth of firework rocket boost are left.
|
|
1047
|
+
|
|
1040
1048
|
#### bot.simpleClick.leftMouse (slot)
|
|
1041
1049
|
|
|
1042
1050
|
abstraction over `bot.clickWindow(slot, 0, 0)`
|
|
@@ -1301,6 +1309,10 @@ Fires when an attribute of an entity changes.
|
|
|
1301
1309
|
#### "entityEquip" (entity)
|
|
1302
1310
|
#### "entitySleep" (entity)
|
|
1303
1311
|
#### "entitySpawn" (entity)
|
|
1312
|
+
#### "entityElytraFlew" (entity)
|
|
1313
|
+
|
|
1314
|
+
An entity started elytra flying.
|
|
1315
|
+
|
|
1304
1316
|
#### "itemDrop" (entity)
|
|
1305
1317
|
#### "playerCollect" (collector, collected)
|
|
1306
1318
|
|
|
@@ -1384,7 +1396,7 @@ Fires when a note block goes off somewhere.
|
|
|
1384
1396
|
* `pitch`: The pitch of the note (between 0-24 inclusive where 0 is the
|
|
1385
1397
|
lowest and 24 is the highest). More information about how the pitch values
|
|
1386
1398
|
correspond to notes in real life are available on the
|
|
1387
|
-
[official Minecraft wiki](http://
|
|
1399
|
+
[official Minecraft wiki](http://minecraft.wiki/w/Note_Block).
|
|
1388
1400
|
|
|
1389
1401
|
#### "pistonMove" (block, isPulling, direction)
|
|
1390
1402
|
|
|
@@ -1417,6 +1429,12 @@ This occurs whether the process was completed or aborted.
|
|
|
1417
1429
|
|
|
1418
1430
|
* `block` - the block that still exists
|
|
1419
1431
|
|
|
1432
|
+
#### "usedFirework" (fireworkEntityId)
|
|
1433
|
+
|
|
1434
|
+
Fires when the bot uses a firework while elytra flying.
|
|
1435
|
+
|
|
1436
|
+
* `fireworkEntityId` - the entity id of the firework.
|
|
1437
|
+
|
|
1420
1438
|
#### "move"
|
|
1421
1439
|
|
|
1422
1440
|
Fires when the bot moves. If you want the current position, use
|
|
@@ -1851,6 +1869,11 @@ This function returns a `Promise`, with `void` as its argument once tossing is c
|
|
|
1851
1869
|
to match any metadata
|
|
1852
1870
|
* `count` - how many you want to toss. `null` is an alias for `1`.
|
|
1853
1871
|
|
|
1872
|
+
#### bot.elytraFly()
|
|
1873
|
+
|
|
1874
|
+
This function returns a `Promise`, with `void` as its argument once activating
|
|
1875
|
+
elytra flight is complete. It will throw an Error if it fails.
|
|
1876
|
+
|
|
1854
1877
|
#### bot.dig(block, [forceLook = true], [digFace])
|
|
1855
1878
|
|
|
1856
1879
|
This function returns a `Promise`, with `void` as its argument when the block is broken or you are interrupted.
|
|
@@ -1946,7 +1969,9 @@ Use fishing rod
|
|
|
1946
1969
|
|
|
1947
1970
|
#### bot.activateItem(offHand=false)
|
|
1948
1971
|
|
|
1949
|
-
Activates the currently held item. This is how you eat, shoot bows, throw an
|
|
1972
|
+
Activates the currently held item. This is how you eat, shoot bows, throw an
|
|
1973
|
+
egg, activate firework rockets, etc.
|
|
1974
|
+
|
|
1950
1975
|
Optional parameter is `false` for main hand and `true` for off hand.
|
|
1951
1976
|
|
|
1952
1977
|
#### bot.deactivateItem()
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Contribuir
|
|
2
|
+
|
|
3
|
+
O Mineflayer foi originalmente criado principalmente por [andrewrk](http://github.com/andrewrk), mas tem sido muito aprimorado e corrigido por muitos [contribuidores](https://github.com/andrewrk/mineflayer/graphs/contributors). Portanto, é importante saber a melhor maneira de contribuir para o Mineflayer.
|
|
4
|
+
|
|
5
|
+
## Organização de Problemas
|
|
6
|
+
|
|
7
|
+
Temos 3 etiquetas para 3 fases de organização de problemas:
|
|
8
|
+
|
|
9
|
+
* Estágio 1: (Fase 1) criado por alguém novo no projeto, não sabemos se merece uma implementação / solução
|
|
10
|
+
* Estágio 2: (Fase 2) ideia promissora, mas é necessário pensar mais sobre o assunto antes de implementá-lo
|
|
11
|
+
* Estágio 3: (Fase 3) a ideia é muito precisa, só precisa ser programada
|
|
12
|
+
|
|
13
|
+
Links como https://github.com/PrismarineJS/mineflayer/issues?q=is%3Aopen+is%3Aissue+-label%3AStage1 podem ser usados como filtro para a fase 1 se você estiver procurando coisas prontas para serem contribuídas.
|
|
14
|
+
|
|
15
|
+
## Criando Testes
|
|
16
|
+
O Mineflayer possui dois tipos de testes:
|
|
17
|
+
|
|
18
|
+
* [Testes internos](test/internalTest.js): testes feitos com um servidor simples criado com o node-minecraft-protocol
|
|
19
|
+
* [Testes externos](test/externalTests/): testes feitos com um servidor Vanilla
|
|
20
|
+
|
|
21
|
+
O objetivo desses testes é determinar automaticamente o que funciona e o que não funciona no Mineflayer, tornando mais fácil a correção de problemas.
|
|
22
|
+
|
|
23
|
+
### Criando um Teste Externo
|
|
24
|
+
|
|
25
|
+
Para criar um teste externo, basta criar um arquivo em [test/externalTests](test/externalTests).
|
|
26
|
+
|
|
27
|
+
Um exemplo: [test/externalTests/digAndBuild.js](https://github.com/PrismarineJS/mineflayer/blob/master/test/externalTests/digAndBuild.js)
|
|
28
|
+
|
|
29
|
+
Esse arquivo deve exportar uma função que retorna uma função ou um array de funções que recebem o objeto bot e um callback como parâmetros, e deve conter verificações para determinar se a função testada falhou.
|
|
30
|
+
|
|
31
|
+
## Criando um Plugin de Terceiros
|
|
32
|
+
O Mineflayer suporta plugins; qualquer pessoa pode criar um plugin que adiciona uma API de nível mais alto acima do Mineflayer.
|
|
33
|
+
|
|
34
|
+
Vários plugins de terceiros foram [criados](https://github.com/andrewrk/mineflayer#third-party-plugins).
|
|
35
|
+
|
|
36
|
+
Para criar um novo plugin, você deve:
|
|
37
|
+
|
|
38
|
+
1. Criar um novo repositório.
|
|
39
|
+
2. No seu arquivo index.js, exportar uma função para inicializar o plugin com o argumento Mineflayer ([exemplo](https://github.com/andrewrk/mineflayer-navigate/blob/e24cb6a868ce64ae43bea2d035832c15ed01d301/index.js#L18)).
|
|
40
|
+
3. Essa função deve retornar uma função para introduzir o plugin com o objeto bot ([exemplo](https://github.com/andrewrk/mineflayer-navigate/blob/e24cb6a868ce64ae43bea2d035832c15ed01d301/index.js#L23)).
|
|
41
|
+
4. A partir dessa função, você pode adicionar mais funcionalidades ao bot ([exemplo](https://github.com/andrewrk/mineflayer-navigate/blob/e24cb6a868ce64ae43bea2d035832c15ed01d301/index.js#L32)).
|
|
42
|
+
|
|
43
|
+
Como o objeto Mineflayer é passado como argumento, esse plugin de terceiros não deve depender do Mineflayer (não deve haver referência ao Mineflayer no package.json).
|
|
44
|
+
|
|
45
|
+
Veja um [exemplo completo](https://github.com/andrewrk/mineflayer-navigate/tree/e24cb6a868ce64ae43bea2d035832c15ed01d301) aqui.
|
|
46
|
+
|
|
47
|
+
## Relatando Bugs
|
|
48
|
+
O Mineflayer funciona bem na maioria das situações, mas às vezes ainda pode ter bugs.
|
|
49
|
+
|
|
50
|
+
Ao encontrar um bug, é melhor relatar o erro fornecendo as seguintes informações:
|
|
51
|
+
|
|
52
|
+
* O que você está tentando fazer (o objetivo em inglês).
|
|
53
|
+
* O que você tentou (o código).
|
|
54
|
+
* O que aconteceu.
|
|
55
|
+
* O que você esperava que acontecesse.
|
|
56
|
+
|
|
57
|
+
## Código do Mineflayer
|
|
58
|
+
Aqui estão algumas coisas a se considerar ao criar uma solicitação de pull (pull request) ou fazer um commit:
|
|
59
|
+
|
|
60
|
+
### Tratamento de Erros
|
|
61
|
+
Na maioria dos casos, o Mineflayer não deve quebrar ou travar o bot. Mesmo se algo der errado, o bot pode seguir uma rota alternativa para alcançar o objetivo.
|
|
62
|
+
|
|
63
|
+
Isso significa que não devemos usar `throw new Error("erro")`, mas sim passar o erro junto com o callback.
|
|
64
|
+
|
|
65
|
+
Por exemplo:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
function myfunction (param1, callback) {
|
|
69
|
+
let toDo = 1
|
|
70
|
+
toDo = 2
|
|
71
|
+
if (toDo === 2) { // everything worked (todo está funcionado)
|
|
72
|
+
callback()
|
|
73
|
+
} else {
|
|
74
|
+
callback(new Error('something failed')) // (algo falhou)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Veja outro exemplo no [código do Mineflayer](https://github.com/andrewrk/mineflayer/blob/a8736c4ea473cf1a609c5a29046c0cdad006d429/lib/plugins/bed.js#L10).
|
|
80
|
+
|
|
81
|
+
### Atualizando a Documentação
|
|
82
|
+
A tabela de conteúdo no arquivo docs/api.md é gerada com o Doctoc. Após atualizar o arquivo, você deve executar doctoc docs/api.md para atualizar a tabela de conteúdo.
|
|
83
|
+
|
|
84
|
+
Esta documentação não é oficialmente mantida; para ver as informações mais recentes, consulte a documentação original: [unstable_api](../CONTRIBUTING.md).
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
## Perguntas Frequentes
|
|
2
|
+
|
|
3
|
+
Este documento de perguntas frequentes tem o objetivo de ajudar as pessoas com informações básicas.
|
|
4
|
+
|
|
5
|
+
## Como ocultar erros?
|
|
6
|
+
|
|
7
|
+
Para ocultar erros, você pode adicionar a opção `hideErrors: true` nas configurações ao criar o bot. Também é possível usar os seguintes eventos:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
client.on('error', () => {})
|
|
11
|
+
client.on('end', () => {})
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Meu evento de chat não está sendo emitido em um servidor personalizado. Como posso resolver isso?
|
|
15
|
+
|
|
16
|
+
Alguns servidores Spigot, em particular certos plugins, utilizam formatos personalizados de chat. Nesse caso, é necessário analisar esses formatos com expressões regulares personalizadas. Recomenda-se ler e modificar o arquivo [chat_parsing.js](https://github.com/PrismarineJS/mineflayer/blob/master/examples/chat_parsing.js) para que funcione com o plugin de chat específico do seu servidor. Você também pode consultar http://prismarinejs.github.io/mineflayer/#/tutorial?id=custom-chat para obter mais informações.
|
|
17
|
+
|
|
18
|
+
## Como posso coletar informações de um plugin de chat personalizado?
|
|
19
|
+
|
|
20
|
+
A maioria dos servidores de Minecraft possui plugins que enviam mensagens ao chat quando ocorrem eventos. Se a informação enviada for simples, você pode utilizar a solução mencionada anteriormente. No entanto, se as mensagens contêm muita informação em um único bloco de texto, outra opção é utilizar o evento `"messagestr"`, que permite analisar as mensagens de forma mais fácil.
|
|
21
|
+
|
|
22
|
+
**Exemplo:**
|
|
23
|
+
|
|
24
|
+
Suponha que a mensagem seja semelhante a esta:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
(!) U9G ganhou o /jackpot e recebeu
|
|
28
|
+
$26,418,402,450! Eles compraram 2,350,000 (76.32%) bilhetes
|
|
29
|
+
de um total de 3,079,185 bilhetes vendidos!
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const regex = {
|
|
34
|
+
first: /\(!\) (.+) ganhou o \/jackpot e recebeu +/,
|
|
35
|
+
second: /\$(.+)! Eles compraram (.+) \((.+)%\) bilhetes do total de /,
|
|
36
|
+
third: /(.+) bilhetes vendidos!/
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let jackpot = {}
|
|
40
|
+
bot.on('messagestr', msg => {
|
|
41
|
+
if (regex.first.test(msg)) {
|
|
42
|
+
const username = msg.match(regex.first)[1]
|
|
43
|
+
jackpot.username = username
|
|
44
|
+
} else if (regex.second.test(msg)) {
|
|
45
|
+
const [, moneyWon, boughtTickets, winPercent] = msg.match(regex.second)
|
|
46
|
+
jackpot.moneyWon = parseInt(moneyWon.replace(/,/g, ''))
|
|
47
|
+
jackpot.boughtTickets = parseInt(boughtTickets.replace(/,/g, ''))
|
|
48
|
+
jackpot.winPercent = parseFloat(winPercent)
|
|
49
|
+
} else if (regex.third.test(msg)) {
|
|
50
|
+
const totalTickets = msg.match(regex.third)[1]
|
|
51
|
+
jackpot.totalTickets = parseInt(totalTickets.replace(/,/g, ''))
|
|
52
|
+
onDone(jackpot)
|
|
53
|
+
jackpot = {}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Como posso enviar um comando?
|
|
59
|
+
|
|
60
|
+
Usando `bot.chat()`.
|
|
61
|
+
|
|
62
|
+
**Exmemplo:**
|
|
63
|
+
```js
|
|
64
|
+
bot.chat('/give @p diamond')
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### É possível criar vários bots e controlá-los separadamente?
|
|
68
|
+
|
|
69
|
+
Você pode criar bots diferentes com a função `createBot` e executar ações diferentes para cada um deles. Dê uma olhada no arquivo `multiple.js` para mais informações.
|
|
70
|
+
|
|
71
|
+
### Como faço para o bot largar todo o seu inventário?
|
|
72
|
+
|
|
73
|
+
Você pode usar a função `bot.inventory.items()` para obter uma matriz dos itens no inventário do bot. Você pode criar uma função recursiva para largar cada item usando `bot.toss()`. Veja um exemplo [aqui](https://gist.github.com/dada513/3d88f772be4224b40f9e5d1787bd63e9).
|
|
74
|
+
|
|
75
|
+
### Como vejo os pacotes que foram enviados/recebidos?
|
|
76
|
+
|
|
77
|
+
Você pode ativar o modo de depuração. Para obter mais informações, consulte [este link](https://github.com/PrismarineJS/mineflayer/blob/master/docs/br/README_BR.md#depuraci%C3%B3n).
|
|
78
|
+
|
|
79
|
+
### Quero evitar desconexões devido a lag no servidor, como posso fazer isso?
|
|
80
|
+
|
|
81
|
+
Uma maneira de evitar desconexões devido à latência no servidor é aumentar o valor na opção `checkTimeoutInterval` (por exemplo, `300*1000`, que representa 5 minutos, em vez do valor padrão, que é 30 segundos). Se mesmo assim você continuar sendo desconectado do servidor, você pode se reconectar automaticamente usando este exemplo [aqui](https://github.com/PrismarineJS/mineflayer/blob/master/examples/reconnector.js).
|
|
82
|
+
|
|
83
|
+
### Como posso obter a descrição/texto de um item?
|
|
84
|
+
|
|
85
|
+
Você pode usar a propriedade `item.nbt`. É recomendável utilizar a biblioteca `prismarine-nbt`. O método `nbt.simplify()` pode ser útil para simplificar a obtenção da descrição de um item.
|
|
86
|
+
|
|
87
|
+
**Exemplo:**
|
|
88
|
+
```js
|
|
89
|
+
function getLore (item) {
|
|
90
|
+
let message = ''
|
|
91
|
+
if (item.nbt == null) return message
|
|
92
|
+
|
|
93
|
+
const nbt = require('prismarine-nbt')
|
|
94
|
+
const ChatMessage = require('prismarine-chat')(bot.version)
|
|
95
|
+
|
|
96
|
+
const data = nbt.simplify(item.nbt)
|
|
97
|
+
const display = data.display
|
|
98
|
+
if (display == null) return message
|
|
99
|
+
|
|
100
|
+
const lore = display.Lore
|
|
101
|
+
if (lore == null) return message
|
|
102
|
+
for (const line of lore) {
|
|
103
|
+
message += new ChatMessage(line).toString()
|
|
104
|
+
message += '\n'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return message
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Como posso enviar uma mensagem do console para o servidor?
|
|
112
|
+
|
|
113
|
+
Você pode usar uma biblioteca como `repl` para ler o que você escreve no console e usar `bot.chat()` para enviá-lo para o servidor. Você pode encontrar um exemplo [aqui](https://github.com/PrismarineJS/mineflayer/blob/master/examples/repl.js).
|
|
114
|
+
|
|
115
|
+
### Ao criar um plugin, como posso especificar outro plugin como dependência?
|
|
116
|
+
|
|
117
|
+
Na função `inject()` do seu plugin, você pode executar a função `bot.loadPlugin()` para carregar esse plugin. Se o plugin já estiver carregado anteriormente, nada acontecerá.
|
|
118
|
+
|
|
119
|
+
Nota: a ordem em que os plugins são carregados é dinâmica; você nunca deve chamar outro plugin em sua função `inject()`.
|
|
120
|
+
|
|
121
|
+
### Como posso usar um proxy SOCKS5?
|
|
122
|
+
|
|
123
|
+
Nas opções de `mineflayer.createBot(opções)`, remova o seu `host` das opções e coloque as informações necessárias nas variáveis `PROXY_IP`, `PROXY_PORT`, `PROXY_USERNAME`, `PROXY_PASSWORD`, `MC_SERVER_IP` e `MC_SERVER_PORT`. Em seguida, adicione o seguinte ao seu objeto de opções:
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
connect: (client) => {
|
|
127
|
+
socks.createConnection({
|
|
128
|
+
proxy: {
|
|
129
|
+
host: PROXY_IP,
|
|
130
|
+
port: PROXY_PORT,
|
|
131
|
+
type: 5,
|
|
132
|
+
userId: PROXY_USERNAME,
|
|
133
|
+
password: PROXY_PASSWORD
|
|
134
|
+
},
|
|
135
|
+
command: 'connect',
|
|
136
|
+
destination: {
|
|
137
|
+
host: MC_SERVER_IP,
|
|
138
|
+
port: MC_SERVER_PORT
|
|
139
|
+
}
|
|
140
|
+
}, (err, info) => {
|
|
141
|
+
if (err) {
|
|
142
|
+
console.log(err)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
client.setSocket(info.socket)
|
|
146
|
+
client.emit('connect')
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
# Erros Comuns
|
|
152
|
+
|
|
153
|
+
### `UnhandledPromiseRejectionWarning: Error: Failed to read asymmetric key`
|
|
154
|
+
|
|
155
|
+
Isso ocorre quando você fornece uma versão incorreta ao mineflayer, ou o mineflayer detecta a versão errada.
|
|
156
|
+
|
|
157
|
+
### `TypeError: Cannot read property '?' of undefined`
|
|
158
|
+
|
|
159
|
+
Você pode estar tentando acessar uma propriedade do bot que ainda não existe; tente acessar a propriedade após o evento `spawn`.
|
|
160
|
+
|
|
161
|
+
### `SyntaxError: Unexpected token '?'`
|
|
162
|
+
|
|
163
|
+
Atualize a versão do seu Node.js.
|
|
164
|
+
|
|
165
|
+
### O bot não consegue quebrar/colocar blocos ou abrir baús
|
|
166
|
+
|
|
167
|
+
Verifique se a proteção do spawn não está impedindo o bot de realizar a ação.
|
|
168
|
+
|
|
169
|
+
Esta documentação não é oficial. Para as informações mais atualizadas, consulte a documentação original: [FAQ](../FAQ.md).
|