mineflayer 3.12.0 → 3.14.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mineflayer
2
2
 
3
- [![NPM version](https://badge.fury.io/js/mineflayer.svg)](http://badge.fury.io/js/mineflayer)
3
+ [![NPM version](https://badge.fury.io/js/mineflayer.svg)](https://www.npmjs.com/package/mineflayer)
4
4
  [![Build Status](https://github.com/PrismarineJS/mineflayer/workflows/CI/badge.svg)](https://github.com/PrismarineJS/mineflayer/actions?query=workflow%3A%22CI%22)
5
5
  [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
6
6
  [![Issue Hunt](https://github.com/BoostIO/issuehunt-materials/blob/master/v1/issuehunt-shield-v1.svg)](https://issuehunt.io/r/PrismarineJS/mineflayer)
package/docs/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mineflayer
2
2
 
3
- [![NPM version](https://badge.fury.io/js/mineflayer.svg)](http://badge.fury.io/js/mineflayer)
3
+ [![NPM version](https://badge.fury.io/js/mineflayer.svg)](https://www.npmjs.com/package/mineflayer)
4
4
  [![Build Status](https://github.com/PrismarineJS/mineflayer/workflows/CI/badge.svg)](https://github.com/PrismarineJS/mineflayer/actions?query=workflow%3A%22CI%22)
5
5
  [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
6
6
  [![Issue Hunt](https://github.com/BoostIO/issuehunt-materials/blob/master/v1/issuehunt-shield-v1.svg)](https://issuehunt.io/r/PrismarineJS/mineflayer)
package/docs/history.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 3.14.1
2
+
3
+ * Fix arm_animation and use_entity (@amorashi)
4
+
5
+ ## 3.14.0
6
+
7
+ * Make prismarine-entity versioned (@u9g)
8
+ * fix(typings): Added OpenContainer (@SaubereSache)
9
+
10
+ ## 3.13.1
11
+
12
+ * Fix bug with force lastSentPitch in bot.look (@KadaverBrutalo10)
13
+ * Fix typo harming type safety (@Eagle-Anne)
14
+
15
+ ## 3.13.0
16
+
17
+ * compute scoreboard displayName dynamically (@U9G)
18
+ * SkinsRestorer fix (@U5B)
19
+ * Fix bot not swinging arm on block place (@IceTank)
20
+
1
21
  ## 3.12.0
2
22
 
3
23
  * Bypass anticheats that detect sensitivity (@mat-1)
@@ -0,0 +1,45 @@
1
+ /*
2
+ *
3
+ * A bot that attacks the player that sends a message or the nearest entity (excluding players)
4
+ *
5
+ */
6
+ const mineflayer = require('mineflayer')
7
+
8
+ if (process.argv.length < 4 || process.argv.length > 6) {
9
+ console.log('Usage : node attack.js <host> <port> [<name>] [<password>]')
10
+ process.exit(1)
11
+ }
12
+
13
+ const bot = mineflayer.createBot({
14
+ host: process.argv[2],
15
+ port: parseInt(process.argv[3]),
16
+ username: process.argv[4] ? process.argv[4] : 'attack',
17
+ password: process.argv[5]
18
+ })
19
+
20
+ bot.on('spawn', () => {
21
+ bot.on('chat', (username, message) => {
22
+ if (message === 'attack me') attackPlayer(username)
23
+ else if (message === 'attack') attackEntity()
24
+ })
25
+ })
26
+
27
+ function attackPlayer (username) {
28
+ const player = bot.players[username]
29
+ if (!player || !player.entity) {
30
+ bot.chat('I can\'t see you')
31
+ } else {
32
+ bot.chat(`Attacking ${player.username}`)
33
+ bot.attack(player.entity)
34
+ }
35
+ }
36
+
37
+ function attackEntity () {
38
+ const entity = bot.nearestEntity()
39
+ if (!entity) {
40
+ bot.chat('No nearby entities')
41
+ } else {
42
+ bot.chat(`Attacking ${entity.name ?? entity.username}`)
43
+ bot.attack(entity)
44
+ }
45
+ }
package/index.d.ts CHANGED
@@ -201,7 +201,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
201
201
  blockInSight: (maxSteps: number, vectorLength: number) => Block | null
202
202
 
203
203
  blockAtCursor: (maxDistance?: number, matcher?: Function) => Block | null
204
- blockAtEntityCursor: (entity?: entity, maxDistance?: number, matcher?: Function) => Block | null
204
+ blockAtEntityCursor: (entity?: Entity, maxDistance?: number, matcher?: Function) => Block | null
205
205
 
206
206
  canSeeBlock: (block: Block) => boolean
207
207
 
@@ -343,6 +343,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
343
343
  callback?: (err?: Error) => void
344
344
  ) => Promise<void>
345
345
 
346
+ openContainer: (chest: Block | Entity) => Promise<Chest | Furnace | Dispenser>
347
+
346
348
  openChest: (chest: Block | Entity) => Promise<Chest>
347
349
 
348
350
  openFurnace: (furnace: Block) => Promise<Furnace>
package/lib/features.json CHANGED
@@ -318,5 +318,10 @@
318
318
  "name": "setSlotAsTransaction",
319
319
  "description": "use setslot as transaction instead of just hoping it'll work",
320
320
  "versions": ["1.17", "1.17.1"]
321
+ },
322
+ {
323
+ "name": "armAnimationBeforeUse",
324
+ "description": "arm animation packet sent before use entity packet",
325
+ "versions": ["1.8", "1.8.9"]
321
326
  }
322
327
  ]
@@ -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
- dimension = packet.dimension
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 (dimension === packet.dimension) return
520
- dimension = packet.dimension
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
 
@@ -1,5 +1,4 @@
1
1
  const { Vec3 } = require('vec3')
2
- const Entity = require('prismarine-entity')
3
2
  const conv = require('../conversions')
4
3
  const NAMED_ENTITY_HEIGHT = 1.62
5
4
  const NAMED_ENTITY_WIDTH = 0.6
@@ -26,6 +25,7 @@ const entityStatusEvents = {
26
25
  }
27
26
 
28
27
  function inject (bot, { version }) {
28
+ const Entity = require('prismarine-entity')(version)
29
29
  const objects = require('minecraft-data')(version).objects
30
30
  const mobs = require('minecraft-data')(version).mobs
31
31
  const entitiesArray = require('minecraft-data')(version).entitiesArray
@@ -89,7 +89,11 @@ function inject (bot, { version }) {
89
89
  return best
90
90
  }
91
91
 
92
- bot._client.once('login', (packet) => {
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
@@ -544,11 +548,18 @@ function inject (bot, { version }) {
544
548
  }
545
549
 
546
550
  function attack (target, swing = true) {
547
- // arm animation comes before the use_entity packet
548
- if (swing) {
549
- swingArm()
551
+ // arm animation comes before the use_entity packet on 1.8
552
+ if (bot.supportFeature('armAnimationBeforeUse')) {
553
+ if (swing) {
554
+ swingArm()
555
+ }
556
+ useEntity(target, 1)
557
+ } else {
558
+ useEntity(target, 1)
559
+ if (swing) {
560
+ swingArm()
561
+ }
550
562
  }
551
- useEntity(target, 1)
552
563
  }
553
564
 
554
565
  function mount (target) {
@@ -7,7 +7,7 @@ function inject (bot, { version }) {
7
7
  *
8
8
  * @param {import('prismarine-block').Block} referenceBlock
9
9
  * @param {import('vec3').Vec3} faceVector
10
- * @param {{half?: 'top'|'bottom', delta?: import('vec3').Vec3, forceLook?: boolean | 'ignore', offhand?: boolean}} options
10
+ * @param {{half?: 'top'|'bottom', delta?: import('vec3').Vec3, forceLook?: boolean | 'ignore', offhand?: boolean, swingArm?: 'right' | 'left', showHand?: boolean}} options
11
11
  */
12
12
  async function _genericPlace (referenceBlock, faceVector, options) {
13
13
  let handToPlaceWith = 0
@@ -39,6 +39,10 @@ function inject (bot, { version }) {
39
39
  // TODO: tell the server that we are sneaking while doing this
40
40
  const pos = referenceBlock.position
41
41
 
42
+ if (options.swingArm) {
43
+ bot.swingArm(options.swingArm, options.showHand)
44
+ }
45
+
42
46
  if (bot.supportFeature('blockPlaceHasHeldItem')) {
43
47
  const packet = {
44
48
  location: pos,
@@ -240,6 +240,7 @@ function inject (bot, { physicsEnabled }) {
240
240
 
241
241
  if (force) {
242
242
  lastSentYaw = yaw
243
+ lastSentPitch = pitch
243
244
  return
244
245
  }
245
246
 
@@ -21,7 +21,7 @@ function inject (bot) {
21
21
  }
22
22
 
23
23
  async function placeBlock (referenceBlock, faceVector) {
24
- await placeBlockWithOptions(referenceBlock, faceVector, {})
24
+ await placeBlockWithOptions(referenceBlock, faceVector, { swingArm: 'right' })
25
25
  }
26
26
 
27
27
  bot.placeBlock = callbackify(placeBlock)
@@ -5,6 +5,12 @@ module.exports = inject
5
5
  function inject (bot, { version }) {
6
6
  const Item = require('prismarine-item')(version)
7
7
 
8
+ /**
9
+ *
10
+ * @param {import('prismarine-block').Block} referenceBlock
11
+ * @param {import('vec3').Vec3} faceVector
12
+ * @param {{forceLook?: boolean | 'ignore', offhand?: boolean, swingArm?: 'right' | 'left', showHand?: boolean}} options
13
+ */
8
14
  async function placeEntityWithOptions (referenceBlock, faceVector, options) {
9
15
  if (!bot.heldItem) throw new Error('must be holding an item to place an entity')
10
16
 
@@ -20,14 +26,14 @@ function inject (bot, { version }) {
20
26
  name = bot.heldItem.spawnEggMobName
21
27
  }
22
28
 
23
- const pos = await bot._genericPlace(referenceBlock, faceVector, options)
24
-
25
29
  if (type === 'spawn_egg') {
26
- bot.swingArm(undefined, false)
27
- } else {
28
- bot.swingArm()
30
+ options.showHand = false
29
31
  }
30
32
 
33
+ if (!options.swingArm) options.swingArm = options.offhand ? 'left' : 'right'
34
+
35
+ const pos = await bot._genericPlace(referenceBlock, faceVector, options)
36
+
31
37
  if (type === 'boat') {
32
38
  if (bot.supportFeature('useItemWithOwnPacket')) {
33
39
  bot._client.write('use_item', {
@@ -1,9 +1,7 @@
1
- const ScoreBoard = require('../scoreboard')
2
-
3
1
  module.exports = inject
4
2
 
5
3
  function inject (bot) {
6
- const ChatMessage = require('prismarine-chat')(bot.version)
4
+ const ScoreBoard = require('../scoreboard')(bot)
7
5
  const scoreboards = {}
8
6
 
9
7
  bot._client.on('scoreboard_objective', (packet) => {
@@ -29,12 +27,7 @@ function inject (bot) {
29
27
  bot._client.on('scoreboard_score', (packet) => {
30
28
  const scoreboard = scoreboards[packet.scoreName]
31
29
  if (scoreboard !== undefined && packet.action === 0) {
32
- const { itemName, value } = packet
33
- let displayName = new ChatMessage(itemName)
34
- if (itemName in bot.teamMap) {
35
- displayName = bot.teamMap[itemName].displayName(itemName)
36
- }
37
- const updated = scoreboard.add(itemName, value, displayName)
30
+ const updated = scoreboard.add(packet.itemName, packet.value)
38
31
  bot.emit('scoreUpdated', scoreboard, updated)
39
32
  }
40
33
 
package/lib/scoreboard.js CHANGED
@@ -4,49 +4,62 @@ const sortItems = (a, b) => {
4
4
  return 1
5
5
  }
6
6
 
7
- class ScoreBoard {
8
- constructor (packet) {
9
- this.name = packet.name
10
- this.setTitle(packet.displayText)
11
- this.itemsMap = {}
12
- }
7
+ module.exports = (bot) => {
8
+ const ChatMessage = require('prismarine-chat')(bot.version)
13
9
 
14
- setTitle (title) {
15
- try {
16
- this.title = JSON.parse(title).text // version>1.13
17
- } catch {
18
- this.title = title
10
+ class ScoreBoard {
11
+ constructor (packet) {
12
+ this.name = packet.name
13
+ this.setTitle(packet.displayText)
14
+ this.itemsMap = {}
19
15
  }
20
- }
21
16
 
22
- add (name, value, displayName) {
23
- this.itemsMap[name] = { name, value, displayName }
24
- return this.itemsMap[name]
25
- }
17
+ setTitle (title) {
18
+ try {
19
+ this.title = JSON.parse(title).text // version>1.13
20
+ } catch {
21
+ this.title = title
22
+ }
23
+ }
26
24
 
27
- remove (name) {
28
- const removed = this.itemsMap[name]
29
- delete this.itemsMap[name]
30
- return removed
31
- }
25
+ add (name, value) {
26
+ this.itemsMap[name] = { name, value }
27
+ this.itemsMap[name] = {
28
+ name,
29
+ value,
30
+ get displayName () {
31
+ if (name in bot.teamMap) {
32
+ return bot.teamMap[name].displayName(name)
33
+ }
34
+ return new ChatMessage(name)
35
+ }
36
+ }
37
+ return this.itemsMap[name]
38
+ }
32
39
 
33
- get items () {
34
- return Object.values(this.itemsMap).sort(sortItems)
40
+ remove (name) {
41
+ const removed = this.itemsMap[name]
42
+ delete this.itemsMap[name]
43
+ return removed
44
+ }
45
+
46
+ get items () {
47
+ return Object.values(this.itemsMap).sort(sortItems)
48
+ }
35
49
  }
36
- }
37
50
 
38
- ScoreBoard.positions = {
39
- get list () {
40
- return this[0]
41
- },
51
+ ScoreBoard.positions = {
52
+ get list () {
53
+ return this[0]
54
+ },
42
55
 
43
- get sidebar () {
44
- return this[1]
45
- },
56
+ get sidebar () {
57
+ return this[1]
58
+ },
46
59
 
47
- get belowName () {
48
- return this[2]
60
+ get belowName () {
61
+ return this[2]
62
+ }
49
63
  }
64
+ return ScoreBoard
50
65
  }
51
-
52
- module.exports = ScoreBoard
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "3.12.0",
3
+ "version": "3.14.1",
4
4
  "description": "create minecraft bots with a stable, high level API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "prismarine-block": "^1.10.3",
28
28
  "prismarine-chat": "^1.3.3",
29
29
  "prismarine-chunk": "^1.26.0",
30
- "prismarine-entity": "^1.2.0",
30
+ "prismarine-entity": "^2.0.0",
31
31
  "prismarine-item": "^1.11.0",
32
32
  "prismarine-nbt": "^2.0.0",
33
33
  "prismarine-physics": "^1.3.1",