Skip to content

Commit 3d8a1aa

Browse files
authored
Fixes fireworkRocketDuration calculation (#3222)
* fix firework duration when elytra flying * update zh api doc * fix lint * restart CI
1 parent 08208e2 commit 3d8a1aa

4 files changed

Lines changed: 18 additions & 20 deletions

File tree

docs/api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,12 @@ This occurs whether the process was completed or aborted.
14291429

14301430
* `block` - the block that still exists
14311431

1432-
#### "usedfirework"
1432+
#### "usedFirework" (fireworkEntityId)
14331433

14341434
Fires when the bot uses a firework while elytra flying.
14351435

1436+
* `fireworkEntityId` - the entity id of the firework.
1437+
14361438
#### "move"
14371439

14381440
Fires when the bot moves. If you want the current position, use

docs/zh/README_ZH_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ Mineflayer 支持插件;任何人都可以创建一个插件,在 Mineflayer
240240
### 示例
241241

242242
`npm run mocha_test -- -g "1.18.1.*BlockFinder"` 进行1.18.1寻路测试
243+
243244
## 许可证
244245

245246
[MIT](../LICENSE)

docs/zh/api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,12 @@ This occurs whether the process was completed or aborted.
13391339

13401340
* `block` - 方块仍然存在
13411341

1342+
#### "usedFirework" (fireworkEntityId)
1343+
1344+
在机器人在鞘翅飞行时使用烟花火箭时触发
1345+
1346+
* `fireworkEntityId` - 烟花火箭的实体编号
1347+
13421348
#### "move"
13431349

13441350
当机器人移动时触发. 如果需要当前位置,请使用

lib/plugins/entities.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -369,36 +369,25 @@ function inject (bot) {
369369
}
370370
if (bot.fireworkRocketDuration !== 0 && entity.id === bot.entity?.id && !elytraFlying) {
371371
bot.fireworkRocketDuration = 0
372-
knownFireworks.splice(0, knownFireworks.length)
372+
knownFireworks.clear()
373373
}
374374

375375
if (startedFlying) {
376376
bot.emit('entityElytraFlew', entity)
377377
}
378378
}
379379

380-
const knownFireworks = []
380+
const knownFireworks = new Set()
381381
function handleBotUsedFireworkRocket (fireworkEntityId, fireworkInfo) {
382-
if (knownFireworks.includes(fireworkEntityId)) return
383-
knownFireworks.push(fireworkEntityId)
384-
let flightDur = 1
385-
if (fireworkInfo?.nbtData != null) {
386-
let nbt = fireworkInfo.nbtData
387-
if (nbt.type === 'compound' && nbt.value.Fireworks != null) {
388-
nbt = nbt.value.Fireworks
389-
if (nbt.type === 'compound' && nbt.value.Flight != null) {
390-
nbt = nbt.value.Flight
391-
if (nbt.type === 'int') {
392-
flightDur += nbt.value
393-
}
394-
}
395-
}
396-
}
397-
const baseDuration = 10 * flightDur
382+
if (knownFireworks.has(fireworkEntityId)) return
383+
knownFireworks.add(fireworkEntityId)
384+
let flightDur = fireworkInfo?.nbtData?.value?.Fireworks?.value?.Flight.value ?? 1
385+
if (typeof flightDur !== 'number') { flightDur = 1 }
386+
const baseDuration = 10 * (flightDur + 1)
398387
const randomDuration = Math.floor(Math.random() * 6) + Math.floor(Math.random() * 7)
399388
bot.fireworkRocketDuration = baseDuration + randomDuration
400389

401-
bot.emit('usedFirework')
390+
bot.emit('usedFirework', fireworkEntityId)
402391
}
403392

404393
let fireworkEntityName

0 commit comments

Comments
 (0)