Skip to content

Commit 9260cf8

Browse files
authored
Merge #119: Replace With<GameProfile> -> With<PlayerMarker>
Replace With<GameProfile> -> With<PlayerMarker>
2 parents d669599 + b681452 commit 9260cf8

9 files changed

Lines changed: 37 additions & 23 deletions

File tree

.github/workflows/meloncraft-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Build
1919
run: cargo build --verbose --workspace
2020
- name: Run tests
21-
run: cargo test --verbose --workspace
21+
run: cargo test --verbose --workspace --bins --tests
2222
- name: Lint with clippy
2323
run: cargo clippy
2424
- name: Check formatting

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ manual_hash_one = "forbid"
168168
manual_inspect = "forbid"
169169
manual_is_multiple_of = "forbid"
170170
manual_main_separator_str = "forbid"
171+
manual_noop_waker = "forbid"
172+
manual_option_zip = "forbid"
173+
manual_pop_if = "forbid"
171174
manual_ok_err = "forbid"
172175
manual_option_as_slice = "forbid"
173176
manual_range_patterns = "forbid"

src/meloncraft_chat/src/title.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
/// See the fields for more details.
55
#[derive(Debug, Clone)]
66
pub enum TitlePosition {
7-
87
/// Display the message in the middle of the screen.
98
/// Largest font size.
109
Title,
11-
10+
1211
/// Display the message just below where a [`TitlePosition::Title`] would be,
1312
/// in a smaller font size.
1413
///
@@ -25,7 +24,6 @@ pub enum TitlePosition {
2524
/// fade out.
2625
#[derive(Debug, Clone)]
2726
pub struct TitleTimings {
28-
2927
/// The number of ticks that it takes for any titles to fade *in* on the client's screen.
3028
pub fade_in_ticks: i32,
3129

@@ -35,4 +33,3 @@ pub struct TitleTimings {
3533
/// The number of ticks that it takes for any titles to fade *out* on the client's screen.
3634
pub fade_out_ticks: i32,
3735
}
38-

src/meloncraft_chat_broadcasting/src/send.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ pub fn send_player_chat(
3434
});
3535
}
3636
}
37-

src/meloncraft_packet_forwarding/src/chat_message.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use bevy::ecs::message::{MessageReader, MessageWriter};
22
use meloncraft_chat::send::{ClearTitles, SendChatMessage, SendTitleMessage};
33
use meloncraft_chat::sent::PlayerSentChatMessage;
44
use meloncraft_chat::title::TitlePosition;
5-
use meloncraft_packets::{ClientboundClearTitles, ClientboundSetActionbarText, ClientboundSetSubtitleText, ClientboundSetTitleAnimationTimes, ClientboundSetTitleText, ClientboundSystemChat, ServerboundChat};
5+
use meloncraft_packets::{
6+
ClientboundClearTitles, ClientboundSetActionbarText, ClientboundSetSubtitleText,
7+
ClientboundSetTitleAnimationTimes, ClientboundSetTitleText, ClientboundSystemChat,
8+
ServerboundChat,
9+
};
610

711
pub fn fwd_player_sent(
812
mut chat_pr: MessageReader<ServerboundChat>,
@@ -42,7 +46,12 @@ pub fn fwd_send_title(
4246
for send_title in send_title_mr.read() {
4347
for receiver in send_title.receivers.clone() {
4448
if let Some(times) = &send_title.times {
45-
set_title_animation_times_pw.write(ClientboundSetTitleAnimationTimes { client: receiver, fade_in_ticks: times.fade_in_ticks, stay_ticks: times.stay_ticks, fade_out_ticks: times.fade_out_ticks });
49+
set_title_animation_times_pw.write(ClientboundSetTitleAnimationTimes {
50+
client: receiver,
51+
fade_in_ticks: times.fade_in_ticks,
52+
stay_ticks: times.stay_ticks,
53+
fade_out_ticks: times.fade_out_ticks,
54+
});
4655
}
4756

4857
match send_title.position {
@@ -51,19 +60,19 @@ pub fn fwd_send_title(
5160
client: receiver,
5261
title: send_title.message.clone(),
5362
});
54-
},
63+
}
5564
TitlePosition::Subtitle => {
5665
set_subtitle_text_pw.write(ClientboundSetSubtitleText {
5766
client: receiver,
5867
title: send_title.message.clone(),
5968
});
60-
},
69+
}
6170
TitlePosition::Actionbar => {
6271
set_actionbar_text_pw.write(ClientboundSetActionbarText {
6372
client: receiver,
6473
title: send_title.message.clone(),
6574
});
66-
},
75+
}
6776
}
6877
}
6978
}
@@ -76,7 +85,10 @@ pub fn fwd_clear_titles(
7685
for send_title in clear_title_mr.read() {
7786
for receiver in send_title.receivers.clone() {
7887
// for now, we always 'reset'.
79-
clear_titles_pw.write(ClientboundClearTitles { client: receiver, reset: true });
88+
clear_titles_pw.write(ClientboundClearTitles {
89+
client: receiver,
90+
reset: true,
91+
});
8092
}
8193
}
8294
}

