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

Superflat Worldgeneration #63

Merged
merged 23 commits into from
Aug 28, 2024
Merged

Superflat Worldgeneration #63

merged 23 commits into from
Aug 28, 2024

Conversation

DaniD3v
Copy link
Contributor

@DaniD3v DaniD3v commented Aug 28, 2024

This PR adds Superflat Worldgeneration.

image

By default the vanilla ./world file is still read but chunks that are not generated yet are replaced by newly generated chunks.

This is currently not configurable because I plan on making it configurable after the "move config to LazyLock" PR will be rejected/merged.

If I went a bit overboard with all the refactors tell me and I'll cherry-pick the commits into another branch.

All of the commits compile individually and were checked with

cargo clippy -- -W clippy::complexity -W clippy::correctness -W clippy::perf -W clippy::style -W clippy::suspicious
cargo build
cargo check --release
cargo fmt --check

related to #36

DaniD3v added 18 commits August 28, 2024 12:38
These ensure that there aren't any out of bound values
and make the code significantly more readable
Renamed `WORLD_Y_START_AT` to `WORLD_LOWEST_Y`.
Added `WORLD_Y_END_AT`.
Changed the type to i16 for ergonomics.
Moved the constants under the use statements for readability.
renamed a few fields for clarity.
added examples for fields that might not immediately be obvious.
removed some `Option`s that are not necessary.

renamed `BlockElement` to `BlockType` because you could mistake
`BlockElement` for the main way to represent a Block (e.g. in Chunks).
`i32` is really ambiguous and it is not immediately obvious what it is supposed to represent.
`BlockId` is much more readable.

Changed internal type to u16 because we currently have ~30k/64k block states.
(and i32 doesn't make a lot of sense for an Id, except when replicating mojang behavior)
Simply count blocks instead of doing some complex operation with k/j/i
Marked comment with TODO
Replaced if/else condition with std::cmp::max
Removed some redundant `.enumerate()`s
ChunkBlocks makes it easy & safer to access blocks of a chunk.
It also makes it possible to consistently handle the heightmap updates in 1 place.
Moved `BlockId` to it's own file.
Prefixed all of the `block_registry` types with Registry to avoid confusion.
Made stuff that should not be public private.
Added new error types to indicate a chunk should be generated.
Renamed to `fetch_chunks` to indicate that it no longer just reads chunks (might write to the worldfile in the future)
Take a reference to a slice instead of an owned vector because the data is Copy anyways.

Remove the ChunkCoordinates that are sent over the mpsc Sender.
- The coordinates are stored in ChunkData anyways.
- If there is an Error the coordinates should not matter because the error can't be recovered from.

Moved the reading from file logic to `read_chunk`.
- So that we don't always have to repeat `channel.blocking_send(...); return;`
- To make it clearly distinct from the main program logic.

Replaced some verbose match statements with `Result.map_err()`.
When loading a partially generated world there's some
incomplete chunks that might not have a heightmap yet.

If that is the case we return a ChunkNotGeneratedError
to indicate that it's ok to (re-)generate it.
@DaniD3v
Copy link
Contributor Author

DaniD3v commented Aug 28, 2024

image
I did not change that yet because it kinda relies on the config changes.

pumpkin-world/Cargo.toml Outdated Show resolved Hide resolved
pumpkin-world/src/world_gen/implementations/superflat.rs Outdated Show resolved Hide resolved
…ile.

Moved warning about ./world folder to only appear when necessary +
Updated warning contents to reflect changes

Made the save_file in the `Level` struct optional
in case someone wants an entirely generated World.

Removed now redundant asserts.
@Snowiiii
Copy link
Member

Great job. Thank you @DaniD3v ❤️

@Snowiiii Snowiiii merged commit 0ba9b37 into Pumpkin-MC:master Aug 28, 2024
5 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