Commit graph

330 commits

Author SHA1 Message Date
Ryan Johnson 9f8250d4f9
Update README.md with current project status. 2023-02-03 19:04:54 -08:00
CaveNightingale ca269cd03e
Add a simple SNBT parser (#201)
To implement the hoverEvent show_item, we need an SNBT parser and a SNBT
serializer.
An SNBT parser is implemented in this commit.
2023-02-03 03:16:27 -08:00
Ryan Johnson b5a355c756
Non-Object Text Deserialization (#194)
- Extends `Text`'s `Deserialize` impl to allow for deserializing JSON
data types other than objects.
- Add additional `From` impls for `Text`.
- Better `Debug` impl for `Text`.
- Tweaked text unit tests.
2023-01-21 00:17:19 -08:00
Guac ad89e4457c
Implement clientbound packets (#190)
Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2023-01-19 22:00:35 -08:00
Ryan Johnson 34c01d0f24
Add debug logging to valence_protocol (#191)
Adds `tracing` to `valence_protocol` so we can log debug info about
partially decoded packets. `packet_inspector` has been set to print log
messages at the debug level.
2023-01-16 16:32:22 -08:00
Ryan Johnson ad675547b2
Update packet inspector README 2023-01-11 22:58:00 -08:00
Ryan Johnson 7574fa33c5
Commands and recipe book packets (#183)
Implement the commands and recipe book packets. Also reorganizes some
modules in valence_protocol.
2022-12-31 22:59:22 -08:00
Ryan Johnson 8d9c0a7553
Add recipe and tags packets (#182)
Also improve generated `Encode`, `Decode` error messages and fix
unnecessary build script reruns.
2022-12-30 06:18:24 -08:00
Ryan 623e88908d Disable biome extractor
Need to figure out what became of the biome registry in 1.19.3
2022-12-29 23:31:06 -08:00
Ryan Johnson e386c9e2c2
Add Anvil file format support to README.md 2022-12-29 21:16:33 -08:00
Ryan Johnson c9aeda7dbd
Support NBT lists of type TAG_End (#181)
In NBT, lists are allowed to have the element type TAG_End iff their
length is zero. This adds an explicit `List::End` enum variant to
valence_nbt.
2022-12-29 18:10:29 -08:00
Ryan Johnson 2597e92b8f
Reorganize Packages (#180)
Moves all the packages to the `crates/` directory.
2022-12-29 16:51:05 -08:00
jivvy 295678e92d
Add Particles (#150)
Implements the clientbound particle packet.

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-12-29 00:26:19 -08:00
Ryan Johnson 5d3364d452
Update to 1.19.3 (#171)
Closes #165
2022-12-28 00:42:54 -08:00
Terminator 6de5de57a5
Anvil file support (blocks and biomes) (#145)
Adds the `valence_anvil` crate for loading anvil worlds. It can only read blocks and biomes currently. Support for saving data is to be added later.

Co-authored-by: Ryan <ryanj00a@gmail.com>
2022-12-26 06:55:52 -08:00
UStuej 8a7782e16f
Update doc (#178)
Refer to `EncodePacket` and `DecodePacket` instead of `Packet`.
2022-12-24 17:13:42 -08:00
Ryan Johnson c26bbe7ec2
Valence protocol redesign (#177)
- Fix performance issues related to writing individual bytes instead of
using `Write::write_all`.
- Make manual implementations of `Encode` and `Decode` easier:
  - Remove `encoded_len` method from `Encode`
  - Split `Packet` trait into `EncodePacket` and `DecodePacket`.
  - Simplify derive macros.
2022-12-23 06:30:57 -08:00
Ryan Johnson 1f5ec6f94f
Valence protocol benchmarks (#175)
Adds criterion benchmarks for some packets and `VarInt` in
`valence_protocol`
2022-12-21 01:24:02 -08:00
Ryan Johnson 2fc59d90a8
Improve valence_nbt write perf and remove zerocopy dependency (#174) 2022-12-20 20:17:07 -08:00
Carson McManus 4194acaa67
Use Option<InventoryId> for open_inventory on client (#167)
- automatically handle CloseContainer packet so the client updates open_inventory
- Use `Option<InventoryId>` for `open_inventory` on client

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-12-19 06:55:26 -08:00
Terminator c4ed95a7d3
Performance enhancements for #141 (#173)
This PR also includes the Criterion benchmark.

## Before this commit
> Benchmarking BlockState::to_kind
> Benchmarking BlockState::to_kind: Warming up for 3.0000 s Benchmarking
BlockState::to_kind: Collecting 100 samples in estimated 20.045 s (273k
iterations) Benchmarking BlockState::to_kind: Analyzing
> BlockState::to_kind     time:   [68.925 µs 69.202 µs 69.477 µs]
> 
> Found 5 outliers among 100 measurements (5.00%)
>   4 (4.00%) high mild
>   1 (1.00%) high severe

## After this commit
> Benchmarking BlockState::to_kind
> Benchmarking BlockState::to_kind: Warming up for 3.0000 s Benchmarking
BlockState::to_kind: Collecting 100 samples in estimated 20.010 s (3.8M
iterations) Benchmarking BlockState::to_kind: Analyzing
> BlockState::to_kind     time:   [1.5814 µs 1.5859 µs 1.5912 µs]
> change: [-97.692% -97.678% -97.666%] (p = 0.00 < 0.05)
>                         Performance has improved.
> Found 4 outliers among 100 measurements (4.00%)
>   4 (4.00%) high mild

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-12-19 06:25:26 -08:00
Ryan aeea435a7e Fix examples, but for real this time 2022-12-19 06:24:06 -08:00
Ryan 4e302ca09f Remove remaining unnecessary casts in examples 2022-12-19 06:11:03 -08:00
Ryan 985f7891e4 Remove unnecessary casts in death example 2022-12-19 02:17:35 -08:00
Ryan 01ff465db9 Remove unnecessary casts in parkour example 2022-12-19 01:50:51 -08:00
Ryan Johnson d85b7f5e89
Update packet inspector and fix packet bugs (#172)
- Implement `encoded_len` for packet enums.
- Fix bug in `has_next_packet` causing a later `unwrap` to panic.
- Add robust `encoded_len` check in `PacketEncoder` for debug builds.
- Split packet inspector regex into separate "inclusive" and "exclusive"
arguments because the `regex` crate does not support negative lookahead.
- Better `Debug` impls for `Ident` and `Compound`.
- Remove read/write timeouts from packet inspector.
2022-12-16 08:23:48 -08:00
Terminator c73abacc98
Re-visit From impl for native data types found in NBT data format. (#169) 2022-12-15 18:38:52 -08:00
Ryan Johnson 740778ec41
Update chunk data packet cache lazily (#170)
Previously, the chunk data cache was regenerated at the end of each tick
every time a block or biome was modified in a chunk. This causes
performance problems in situations where chunks are being modified every
tick, like the conway example or redstone machines.

This changes things so that the chunk data packet is regenerated only
when a client actually needs to load the chunk. This isn't perfect
because the regeneration cannot happen in parallel, but the benefits
outweigh the costs. (The chunk data packet _is_ generated in parallel
when the chunk is first created. There is also some parallelism when
clients are loading different chunks. The packet cache is guarded by a
`Mutex`.)

This has revealed that compression is surprisingly slow. This should be
investigated later.
2022-12-13 22:56:22 -08:00
Carson McManus 8b50e93b0e
add swap_slot to Inventory (#168)
This effectively exposes the slice `swap` method:
https://doc.rust-lang.org/std/primitive.slice.html#method.swap
2022-12-11 09:35:14 -08:00
Ryan Johnson ae7eaf15fc
Big Optimizations (#164)
Closes #84

# Changes

- Implemented new algorithm for tracking loaded entities and chunks.
- The client does not need to maintain a list of loaded chunks and
entities anymore, as this information can be inferred using carefully
maintained data from the previous tick.
- Chunks are used as a spatial partition for entities. Entity visibility
is now based on chunk visibility rather than the euclidean distance to
clients.
- The BVH is no longer strictly necessary, so it has been moved to the
new `valence_spatial_index` crate.
- The API has been generalized to support things other than entities.
The crate does not have a dependency on the main `valence` crate.
- Chunk, entity, and player list packets are now aggressively cached to
increase performance.
- Chunk packets now include some filler light data. This makes the
vanilla client lag a lot less.
- Entities and chunks must now be marked as deleted before they are
removed.
- Improved `ChunkPos` interface.
- Added function to get the duration per tick.
- Added `Index` and `IndexMut` impls to collection types.

As a result of the above changes, performance under heavy load has
increased significantly. With the rust-mc-bot test on my machine, I went
from a max of ~1000 players to ~4000 players.
2022-12-11 02:37:02 -08:00
Carson McManus 4188bd71bb
re-implement inventory_piano example (#166)
# Test plan

```
cargo r -r --example inventory_piano
```

Co-authored-by: Ryan Johnson <ryanj00a@gmail.com>
2022-12-10 18:08:32 -08:00
Ryan b61bdbb71d Fix conflicting Debug impl on bitfield structs 2022-12-09 17:02:37 -08:00
Ryan Johnson 842ddb4127
Optimize sending tracked entity data (#163) 2022-11-30 15:55:46 -08:00
Ryan Johnson 0e28e5ad05
Improve slab_rc implementation (#162) 2022-11-29 17:14:04 -08:00
Ryan Johnson 58f8197913
Client Cleanup (#159)
# Noteworthy Changes
- Simplified the `client` module and update procedure. Sending packets
is not deferred unless necessary.
- Client events are no longer buffered in `Client` before reaching the
user.
- Expanded `ClientEvent` to account for most packets.
- Most types containing custom `state` now implement `Deref` and
`DerefMut`. This means you don't have to write `.state` all over the
place. `Server` was excluded from this because it does not play well
with the borrow checker.
- Fixed bugs related to entity visibility.
- Client now correctly holds the semaphore permit from the initial
connection.
- Other miscellaneous API changes throughout the project. 

# Known Issues
- Inventory stuff is still incomplete. The inventory examples have been
temporarily disabled.
2022-11-29 03:37:32 -08:00
Sandro Marques 6437381339
Translation key extractor and code generator (#160)
Generates a new `translation_key.rs` with all bundled translations.
Closes #158.
2022-11-27 05:12:08 -08:00
Sandro Marques 86be031a31
Implement missing text component types (#144)
Implements the remaining text component types. Should hopefully close
#19.

Co-authored-by: Ryan <ryanj00a@gmail.com>
2022-11-19 16:48:01 -08:00
Ryan Johnson 4226201fed
Replace log crate with tracing (#157)
The `tracing` crate seems to be the go-to
logging/profiling/instrumentation solution nowadays. Perhaps in the
future we could use `tracing` for profiling instead of (or in addition
to) the `perf`-based `cargo flamegraph` command. This would sidestep the
issue of `rayon` polluting the output. I conducted an initial experiment
by adding some more spans but wasn't very happy with the result.

Log messages have also been improved. There is some additional context
and events are raised when clients are added/removed from the server.
2022-11-16 18:22:44 -08:00
Ryan Johnson ab2e1081ed
Re-export common items at the root of valence_protocol (#156) 2022-11-14 22:30:20 -08:00
Ryan 74e4f10ec5 Don't send empty MOTION_BLOCKING heightmap
The client seems to initialize it to zero when you don't send it, so
there's no point in sending an empty motion_blocking.
2022-11-14 17:18:49 -08:00
Ryan 21590a396c Fix cargo:rerun-if-changed=... in valence_protocol 2022-11-14 12:08:32 -08:00
Ryan Johnson 4b155f4c9b
Expand on the "encoded buf" idea in valence_protocol (#155)
Adds a `Cached<T>` type and renames some things.
2022-11-14 01:01:28 -08:00
Ryan Johnson b8e41cbb9a
Change 'Flexible' bullet in README.md
With the introduction of `valence_protocol` and some future plans, I've decided it's unrealistic to try and hide all the protocol code. There are situations where direct access is necessary.
2022-11-13 06:44:22 -08:00
Ryan Johnson 420f2d1b7c
Move protocol code to valence_protocol + redesigns (#153)
Closes #83 

This PR aims to move all of Valence's networking code to the new
`valence_protocol` crate. Anything not specific to valence is going in
the new crate. It also redesigns the way packets are defined and makes a
huge number of small additions and improvements. It should be much
easier to see where code is supposed to go from now on.

`valence_protocol` is a new library which enables interactions with
Minecraft's protocol. It is completely decoupled from valence and can be
used to build new clients, servers, tools, etc.

There are two additions that will help with #5 especially:
- It is now easy to define new packets or modifications of existing
packets. Not all packets need to be bidirectional.
- The `CachedEncode` type has been created. This is used to safely cache
redundant calls to `Encode::encode`.
2022-11-13 06:10:42 -08:00
Ryan Johnson 9f1c946839
Check off proxy support in README.md 2022-11-12 16:45:57 -08:00
emortaldev b1561eda73
Fix proxy joins (#154) 2022-11-12 06:32:00 -08:00
Ryan 923fabe890 Fix missing tokio context on client disconnect
The `PlayPacketController` might spawn a tokio task, but it was not in a
tokio context when that happened. This is because tokio contexts are
thread-local, but rayon tasks run in their own thread pool.
2022-11-09 18:30:44 -08:00
UStuej bb43856c9e
Implement radians conversions for ByteAngle (#149)
Adds `from_radians` function and `to_radians` method for `ByteAngle`.
2022-11-01 22:00:38 -07:00
Ryan Johnson ff136c2a4a
Clean up Config docs and add compression threshold (#148) 2022-11-01 20:27:08 -07:00
Carson McManus a885b949da
Better consume for inventories (#147)
- rework `consume_one` into `consume`
- update `consume_one_held_item` to `consume_held_item` to match
`consume`
- remove an unnecessary clone

Originally, I was planning on removing this function altogether. After
thinking about it for a bit though, I think it provides enough of a
convenience for end users to warrant keeping it.

This also implements the fix that was originally in #124
2022-11-01 19:31:28 -07:00