mineflayer 4.25.0 → 4.26.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.
@@ -12,10 +12,10 @@ jobs:
12
12
 
13
13
  steps:
14
14
  - uses: actions/checkout@v2
15
- - name: Use Node.js 18.x
15
+ - name: Use Node.js 22.x
16
16
  uses: actions/setup-node@v1.4.4
17
17
  with:
18
- node-version: 18.x
18
+ node-version: 22.x
19
19
  - run: npm i && npm run lint
20
20
 
21
21
  PrepareSupportedVersions:
@@ -25,10 +25,10 @@ jobs:
25
25
 
26
26
  steps:
27
27
  - uses: actions/checkout@v2
28
- - name: Use Node.js 18.x
28
+ - name: Use Node.js 22.x
29
29
  uses: actions/setup-node@v1.4.4
30
30
  with:
31
- node-version: 18.x
31
+ node-version: 22.x
32
32
  - id: set-matrix
33
33
  run: |
34
34
  node -e "
@@ -45,10 +45,10 @@ jobs:
45
45
 
46
46
  steps:
47
47
  - uses: actions/checkout@v2
48
- - name: Use Node.js 18.x
48
+ - name: Use Node.js 22.x
49
49
  uses: actions/setup-node@v1.4.4
50
50
  with:
51
- node-version: 18.x
51
+ node-version: 22.x
52
52
  - name: Setup Java JDK
53
53
  uses: actions/setup-java@v1.4.3
54
54
  with:
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Set up Node.js
14
14
  uses: actions/setup-node@master
15
15
  with:
16
- node-version: 18.0.0
16
+ node-version: 22.0.0
17
17
  - id: publish
18
18
  uses: JS-DevTools/npm-publish@v1
19
19
  with:
package/docs/history.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 4.26.0
2
+ * [Use node 22 (#3570)](https://github.com/PrismarineJS/mineflayer/commit/dbff9314418d30df203c32fe83f2a1b56653d0a6) (thanks @rom1504)
3
+ * [Fix infinity setTimeout by throwing error (#3561)](https://github.com/PrismarineJS/mineflayer/commit/69539494c88c2ca718330142839a35414ecd3bda) (thanks @BBpezsgo)
4
+ * [Prevent TypeError when removing event lPrevent TypeError when removing event listeners in switchWorld (BunJS issue maybe)isteners in switchWorld (#3544)](https://github.com/PrismarineJS/mineflayer/commit/e974e703a875d16f5e36d35574bf334a20c76b1b) (thanks @0x15d3v2)
5
+ * [Mounting for other entities and fix bot not dismounting when the vehicle is gone (#3384)](https://github.com/PrismarineJS/mineflayer/commit/08b7317b57ca5c2f1a6ddd116bd0c74c2e10c20c) (thanks @qwqtoday)
6
+
1
7
  ## 4.25.0
2
8
  * [1.21.4 (#3546)](https://github.com/PrismarineJS/mineflayer/commit/8bbf5669f5ff3ea8a708633e51b47c312dc7a26b) (thanks @extremeheat)
3
9
 
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  if (typeof process !== 'undefined' && !process.browser && process.platform !== 'browser' && parseInt(process.versions.node.split('.')[0]) < 18) {
2
2
  console.error('Your node version is currently', process.versions.node)
3
- console.error('Please update it to a version >= 18.x.x from https://nodejs.org/')
3
+ console.error('Please update it to a version >= 22.x.x from https://nodejs.org/')
4
4
  process.exit(1)
5
5
  }
6
6
 
@@ -511,7 +511,7 @@ function inject (bot, { version, storageBuilder, hideErrors }) {
511
511
  }
512
512
 
513
513
  for (const [name, listener] of Object.entries(bot._events)) {
514
- if (name.startsWith('blockUpdate:')) {
514
+ if (name.startsWith('blockUpdate:') && typeof listener === 'function') {
515
515
  bot.emit(name, null, null)
516
516
  bot.off(name, listener)
517
517
  }
@@ -24,6 +24,11 @@ function inject (bot) {
24
24
  digFace = 'auto'
25
25
  }
26
26
 
27
+ const waitTime = bot.digTime(block)
28
+ if (waitTime === Infinity) {
29
+ throw new Error(`dig time for ${block?.name ?? block} is Infinity`)
30
+ }
31
+
27
32
  bot.targetDigFace = 1 // Default (top)
28
33
 
29
34
  if (forceLook !== 'ignore') {
@@ -127,7 +132,6 @@ function inject (bot) {
127
132
  location: block.position,
128
133
  face: bot.targetDigFace // default face is 1 (top)
129
134
  })
130
- const waitTime = bot.digTime(block)
131
135
  waitTimeout = setTimeout(finishDigging, waitTime)
132
136
  bot.targetDigBlock = block
133
137
  bot.swingArm()
@@ -803,26 +803,73 @@ function inject (bot) {
803
803
 
804
804
  // attaching to a vehicle
805
805
  bot._client.on('attach_entity', (packet) => {
806
- if (packet.entityId !== bot.entity.id) return
807
- const vehicle = bot.vehicle
808
- if (packet.vehicleId === -1) {
809
- bot.vehicle = null
810
- bot.emit('dismount', vehicle)
811
- } else {
812
- bot.vehicle = bot.entities[packet.vehicleId]
813
- bot.emit('mount')
806
+ const passenger = fetchEntity(packet.entityId)
807
+ const vehicle = packet.vehicleId === -1 ? null : fetchEntity(packet.vehicleId)
808
+
809
+ const originalVehicle = passenger.vehicle
810
+ if (originalVehicle !== null) {
811
+ const index = originalVehicle.passengers.indexOf(passenger)
812
+ originalVehicle.passengers = originalVehicle.passengers.splice(index, 1)
813
+ }
814
+ passenger.vehicle = vehicle
815
+ vehicle.passengers.push(passenger)
816
+
817
+ if (packet.entityId === bot.entity.id) {
818
+ const vehicle = bot.vehicle
819
+ if (packet.vehicleId === -1) {
820
+ bot.vehicle = null
821
+ bot.emit('dismount', vehicle)
822
+ } else {
823
+ bot.vehicle = bot.entities[packet.vehicleId]
824
+ bot.emit('mount')
825
+ }
814
826
  }
815
827
  })
816
828
 
817
829
  bot._client.on('set_passengers', ({ entityId, passengers }) => {
818
- if (passengers[0] !== bot.entity.id) return
819
- const vehicle = bot.vehicle
820
- if (entityId === -1) {
830
+ const passengerEntities = passengers.map((passengerId) => fetchEntity(passengerId))
831
+ const vehicle = entityId === -1 ? null : bot.entities[entityId]
832
+
833
+ for (const passengerEntity of passengerEntities) {
834
+ const originalVehicle = passengerEntity.vehicle
835
+ if (originalVehicle !== null) {
836
+ const index = originalVehicle.passengers.indexOf(passengerEntity)
837
+ originalVehicle.passengers = originalVehicle.passengers.splice(index, 1)
838
+ }
839
+ passengerEntity.vehicle = vehicle
840
+ if (vehicle !== null) {
841
+ vehicle.passengers.push(passengerEntity)
842
+ }
843
+ }
844
+
845
+ if (passengers.includes(bot.entity.id)) {
846
+ const originalVehicle = bot.vehicle
847
+ if (entityId === -1) {
848
+ bot.vehicle = null
849
+ bot.emit('dismount', originalVehicle)
850
+ } else {
851
+ bot.vehicle = bot.entities[entityId]
852
+ bot.emit('mount')
853
+ }
854
+ }
855
+ })
856
+
857
+ // dismounting when the vehicle is gone
858
+ bot._client.on('entityGone', (entity) => {
859
+ if (bot.vehicle === entity) {
821
860
  bot.vehicle = null
822
- bot.emit('dismount', vehicle)
823
- } else {
824
- bot.vehicle = bot.entities[entityId]
825
- bot.emit('mount')
861
+ bot.emit('dismount', (entity))
862
+ }
863
+ if (entity.passengers) {
864
+ for (const passenger of entity.passengers) {
865
+ passenger.vehicle = null
866
+ }
867
+ }
868
+ if (entity.vehicle) {
869
+ const index = entity.vehicle.passengers.indexOf(entity)
870
+ if (index !== -1) {
871
+ entity.vehicle.passengers = entity.vehicle.passengers.splice(index, 1)
872
+ }
826
873
  }
827
874
  })
828
875
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "4.25.0",
3
+ "version": "4.26.0",
4
4
  "description": "create minecraft bots with a stable, high level API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "url": "git://github.com/PrismarineJS/mineflayer.git"
18
18
  },
19
19
  "engines": {
20
- "node": ">=18"
20
+ "node": ">=22"
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
@@ -27,7 +27,7 @@
27
27
  "prismarine-block": "^1.17.0",
28
28
  "prismarine-chat": "^1.7.1",
29
29
  "prismarine-chunk": "^1.36.0",
30
- "prismarine-entity": "^2.3.0",
30
+ "prismarine-entity": "^2.5.0",
31
31
  "prismarine-item": "^1.15.0",
32
32
  "prismarine-nbt": "^2.0.0",
33
33
  "prismarine-physics": "^1.9.0",