Skip to content

Commit c5e8674

Browse files
authored
Merge branch 'main' into feat/sponge_schem
2 parents 23e28d9 + e933fd6 commit c5e8674

File tree

17 files changed

+133
-78
lines changed

17 files changed

+133
-78
lines changed

Diff for: .github/ISSUE_TEMPLATE/bug_report.yml

+6-20
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@ body:
66
attributes:
77
label: Valence Version
88
description: What version of Valence are you using? If you are targeting a specific commit or branch, put that instead.
9-
placeholder: version, branch, or commit hash
9+
placeholder: Version, branch, or commit hash.
1010
validations:
1111
required: true
1212
- type: textarea
1313
attributes:
1414
label: Current Behavior
15-
description: A concise description of what you're experiencing.
15+
description: A concise description of what you're experiencing. Include any screenshots or additional information here.
1616
validations:
1717
required: false
1818
- type: textarea
1919
attributes:
2020
label: Expected Behavior
21-
description: A concise description of what you expected to happen.
21+
description: A concise description of what you expected to happen.
2222
validations:
2323
required: true
24-
- type: textarea
25-
attributes:
26-
label: Minimal Reproducible Example
27-
description: Do you have a playground to reproduce this bug? Paste it here. It should be a minimal example that exhibits the behavior. If the problem can be reproduced with one of the examples, just indicate which one instead.
28-
render: Rust
2924
- type: textarea
3025
attributes:
3126
label: Steps To Reproduce
@@ -37,19 +32,10 @@ body:
3732
4. See error
3833
validations:
3934
required: true
40-
- type: checkboxes
41-
attributes:
42-
label: Checklist
43-
options:
44-
- label: I have searched the issues of this repo and believe that this is not a duplicate.
45-
required: true
46-
- label: This used to work before.
4735
- type: textarea
4836
attributes:
49-
label: Anything else?
50-
description: |
51-
Links? References? Version Numbers? Anything that will give us more context about the issue you are encountering!
52-
53-
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
37+
label: Minimal Reproducible Example
38+
description: A minimal example that exhibits the behavior. If you have a playground, paste it here. If the problem can be reproduced with one of the examples, just indicate which one instead.
39+
render: Rust
5440
validations:
5541
required: false

Diff for: .github/ISSUE_TEMPLATE/feature_request.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ labels: [enhancement]
44
body:
55
- type: textarea
66
attributes:
7-
label: Is your feature request related to a problem? Please describe.
8-
description: A clear and concise description of what the problem is.
9-
placeholder: I'm always frustrated when...
7+
label: Describe the problem related to your feature request.
8+
description: A clear description of what the problem is.
109
validations:
1110
required: true
1211
- type: textarea
1312
attributes:
14-
label: Describe the solution you'd like
15-
description: A clear and concise description of what you want to happen.
16-
placeholder: I would like to be able to...
13+
label: Describe the solution you would like.
14+
description: The solution you propose for the problem presented.
1715
validations:
1816
required: true
1917
- type: textarea

Diff for: .github/pull_request_template.md

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
<!-- Please make sure that your PR is aligned with the guidelines in CONTRIBUTING.md to the best of your ability. -->
2-
<!-- Good PRs have tests! Make sure you have sufficient test coverage. -->
3-
41
## Description
52

6-
<!-- Describe the changes you've made. You may include any justification you want here. -->
3+
Describe the changes you've made. Link to any issues that this PR fixes or addresses.
74

85
## Test Plan
96

10-
<!-- Explain how you tested your changes, and include any code that you used to test this. -->
11-
<!-- If there is an example that is sufficient to use in place of a playground, replace the playground section with a note that indicates this. -->
7+
Explain the steps necessary to test your changes. If you used a playground, include the code in the details below.
8+
9+
Steps:
10+
1.
1211

1312
<details>
1413

