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

Anvil parser #100

Merged
merged 10 commits into from
Oct 29, 2024
Merged

Anvil parser #100

merged 10 commits into from
Oct 29, 2024

Conversation

ReCore-sys
Copy link
Collaborator

This PR adds a memory-mapped anvil file reader

Description

The anvil file format is how minecraft chunks are stored in the vanilla implementation. Even though we aren't using the anvil file format to store our chunks, we still need to be able to read it in order to to import chunks. Due to that, this system only supports reading, not writing. While reading single chunks at a time is supported, it is optimized for reading all of the chunks from an anvil file in one go.

Motivation and Context

This is needed in order to import chunks from vanilla

How has this been tested?

Unit tests are included that verify it has the same output as fastanvil and that it can read valid anvil files properly. It also checks to make sure invalid anvil files cannot be read properly, as due to the minimal format it is reasonably possible for an invalid file to produce gibberish data. The ZLIB Addler32 checksum is checked to make sure the nbt data is correct.
This feature does use memory-mapping to speed up IO processes, but this does come with inherent unsafe code usage. This unsafe code is handled entirely by the memmap2 crate and we just have to use a couple unsafe blocks so we can use the unsafe functions they provide, so the chance of the unsafe code causing issues is minimal and the memmap2 crate would be at complete fault if that happened.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (restructuring code, without changing its behavior)

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Clippy passes with no warnings.

@Sweattypalms
Copy link
Member

Thanks 🤤

@Sweattypalms Sweattypalms merged commit f852606 into rewrite/v3 Oct 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants