Commit Graph

73 Commits

Author SHA1 Message Date
Alexander Medvedev
b40c2fa988 Add Experimental Plains biome
Also add Perlin noise
2024-09-06 17:54:14 +01:00
Alexander Medvedev
91d190c212 Remove unused deps
to mention is the take_mut dep i removed. Its heavily outdated and uses unsafe combined with pointer magic.
2024-09-06 13:30:57 +01:00
DaniD3v
12e3732765 Replaced #[allow()]'s with #[expect()] 2024-09-06 11:20:53 +02:00
DaniD3v
e08309aacd Removed unused #[allow()]'s 2024-09-06 11:19:52 +02:00
Snowiiii
1f4fe2a26e Fix: Chunk loading dead lock 2024-09-01 23:14:53 +02:00
Snowiiii
5c0dffbf9d Dynamic chunk loading 2024-09-01 18:04:27 +02:00
DaniD3v
8a2e7cada8 Removed lazy_static!{} in favor of LazyLock 2024-08-31 20:34:00 +02:00
Snowiiii
ee4e18282e Support multiple worlds
- We moved all players to seperate worlds. This will save performance when many different players are on different worlds. The only thing broken now are commands because of async stuff
2024-08-31 11:39:59 +02:00
Snowiiii
f45ebb2d4f Cache: Chunks 2024-08-30 18:42:54 +02:00
lukas0008
ab73f3a3a4 Cargo fmt 2024-08-30 18:00:23 +02:00
lukas0008
8bb00e26be Make ChunkData use Vector2 instead of ChunkCoordinates 2024-08-30 17:40:55 +02:00
lukas0008
5f05a1886b Change coordinates, and add .get_block to ChunkBlocks
- Renamed ChunkRelativeScalar to ChunkRelativeOffset
- Added more traits to Height and ChunkRelativeOffset
- Added .get_block to ChunkBlocks
2024-08-30 15:07:54 +02:00
DaniD3v
ff06d05487 Made ChunkNBT struct slightly more readable 2024-08-28 17:35:01 +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
lukas0008
0d05e5ef36 Add .set_block on ChunkData 2024-08-21 17:31:43 +02:00
Snowiiii
49dfc18818 Fix: Clippy & fmt 2024-08-20 13:23:32 +02:00
Bryntet
006eacfadf Merge branch 'master' into master 2024-08-20 12:56:00 +02:00
Edvin Bryntesson
c18cbdc06b add logic for placing blocks 2024-08-20 12:32:05 +02:00
Edvin Bryntesson
1b1300e194 make registries public 2024-08-20 12:31:46 +02:00
Edvin Bryntesson
f4ab2ce585 fix global registry and add function to easily access minecraft ids 2024-08-20 12:30:42 +02:00
Edvin Bryntesson
47a7117fea fix error message 2024-08-20 12:29:39 +02:00
Edvin Bryntesson
b2430ce3d4 make block place the item that is held. 2024-08-20 11:23:21 +02:00
Edvin Bryntesson
3d21a991a0 rename item_categories.rs 2024-08-20 10:13:19 +02:00
Edvin Bryntesson
658cb297f1 add item category checks
this is for if a specific slot can only accept a specific category of items, like you can only put helmets in the helmet armor slot
2024-08-19 23:39:39 +02:00
Edvin Bryntesson
918364f536 add item id and count to item struct 2024-08-19 23:38:05 +02:00
Edvin Bryntesson
9e14952046 fix typo 2024-08-19 23:37:35 +02:00
Alexander Medvedev
222b40c8bd Add World struct
We also check now if world exits
2024-08-19 21:14:48 +01:00
Alexander Medvedev
de7b3aa2ea Fix: all clippy warns 2024-08-19 20:08:02 +01:00
Kolibroid
1a21290e0f Fix some minor typos 2024-08-19 17:52:04 +01:00
lukas0008
fdb94d43fa Fix: Place block on correct side 2024-08-17 20:40:26 +02:00