mineflayer 3.11.0 → 3.13.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/FUNDING.yml +0 -2
- package/README.md +16 -15
- package/docs/README.md +16 -15
- package/docs/api.md +25 -16
- package/docs/es/README_ES.md +1 -1
- package/docs/es/api_es.md +34 -18
- package/docs/fr/README_FR.md +1 -1
- package/docs/history.md +29 -0
- package/docs/ru/README_RU.md +1 -1
- package/docs/ru/api_ru.md +1 -1
- package/docs/tr/README_TR.md +1 -1
- package/docs/zh/README_ZH_CN.md +1 -1
- package/examples/chatterbox.js +1 -1
- package/examples/discord.js +15 -5
- package/examples/python/basic.py +2 -2
- package/examples/python/chatterbox.py +1 -1
- package/examples/screenshot-with-node-canvas-webgl/screenshot.js +2 -2
- package/index.d.ts +99 -97
- package/lib/conversions.js +1 -1
- package/lib/loader.js +4 -4
- package/lib/plugins/bed.js +1 -1
- package/lib/plugins/block_actions.js +1 -1
- package/lib/plugins/blocks.js +18 -4
- package/lib/plugins/chat.js +2 -0
- package/lib/plugins/command_block.js +1 -1
- package/lib/plugins/creative.js +1 -1
- package/lib/plugins/digging.js +2 -17
- package/lib/plugins/entities.js +13 -9
- package/lib/plugins/explosion.js +3 -1
- package/lib/plugins/game.js +7 -0
- package/lib/plugins/generic_place.js +5 -10
- package/lib/plugins/inventory.js +17 -9
- package/lib/plugins/physics.js +16 -5
- package/lib/plugins/place_block.js +1 -1
- package/lib/plugins/place_entity.js +11 -5
- package/lib/plugins/ray_trace.js +10 -0
- package/lib/plugins/scoreboard.js +2 -9
- package/lib/plugins/sound.js +1 -1
- package/lib/plugins/spawn_point.js +1 -1
- package/lib/plugins/villager.js +2 -3
- package/lib/scoreboard.js +48 -35
- package/lib/version.js +1 -1
- package/package.json +23 -22
package/docs/zh/README_ZH_CN.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[](https://gitpod.io/#https://github.com/PrismarineJS/mineflayer)
|
|
11
11
|
[](https://colab.research.google.com/github/PrismarineJS/mineflayer/blob/master/docs/mineflayer.ipynb)
|
|
12
12
|
|
|
13
|
-
|
|
|
13
|
+
| <sub>EN</sub> [英语](../README.md) | <sub>RU</sub> [俄语](../ru/README_RU.md) | <sub>ES</sub> [西班牙语](../es/README_ES.md) | <sub>FR</sub> [法语](../fr/README_FR.md) | <sub>TR</sub> [土耳其语](../tr/README_TR.md) | <sub>ZH</sub> [中文](README_ZH_CN.md) |
|
|
14
14
|
|-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|----------------------------|
|
|
15
15
|
|
|
16
16
|
使用强大、稳定、高级的JavaScript [API](../api.md) 来开发Minecraft机器人,同时支持 Python。
|
package/examples/chatterbox.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* a few informations while you are in game.
|
|
14
14
|
*/
|
|
15
15
|
const mineflayer = require('mineflayer')
|
|
16
|
-
const Vec3 = require('vec3')
|
|
16
|
+
const { Vec3 } = require('vec3')
|
|
17
17
|
|
|
18
18
|
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
19
19
|
console.log('Usage : node chatterbot.js <host> <port> [<name>] [<password>]')
|
package/examples/discord.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* This example is a very simple way how to connect a discord bot with a mineflayer bot.
|
|
3
3
|
* For this example you will need discord.js installed. You can install with: npm install discord.js
|
|
4
|
-
*
|
|
4
|
+
* This example uses discord.js v13
|
|
5
5
|
* You need to do this before running this example:
|
|
6
6
|
* - You need to get a discord token
|
|
7
7
|
* - You need to get the id of the channel you want to use
|
|
@@ -12,9 +12,18 @@ if (process.argv.length < 6 || process.argv.length > 8) {
|
|
|
12
12
|
process.exit(1)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
// Load discord
|
|
16
|
-
const
|
|
17
|
-
|
|
15
|
+
// Load discord.js
|
|
16
|
+
const {
|
|
17
|
+
Client,
|
|
18
|
+
Intents
|
|
19
|
+
} = require('discord.js')
|
|
20
|
+
// Create Discord intentions, required in v13
|
|
21
|
+
const intents = new Intents(['GUILDS', 'GUILD_MESSAGES'])
|
|
22
|
+
// Create Discord client
|
|
23
|
+
const client = new Client({
|
|
24
|
+
intents: intents
|
|
25
|
+
})
|
|
26
|
+
|
|
18
27
|
let channel = process.argv[3]
|
|
19
28
|
|
|
20
29
|
// Load mineflayer
|
|
@@ -28,6 +37,7 @@ const bot = mineflayer.createBot({
|
|
|
28
37
|
|
|
29
38
|
client.on('ready', () => {
|
|
30
39
|
console.log(`The discord bot logged in! Username: ${client.user.username}!`)
|
|
40
|
+
// Find the Discord channel messages will be sent to
|
|
31
41
|
channel = client.channels.cache.get(channel)
|
|
32
42
|
if (!channel) {
|
|
33
43
|
console.log(`I could not find the channel (${process.argv[3]})!\nUsage : node discord.js <discord bot token> <channel id> <host> <port> [<name>] [<password>]`)
|
|
@@ -36,7 +46,7 @@ client.on('ready', () => {
|
|
|
36
46
|
})
|
|
37
47
|
|
|
38
48
|
// Redirect Discord messages to in-game chat
|
|
39
|
-
client.on('
|
|
49
|
+
client.on('messageCreate', message => {
|
|
40
50
|
// Only handle messages in specified channel
|
|
41
51
|
if (message.channel.id !== channel.id) return
|
|
42
52
|
// Ignore messages from the bot itself
|
package/examples/python/basic.py
CHANGED
|
@@ -21,7 +21,7 @@ def handle(*args):
|
|
|
21
21
|
movements = pathfinder.Movements(bot, mcData)
|
|
22
22
|
|
|
23
23
|
@On(bot, 'chat')
|
|
24
|
-
def handleMsg(sender, message, *args):
|
|
24
|
+
def handleMsg(this, sender, message, *args):
|
|
25
25
|
print("Got message", sender, message)
|
|
26
26
|
if sender and (sender != BOT_USERNAME):
|
|
27
27
|
bot.chat('Hi, you said ' + message)
|
|
@@ -39,4 +39,4 @@ def handle(*args):
|
|
|
39
39
|
|
|
40
40
|
@On(bot, "end")
|
|
41
41
|
def handle(*args):
|
|
42
|
-
print("Bot ended!", args)
|
|
42
|
+
print("Bot ended!", args)
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# a few informations while you are in game.
|
|
14
14
|
# ===========================================================================
|
|
15
15
|
import sys, re
|
|
16
|
-
from javascript import require, On, Once
|
|
16
|
+
from javascript import require, On, Once, console
|
|
17
17
|
|
|
18
18
|
mineflayer = require("mineflayer", "latest")
|
|
19
19
|
Vec3 = require("vec3").Vec3
|
|
@@ -11,8 +11,8 @@ global.Worker = require('worker_threads').Worker
|
|
|
11
11
|
const THREE = require('three')
|
|
12
12
|
const { createCanvas } = require('node-canvas-webgl/lib')
|
|
13
13
|
const fs = require('fs').promises
|
|
14
|
-
const Vec3 = require('vec3')
|
|
15
|
-
const EventEmitter = require('events')
|
|
14
|
+
const { Vec3 } = require('vec3')
|
|
15
|
+
const { EventEmitter } = require('events')
|
|
16
16
|
|
|
17
17
|
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
18
18
|
console.log('Usage : node screenshot.js <host> <port> [<name>] [<password>]')
|
package/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Block } from 'prismarine-block'
|
|
|
9
9
|
import { Entity } from 'prismarine-entity'
|
|
10
10
|
import { ChatMessage } from 'prismarine-chat'
|
|
11
11
|
|
|
12
|
+
export function createBot (options: { client: Client } & Partial<BotOptions>): Bot
|
|
12
13
|
export function createBot (options: BotOptions): Bot
|
|
13
14
|
|
|
14
15
|
export interface BotOptions extends ClientOptions {
|
|
@@ -25,6 +26,7 @@ export interface BotOptions extends ClientOptions {
|
|
|
25
26
|
physicsEnabled?: boolean
|
|
26
27
|
client?: Client
|
|
27
28
|
brand?: string
|
|
29
|
+
defaultChatPatterns?: boolean
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export type ChatLevel = 'enabled' | 'commandsOnly' | 'disabled'
|
|
@@ -44,112 +46,111 @@ interface BotEvents {
|
|
|
44
46
|
translate: string | null,
|
|
45
47
|
jsonMsg: ChatMessage,
|
|
46
48
|
matches: string[] | null
|
|
47
|
-
) => void
|
|
49
|
+
) => Promise<void> | void
|
|
48
50
|
whisper: (
|
|
49
51
|
username: string,
|
|
50
52
|
message: string,
|
|
51
53
|
translate: string | null,
|
|
52
54
|
jsonMsg: ChatMessage,
|
|
53
55
|
matches: string[] | null
|
|
54
|
-
) => void
|
|
55
|
-
actionBar: (jsonMsg: ChatMessage) => void
|
|
56
|
-
error: (err: Error) => void
|
|
57
|
-
message: (jsonMsg: ChatMessage, position: string) => void
|
|
58
|
-
messagestr: (message: string, position: string, jsonMsg: ChatMessage) => void
|
|
59
|
-
unmatchedMessage: (stringMsg: string, jsonMsg: ChatMessage) => void
|
|
60
|
-
inject_allowed: () => void
|
|
61
|
-
login: () => void
|
|
62
|
-
spawn: () => void
|
|
63
|
-
respawn: () => void
|
|
64
|
-
game: () => void
|
|
65
|
-
title: (text: string) => void
|
|
66
|
-
rain: () => void
|
|
67
|
-
time: () => void
|
|
68
|
-
kicked: (reason: string, loggedIn: boolean) => void
|
|
69
|
-
end: () => void
|
|
70
|
-
spawnReset: () => void
|
|
71
|
-
death: () => void
|
|
72
|
-
health: () => void
|
|
73
|
-
breath: () => void
|
|
74
|
-
entitySwingArm: (entity: Entity) => void
|
|
75
|
-
entityHurt: (entity: Entity) => void
|
|
76
|
-
entityDead: (entity: Entity) => void
|
|
77
|
-
entityTaming: (entity: Entity) => void
|
|
78
|
-
entityTamed: (entity: Entity) => void
|
|
79
|
-
entityShakingOffWater: (entity: Entity) => void
|
|
80
|
-
entityEatingGrass: (entity: Entity) => void
|
|
81
|
-
entityWake: (entity: Entity) => void
|
|
82
|
-
entityEat: (entity: Entity) => void
|
|
83
|
-
entityCriticalEffect: (entity: Entity) => void
|
|
84
|
-
entityMagicCriticalEffect: (entity: Entity) => void
|
|
85
|
-
entityCrouch: (entity: Entity) => void
|
|
86
|
-
entityUncrouch: (entity: Entity) => void
|
|
87
|
-
entityEquip: (entity: Entity) => void
|
|
88
|
-
entitySleep: (entity: Entity) => void
|
|
89
|
-
entitySpawn: (entity: Entity) => void
|
|
90
|
-
itemDrop: (entity: Entity) => void
|
|
91
|
-
playerCollect: (collector: Entity, collected: Entity) => void
|
|
92
|
-
entityAttributes: (entity: Entity) => void
|
|
93
|
-
entityGone: (entity: Entity) => void
|
|
94
|
-
entityMoved: (entity: Entity) => void
|
|
95
|
-
entityDetach: (entity: Entity, vehicle: Entity) => void
|
|
96
|
-
entityAttach: (entity: Entity, vehicle: Entity) => void
|
|
97
|
-
entityUpdate: (entity: Entity) => void
|
|
98
|
-
entityEffect: (entity: Entity, effect: Effect) => void
|
|
99
|
-
entityEffectEnd: (entity: Entity, effect: Effect) => void
|
|
100
|
-
playerJoined: (player: Player) => void
|
|
101
|
-
playerUpdated: (player: Player) => void
|
|
102
|
-
playerLeft: (entity: Player) => void
|
|
103
|
-
blockUpdate: (oldBlock: Block | null, newBlock: Block) => void
|
|
104
|
-
'blockUpdate:(x, y, z)': (oldBlock: Block | null, newBlock: Block) => void
|
|
105
|
-
chunkColumnLoad: (entity: Vec3) => void
|
|
106
|
-
chunkColumnUnload: (entity: Vec3) => void
|
|
56
|
+
) => Promise<void> | void
|
|
57
|
+
actionBar: (jsonMsg: ChatMessage) => Promise<void> | void
|
|
58
|
+
error: (err: Error) => Promise<void> | void
|
|
59
|
+
message: (jsonMsg: ChatMessage, position: string) => Promise<void> | void
|
|
60
|
+
messagestr: (message: string, position: string, jsonMsg: ChatMessage) => Promise<void> | void
|
|
61
|
+
unmatchedMessage: (stringMsg: string, jsonMsg: ChatMessage) => Promise<void> | void
|
|
62
|
+
inject_allowed: () => Promise<void> | void
|
|
63
|
+
login: () => Promise<void> | void
|
|
64
|
+
spawn: () => Promise<void> | void
|
|
65
|
+
respawn: () => Promise<void> | void
|
|
66
|
+
game: () => Promise<void> | void
|
|
67
|
+
title: (text: string) => Promise<void> | void
|
|
68
|
+
rain: () => Promise<void> | void
|
|
69
|
+
time: () => Promise<void> | void
|
|
70
|
+
kicked: (reason: string, loggedIn: boolean) => Promise<void> | void
|
|
71
|
+
end: (reason: string) => Promise<void> | void
|
|
72
|
+
spawnReset: () => Promise<void> | void
|
|
73
|
+
death: () => Promise<void> | void
|
|
74
|
+
health: () => Promise<void> | void
|
|
75
|
+
breath: () => Promise<void> | void
|
|
76
|
+
entitySwingArm: (entity: Entity) => Promise<void> | void
|
|
77
|
+
entityHurt: (entity: Entity) => Promise<void> | void
|
|
78
|
+
entityDead: (entity: Entity) => Promise<void> | void
|
|
79
|
+
entityTaming: (entity: Entity) => Promise<void> | void
|
|
80
|
+
entityTamed: (entity: Entity) => Promise<void> | void
|
|
81
|
+
entityShakingOffWater: (entity: Entity) => Promise<void> | void
|
|
82
|
+
entityEatingGrass: (entity: Entity) => Promise<void> | void
|
|
83
|
+
entityWake: (entity: Entity) => Promise<void> | void
|
|
84
|
+
entityEat: (entity: Entity) => Promise<void> | void
|
|
85
|
+
entityCriticalEffect: (entity: Entity) => Promise<void> | void
|
|
86
|
+
entityMagicCriticalEffect: (entity: Entity) => Promise<void> | void
|
|
87
|
+
entityCrouch: (entity: Entity) => Promise<void> | void
|
|
88
|
+
entityUncrouch: (entity: Entity) => Promise<void> | void
|
|
89
|
+
entityEquip: (entity: Entity) => Promise<void> | void
|
|
90
|
+
entitySleep: (entity: Entity) => Promise<void> | void
|
|
91
|
+
entitySpawn: (entity: Entity) => Promise<void> | void
|
|
92
|
+
itemDrop: (entity: Entity) => Promise<void> | void
|
|
93
|
+
playerCollect: (collector: Entity, collected: Entity) => Promise<void> | void
|
|
94
|
+
entityAttributes: (entity: Entity) => Promise<void> | void
|
|
95
|
+
entityGone: (entity: Entity) => Promise<void> | void
|
|
96
|
+
entityMoved: (entity: Entity) => Promise<void> | void
|
|
97
|
+
entityDetach: (entity: Entity, vehicle: Entity) => Promise<void> | void
|
|
98
|
+
entityAttach: (entity: Entity, vehicle: Entity) => Promise<void> | void
|
|
99
|
+
entityUpdate: (entity: Entity) => Promise<void> | void
|
|
100
|
+
entityEffect: (entity: Entity, effect: Effect) => Promise<void> | void
|
|
101
|
+
entityEffectEnd: (entity: Entity, effect: Effect) => Promise<void> | void
|
|
102
|
+
playerJoined: (player: Player) => Promise<void> | void
|
|
103
|
+
playerUpdated: (player: Player) => Promise<void> | void
|
|
104
|
+
playerLeft: (entity: Player) => Promise<void> | void
|
|
105
|
+
blockUpdate: (oldBlock: Block | null, newBlock: Block) => Promise<void> | void
|
|
106
|
+
'blockUpdate:(x, y, z)': (oldBlock: Block | null, newBlock: Block) => Promise<void> | void
|
|
107
|
+
chunkColumnLoad: (entity: Vec3) => Promise<void> | void
|
|
108
|
+
chunkColumnUnload: (entity: Vec3) => Promise<void> | void
|
|
107
109
|
soundEffectHeard: (
|
|
108
110
|
soundName: string,
|
|
109
111
|
position: Vec3,
|
|
110
112
|
volume: number,
|
|
111
113
|
pitch: number
|
|
112
|
-
) => void
|
|
114
|
+
) => Promise<void> | void
|
|
113
115
|
hardcodedSoundEffectHeard: (
|
|
114
116
|
soundId: number,
|
|
115
117
|
soundCategory: number,
|
|
116
118
|
position: Vec3,
|
|
117
119
|
volume: number,
|
|
118
120
|
pitch: number
|
|
119
|
-
) => void
|
|
120
|
-
noteHeard: (block: Block, instrument: Instrument, pitch: number) => void
|
|
121
|
-
pistonMove: (block: Block, isPulling: number, direction: number) => void
|
|
122
|
-
chestLidMove: (block: Block, isOpen: number) => void
|
|
123
|
-
blockBreakProgressObserved: (block: Block, destroyStage: number) => void
|
|
124
|
-
blockBreakProgressEnd: (block: Block) => void
|
|
125
|
-
diggingCompleted: (block: Block) => void
|
|
126
|
-
diggingAborted: (block: Block) => void
|
|
127
|
-
move: () => void
|
|
128
|
-
forcedMove: () => void
|
|
129
|
-
mount: () => void
|
|
130
|
-
dismount: (vehicle: Entity) => void
|
|
131
|
-
windowOpen: (
|
|
132
|
-
windowClose: (
|
|
133
|
-
sleep: () => void
|
|
134
|
-
wake: () => void
|
|
135
|
-
experience: () => void
|
|
136
|
-
physicsTick: () => void
|
|
137
|
-
physicTick: () => void
|
|
138
|
-
scoreboardCreated: (scoreboard: ScoreBoard) => void
|
|
139
|
-
scoreboardDeleted: (scoreboard: ScoreBoard) => void
|
|
140
|
-
scoreboardTitleChanged: (scoreboard: ScoreBoard) => void
|
|
141
|
-
scoreUpdated: (scoreboard: ScoreBoard, item: number) => void
|
|
142
|
-
scoreRemoved: (scoreboard: ScoreBoard, item: number) => void
|
|
143
|
-
scoreboardPosition: (position: DisplaySlot, scoreboard: ScoreBoard) => void
|
|
144
|
-
teamCreated: (team: Team) => void
|
|
145
|
-
teamRemoved: (team: Team) => void
|
|
146
|
-
teamUpdated: (team: Team) => void
|
|
147
|
-
teamMemberAdded: (team: Team) => void
|
|
148
|
-
teamMemberRemoved: (team: Team) => void
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
resourcePack: (url: string, hash: string) => void
|
|
121
|
+
) => Promise<void> | void
|
|
122
|
+
noteHeard: (block: Block, instrument: Instrument, pitch: number) => Promise<void> | void
|
|
123
|
+
pistonMove: (block: Block, isPulling: number, direction: number) => Promise<void> | void
|
|
124
|
+
chestLidMove: (block: Block, isOpen: number) => Promise<void> | void
|
|
125
|
+
blockBreakProgressObserved: (block: Block, destroyStage: number) => Promise<void> | void
|
|
126
|
+
blockBreakProgressEnd: (block: Block) => Promise<void> | void
|
|
127
|
+
diggingCompleted: (block: Block) => Promise<void> | void
|
|
128
|
+
diggingAborted: (block: Block) => Promise<void> | void
|
|
129
|
+
move: () => Promise<void> | void
|
|
130
|
+
forcedMove: () => Promise<void> | void
|
|
131
|
+
mount: () => Promise<void> | void
|
|
132
|
+
dismount: (vehicle: Entity) => Promise<void> | void
|
|
133
|
+
windowOpen: (window: Window) => Promise<void> | void
|
|
134
|
+
windowClose: (window: Window) => Promise<void> | void
|
|
135
|
+
sleep: () => Promise<void> | void
|
|
136
|
+
wake: () => Promise<void> | void
|
|
137
|
+
experience: () => Promise<void> | void
|
|
138
|
+
physicsTick: () => Promise<void> | void
|
|
139
|
+
physicTick: () => Promise<void> | void
|
|
140
|
+
scoreboardCreated: (scoreboard: ScoreBoard) => Promise<void> | void
|
|
141
|
+
scoreboardDeleted: (scoreboard: ScoreBoard) => Promise<void> | void
|
|
142
|
+
scoreboardTitleChanged: (scoreboard: ScoreBoard) => Promise<void> | void
|
|
143
|
+
scoreUpdated: (scoreboard: ScoreBoard, item: number) => Promise<void> | void
|
|
144
|
+
scoreRemoved: (scoreboard: ScoreBoard, item: number) => Promise<void> | void
|
|
145
|
+
scoreboardPosition: (position: DisplaySlot, scoreboard: ScoreBoard) => Promise<void> | void
|
|
146
|
+
teamCreated: (team: Team) => Promise<void> | void
|
|
147
|
+
teamRemoved: (team: Team) => Promise<void> | void
|
|
148
|
+
teamUpdated: (team: Team) => Promise<void> | void
|
|
149
|
+
teamMemberAdded: (team: Team) => Promise<void> | void
|
|
150
|
+
teamMemberRemoved: (team: Team) => Promise<void> | void
|
|
151
|
+
bossBarDeleted: (bossBar: BossBar) => Promise<void> | void
|
|
152
|
+
bossBarUpdated: (bossBar: BossBar) => Promise<void> | void
|
|
153
|
+
resourcePack: (url: string, hash: string) => Promise<void> | void
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
export interface Bot extends TypedEmitter<BotEvents> {
|
|
@@ -193,13 +194,14 @@ export interface Bot extends TypedEmitter<BotEvents> {
|
|
|
193
194
|
|
|
194
195
|
supportFeature: (feature: string) => boolean
|
|
195
196
|
|
|
196
|
-
end: () => void
|
|
197
|
+
end: (reason?: string) => void
|
|
197
198
|
|
|
198
199
|
blockAt: (point: Vec3) => Block | null
|
|
199
200
|
|
|
200
201
|
blockInSight: (maxSteps: number, vectorLength: number) => Block | null
|
|
201
202
|
|
|
202
203
|
blockAtCursor: (maxDistance?: number, matcher?: Function) => Block | null
|
|
204
|
+
blockAtEntityCursor: (entity?: entity, maxDistance?: number, matcher?: Function) => Block | null
|
|
203
205
|
|
|
204
206
|
canSeeBlock: (block: Block) => boolean
|
|
205
207
|
|
|
@@ -257,6 +259,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
|
|
|
257
259
|
|
|
258
260
|
clearControlStates: () => void
|
|
259
261
|
|
|
262
|
+
getExplosionDamages: (targetEntity: Entity, position: Vec3, radius: number, rawDamages?: boolean) => number | null
|
|
263
|
+
|
|
260
264
|
lookAt: (point: Vec3, force?: boolean, callback?: () => void) => Promise<void>
|
|
261
265
|
|
|
262
266
|
look: (
|
|
@@ -339,11 +343,11 @@ export interface Bot extends TypedEmitter<BotEvents> {
|
|
|
339
343
|
callback?: (err?: Error) => void
|
|
340
344
|
) => Promise<void>
|
|
341
345
|
|
|
342
|
-
openChest: (chest: Block | Entity) => Promise<
|
|
346
|
+
openChest: (chest: Block | Entity) => Promise<Chest>
|
|
343
347
|
|
|
344
348
|
openFurnace: (furnace: Block) => Promise<Furnace>
|
|
345
349
|
|
|
346
|
-
openDispenser: (dispenser: Block) => Promise<
|
|
350
|
+
openDispenser: (dispenser: Block) => Promise<Dispenser>
|
|
347
351
|
|
|
348
352
|
openEnchantmentTable: (enchantmentTable: Block) => Promise<EnchantmentTable>
|
|
349
353
|
|
|
@@ -351,7 +355,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
|
|
|
351
355
|
|
|
352
356
|
openVillager: (
|
|
353
357
|
villager: Entity
|
|
354
|
-
) => Villager
|
|
358
|
+
) => Promise<Villager>
|
|
355
359
|
|
|
356
360
|
trade: (
|
|
357
361
|
villagerInstance: Villager,
|
|
@@ -612,8 +616,6 @@ interface ConditionalStorageEvents extends StorageEvents {
|
|
|
612
616
|
ready: () => void
|
|
613
617
|
}
|
|
614
618
|
|
|
615
|
-
type ContainerWindow = Anvil | Furnace | Chest | EnchantmentTable | Villager
|
|
616
|
-
|
|
617
619
|
export class Chest extends (EventEmitter as new () => TypedEmitter<StorageEvents>) {
|
|
618
620
|
window: object | /* prismarine-windows ChestWindow */ null
|
|
619
621
|
|
|
@@ -831,7 +833,7 @@ export class BossBar {
|
|
|
831
833
|
);
|
|
832
834
|
}
|
|
833
835
|
|
|
834
|
-
export
|
|
835
|
-
export
|
|
836
|
+
export let supportedVersions: string[]
|
|
837
|
+
export let testedVersions: string[]
|
|
836
838
|
|
|
837
839
|
export function supportFeature (feature: string, version: string): boolean
|
package/lib/conversions.js
CHANGED
package/lib/loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const mc = require('minecraft-protocol')
|
|
2
|
-
const EventEmitter = require('events')
|
|
2
|
+
const { EventEmitter } = require('events')
|
|
3
3
|
const pluginLoader = require('./plugin_loader')
|
|
4
4
|
const supportFeature = require('./supportFeature')
|
|
5
5
|
const plugins = {
|
|
@@ -70,7 +70,7 @@ function createBot (options = {}) {
|
|
|
70
70
|
options.brand = options.brand ?? 'vanilla'
|
|
71
71
|
const bot = new EventEmitter()
|
|
72
72
|
bot._client = options.client
|
|
73
|
-
bot.end = () => bot._client.end()
|
|
73
|
+
bot.end = (reason) => bot._client.end(reason)
|
|
74
74
|
if (options.logErrors) {
|
|
75
75
|
bot.on('error', err => {
|
|
76
76
|
if (!options.hideErrors) {
|
|
@@ -99,8 +99,8 @@ function createBot (options = {}) {
|
|
|
99
99
|
bot._client.on('error', (err) => {
|
|
100
100
|
bot.emit('error', err)
|
|
101
101
|
})
|
|
102
|
-
bot._client.on('end', () => {
|
|
103
|
-
bot.emit('end')
|
|
102
|
+
bot._client.on('end', (reason) => {
|
|
103
|
+
bot.emit('end', reason)
|
|
104
104
|
})
|
|
105
105
|
if (!bot._client.wait_connect) next()
|
|
106
106
|
else bot._client.once('connect_allowed', next)
|
package/lib/plugins/bed.js
CHANGED
package/lib/plugins/blocks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const Vec3 = require('vec3')
|
|
1
|
+
const { Vec3 } = require('vec3')
|
|
2
2
|
const assert = require('assert')
|
|
3
3
|
const Painting = require('../painting')
|
|
4
4
|
const { onceWithCleanup, callbackify } = require('../promise_utils')
|
|
@@ -476,6 +476,7 @@ function inject (bot, { version, storageBuilder }) {
|
|
|
476
476
|
// if we get a respawn packet and the dimension is changed,
|
|
477
477
|
// unload all chunks from memory.
|
|
478
478
|
let dimension
|
|
479
|
+
let worldName
|
|
479
480
|
function dimensionToFolderName (dimension) {
|
|
480
481
|
if (bot.supportFeature('dimensionIsAnInt')) {
|
|
481
482
|
return dimensionNames[dimension]
|
|
@@ -511,13 +512,26 @@ function inject (bot, { version, storageBuilder }) {
|
|
|
511
512
|
}
|
|
512
513
|
|
|
513
514
|
bot._client.on('login', (packet) => {
|
|
514
|
-
|
|
515
|
+
if (bot.supportFeature('dimensionIsAnInt')) {
|
|
516
|
+
dimension = packet.dimension
|
|
517
|
+
} else {
|
|
518
|
+
dimension = packet.dimension
|
|
519
|
+
worldName = packet.worldName
|
|
520
|
+
}
|
|
515
521
|
switchWorld()
|
|
516
522
|
})
|
|
517
523
|
|
|
518
524
|
bot._client.on('respawn', (packet) => {
|
|
519
|
-
if (
|
|
520
|
-
|
|
525
|
+
if (bot.supportFeature('dimensionIsAnInt')) { // <=1.15.2
|
|
526
|
+
if (dimension === packet.dimension) return
|
|
527
|
+
dimension = packet.dimension
|
|
528
|
+
} else { // >= 1.15.2
|
|
529
|
+
if (dimension === packet.dimension) return
|
|
530
|
+
if (worldName === packet.worldName && packet.copyMetadata === true) return // don't unload chunks if in same world and metaData is true
|
|
531
|
+
// Metadata is true when switching dimensions however, then the world name is different
|
|
532
|
+
dimension = packet.dimension
|
|
533
|
+
worldName = packet.worldName
|
|
534
|
+
}
|
|
521
535
|
switchWorld()
|
|
522
536
|
})
|
|
523
537
|
|
package/lib/plugins/chat.js
CHANGED
|
@@ -4,6 +4,7 @@ module.exports = inject
|
|
|
4
4
|
|
|
5
5
|
function inject (bot, options) {
|
|
6
6
|
const CHAT_LENGTH_LIMIT = options.chatLengthLimit ?? (bot.supportFeature('lessCharsInChat') ? 100 : 256)
|
|
7
|
+
const defaultChatPatterns = options.defaultChatPatterns ?? true
|
|
7
8
|
|
|
8
9
|
const ChatMessage = require('prismarine-chat')(bot.version)
|
|
9
10
|
// chat.pattern.type will emit an event for bot.on() of the same type, eg chatType = whisper will trigger bot.on('whisper')
|
|
@@ -171,6 +172,7 @@ function inject (bot, options) {
|
|
|
171
172
|
bot.tabComplete = callbackify(tabComplete)
|
|
172
173
|
|
|
173
174
|
function addDefaultPatterns () {
|
|
175
|
+
if (!defaultChatPatterns) return
|
|
174
176
|
const USERNAME_REGEX = '(?:\\(.+\\)|\\[.+\\]|.)*?(\\w+)'
|
|
175
177
|
bot.addChatPattern('whisper', new RegExp(`^${USERNAME_REGEX} whispers(?: to you)?:? (.*)$`), { deprecated: true })
|
|
176
178
|
bot.addChatPattern('whisper', new RegExp(`^\\[${USERNAME_REGEX} -> \\w+\\s?\\] (.*)$`), { deprecated: true })
|
package/lib/plugins/creative.js
CHANGED
package/lib/plugins/digging.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const nbt = require('prismarine-nbt')
|
|
2
1
|
const { performance } = require('perf_hooks')
|
|
3
2
|
const { createDoneTask, createTask } = require('../promise_utils')
|
|
4
3
|
const BlockFaces = require('prismarine-world').iterators.BlockFace
|
|
@@ -176,20 +175,6 @@ function inject (bot) {
|
|
|
176
175
|
return block && block.diggable && block.position.offset(0.5, 0.5, 0.5).distanceTo(bot.entity.position.offset(0, 1.65, 0)) <= 5.1
|
|
177
176
|
}
|
|
178
177
|
|
|
179
|
-
function getItemEnchantments (item) {
|
|
180
|
-
if (item.nbt) {
|
|
181
|
-
const simplifiedNbt = nbt.simplify(item.nbt)
|
|
182
|
-
|
|
183
|
-
if (simplifiedNbt.Enchantments) {
|
|
184
|
-
return simplifiedNbt.Enchantments
|
|
185
|
-
}
|
|
186
|
-
if (simplifiedNbt.ench) {
|
|
187
|
-
return simplifiedNbt.ench
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return []
|
|
191
|
-
}
|
|
192
|
-
|
|
193
178
|
function digTime (block) {
|
|
194
179
|
let type = null
|
|
195
180
|
let enchantments = []
|
|
@@ -198,14 +183,14 @@ function inject (bot) {
|
|
|
198
183
|
const currentlyHeldItem = bot.heldItem
|
|
199
184
|
if (currentlyHeldItem) {
|
|
200
185
|
type = currentlyHeldItem.type
|
|
201
|
-
enchantments =
|
|
186
|
+
enchantments = currentlyHeldItem.enchants
|
|
202
187
|
}
|
|
203
188
|
|
|
204
189
|
// Append helmet enchantments (because Aqua Affinity actually affects dig speed)
|
|
205
190
|
const headEquipmentSlot = bot.getEquipmentDestSlot('head')
|
|
206
191
|
const headEquippedItem = bot.inventory.slots[headEquipmentSlot]
|
|
207
192
|
if (headEquippedItem) {
|
|
208
|
-
const helmetEnchantments =
|
|
193
|
+
const helmetEnchantments = headEquippedItem.enchants
|
|
209
194
|
enchantments = enchantments.concat(helmetEnchantments)
|
|
210
195
|
}
|
|
211
196
|
|
package/lib/plugins/entities.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const Vec3 = require('vec3')
|
|
1
|
+
const { Vec3 } = require('vec3')
|
|
2
2
|
const Entity = require('prismarine-entity')
|
|
3
3
|
const conv = require('../conversions')
|
|
4
4
|
const NAMED_ENTITY_HEIGHT = 1.62
|
|
@@ -89,7 +89,11 @@ function inject (bot, { version }) {
|
|
|
89
89
|
return best
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
// Reset list of players and entities on login
|
|
93
|
+
bot._client.on('login', (packet) => {
|
|
94
|
+
bot.players = {}
|
|
95
|
+
bot.uuidToUsername = {}
|
|
96
|
+
bot.entities = {}
|
|
93
97
|
// login
|
|
94
98
|
bot.entity = fetchEntity(packet.entityId)
|
|
95
99
|
bot.username = bot._client.username
|
|
@@ -483,15 +487,15 @@ function inject (bot, { version }) {
|
|
|
483
487
|
} else if (packet.action === 3 && item.displayName) {
|
|
484
488
|
player.displayName = new ChatMessage(JSON.parse(item.displayName))
|
|
485
489
|
} else if (packet.action === 4) {
|
|
486
|
-
if (player.entity === bot.entity)
|
|
490
|
+
if (player.entity === bot.entity) continue
|
|
487
491
|
|
|
488
492
|
player.entity = null
|
|
489
493
|
delete bot.players[player.username]
|
|
490
494
|
delete bot.uuidToUsername[item.UUID]
|
|
491
495
|
bot.emit('playerLeft', player)
|
|
492
|
-
|
|
496
|
+
continue
|
|
493
497
|
} else {
|
|
494
|
-
|
|
498
|
+
continue
|
|
495
499
|
}
|
|
496
500
|
|
|
497
501
|
bot.emit('playerUpdated', player)
|
|
@@ -531,8 +535,8 @@ function inject (bot, { version }) {
|
|
|
531
535
|
bot.useOn = useOn
|
|
532
536
|
bot.moveVehicle = moveVehicle
|
|
533
537
|
|
|
534
|
-
function swingArm (arm = '
|
|
535
|
-
const hand = arm === '
|
|
538
|
+
function swingArm (arm = 'right', showHand = true) {
|
|
539
|
+
const hand = arm === 'right' ? 0 : 1
|
|
536
540
|
const packet = {}
|
|
537
541
|
if (showHand) packet.hand = hand
|
|
538
542
|
bot._client.write('arm_animation', packet)
|
|
@@ -544,11 +548,11 @@ function inject (bot, { version }) {
|
|
|
544
548
|
}
|
|
545
549
|
|
|
546
550
|
function attack (target, swing = true) {
|
|
547
|
-
|
|
548
|
-
|
|
551
|
+
// arm animation comes before the use_entity packet
|
|
549
552
|
if (swing) {
|
|
550
553
|
swingArm()
|
|
551
554
|
}
|
|
555
|
+
useEntity(target, 1)
|
|
552
556
|
}
|
|
553
557
|
|
|
554
558
|
function mount (target) {
|
package/lib/plugins/explosion.js
CHANGED
|
@@ -77,7 +77,7 @@ function inject (bot) {
|
|
|
77
77
|
// The following modifiers are constant for the input targetEntity and doesnt depend
|
|
78
78
|
// on the source position, so if the goal is to compare between positions they can be
|
|
79
79
|
// ignored to save computations
|
|
80
|
-
if (!rawDamages) {
|
|
80
|
+
if (!rawDamages && targetEntity.attributes['generic.armor']) {
|
|
81
81
|
const armor = getAttributeValue(targetEntity.attributes['generic.armor'])
|
|
82
82
|
const armorToughness = getAttributeValue(targetEntity.attributes[armorThoughnessKey])
|
|
83
83
|
damages = getDamageAfterAbsorb(damages, armor, armorToughness)
|
|
@@ -85,6 +85,8 @@ function inject (bot) {
|
|
|
85
85
|
// TODO: protection enchantment and resistance effects
|
|
86
86
|
|
|
87
87
|
if (targetEntity.type === 'player') damages *= difficultyValues[bot.game.difficulty] * 0.5
|
|
88
|
+
} else if (!rawDamages && !targetEntity.attributes['generic.armor']) {
|
|
89
|
+
return null
|
|
88
90
|
}
|
|
89
91
|
return Math.floor(damages)
|
|
90
92
|
}
|
package/lib/plugins/game.js
CHANGED
|
@@ -90,4 +90,11 @@ function inject (bot, options) {
|
|
|
90
90
|
bot._client.on(brandChannel, (serverBrand) => {
|
|
91
91
|
bot.game.serverBrand = serverBrand
|
|
92
92
|
})
|
|
93
|
+
|
|
94
|
+
// mimic the vanilla 1.17 client to prevent anticheat kicks
|
|
95
|
+
bot._client.on('ping', (data) => {
|
|
96
|
+
bot._client.write('pong', {
|
|
97
|
+
id: data.id
|
|
98
|
+
})
|
|
99
|
+
})
|
|
93
100
|
}
|