@@ -19,11 +18,3 @@ PASTE YOUR PLAYGROUND CODE HERE
1918
```
2019

2120
</details>
22-
23-
<!-- You need to include steps regardless of whether or not you are using a playground. -->
24-
Steps:
25-
1.
26-
27-
#### Related
28-
29-
<!-- Link to any issues that have context for this or that this PR fixes. -->

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ in Minecraft such as minigame servers.
3232
Valence aims to be the following:
3333

3434
* **Complete**. Abstractions for the full breadth of the Minecraft protocol.
35-
* **Flexible**. Valence provides direct access to the lowest levels of Minecraft's protocol when necessary.
36-
* **Modular**. Pick and choose the features you actually need.
35+
* **Flexible**. Can easily extend Valence from within user code. Direct access to the Minecraft protocol is provided.
36+
* **Modular**. Pick and choose the components you need.
3737
* **Intuitive**. An API that is easy to use and difficult to misuse. Extensive documentation and examples are important.
3838
* **Efficient**. Optimal use of system resources with multiple CPU cores in mind. Valence uses very little memory and
3939
can
@@ -45,7 +45,7 @@ Valence aims to be the following:
4545

4646
## Current Status
4747

48-
Valence is still early in development with many features unimplemented or incomplete. Expect to encounter bugs, limitations, and breaking changes. Here are some noteworthy achievements:
48+
⚠️ **Valence is still early in development with many features unimplemented or incomplete. Expect to encounter bugs, limitations, and breaking changes.** Here are some noteworthy achievements:
4949

5050
- `valence_nbt`: A speedy new library for Minecraft's Named Binary Tag (NBT) format.
5151
- `valence_protocol`: A library for working with Minecraft's protocol. Does not depend on Valence and can be used in

Diff for: crates/valence/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ anyhow = "1.0.65"
1616
arrayvec = "0.7.2"
1717
async-trait = "0.1.60"
1818
base64 = "0.21.0"
19-
bevy_app = { git = "https://github.com/bevyengine/bevy/", rev = "2ea00610188dce1eba1172a3ded8244570189230" }
20-
bevy_ecs = { git = "https://github.com/bevyengine/bevy/", rev = "2ea00610188dce1eba1172a3ded8244570189230" }
19+
bevy_app = "0.10"
20+
bevy_ecs = "0.10"
2121
bitfield-struct = "0.3.1"
2222
bytes = "1.2.1"
2323
flume = "0.10.14"

Diff for: crates/valence/src/server/connect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use valence_protocol::packet::s2c::login::{
3131
LoginCompressionS2c, LoginDisconnectS2c, LoginHelloS2c, LoginQueryRequestS2c, LoginSuccessS2c,
3232
};
3333
use valence_protocol::packet::s2c::status::{QueryPongS2c, QueryResponseS2c};
34-
use valence_protocol::raw_bytes::RawBytes;
34+
use valence_protocol::raw::RawBytes;
3535
use valence_protocol::text::Text;
3636
use valence_protocol::types::Property;
3737
use valence_protocol::username::Username;

Diff for: crates/valence_anvil/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ valence_nbt = { version = "0.5.0", path = "../valence_nbt" }
2020

2121
[dev-dependencies]
2222
anyhow = "1.0.68"
23-
bevy_ecs = { git = "https://github.com/bevyengine/bevy/", rev = "2ea00610188dce1eba1172a3ded8244570189230" }
23+
bevy_ecs = "0.10"
2424
clap = "4.1.4"
2525
criterion = "0.4.0"
2626
flume = "0.10.14"

Diff for: crates/valence_protocol/src/lib.rs

+42-16
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub mod ident;
9595
mod impls;
9696
pub mod item;
9797
pub mod packet;
98-
pub mod raw_bytes;
98+
pub mod raw;
9999
pub mod sound;
100100
pub mod text;
101101
pub mod tracked_data;
@@ -261,9 +261,9 @@ pub trait Decode<'a>: Sized {
261261
/// type must implement [`Encode`], [`Decode`], and [`fmt::Debug`].
262262
///
263263
/// ```
264-
/// use valence_protocol::{Encode, Packet};
264+
/// use valence_protocol::{Decode, Encode, Packet};
265265
///
266-
/// #[derive(Encode, Packet, Debug)]
266+
/// #[derive(Encode, Decode, Packet, Debug)]
267267
/// #[packet_id = 42]
268268
/// struct MyStruct {
269269
/// first: i32,
@@ -282,6 +282,11 @@ pub trait Packet<'a>: Sized + fmt::Debug {
282282
/// The packet returned by [`Self::packet_id`]. If the packet ID is not
283283
/// statically known, then a negative value is used instead.
284284
const PACKET_ID: i32 = -1;
285+
/// Returns the ID of this packet.
286+
fn packet_id(&self) -> i32;
287+
/// Returns the name of this packet, typically without whitespace or
288+
/// additional formatting.
289+
fn packet_name(&self) -> &str;
285290
/// Like [`Encode::encode`], but a leading [`VarInt`] packet ID must be
286291
/// written first.
287292
///
@@ -292,14 +297,14 @@ pub trait Packet<'a>: Sized + fmt::Debug {
292297
///
293298
/// [`VarInt`]: var_int::VarInt
294299
fn decode_packet(r: &mut &'a [u8]) -> Result<Self>;
295-
/// Returns the ID of this packet.
296-
fn packet_id(&self) -> i32;
297300
}
298301

