Skip to content

Commit 4562967

Browse files
committed
set player metadata on init instead of login
1 parent 87c34e1 commit 4562967

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

azalea-client/src/client.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ impl Client {
325325
game_profile: GameProfileComponent(game_profile),
326326
client_information: crate::ClientInformation::default(),
327327
instance_holder,
328+
metadata: azalea_entity::metadata::PlayerMetadataBundle::default(),
328329
},
329330
InConfigState,
330331
));
@@ -729,6 +730,8 @@ pub struct LocalPlayerBundle {
729730
pub game_profile: GameProfileComponent,
730731
pub client_information: ClientInformation,
731732
pub instance_holder: InstanceHolder,
733+
734+
pub metadata: azalea_entity::metadata::PlayerMetadataBundle,
732735
}
733736

734737
/// A bundle for the components that are present on a local player that is

azalea-client/src/packet_handling/game.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use azalea_core::{
1414
};
1515
use azalea_entity::{
1616
indexing::{EntityIdIndex, EntityUuidIndex},
17-
metadata::{apply_metadata, Health, PlayerMetadataBundle},
17+
metadata::{apply_metadata, Health},
1818
Dead, EntityBundle, EntityKind, LastSentPosition, LoadedBy, LocalEntity, LookDirection,
19-
Physics, PlayerBundle, Position, RelativeEntityUpdate,
19+
Physics, Position, RelativeEntityUpdate,
2020
};
2121
use azalea_protocol::{
2222
packets::{
@@ -298,15 +298,12 @@ pub fn process_packet_events(ecs: &mut World) {
298298
}
299299
instance_holder.instance = weak_instance;
300300

301-
let player_bundle = PlayerBundle {
302-
entity: EntityBundle::new(
303-
game_profile.uuid,
304-
Vec3::default(),
305-
azalea_registry::EntityKind::Player,
306-
new_instance_name,
307-
),
308-
metadata: PlayerMetadataBundle::default(),
309-
};
301+
let entity_bundle = EntityBundle::new(
302+
game_profile.uuid,
303+
Vec3::default(),
304+
azalea_registry::EntityKind::Player,
305+
new_instance_name,
306+
);
310307
let entity_id = MinecraftEntityId(p.player_id);
311308
// insert our components into the ecs :)
312309
commands.entity(player_entity).insert((
@@ -315,7 +312,7 @@ pub fn process_packet_events(ecs: &mut World) {
315312
current: p.common.game_type,
316313
previous: p.common.previous_game_type.into(),
317314
},
318-
player_bundle,
315+
entity_bundle,
319316
));
320317

321318
azalea_entity::indexing::add_entity_to_indexes(
@@ -1433,22 +1430,19 @@ pub fn process_packet_events(ecs: &mut World) {
14331430
instance_holder.instance = weak_instance;
14341431

14351432
// this resets a bunch of our components like physics and stuff
1436-
let player_bundle = PlayerBundle {
1437-
entity: EntityBundle::new(
1438-
game_profile.uuid,
1439-
Vec3::default(),
1440-
azalea_registry::EntityKind::Player,
1441-
new_instance_name,
1442-
),
1443-
metadata: PlayerMetadataBundle::default(),
1444-
};
1433+
let entity_bundle = EntityBundle::new(
1434+
game_profile.uuid,
1435+
Vec3::default(),
1436+
azalea_registry::EntityKind::Player,
1437+
new_instance_name,
1438+
);
14451439
// update the local gamemode and metadata things
14461440
commands.entity(player_entity).insert((
14471441
LocalGameMode {
14481442
current: p.common.game_type,
14491443
previous: p.common.previous_game_type.into(),
14501444
},
1451-
player_bundle,
1445+
entity_bundle,
14521446
));
14531447
}
14541448

azalea-client/tests/simulation.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ use azalea_client::{
88
};
99
use azalea_core::{
1010
game_type::{GameMode, OptionalGameType},
11-
position::Vec3,
1211
resource_location::ResourceLocation,
1312
tick::GameTick,
1413
};
15-
use azalea_entity::{metadata::Health, LocalEntity, Position};
14+
use azalea_entity::{
15+
metadata::{Health, PlayerMetadataBundle},
16+
LocalEntity,
17+
};
1618
use azalea_protocol::packets::{
1719
common::CommonPlayerSpawnInfo,
18-
config::ClientboundFinishConfiguration,
20+
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
1921
game::{ClientboundLogin, ClientboundSetHealth},
2022
ConnectionProtocol, Packet, ProtocolPacket,
2123
};
@@ -26,6 +28,7 @@ use bevy_app::PluginGroup;
2628
use bevy_ecs::{prelude::*, schedule::ExecutorKind};
2729
use bevy_log::{tracing_subscriber, LogPlugin};
2830
use parking_lot::{Mutex, RwLock};
31+
use simdnbt::owned::{NbtCompound, NbtTag};
2932
use tokio::{sync::mpsc, time::sleep};
3033
use uuid::Uuid;
3134

@@ -36,6 +39,19 @@ fn test_set_health_before_login() {
3639
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
3740
assert!(simulation.has_component::<InConfigState>());
3841

42+
simulation.receive_packet(ClientboundRegistryData {
43+
registry_id: ResourceLocation::new("minecraft:dimension_type"),
44+
entries: vec![(
45+
ResourceLocation::new("minecraft:overworld"),
46+
Some(NbtCompound::from_values(vec![
47+
("height".into(), NbtTag::Int(384)),
48+
("min_y".into(), NbtTag::Int(-64)),
49+
])),
50+
)]
51+
.into_iter()
52+
.collect(),
53+
});
54+
simulation.tick();
3955
simulation.receive_packet(ClientboundFinishConfiguration);
4056
simulation.tick();
4157

@@ -62,7 +78,7 @@ fn test_set_health_before_login() {
6278
do_limited_crafting: false,
6379
common: CommonPlayerSpawnInfo {
6480
dimension_type: DimensionType::Overworld,
65-
dimension: ResourceLocation::new("overworld"),
81+
dimension: ResourceLocation::new("minecraft:overworld"),
6682
seed: 0,
6783
game_type: GameMode::Survival,
6884
previous_game_type: OptionalGameType(None),
@@ -124,7 +140,7 @@ pub fn create_local_player_bundle(
124140
connection_protocol,
125141
};
126142

127-
let (local_player_events_sender, local_player_events_receiver) = mpsc::unbounded_channel();
143+
let (local_player_events_sender, _local_player_events_receiver) = mpsc::unbounded_channel();
128144

129145
let instance = Instance::default();
130146
let instance_holder = InstanceHolder::new(entity, Arc::new(RwLock::new(instance)));
@@ -135,7 +151,9 @@ pub fn create_local_player_bundle(
135151
game_profile: GameProfileComponent(GameProfile::new(Uuid::nil(), "azalea".to_owned())),
136152
client_information: ClientInformation::default(),
137153
instance_holder,
154+
metadata: PlayerMetadataBundle::default(),
138155
};
156+
139157
(
140158
local_player_bundle,
141159
outgoing_packets_receiver,
@@ -144,10 +162,6 @@ pub fn create_local_player_bundle(
144162
)
145163
}
146164

147-
fn simulation_instance_name() -> ResourceLocation {
148-
ResourceLocation::new("azalea:simulation")
149-
}
150-
151165
fn create_simulation_app() -> App {
152166
let mut app = App::new();
153167
app.add_plugins(azalea_client::DefaultPlugins.build().disable::<LogPlugin>());
@@ -201,7 +215,6 @@ impl Simulation {
201215
pub fn receive_packet<P: ProtocolPacket + Debug>(&mut self, packet: impl Packet<P>) {
202216
let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap();
203217
self.incoming_packet_queue.lock().push(buf.into());
204-
println!("added to incoming_packet_queue");
205218
}
206219

207220
pub fn tick(&mut self) {
@@ -216,9 +229,6 @@ impl Simulation {
216229
pub fn has_component<T: Component>(&self) -> bool {
217230
self.app.world().get::<T>(self.entity).is_some()
218231
}
219-
pub fn position(&self) -> Vec3 {
220-
*self.component::<Position>()
221-
}
222232
}
223233

224234
fn tick_app(app: &mut App) {

azalea-entity/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,6 @@ impl EntityBundle {
478478
}
479479
}
480480

481-
/// A bundle of the components that are always present for a player.
482-
#[derive(Bundle)]
483-
pub struct PlayerBundle {
484-
pub entity: EntityBundle,
485-
pub metadata: metadata::PlayerMetadataBundle,
486-
}
487-
488481
/// A marker component that signifies that this entity is "local" and shouldn't
489482
/// be updated by other clients.
490483
///

0 commit comments

Comments
 (0)