mineflayer 4.25.0 → 4.27.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/api.md CHANGED
@@ -2122,7 +2122,19 @@ These are lower level methods for the inventory, they can be useful sometimes bu
2122
2122
 
2123
2123
  This function returns a `Promise`, with `void` as its argument upon completion.
2124
2124
 
2125
- The only valid mode option at the moment is 0. Shift clicking or mouse dragging is not implemented.
2125
+ mode support:
2126
+ - stable:
2127
+ - mouse clicks (0)
2128
+
2129
+ - experimental:
2130
+ - shift clicks (1)
2131
+ - number clicks (2)
2132
+ - middle clicks (3)
2133
+ - drop clicks (4)
2134
+
2135
+ - unimplemented:
2136
+ - drag clicks (5)
2137
+ - double clicks (6)
2126
2138
 
2127
2139
  Click on the current window. See details at https://wiki.vg/Protocol#Click_Container
2128
2140
 
package/docs/history.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 4.27.0
2
+ * [Entity Passengers get pushed wrongly (#3601)](https://github.com/PrismarineJS/mineflayer/commit/deb03b52d1e015ece9df1f14536f168f64895c81) (thanks @SinanAkkoyun)
3
+ * [Update bot.clickWindow documentation (#3574)](https://github.com/PrismarineJS/mineflayer/commit/188db17bbb95461743aec2823695c360685559b0) (thanks @kaduvert)
4
+ * [Saving uuid for non-players too (#3603)](https://github.com/PrismarineJS/mineflayer/commit/9937be9b49bb3dd7cd5502c0424809fa66eb60b3) (thanks @SinanAkkoyun)
5
+
6
+ ## 4.26.0
7
+ * [Use node 22 (#3570)](https://github.com/PrismarineJS/mineflayer/commit/dbff9314418d30df203c32fe83f2a1b56653d0a6) (thanks @rom1504)
8
+ * [Fix infinity setTimeout by throwing error (#3561)](https://github.com/PrismarineJS/mineflayer/commit/69539494c88c2ca718330142839a35414ecd3bda) (thanks @BBpezsgo)
9
+ * [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)
10
+ * [Mounting for other entities and fix bot not dismounting when the vehicle is gone (#3384)](https://github.com/PrismarineJS/mineflayer/commit/08b7317b57ca5c2f1a6ddd116bd0c74c2e10c20c) (thanks @qwqtoday)
11
+
1
12
  ## 4.25.0
2
13
  * [1.21.4 (#3546)](https://github.com/PrismarineJS/mineflayer/commit/8bbf5669f5ff3ea8a708633e51b47c312dc7a26b) (thanks @extremeheat)
3
14
 
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()
@@ -207,6 +207,7 @@ function inject (bot) {
207
207
  const entityData = bot.registry.entities[entityType]
208
208
  setEntityData(entity, entityType, entityData)
209
209
  updateEntityPos(entity, pos)
210
+ entity.uuid = uuid
210
211
  return entity
211
212
  }
212
213
 
@@ -803,26 +804,73 @@ function inject (bot) {
803
804
 
804
805
  // attaching to a vehicle
805
806
  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')
807
+ const passenger = fetchEntity(packet.entityId)
808
+ const vehicle = packet.vehicleId === -1 ? null : fetchEntity(packet.vehicleId)
809
+
810
+ const originalVehicle = passenger.vehicle
811
+ if (originalVehicle) {
812
+ const index = originalVehicle.passengers.indexOf(passenger)
813
+ originalVehicle.passengers.splice(index, 1)
814
+ }
815
+ passenger.vehicle = vehicle
816
+ vehicle.passengers.push(passenger)
817
+
818
+ if (packet.entityId === bot.entity.id) {
819
+ const vehicle = bot.vehicle
820
+ if (packet.vehicleId === -1) {
821
+ bot.vehicle = null
822
+ bot.emit('dismount', vehicle)
823
+ } else {
824
+ bot.vehicle = bot.entities[packet.vehicleId]
825
+ bot.emit('mount')
826
+ }
814
827
  }
815
828
  })
816
829
 
817
830
  bot._client.on('set_passengers', ({ entityId, passengers }) => {
818
- if (passengers[0] !== bot.entity.id) return
819
- const vehicle = bot.vehicle
820
- if (entityId === -1) {
831
+ const passengerEntities = passengers.map((passengerId) => fetchEntity(passengerId))
832
+ const vehicle = entityId === -1 ? null : bot.entities[entityId]
833
+
834
+ for (const passengerEntity of passengerEntities) {
835
+ const originalVehicle = passengerEntity.vehicle
836
+ if (originalVehicle) {
837
+ const index = originalVehicle.passengers.indexOf(passengerEntity)
838
+ originalVehicle.passengers.splice(index, 1)
839
+ }
840
+ passengerEntity.vehicle = vehicle
841
+ if (vehicle) {
842
+ vehicle.passengers.push(passengerEntity)
843
+ }
844
+ }
845
+
846
+ if (passengers.includes(bot.entity.id)) {
847
+ const originalVehicle = bot.vehicle
848
+ if (entityId === -1) {
849
+ bot.vehicle = null
850
+ bot.emit('dismount', originalVehicle)
851
+ } else {
852
+ bot.vehicle = bot.entities[entityId]
853
+ bot.emit('mount')
854
+ }
855
+ }
856
+ })
857
+
858
+ // dismounting when the vehicle is gone
859
+ bot._client.on('entityGone', (entity) => {
860
+ if (bot.vehicle === entity) {
821
861
  bot.vehicle = null
822
- bot.emit('dismount', vehicle)
823
- } else {
824
- bot.vehicle = bot.entities[entityId]
825
- bot.emit('mount')
862
+ bot.emit('dismount', (entity))
863
+ }
864
+ if (entity.passengers) {
865
+ for (const passenger of entity.passengers) {
866
+ passenger.vehicle = null
867
+ }
868
+ }
869
+ if (entity.vehicle) {
870
+ const index = entity.vehicle.passengers.indexOf(entity)
871
+ if (index !== -1) {
872
+ entity.vehicle.passengers.splice(index, 1)
873
+ }
826
874
  }
827
875
  })
828
876
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "4.25.0",
3
+ "version": "4.27.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",