mineflayer 4.0.0 → 4.1.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.
@@ -28,7 +28,7 @@ jobs:
28
28
  - javaVersion: 16
29
29
  mcVersion: '1.17.1'
30
30
  - javaVersion: 17
31
- mcVersion: '1.18.1'
31
+ mcVersion: '1.18.2'
32
32
  fail-fast: false
33
33
 
34
34
  steps:
package/docs/api.md CHANGED
@@ -20,8 +20,8 @@
20
20
  - [Biome](#biome)
21
21
  - [Item](#item)
22
22
  - [windows.Window (base class)](#windowswindow-base-class)
23
- - [window.deposit(itemType, metadata, count)](#windowdeposititemtype-metadata-count)
24
- - [window.withdraw(itemType, metadata, count)](#windowwithdrawitemtype-metadata-count)
23
+ - [window.deposit(itemType, metadata, count, nbt)](#windowdeposititemtype-metadata-count-nbt)
24
+ - [window.withdraw(itemType, metadata, count, nbt)](#windowwithdrawitemtype-metadata-count-nbt)
25
25
  - [window.close()](#windowclose)
26
26
  - [Recipe](#recipe)
27
27
  - [mineflayer.Container](#mineflayercontainer)
@@ -94,6 +94,8 @@
94
94
  - [bot.game.hardcore](#botgamehardcore)
95
95
  - [bot.game.maxPlayers](#botgamemaxplayers)
96
96
  - [bot.game.serverBrand](#botgameserverbrand)
97
+ - [bot.game.minY](#botgameminy)
98
+ - [bot.game.height](#botgameheight)
97
99
  - [bot.physicsEnabled](#botphysicsenabled)
98
100
  - [bot.player](#botplayer)
99
101
  - [bot.players](#botplayers)
@@ -113,6 +115,8 @@
113
115
  - [bot.settings.skinParts.showLeftPants - boolean](#botsettingsskinpartsshowleftpants---boolean)
114
116
  - [bot.settings.skinParts.showRightPants - boolean](#botsettingsskinpartsshowrightpants---boolean)
115
117
  - [bot.settings.skinParts.showHat - boolean](#botsettingsskinpartsshowhat---boolean)
118
+ - [bot.settings.enableTextFiltering - boolean](#botsettingsenabletextfiltering---boolean)
119
+ - [bot.settings.enableServerListing - boolean](#botsettingsenableserverlisting---boolean)
116
120
  - [bot.experience.level](#botexperiencelevel)
117
121
  - [bot.experience.points](#botexperiencepoints)
118
122
  - [bot.experience.progress](#botexperienceprogress)
@@ -418,21 +422,23 @@ See [prismarine-item](https://github.com/PrismarineJS/prismarine-item)
418
422
 
419
423
  See [prismarine-windows](https://github.com/PrismarineJS/prismarine-windows)
420
424
 
421
- #### window.deposit(itemType, metadata, count)
425
+ #### window.deposit(itemType, metadata, count, nbt)
422
426
 
423
427
  This function returns a `Promise`, with `void` as its argument when done depositing.
424
428
 
425
429
  * `itemType` - numerical item id
426
430
  * `metadata` - numerical value. `null` means match anything.
427
431
  * `count` - how many to deposit. `null` is an alias to 1.
432
+ * `nbt` - match nbt data. `null` is do not match nbt.
428
433
 
429
- #### window.withdraw(itemType, metadata, count)
434
+ #### window.withdraw(itemType, metadata, count, nbt)
430
435
 
431
- This function returns a `Promise`, with `void` as its argument when done withdrawing.
436
+ This function returns a `Promise`, with `void` as its argument when done withdrawing. Throws and error if the bot has no free room in its inventory.
432
437
 
433
438
  * `itemType` - numerical item id
434
439
  * `metadata` - numerical value. `null` means match anything.
435
440
  * `count` - how many to withdraw. `null` is an alias to 1.
441
+ * `nbt` - match nbt data. `null` is do not match nbt.
436
442
 
437
443
  #### window.close()
438
444
 
@@ -745,6 +751,8 @@ Create and return an instance of the class bot.
745
751
  * [viewDistance](#bot.settings.viewDistance)
746
752
  * [difficulty](#bot.settings.difficulty)
747
753
  * [skinParts](#bot.settings.skinParts)
754
+ * [enableTextFiltering](#bot.settings.enableTextFiltering)
755
+ * [enableServerListing](#bot.settings.enableServerListing)
748
756
  * chatLengthLimit : the maximum amount of characters that can be sent in a single message. If this is not set, it will be 100 in < 1.11 and 256 in >= 1.11.
749
757
  * defaultChatPatterns: defaults to true, set to false to not add the patterns such as chat and whisper
750
758
 
@@ -881,6 +889,7 @@ Default true, whether or not you receive color codes in chats from the server.
881
889
 
882
890
  #### bot.settings.viewDistance
883
891
 
892
+ Can be a string listed below or a postive number.
884
893
  Choices:
885
894
  * `far` (default)
886
895
  * `normal`
@@ -911,7 +920,10 @@ If you have a cape you can turn it off by setting this to false.
911
920
 
912
921
  ##### bot.settings.skinParts.showHat - boolean
913
922
 
914
-
923
+ #### bot.settings.enableTextFiltering - boolean
924
+ Unused, defaults to false in Notchian (Vanilla) client.
925
+ #### bot.settings.enableServerListing - boolean
926
+ This setting is sent to the server to determine whether the player should show up in server listings
915
927
  #### bot.experience.level
916
928
 
917
929
  #### bot.experience.points
package/docs/history.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 4.1.0
2
+
3
+ * 1.18.2 support
4
+ * Add nbt option to withdraw and deposit
5
+
1
6
  ## 4.0.0
2
7
 
3
8
  * useEntity maintains sneak state
package/docs/tutorial.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - [Logging in](#logging-in)
18
18
  - [Passing along functions](#passing-along-functions)
19
19
  - [Listening for an event](#listening-for-an-event)
20
- - [Callbacks](#callbacks)
20
+ - [Promises](#promises)
21
21
  - [Correct and incorrect approach](#correct-and-incorrect-approach)
22
22
  - [Advanced](#advanced)
23
23
  - [Asynchronousy](#asynchronousy)
@@ -430,18 +430,18 @@ To remove specific listener you can use `bot.removeListener()` method.
430
430
 
431
431
  Not only bot object, [`Chest`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerchest), [`Furnace`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerfurnace), [`Dispenser`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerdispenser), [`EnchantmentTable`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerenchantmenttable), [`Villager`](http://mineflayer.prismarine.js.org/#/api?id=mineflayervillager) object also have their own events!
432
432
 
433
- ### Callbacks
434
- A [callback](https://en.wikipedia.org/wiki/Callback_(computer_programming)) is a function that you can give to another function, that is expected to be *called back*, generally when that function ends.
435
- In Mineflayer, callbacks are often used to handle errors.
433
+ ### Promises
434
+ A [promise](https://nodejs.dev/learn/understanding-javascript-promises) is a function that you can use the `await` variable to wait on until it's job is complete. (you can omit the await to not wait for results)
436
435
 
437
436
  ```js
438
- bot.consume((error) => {
439
- if (error) { // This checks if an error occurred.
440
- console.log(error)
441
- } else {
437
+ async function consume (bot) {
438
+ try {
439
+ await bot.consume()
442
440
  console.log('Finished consuming')
441
+ } catch (err) {
442
+ console.log(error)
443
443
  }
444
- })
444
+ }
445
445
  ```
446
446
 
447
447
  The above code will try to consume what the bot is currently holding.
@@ -456,91 +456,40 @@ Below is an example of a bot that will craft oak logs into oak planks and then i
456
456
  Incorect approach ❌:
457
457
 
458
458
  ```js
459
- const plankRecipe = bot.recipesFor(5)[0] // Get the first recipe for item id 5, which is oak planks.
460
- bot.craft(plankRecipe, 1) // ❌ start crafting oak planks.
459
+ function craft (bot) {
460
+ const mcData = require('minecraft-data')(bot.version)
461
+ const plankRecipe = bot.recipesFor(mcData.itemsByName.oak_planks.id ?? mcData.itemsByName.planks.id)[0] // Get the first recipe for oak planks
462
+ bot.craft(plankRecipe, 1) // ❌ start crafting oak planks.
461
463
 
462
- const stickRecipe = bot.recipesFor(280)[0] // Get the first recipe for item id 5, which is sticks.
463
- bot.craft(stickRecipe, 1) // ❌ start crafting sticks.
464
+ const stickRecipe = bot.recipesFor(mcData.itemsByName.sticks.id)[0] // Get the first recipe for sticks
465
+ bot.craft(stickRecipe, 1) // ❌ start crafting sticks.
466
+ }
464
467
  ```
465
468
 
466
- Correct approach with callbacks ✔️:
469
+ Correct approach with promises ✔️:
467
470
 
468
471
  ```js
469
- const plankRecipe = bot.recipesFor(5)[0]
470
-
471
- bot.craft(plankRecipe, 1, null, (error) => {
472
- // After bot.craft(plankRecipe, ...) is finished, this callback is called and we continue. ✔️
473
- if (error) { // Check if an error happened.
474
- console.log(error)
475
- } else {
476
- const stickRecipe = bot.recipesFor(280)[0]
477
-
478
- bot.craft(stickRecipe, 1, null, (error) => {
479
- // After bot.craft(stickRecipe, ...) is finished, this callback is called and we continue. ✔️
480
- if (error) { // Check if an error happened.
481
- console.log(error)
482
- } else {
483
- bot.chat('Crafting Sticks finished')
484
- }
485
- })
486
- }
487
- })
472
+ async function craft (bot) {
473
+ const mcData = require('minecraft-data')(bot.version)
474
+ const plankRecipe = bot.recipesFor(mcData.itemsByName.oak_planks.id ?? mcData.itemsByName.planks.id)[0]
475
+ await bot.craft(plankRecipe, 1, null)
476
+ const stickRecipe = bot.recipesFor(mcData.itemsByName.sticks.id)[0]
477
+ await bot.craft(stickRecipe, 1, null)
478
+ bot.chat('Crafting Sticks finished')
479
+ }
488
480
  ```
489
481
 
490
482
  The reason the incorrect approach is wrong is because when `bot.craft()` is called, the code will continue below while the bot is crafting.
491
483
  By the time the code reaches the second `bot.craft()`, the first probably hasn't finished yet, which means the wanted resource is not available yet.
492
- Using callbacks can fix this because they will only be called after the `bot.craft()` is finished.
484
+ Using promises can fix this because they will only be called after the `bot.craft()` is finished.
493
485
 
494
- More on the [bot.craft()](https://mineflayer.prismarine.js.org/#/api?id=botcraftrecipe-count-craftingtable-callback) method.
486
+ More on the [bot.craft()](https://github.com/PrismarineJS/mineflayer/blob/master/docs/api.md#botcraftrecipe-count-craftingtable) method.
495
487
 
496
488
  ## Advanced
497
489
 
498
490
  The following concepts aren't necessary to create a Mineflayer bot, but they can be useful to understand and create more advanced bots.
499
491
  We assume you have understood the [Basics](#basics) tutorial.
500
492
 
501
- ### Asynchronousy
502
- In Javascript, asynchronousy is an important concept.
503
- By default, Javascript will run everything line by line, and only go to the next line if the current line is done. This is called blocking.
504
- However, sometimes you have to do something that takes a relatively long time, and you don't want your whole program to block and wait for it to finish.
505
-
506
- Interacting with the filesystem is often done using asynchronousy, because reading and writing large files can take a long time.
507
-
508
- ```js
509
- const myPromise = new Promise((resolve, reject) => {
510
- setTimeout(() => {
511
- resolve('Success!') // Yay! Everything went well!
512
- }, 1000)
513
- })
514
-
515
- myPromise.then((successMessage) => {
516
- console.log(successMessage)
517
- })
518
-
519
- myPromise.catch((error) => {
520
- console.log(error)
521
- })
522
- ```
523
-
524
- The above codes uses what is called a Promise. A promise promises it will eventually complete.
525
- The function given you a promise always has 2 parameters, a `resolve` function and a `reject` function.
526
- If the promise is successful, it will call the `resolve` function, otherwise it will call the `reject` function.
527
- The above code uses a `setTimeout`, which calls the given function after the set amount of milliseconds, 1000 in this case.
528
- You can then tell the promise what it should do when it succeeds with `.then(function)` or when it fails with `.catch(function)`
529
-
530
- The `.then` and `.catch` function can also be chained together with the promise to simplify the code.
531
-
532
- ```js
533
- const myPromise = new Promise((resolve, reject) => {
534
- setTimeout(() => {
535
- resolve('Success!') // Yay! Everything went well!
536
- }, 1000)
537
- }).then((successMessage) => {
538
- console.log(successMessage)
539
- }).catch((error) => {
540
- console.log(error)
541
- })
542
- ```
543
-
544
493
  ### Loop over an object
545
494
 
546
495
  The `for of` loop described in the [loops](#loops) chapter can also be used to loop over an object.
package/index.d.ts CHANGED
@@ -328,8 +328,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
328
328
 
329
329
  craft: (
330
330
  recipe: Recipe,
331
- count: number | null,
332
- craftingTable: Block
331
+ count?: number,
332
+ craftingTable?: Block
333
333
  ) => Promise<void>
334
334
 
335
335
  writeBook: (
package/lib/features.json CHANGED
@@ -7,7 +7,7 @@
7
7
  {
8
8
  "name": "spawner",
9
9
  "description": "spawner is called spawner",
10
- "versions": ["1.13", "1.18.1"]
10
+ "versions": ["1.13", "1.18.2"]
11
11
  },
12
12
  {
13
13
  "name": "blockMetadata",
@@ -17,12 +17,12 @@
17
17
  {
18
18
  "name": "blockStateId",
19
19
  "description": "block metadata is encoded as state id",
20
- "versions": ["1.13", "1.18.1"]
20
+ "versions": ["1.13", "1.18.2"]
21
21
  },
22
22
  {
23
23
  "name": "creativeSleepNearMobs",
24
24
  "description": "can sleep near mobs in creative",
25
- "versions": ["1.13", "1.18.1"]
25
+ "versions": ["1.13", "1.18.2"]
26
26
  },
27
27
  {
28
28
  "name": "fixedPointPosition",
@@ -32,7 +32,7 @@
32
32
  {
33
33
  "name": "doublePosition",
34
34
  "description": "Entity positions are represented with double",
35
- "versions": ["1.9", "1.18.1"]
35
+ "versions": ["1.9", "1.18.2"]
36
36
  },
37
37
  {
38
38
  "name": "fixedPointDelta",
@@ -42,7 +42,7 @@
42
42
  {
43
43
  "name": "fixedPointDelta128",
44
44
  "description": "Delta of position are represented with fixed point numbers times 128",
45
- "versions": ["1.9", "1.18.1"]
45
+ "versions": ["1.9", "1.18.2"]
46
46
  },
47
47
  {
48
48
  "name": "customChannelMCPrefixed",
@@ -52,12 +52,12 @@
52
52
  {
53
53
  "name": "customChannelIdentifier",
54
54
  "description": "custom channel is an identifier starting in minecraft namespace",
55
- "versions": ["1.13", "1.18.1"]
55
+ "versions": ["1.13", "1.18.2"]
56
56
  },
57
57
  {
58
58
  "name": "dimensionDataIsAvailable",
59
59
  "description": "dimensionData is available, providing an additional information about the current dimension",
60
- "versions": ["1.17", "1.18.1"]
60
+ "versions": ["1.17", "1.18.2"]
61
61
  },
62
62
  {
63
63
  "name": "useItemWithBlockPlace",
@@ -67,7 +67,7 @@
67
67
  {
68
68
  "name": "useItemWithOwnPacket",
69
69
  "description": "use item is done with its own packet",
70
- "versions": ["1.9", "1.18.1"]
70
+ "versions": ["1.9", "1.18.2"]
71
71
  },
72
72
  {
73
73
  "name": "blockPlaceHasHeldItem",
@@ -87,7 +87,7 @@
87
87
  {
88
88
  "name": "blockPlaceHasInsideBlock",
89
89
  "description": "block_place packet has inside block",
90
- "versions": ["1.14", "1.18.1"]
90
+ "versions": ["1.14", "1.18.2"]
91
91
  },
92
92
  {
93
93
  "name": "teleportUsesPositionPacket",
@@ -102,7 +102,7 @@
102
102
  {
103
103
  "name": "teleportUsesOwnPacket",
104
104
  "description": "teleport is done using its own packet",
105
- "versions": ["1.9", "1.18.1"]
105
+ "versions": ["1.9", "1.18.2"]
106
106
  },
107
107
  {
108
108
  "name": "oneBlockForSeveralVariations",
@@ -112,7 +112,7 @@
112
112
  {
113
113
  "name": "blockSchemeIsFlat",
114
114
  "description": "all variations of a packet have their own id",
115
- "versions": ["1.13", "1.18.1"]
115
+ "versions": ["1.13", "1.18.2"]
116
116
  },
117
117
  {
118
118
  "name": "tabCompleteHasNoToolTip",
@@ -122,7 +122,7 @@
122
122
  {
123
123
  "name": "tabCompleteHasAToolTip",
124
124
  "description": "tab complete has a tool tip",
125
- "versions": ["1.13", "1.18.1"]
125
+ "versions": ["1.13", "1.18.2"]
126
126
  },
127
127
  {
128
128
  "name": "effectAreMinecraftPrefixed",
@@ -132,7 +132,7 @@
132
132
  {
133
133
  "name": "effectAreNotPrefixed",
134
134
  "description": "effect are not prefixed",
135
- "versions": ["1.13", "1.18.1"]
135
+ "versions": ["1.13", "1.18.2"]
136
136
  },
137
137
  {
138
138
  "name": "itemsAreAlsoBlocks",
@@ -142,12 +142,12 @@
142
142
  {
143
143
  "name": "itemsAreNotBlocks",
144
144
  "description": "items are not block",
145
- "versions": ["1.13", "1.18.1"]
145
+ "versions": ["1.13", "1.18.2"]
146
146
  },
147
147
  {
148
148
  "name": "fishingBobberCorrectlyNamed",
149
149
  "description": "the fishing hook entity is named fishing_bobber",
150
- "versions": ["1.14", "1.18.1"]
150
+ "versions": ["1.14", "1.18.2"]
151
151
  },
152
152
  {
153
153
  "name": "editBookIsPluginChannel",
@@ -157,7 +157,7 @@
157
157
  {
158
158
  "name": "hasEditBookPacket",
159
159
  "description": "book editing is handled through a packet",
160
- "versions": ["1.13", "1.18.1"]
160
+ "versions": ["1.13", "1.18.2"]
161
161
  },
162
162
  {
163
163
  "name": "clientUpdateBookIdWhenSign",
@@ -197,12 +197,12 @@
197
197
  {
198
198
  "name": "dimensionIsAWorld",
199
199
  "description": "description is a world name (string)",
200
- "versions": ["1.16.2", "1.18.1"]
200
+ "versions": ["1.16.2", "1.18.2"]
201
201
  },
202
202
  {
203
203
  "name": "dimensionDataIsAvailable",
204
204
  "description": "dimensionData is available, describing additional dimension information",
205
- "versions": ["1.17", "1.18.1"]
205
+ "versions": ["1.17", "1.18.2"]
206
206
  },
207
207
  {
208
208
  "name": "doesntHaveChestType",
@@ -227,22 +227,22 @@
227
227
  {
228
228
  "name": "hasAttackCooldown",
229
229
  "description": "if there is a cooldown after attacks to deal full damage",
230
- "versions": ["1.9", "1.18.1"]
230
+ "versions": ["1.9", "1.18.2"]
231
231
  },
232
232
  {
233
233
  "name": "usesLoginPacket",
234
234
  "description": "uses the login packet as defined in mcData",
235
- "versions": ["1.16", "1.18.1"]
235
+ "versions": ["1.16", "1.18.2"]
236
236
  },
237
237
  {
238
238
  "name": "usesMultiblockSingleLong",
239
239
  "description": "in the multi_block_change packet is stored as a single number",
240
- "versions": ["1.16.2", "1.18.1"]
240
+ "versions": ["1.16.2", "1.18.2"]
241
241
  },
242
242
  {
243
243
  "name": "usesMultiblock3DChunkCoords",
244
244
  "description": "in the multi_block_change packet, all 3 axis coords are defined",
245
- "versions": ["1.16.2", "1.18.1"]
245
+ "versions": ["1.16.2", "1.18.2"]
246
246
  },
247
247
  {
248
248
  "name": "setBlockUsesMetadataNumber",
@@ -257,7 +257,7 @@
257
257
  {
258
258
  "name": "selectingTradeMovesItems",
259
259
  "description": "selecting a trade automatically puts the required items into trading slots",
260
- "versions": ["1.14", "1.18.1"]
260
+ "versions": ["1.14", "1.18.2"]
261
261
  },
262
262
  {
263
263
  "name": "resourcePackUsesHash",
@@ -272,7 +272,7 @@
272
272
  {
273
273
  "name": "teamUsesChatComponents",
274
274
  "description": "teams use chatcomponents for formatting",
275
- "versions": ["1.13", "1.18.1"]
275
+ "versions": ["1.13", "1.18.2"]
276
276
  },
277
277
  {
278
278
  "name": "teamUsesScoreboard",
@@ -287,7 +287,7 @@
287
287
  {
288
288
  "name": "enderCrystalNameNoCapsWithUnderscore",
289
289
  "description": "this is when the end_crystal's entity name is end_crystal",
290
- "versions": ["1.14", "1.18.1"]
290
+ "versions": ["1.14", "1.18.2"]
291
291
  },
292
292
  {
293
293
  "name": "entityNameUpperCaseNoUnderscore",
@@ -307,7 +307,7 @@
307
307
  {
308
308
  "name": "stateIdUsed",
309
309
  "description": "starting in 1.17.1, actionId has been replaced with stateId",
310
- "versions": ["1.17.1", "1.18.1"]
310
+ "versions": ["1.17.1", "1.18.2"]
311
311
  },
312
312
  {
313
313
  "name": "actionIdUsed",
@@ -317,7 +317,7 @@
317
317
  {
318
318
  "name": "setSlotAsTransaction",
319
319
  "description": "use setslot as transaction instead of just hoping it'll work",
320
- "versions": ["1.17", "1.18.1"]
320
+ "versions": ["1.17", "1.18.2"]
321
321
  },
322
322
  {
323
323
  "name": "armAnimationBeforeUse",
@@ -327,7 +327,7 @@
327
327
  {
328
328
  "name": "tallWorld",
329
329
  "description": "world starts at -64 and ends at 384",
330
- "versions": ["1.18", "1.18.1"]
330
+ "versions": ["1.18", "1.18.2"]
331
331
  },
332
332
  {
333
333
  "name": "sendStringifiedSignText",
@@ -306,16 +306,17 @@ function inject (bot, { version, hideErrors }) {
306
306
  window.emit('close')
307
307
  closeWindow(window)
308
308
  }
309
- window.withdraw = async (itemType, metadata, count) => {
309
+
310
+ window.withdraw = async (itemType, metadata, count, nbt) => {
310
311
  if (bot.inventory.emptySlotCount() === 0) {
311
312
  throw new Error('Unable to withdraw, Bot inventory is full.')
312
313
  }
313
-
314
314
  const options = {
315
315
  window,
316
316
  itemType,
317
317
  metadata,
318
318
  count,
319
+ nbt,
319
320
  sourceStart: 0,
320
321
  sourceEnd: window.inventoryStart,
321
322
  destStart: window.inventoryStart,
@@ -323,12 +324,13 @@ function inject (bot, { version, hideErrors }) {
323
324
  }
324
325
  await transfer(options)
325
326
  }
326
- window.deposit = async (itemType, metadata, count) => {
327
+ window.deposit = async (itemType, metadata, count, nbt) => {
327
328
  const options = {
328
329
  window: window,
329
330
  itemType,
330
331
  metadata,
331
332
  count,
333
+ nbt,
332
334
  sourceStart: window.inventoryStart,
333
335
  sourceEnd: window.inventoryEnd,
334
336
  destStart: 0,
@@ -23,13 +23,27 @@ const viewDistanceToBits = {
23
23
  function inject (bot, options) {
24
24
  function setSettings (settings) {
25
25
  extend(bot.settings, settings)
26
+
27
+ // chat
26
28
  const chatBits = chatToBits[bot.settings.chat]
27
29
  assert.ok(chatBits != null, `invalid chat setting: ${bot.settings.chat}`)
28
- const viewDistanceBits = viewDistanceToBits[bot.settings.viewDistance]
30
+
31
+ // view distance
32
+ let viewDistanceBits = null
33
+ if (typeof bot.settings.viewDistance === 'string') {
34
+ viewDistanceBits = viewDistanceToBits[bot.settings.viewDistance]
35
+ } else if (typeof bot.settings.viewDistance === 'number' && bot.settings.viewDistance > 0) { // Make sure view distance is a valid # || should be 2 or more
36
+ viewDistanceBits = bot.settings.viewDistance
37
+ }
29
38
  assert.ok(viewDistanceBits != null, `invalid view distance setting: ${bot.settings.viewDistance}`)
39
+
40
+ // hand
30
41
  const handBits = handToBits[bot.settings.mainHand]
31
42
  assert.ok(handBits != null, `invalid main hand: ${bot.settings.mainHand}`)
32
- bot.settings.showCape = !!bot.settings.showCape
43
+
44
+ // skin
45
+ // cape is inverted, not used at all (legacy?)
46
+ // bot.settings.showCape = !!bot.settings.showCape
33
47
  const skinParts = bot.settings.skinParts.showCape << 0 |
34
48
  bot.settings.skinParts.showJacket << 1 |
35
49
  bot.settings.skinParts.showLeftSleeve << 2 |
@@ -37,13 +51,17 @@ function inject (bot, options) {
37
51
  bot.settings.skinParts.showLeftPants << 4 |
38
52
  bot.settings.skinParts.showRightPants << 5 |
39
53
  bot.settings.skinParts.showHat << 6
54
+
55
+ // write the packet
40
56
  bot._client.write('settings', {
41
57
  locale: bot.settings.locale || 'en_US',
42
58
  viewDistance: viewDistanceBits,
43
59
  chatFlags: chatBits,
44
60
  chatColors: bot.settings.colorsEnabled,
45
61
  skinParts: skinParts,
46
- mainHand: handBits
62
+ mainHand: handBits,
63
+ enableTextFiltering: bot.settings.enableTextFiltering,
64
+ enableServerListing: bot.settings.enableServerListing
47
65
  })
48
66
  }
49
67
 
@@ -67,7 +85,9 @@ function inject (bot, options) {
67
85
  showHat: true
68
86
  }
69
87
  : options.skinParts,
70
- mainHand: options.mainHand || 'right'
88
+ mainHand: options.mainHand || 'right',
89
+ enableTextFiltering: options.enableTextFiltering || false,
90
+ enableServerListing: options.enableServerListing || true
71
91
  }
72
92
 
73
93
  bot._client.once('login', () => {
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  module.exports = {
2
2
  supportedVersions: ['1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18'],
3
- testedVersions: ['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', '1.17.1', '1.18.1']
3
+ testedVersions: ['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', '1.17.1', '1.18.2']
4
4
  } // when updating testedVersions, make sure to update CI.yml
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "create minecraft bots with a stable, high level API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "minecraft-data": "^2.109.0",
25
- "minecraft-protocol": "^1.26.5",
24
+ "minecraft-data": "^2.114.1",
25
+ "minecraft-protocol": "^1.31.0",
26
26
  "prismarine-biome": "^1.1.1",
27
27
  "prismarine-block": "^1.13.1",
28
28
  "prismarine-chat": "^1.3.3",