299302
#[allow(dead_code)]
300303
#[cfg(test)]
301-
mod derive_tests {
304+
mod tests {
302305
use super::*;
306+
use crate::packet::c2s::play::HandSwingC2s;
307+
use crate::packet::C2sPlayPacket;
303308

304309
#[derive(Encode, Decode, Packet, Debug)]
305310
#[packet_id = 1]
@@ -359,18 +364,39 @@ mod derive_tests {
359364
}
360365

361366
#[allow(unconditional_recursion)]
362-
fn has_impls<'a, T>()
367+
fn assert_has_impls<'a, T>()
363368
where
364369
T: Encode + Decode<'a> + Packet<'a>,
365370
{
366-
has_impls::<RegularStruct>();
367-
has_impls::<UnitStruct>();
368-
has_impls::<EmptyStruct>();
369-
has_impls::<TupleStruct>();
370-
has_impls::<StructWithGenerics>();
371-
has_impls::<TupleStructWithGenerics>();
372-
has_impls::<RegularEnum>();
373-
has_impls::<EmptyEnum>();
374-
has_impls::<EnumWithGenericsAndTags>();
371+
assert_has_impls::<RegularStruct>();
372+
assert_has_impls::<UnitStruct>();
373+
assert_has_impls::<EmptyStruct>();
374+
assert_has_impls::<TupleStruct>();
375+
assert_has_impls::<StructWithGenerics>();
376+
assert_has_impls::<TupleStructWithGenerics>();
377+
assert_has_impls::<RegularEnum>();
378+
assert_has_impls::<EmptyEnum>();
379+
assert_has_impls::<EnumWithGenericsAndTags>();
380+
}
381+
382+
#[test]
383+
fn packet_name() {
384+
assert_eq!(UnitStruct.packet_name(), "UnitStruct");
385+
assert_eq!(RegularEnum::Empty.packet_name(), "RegularEnum");
386+
assert_eq!(
387+
StructWithGenerics {
388+
foo: "blah",
389+
bar: ()
390+
}
391+
.packet_name(),
392+
"StructWithGenerics"
393+
);
394+
assert_eq!(
395+
C2sPlayPacket::HandSwingC2s(HandSwingC2s {
396+
hand: Default::default()
397+
})
398+
.packet_name(),
399+
"HandSwingC2s"
400+
);
375401
}
376402
}

Diff for: crates/valence_protocol/src/packet.rs

+24
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ macro_rules! packet_group {
4141
$packet_id
4242
}
4343

44+
fn packet_name(&self) -> &str {
45+
stringify!($packet)
46+
}
47+
4448
#[allow(unused_imports)]
4549
fn encode_packet(&self, mut w: impl std::io::Write) -> crate::Result<()> {
4650
use ::valence_protocol::__private::{Encode, Context, VarInt};
@@ -73,6 +77,14 @@ macro_rules! packet_group {
7377
}
7478
}
7579

80+
fn packet_name(&self) -> &str {
81+
match self {
82+
$(
83+
Self::$packet(pkt) => pkt.packet_name(),
84+
)*
85+
}
86+
}
87+
7688
fn encode_packet(&self, mut w: impl std::io::Write) -> crate::Result<()> {
7789
use crate::Encode;
7890
use crate::var_int::VarInt;
@@ -142,6 +154,10 @@ macro_rules! packet_group {
142154
$packet_id
143155
}
144156

157+
fn packet_name(&self) -> &str {
158+
stringify!($packet)
159+
}
160+
145161
#[allow(unused_imports)]
146162
fn encode_packet(&self, mut w: impl std::io::Write) -> crate::Result<()> {
147163
use ::valence_protocol::__private::{Encode, Context, VarInt};
@@ -174,6 +190,14 @@ macro_rules! packet_group {
174190
}
175191
}
176192

193+
fn packet_name(&self) -> &str {
194+
match self {
195+
$(
196+
Self::$packet(pkt) => pkt.packet_name(),
197+
)*
198+
}
199+
}
200+
177201
fn encode_packet(&self, mut w: impl std::io::Write) -> crate::Result<()> {
178202
use crate::Encode;
179203
use crate::var_int::VarInt;

Diff for: crates/valence_protocol/src/packet/c2s/login/login_query_response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::raw_bytes::RawBytes;
1+
use crate::raw::RawBytes;
22
use crate::var_int::VarInt;
33
use crate::{Decode, Encode};
44

Diff for: crates/valence_protocol/src/packet/c2s/play/custom_payload.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ident::Ident;
2-
use crate::raw_bytes::RawBytes;
2+
use crate::raw::RawBytes;
33
use crate::{Decode, Encode};
44

55
#[derive(Copy, Clone, Debug, Encode, Decode)]

Diff for: crates/valence_protocol/src/packet/s2c/login/login_query_request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ident::Ident;
2-
use crate::raw_bytes::RawBytes;
2+
use crate::raw::RawBytes;
33
use crate::var_int::VarInt;
44
use crate::{Decode, Encode};
55

Diff for: crates/valence_protocol/src/packet/s2c/play/custom_payload.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ident::Ident;
2-
use crate::raw_bytes::RawBytes;
2+
use crate::raw::RawBytes;
33
use crate::{Decode, Encode};
44

55
#[derive(Copy, Clone, Debug, Encode, Decode)]

Diff for: crates/valence_protocol/src/packet/s2c/play/entity_tracker_update.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::raw_bytes::RawBytes;
1+
use crate::raw::RawBytes;
22
use crate::var_int::VarInt;
33
use crate::{Decode, Encode};
44

Diff for: crates/valence_protocol/src/raw_bytes.rs renamed to crates/valence_protocol/src/raw.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::io::Write;
2+
use std::mem;
23

3-
use crate::{Decode, Encode, Result};
4+
use crate::{Decode, Encode, Packet, Result};
45

56
/// While [encoding], the contained slice is written directly to the output
67
/// without any length prefix or metadata.
@@ -10,7 +11,7 @@ use crate::{Decode, Encode, Result};
1011
///
1112
/// [encoding]: Encode
1213
/// [decoding]: Decode
13-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
14+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
1415
pub struct RawBytes<'a>(pub &'a [u8]);
1516

1617
impl Encode for RawBytes<'_> {
@@ -21,9 +22,7 @@ impl Encode for RawBytes<'_> {
2122

2223
impl<'a> Decode<'a> for RawBytes<'a> {
2324
fn decode(r: &mut &'a [u8]) -> Result<Self> {
24-
let slice = *r;
25-
*r = &[];
26-
Ok(Self(slice))
25+
Ok(Self(mem::take(r)))
2726
}
2827
}
2928

@@ -38,3 +37,26 @@ impl<'a> From<RawBytes<'a>> for &'a [u8] {
3837
value.0
3938
}
4039
}
40+
41+
/// A fake [`Packet`] which simply reads all data into a slice, or writes all
42+
/// data from a slice. The packet ID is included in the slice.
43+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
44+
pub struct RawPacket<'a>(pub &'a [u8]);
45+
46+
impl<'a> Packet<'a> for RawPacket<'a> {
47+
fn packet_id(&self) -> i32 {
48+
-1
49+
}
50+
51+
fn packet_name(&self) -> &str {
52+
"RawPacket"
53+
}
54+
55+
fn encode_packet(&self, mut w: impl Write) -> Result<()> {
56+
Ok(w.write_all(self.0)?)
57+
}
58+
59+
fn decode_packet(r: &mut &'a [u8]) -> Result<Self> {
60+
Ok(Self(mem::take(r)))
61+
}
62+
}

0 commit comments

Comments
 (0)