src/meloncraft_packets/src/clientbound/play/set_experience.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ impl ClientboundPacket for ClientboundSetExperience {
4343
reason = "Both are needed for calculating experience level and bar size"
4444
)]
4545
fn data(&self, data: &mut Vec<u8>) {
46-
let bar = self.bar.map_or_else(
47-
|| return experience::total_to_level(self.total.0) % 1.0,
48-
|bar| return bar,
49-
);
50-
let level = self.level.map_or_else(
51-
|| return experience::total_to_level(self.total.0) as i32,
52-
|level| return level,
53-
);
46+
let bar = self
47+
.bar
48+
.unwrap_or_else(|| return experience::total_to_level(self.total.0) % 1.0);
49+
let level = self
50+
.level
51+
.unwrap_or_else(|| return experience::total_to_level(self.total.0) as i32);
5452

5553
data.extend(bar.net_serialize());
5654
data.extend(VarInt(level).net_serialize());

src/meloncraft_player/src/marker.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ use bevy::ecs::component::Component;
44

55
/// Marker to allow querying specifically for player entities. This is added to a client once they
66
/// have *finished* spawning into the world, in the **play** connection state.
7+
///
8+
/// Added **before** the [`LoadedPlayer`] marker.
79
#[derive(Component)]
810
pub struct PlayerMarker;
911

1012
/// Marker to allow querying specifically for player entities. This is added to a client once the
1113
/// *library user* has added any components they need to add before they are acted upon (e.g. positions).
14+
///
15+
/// Added **after** [`PlayerMarker`].
1216
#[derive(Component)]
1317
pub struct LoadedPlayer;

src/meloncraft_player_state/src/movement.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use meloncraft_entity::position::teleport::TeleportEntity;
66
use meloncraft_logger::warnlog;
77
use meloncraft_packets::{ClientboundSynchronizePlayerPosition, ServerboundSetPlayerPosition};
88
use meloncraft_player::GameProfile;
9+
use meloncraft_player::marker::LoadedPlayer;
910

1011
/// System for forwarding player movement packets as [`EntityMoved`] messages.
1112
///
@@ -19,7 +20,7 @@ use meloncraft_player::GameProfile;
1920
pub fn fwd_player_moved(
2021
mut set_position_pr: MessageReader<ServerboundSetPlayerPosition>,
2122
mut player_moved_mw: MessageWriter<EntityMoved>,
22-
existing_positions: Query<&EntityPosition, With<GameProfile>>,
23+
existing_positions: Query<&EntityPosition, With<LoadedPlayer>>,
2324
) {
2425
for packet in set_position_pr.read() {
2526
let Ok(old_position) = existing_positions.get(packet.client) else {

src/meloncraft_world_manager/src/setblock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bevy::math::UVec3;
88
use meloncraft_block::set::SetBlock;
99
use meloncraft_entity::position::EntityPosition;
1010
use meloncraft_packets::ClientboundBlockUpdate;
11-
use meloncraft_player::{ClientViewDistance, GameProfile};
11+
use meloncraft_player::{ClientViewDistance, PlayerMarker};
1212
use meloncraft_world::world::World;
1313

1414
pub fn store_set_blocks(
@@ -41,7 +41,7 @@ pub fn store_set_blocks(
4141

4242
pub fn send_set_blocks(
4343
mut set_block_mr: MessageReader<SetBlock>,
44-
players: Query<(Entity, &ClientViewDistance, &EntityPosition), With<GameProfile>>,
44+
players: Query<(Entity, &ClientViewDistance, &EntityPosition), With<PlayerMarker>>,
4545
mut block_update_pw: MessageWriter<ClientboundBlockUpdate>,
4646
) {
4747
for set_block in set_block_mr.read() {

0 commit comments

Comments
 (0)