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 direct palettes #232

Merged
merged 13 commits into from
Aug 26, 2023
Merged

Conversation

frej4189
Copy link
Contributor

Closes #164

There are a handful of problems with the implementation of direct palettes that would cause errors on some servers (most notably Hypixel).

This PR addresses these issues:

  1. The BitArray readBuffer function always attempts to consume data enough to populate the entire storage. This will cause an error when the server provides a shorter (or longer) long array than needed.
  2. The direct palette uses the server provided bits per value, instead of truncating to the size of the registry.

I generally believe these changes to be correct, but I have not tested any versions below 1.18. I'm putting up the PR now so others can test with mineflayer and so we can get reviews started.

@frej4189
Copy link
Contributor Author

Breaks with lighting information and other similar things that uses BitArray for a wrapping its data.

Also CI won't pass most tests since it relies on dumps generated with the incorrect implementation.

@extremeheat
Copy link
Member

Also CI won't pass most tests since it relies on dumps generated with the incorrect implementation.

What do you mean by "incorrect implementation"? The test data should just be desterilized chunk data off the network, no?

@frej4189
Copy link
Contributor Author

Also CI won't pass most tests since it relies on dumps generated with the incorrect implementation.

What do you mean by "incorrect implementation"? The test data should just be desterilized chunk data off the network, no?

Dumps seem to be generated by pchunk itself

@rom1504
Copy link
Member

rom1504 commented Aug 24, 2023

They are not. Dumps are raw bytes generated using Minecraft-protocol with https://github.com/PrismarineJS/minecraft-chunk-dumper

The tests using them check internal consistency of pchunk between load and dump

So if they're not passing , something is broken

@frej4189
Copy link
Contributor Author

I see.

I haven't fully implemented dumping so that could be the cause of this. I just saw invalid data in the dumps (namely direct palette with bit per block set to 16) but that may well be an issue with the dumping method if it compares the new dumps with the ones from the network.

@rom1504
Copy link
Member

rom1504 commented Aug 25, 2023

If data in the dumps is invalid it means there is a bug in the vanilla Minecraft server implementation

@frej4189
Copy link
Contributor Author

Yeah it's all good. I'm just saying there's something wrong with my dump method. Not that there's something wrong with the dumps

test/test.js Outdated Show resolved Hide resolved
@extremeheat
Copy link
Member

Cc @nickelpro if you have the time to review

@nickelpro
Copy link
Member

Other than the one comment, which might be nonsense because I'm not 100% clear on why that read was there to begin with, LGTM WRT the commit doing what it says it does.

I think there's a bit of repetition here that could use refactoring, but the basic idea of only using GLOBAL_BITS_PER_X when we know that it's big enough is correct and the current behavior should be considered a bug.

I'm less certain about trusting servers about their long counts, but testing should reveal the safety of that.

@frej4189
Copy link
Contributor Author

I don't think there's anymore repetition than earlier so I don't think that's too much of an issue.

With regards to trusting servers long counts, that is also what the Vanilla client does. See https://github.com/extremeheat/extracted_minecraft_data/blob/20e005fafc4928179f144d3ff68413f0ca70808b/client/net/minecraft/network/FriendlyByteBuf.java#L402-L417

@nickelpro
Copy link
Member

I don't think there's anymore repetition than earlier so I don't think that's too much of an issue.

prisChunk being bad is the norm, we do try to improve it from time-to-time. Agree not a blocker.

With regards to trusting servers long counts, that is also what the Vanilla client does.

I'm down for this in principle, I'm just skeptical of modded servers in general to follow vanilla behavior and this entire patch series is about modded server support. Vanilla works fine.

@frej4189
Copy link
Contributor Author

I'm down for this in principle, I'm just skeptical of modded servers in general to follow vanilla behavior and this entire patch series is about modded server support. Vanilla works fine.

While I agree this technically is only a problem on modded servers, the current chunk implementation does in fact not mirror that of the Vanilla client. I am not jumping through hoops to support non-Vanilla servers, I am simply mirroring the Vanilla (client) implementation.

Also to add the current implementation actually does not work on Vanilla servers due to the GLOBAL_BITS_PER_BLOCK constant being incorrect for some versions. It just doesn't cause errors because we seldom fall back on that value.

Copy link
Member

@nickelpro nickelpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments all resolved, I'm happy with this.

Holding off on merge for further field testing/rom's thumbs up

@rom1504
Copy link
Member

rom1504 commented Aug 25, 2023

looks ok but yeah we really need to put more code in common between versions here or it's going to become very hard to maintain fast

@rom1504
Copy link
Member

rom1504 commented Aug 25, 2023

maybe let's wait a few more days if anyone else wants to take a look (maybe @Karang ?)

@frej4189
Copy link
Contributor Author

Will add chunk dumps from Hypixel to test data aswell. I have a few that I tested locally but I haven't extracted it just the way the other dumps are generated so I will have to make some changes.

@frej4189
Copy link
Contributor Author

Added hypixel dumps and made a few changes to the dump tests to account for non-Vanilla format (i.e. histogram will not look like a naturally generated world). I don't think anymore testing is needed, but if anyone has comments to the code itself, feel free.

@@ -376,7 +392,7 @@ versions.forEach((version) => describe(`Chunk implementation for minecraft ${ver
}
}

if (!version.startsWith('1.8')) {
if (!version.startsWith('1.8') && !chunkDump.includes('hypixel')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which are hypixel chunks not the same after dumping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because hypixel provides excess data which is dropped by pchunk (per this PR). See my comment here #232 (comment)

Since the test already iterates over all blocks and palettes in the chunk, it means the two chunks are still functionally the same if the test passes

@rom1504
Copy link
Member

rom1504 commented Aug 26, 2023

@frej4189 if you run the tests with implementation from main on hypixel chunks, does it fail? (eg does this PR fixes it)

@frej4189
Copy link
Contributor Author

@frej4189 if you run the tests with implementation from main on hypixel chunks, does it fail? (eg does this PR fixes it)

It does indeed.

@frej4189
Copy link
Contributor Author

Running current implementation CI here frej4189#1

@rom1504 rom1504 merged commit 6422abc into PrismarineJS:master Aug 26, 2023
2 checks passed
@rom1504
Copy link
Member

rom1504 commented Aug 26, 2023

ok sounds good, thanks for the pr!

@rom1504
Copy link
Member

rom1504 commented Aug 26, 2023

/makerelease

@rom1504bot rom1504bot mentioned this pull request Aug 26, 2023
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.

Error reading direct palettes for 1.18
5 participants