Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes fireworkRocketDuration calculation #3222

Merged
merged 4 commits into from
Dec 17, 2023
Merged

Conversation

szdytom
Copy link
Contributor

@szdytom szdytom commented Nov 1, 2023

The problem

fireworkRocketDuration is set to wrong values that cause elytra to fly shorter (#3221). The correct formula is: 10 × (number of gunpowder + 1) + random value from 0 to 5 + random value from 0 to 6

example picture

The above figure illustrates the difference: the plank post on the left stands for mineflayer's fly height, the log post on the right stands for notchian client fly height (both are done with 1 rocket with flight of 1).

The problem is about the following part:

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
const randomDuration = Math.floor(Math.random() * 6) + Math.floor(Math.random() * 7)
bot.fireworkRocketDuration = baseDuration + randomDuration

There are two bug in this code:

  • Line 385: the nbt may does not exists, but that means the rocket has a flight of 1 instead of 0.
  • Line 391: the type should be byte instead of int (at least for 1.20.1)

Changes

In this pull request:

  • Modified function handleBotUsedFireworkRocket to fix fireworkRocketDuration calculation.
  • Made variable knownFireworks a Set, this in more efficient than using Array.
  • Fixed a typo about event usedFirework in the API document (usedfirework to usedFirework).
  • Added an argument to event usedFirework:
    • fireworkEntityId - the entity id of the firework.
  • Updated the document of Simplified Chinese to add the usedfirework event. I am a native speaker of that language.

Fixes #3221

@szdytom
Copy link
Contributor Author

szdytom commented Nov 1, 2023

/fixlint

@rom1504bot
Copy link
Contributor

No linting errors found.

@rom1504
Copy link
Member

rom1504 commented Dec 17, 2023

seems right

would be good to add a test for this

@rom1504 rom1504 merged commit 3d8a1aa into PrismarineJS:master Dec 17, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

fireworkRocketDuration is calculated wrong, results in elytra to fly shorter
3 participants