forked from valence-rs/valence
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added food and saturation (valence-rs#568)
# Objective - Food and saturation currently don't exist for the player in valence - Closes valence-rs#565 # Solution Adds food and saturation to the `PlayerEntity` and tells the client about any changes. The only problem right now is that the default value for `Health` is the same for ALL entities, so the server tells the client that their health is at 14 when it should be at 20. ## Note Uncertain if best approach. Please lmk if another approach would be better
- Loading branch information
1 parent
4c6af33
commit 7fab7fe
Showing
4 changed files
with
135 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod boss_bar; | ||
mod client; | ||
mod example; | ||
mod hunger; | ||
mod inventory; | ||
mod layer; | ||
mod player_list; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use valence_server::entity::living::Health; | ||
use valence_server::entity::player::{Food, Saturation}; | ||
use valence_server::protocol::packets::play::HealthUpdateS2c; | ||
use valence_server::protocol::VarInt; | ||
|
||
use crate::testing::ScenarioSingleClient; | ||
|
||
#[test] | ||
fn test_hunger() { | ||
let ScenarioSingleClient { | ||
mut app, | ||
client, | ||
mut helper, | ||
layer: _, | ||
} = ScenarioSingleClient::new(); | ||
|
||
app.update(); | ||
helper.clear_received(); | ||
|
||
let og_saturation = app.world.get::<Saturation>(client).unwrap().0; | ||
let og_health = app.world.get::<Health>(client).unwrap().0; | ||
|
||
// set food level to 5 | ||
app.world.get_mut::<Food>(client).unwrap().0 = 5; | ||
|
||
app.update(); | ||
|
||
// make sure the packet was sent | ||
let sent_packets = helper.collect_received(); | ||
|
||
sent_packets.assert_count::<HealthUpdateS2c>(1); | ||
|
||
let packet = sent_packets.first::<HealthUpdateS2c>(); | ||
|
||
assert_eq!(packet.health, og_health); | ||
assert_eq!(packet.food, VarInt(5)); | ||
assert_eq!(packet.food_saturation, og_saturation); | ||
} |