Commit Graph
25 Commits
Author SHA1 Message Date
DaniD3v 3535d2cda1 Fixed new clippy lint 2024-08-31 19:27:06 +02:00
DaniD3v ff06d05487 Made ChunkNBT struct slightly more readable 2024-08-28 17:35:01 +02:00
DaniD3v e2d2b53f41 Fixed bug where whole chunk can break in one mined block 2024-08-28 17:34:56 +02:00
DaniD3v 112a899559 Added logic to generate chunks if they can't be read from the world file.
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.
2024-08-28 17:34:47 +02:00
DaniD3v 43c724dec7 Added Superflat implementation. 2024-08-28 17:34:37 +02:00
DaniD3v 9149e82508 Added WorldGenerator traits and a GenericWorldGenerator. 2024-08-28 17:28:48 +02:00
DaniD3v 4031c4dc13 Added Seed Type. 2024-08-28 12:52:26 +02:00
DaniD3v eb4d47aa74 Added an Enum for Biomes 2024-08-28 12:52:26 +02:00
DaniD3v b5b27885c7 Added ChunkStatus to check if a chunk is fully generated yet.
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.
2024-08-28 12:52:26 +02:00
DaniD3v 17b285081a Refractored read_chunk
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()`.
2024-08-28 12:52:26 +02:00
DaniD3v cdb0e6b761 Refractored coordinates.rs 2024-08-28 12:52:26 +02:00
DaniD3v cf283323fc BlockId refactor.
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.
2024-08-28 12:52:19 +02:00
DaniD3v bef3ddef50 Replaced redundant .map with .for_each 2024-08-28 12:52:19 +02:00
DaniD3v a8d9c89da2 Implemented Default for ChunkHeightmaps and ChunkBlocks 2024-08-28 12:52:19 +02:00
DaniD3v 52c34caaa6 Added ChunkBlocks abstraction for ChunkData
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.
2024-08-28 12:52:07 +02:00
DaniD3v 1d1dd2ed6c Added consts CHUNK_AREA, SUBCHUNK_VOLUME and CHUNK_VOLUME, 2024-08-28 12:52:07 +02:00
DaniD3v 4565133ef5 Refractored ChunkData::from_bytes
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
2024-08-28 12:52:07 +02:00
DaniD3v fe56d32463 Renamed block_size to block_bit_size for readability 2024-08-28 12:52:07 +02:00
DaniD3v 33ec123148 Added BlockIdentifierNotFound Error to differentiate from BlockStateIdNotFound 2024-08-28 12:52:07 +02:00
DaniD3v 43164ee4f1 Added abstraction for BlockId
`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)
2024-08-28 12:52:07 +02:00
DaniD3v 5a21a687d8 Block structs refractor + added comments
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).
2024-08-28 12:52:07 +02:00
DaniD3v 03fcdc2e32 Imported serde::Deserialize to avoid spelling it out frequently. 2024-08-28 12:52:07 +02:00
DaniD3v a0260acd8b WORLD_Y_START_AT refactor
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.
2024-08-28 12:51:43 +02:00
DaniD3v be98a730b0 Added abstraction for coordinates.
These ensure that there aren't any out of bound values
and make the code significantly more readable
2024-08-28 12:38:22 +02:00
DaniD3v 60bb30a883 use rustls instead of system openssl to make compilation easier 2024-08-22 21:11:00 +02:00