Skip to content

Commit

Permalink
Fixes fireworkRocketDuration calculation (#3222)
Browse files Browse the repository at this point in the history
* fix firework duration when elytra flying

* update zh api doc

* fix lint

* restart CI
  • Loading branch information
szdytom authored Dec 17, 2023
1 parent 08208e2 commit 3d8a1aa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
4 changes: 3 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,12 @@ This occurs whether the process was completed or aborted.

* `block` - the block that still exists

#### "usedfirework"
#### "usedFirework" (fireworkEntityId)

Fires when the bot uses a firework while elytra flying.

* `fireworkEntityId` - the entity id of the firework.

#### "move"

Fires when the bot moves. If you want the current position, use
Expand Down
1 change: 1 addition & 0 deletions docs/zh/README_ZH_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ Mineflayer 支持插件;任何人都可以创建一个插件,在 Mineflayer
### 示例

`npm run mocha_test -- -g "1.18.1.*BlockFinder"` 进行1.18.1寻路测试

## 许可证

[MIT](../LICENSE)
6 changes: 6 additions & 0 deletions docs/zh/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,12 @@ This occurs whether the process was completed or aborted.

* `block` - 方块仍然存在

#### "usedFirework" (fireworkEntityId)

在机器人在鞘翅飞行时使用烟花火箭时触发

* `fireworkEntityId` - 烟花火箭的实体编号

#### "move"

当机器人移动时触发. 如果需要当前位置,请使用
Expand Down
27 changes: 8 additions & 19 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,36 +369,25 @@ function inject (bot) {
}
if (bot.fireworkRocketDuration !== 0 && entity.id === bot.entity?.id && !elytraFlying) {
bot.fireworkRocketDuration = 0
knownFireworks.splice(0, knownFireworks.length)
knownFireworks.clear()
}

if (startedFlying) {
bot.emit('entityElytraFlew', entity)
}
}

const knownFireworks = []
const knownFireworks = new Set()
function handleBotUsedFireworkRocket (fireworkEntityId, fireworkInfo) {
if (knownFireworks.includes(fireworkEntityId)) return
knownFireworks.push(fireworkEntityId)
let flightDur = 1
if (fireworkInfo?.nbtData != null) {
let nbt = fireworkInfo.nbtData
if (nbt.type === 'compound' && nbt.value.Fireworks != null) {
nbt = nbt.value.Fireworks
if (nbt.type === 'compound' && nbt.value.Flight != null) {
nbt = nbt.value.Flight
if (nbt.type === 'int') {
flightDur += nbt.value
}
}
}
}
const baseDuration = 10 * flightDur
if (knownFireworks.has(fireworkEntityId)) return
knownFireworks.add(fireworkEntityId)
let flightDur = fireworkInfo?.nbtData?.value?.Fireworks?.value?.Flight.value ?? 1
if (typeof flightDur !== 'number') { flightDur = 1 }
const baseDuration = 10 * (flightDur + 1)
const randomDuration = Math.floor(Math.random() * 6) + Math.floor(Math.random() * 7)
bot.fireworkRocketDuration = baseDuration + randomDuration

bot.emit('usedFirework')
bot.emit('usedFirework', fireworkEntityId)
}

let fireworkEntityName
Expand Down

0 comments on commit 3d8a1aa

Please sign in to comment.