Skip to content

Commit 3a6ce54

Browse files
authored
feat: bot.respawn, fix respawn with flying squid (#3206)
* feat: bot.respawn, fix respawn with flying squid * add typing (cherry picked from commit 66e34da) * add description for .respawn() * up header
1 parent 91108d3 commit 3a6ce54

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

docs/api.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
- ["blockBreakProgressEnd" (block, entity)](#blockbreakprogressend-block-entity)
226226
- ["diggingCompleted" (block)](#diggingcompleted-block)
227227
- ["diggingAborted" (block)](#diggingaborted-block)
228-
- ["usedFirework"](#usedfirework)
228+
- ["usedfirework"](#usedfirework)
229229
- ["move"](#move)
230230
- ["forcedMove"](#forcedmove)
231231
- ["mount"](#mount)
@@ -291,7 +291,7 @@
291291
- [bot.getExplosionDamages(entity, position, radius, [rawDamages])](#botgetexplosiondamagesentity-position-radius-rawdamages)
292292
- [bot.lookAt(point, [force])](#botlookatpoint-force)
293293
- [bot.look(yaw, pitch, [force])](#botlookyaw-pitch-force)
294-
- [bot.updateSign(block, text)](#botupdatesignblock-text)
294+
- [bot.updateSign(block, text, back = false)](#botupdatesignblock-text-back--false)
295295
- [bot.equip(item, destination)](#botequipitem-destination)
296296
- [bot.unequip(destination)](#botunequipdestination)
297297
- [bot.tossStack(item)](#bottossstackitem)
@@ -331,6 +331,7 @@
331331
- [bot.setCommandBlock(pos, command, [options])](#botsetcommandblockpos-command-options)
332332
- [bot.supportFeature(name)](#botsupportfeaturename)
333333
- [bot.waitForTicks(ticks)](#botwaitforticksticks)
334+
- [bot.respawn()](#botrespawn)
334335
- [Lower level inventory methods](#lower-level-inventory-methods)
335336
- [bot.clickWindow(slot, mouseButton, mode)](#botclickwindowslot-mousebutton-mode)
336337
- [bot.putSelectedItemRange(start, end, window, slot)](#botputselecteditemrangestart-end-window-slot)
@@ -2103,6 +2104,10 @@ The list of available features can be found inside the [./lib/features.json](htt
21032104

21042105
This is a promise-based function that waits for a given number of in-game ticks to pass before continuing. This is useful for quick timers that need to function with specific timing, regardless of the given physics tick speed of the bot. This is similar to the standard Javascript setTimeout function, but runs on the physics timer of the bot specifically.
21052106

2107+
#### bot.respawn()
2108+
2109+
When `respawn` option is disabled, you can call this method manually to respawn.
2110+
21062111
### Lower level inventory methods
21072112

21082113
These are lower level methods for the inventory, they can be useful sometimes but prefer the inventory methods presented above if you can.

index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface BotEvents {
6767
unmatchedMessage: (stringMsg: string, jsonMsg: ChatMessage) => Promise<void> | void
6868
inject_allowed: () => Promise<void> | void
6969
login: () => Promise<void> | void
70+
/** When `respawn` option is disabled, you can call this method manually to respawn. */
7071
spawn: () => Promise<void> | void
7172
respawn: () => Promise<void> | void
7273
game: () => Promise<void> | void
@@ -427,6 +428,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
427428
acceptResourcePack: () => void
428429

429430
denyResourcePack: () => void
431+
432+
respawn: () => void
430433
}
431434

432435
export interface simpleClick {

lib/plugins/health.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ function inject (bot, options) {
2525
bot.emit('death')
2626
}
2727
if (!options.respawn) return
28-
bot._client.write('client_command', { payload: 0 })
28+
bot.respawn()
2929
} else if (bot.health > 0 && !bot.isAlive) {
3030
bot.isAlive = true
3131
bot.emit('spawn')
3232
}
3333
})
34+
35+
const respawn = () => {
36+
if (bot.isAlive) return
37+
bot._client.write('client_command', bot.supportFeature('respawnIsPayload') ? { payload: 0 } : { actionId: 0 })
38+
}
39+
40+
bot.respawn = respawn
3441
}

0 commit comments

Comments
 (0)