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

Fix type error on chest open #2684

Merged
merged 1 commit into from
Aug 7, 2022
Merged

Conversation

IceTank
Copy link
Contributor

@IceTank IceTank commented Jul 3, 2022

There is a missing null check when trying to access a block. If that block is outside the render distance blockAt can return null causing a type error. See PrismarineJS discord message for an example https://discord.com/channels/413438066984747026/413438150594265099/993210395990949988

@rom1504
Copy link
Member

rom1504 commented Jul 20, 2022

in case it's null, what is the expected return value?

@IceTank
Copy link
Contributor Author

IceTank commented Jul 20, 2022

in case it's null, what is the expected return value?

'single' after the for loop.
I am not 100% sure what this code is used for tbh but I know it is failing for 1.8 with chests that boarder unloaded chunks. That makes sense as blockAt can return null for unloaded chunks. I assume 1.8 does not have connected chest block types and the game just connects chest that are adjacent to each other?

@rom1504
Copy link
Member

rom1504 commented Jul 20, 2022

'single' after the for loop.

That's what your code change would make it do, but does it make sense?

@IceTank
Copy link
Contributor Author

IceTank commented Jul 20, 2022

So I think a chest can either be a single chest or a double chest. If the chest block does not store what chest type it is mineflayer tries to guess what chest type the chest it want's to open is. On 1.8 if a chunk is empty it is not send at all and mineflayer thinks that chunk is unloaded. So when you open a single chest at a chunk corner mineflayer will crash as blockAt will return null. There can be double chests at chunk borders that can still work if both chest blocks are within loaded chunks. I don't see how 1.8 would tell the client that a single chest at a chunk corner can be a double chest with the other chest block being within the unloaded chunk. For newer versions you can have chest blocks that say if they are single or double chest blocks. And mineflayer uses that to know what type off chest it opens. It looks like this function is only used to emit the chest lid move event. And that requires knowledge off if a chest is a double chest or a single chest. I have not tested it by my guess is that on 1.8 you would only see a single chest opening when you observer a double chest opening that is half in a loaded chunk.

@rom1504 rom1504 added this to Needs triage in PR Triage Aug 7, 2022
@rom1504 rom1504 merged commit 9fdb6ab into PrismarineJS:master Aug 7, 2022
PR Triage automation moved this from Needs triage to Closed Aug 7, 2022
@IceTank IceTank deleted the type-error-fix branch August 7, 2022 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PR Triage
  
Closed
Development

Successfully merging this pull request may close these issues.

None yet

2 participants