mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
set player metadata on init instead of login
This commit is contained in:
parent
87c34e1c33
commit
4562967b61
4 changed files with 42 additions and 42 deletions
|
@ -325,6 +325,7 @@ impl Client {
|
|||
game_profile: GameProfileComponent(game_profile),
|
||||
client_information: crate::ClientInformation::default(),
|
||||
instance_holder,
|
||||
metadata: azalea_entity::metadata::PlayerMetadataBundle::default(),
|
||||
},
|
||||
InConfigState,
|
||||
));
|
||||
|
@ -729,6 +730,8 @@ pub struct LocalPlayerBundle {
|
|||
pub game_profile: GameProfileComponent,
|
||||
pub client_information: ClientInformation,
|
||||
pub instance_holder: InstanceHolder,
|
||||
|
||||
pub metadata: azalea_entity::metadata::PlayerMetadataBundle,
|
||||
}
|
||||
|
||||
/// A bundle for the components that are present on a local player that is
|
||||
|
|
|
@ -14,9 +14,9 @@ use azalea_core::{
|
|||
};
|
||||
use azalea_entity::{
|
||||
indexing::{EntityIdIndex, EntityUuidIndex},
|
||||
metadata::{apply_metadata, Health, PlayerMetadataBundle},
|
||||
metadata::{apply_metadata, Health},
|
||||
Dead, EntityBundle, EntityKind, LastSentPosition, LoadedBy, LocalEntity, LookDirection,
|
||||
Physics, PlayerBundle, Position, RelativeEntityUpdate,
|
||||
Physics, Position, RelativeEntityUpdate,
|
||||
};
|
||||
use azalea_protocol::{
|
||||
packets::{
|
||||
|
@ -298,15 +298,12 @@ pub fn process_packet_events(ecs: &mut World) {
|
|||
}
|
||||
instance_holder.instance = weak_instance;
|
||||
|
||||
let player_bundle = PlayerBundle {
|
||||
entity: EntityBundle::new(
|
||||
game_profile.uuid,
|
||||
Vec3::default(),
|
||||
azalea_registry::EntityKind::Player,
|
||||
new_instance_name,
|
||||
),
|
||||
metadata: PlayerMetadataBundle::default(),
|
||||
};
|
||||
let entity_bundle = EntityBundle::new(
|
||||
game_profile.uuid,
|
||||
Vec3::default(),
|
||||
azalea_registry::EntityKind::Player,
|
||||
new_instance_name,
|
||||
);
|
||||
let entity_id = MinecraftEntityId(p.player_id);
|
||||
// insert our components into the ecs :)
|
||||
commands.entity(player_entity).insert((
|
||||
|
@ -315,7 +312,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
|||
current: p.common.game_type,
|
||||
previous: p.common.previous_game_type.into(),
|
||||
},
|
||||
player_bundle,
|
||||
entity_bundle,
|
||||
));
|
||||
|
||||
azalea_entity::indexing::add_entity_to_indexes(
|
||||
|
@ -1433,22 +1430,19 @@ pub fn process_packet_events(ecs: &mut World) {
|
|||
instance_holder.instance = weak_instance;
|
||||
|
||||
// this resets a bunch of our components like physics and stuff
|
||||
let player_bundle = PlayerBundle {
|
||||
entity: EntityBundle::new(
|
||||
game_profile.uuid,
|
||||
Vec3::default(),
|
||||
azalea_registry::EntityKind::Player,
|
||||
new_instance_name,
|
||||
),
|
||||
metadata: PlayerMetadataBundle::default(),
|
||||
};
|
||||
let entity_bundle = EntityBundle::new(
|
||||
game_profile.uuid,
|
||||
Vec3::default(),
|
||||
azalea_registry::EntityKind::Player,
|
||||
new_instance_name,
|
||||
);
|
||||
// update the local gamemode and metadata things
|
||||
commands.entity(player_entity).insert((
|
||||
LocalGameMode {
|
||||
current: p.common.game_type,
|
||||
previous: p.common.previous_game_type.into(),
|
||||
},
|
||||
player_bundle,
|
||||
entity_bundle,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,14 +8,16 @@ use azalea_client::{
|
|||
};
|
||||
use azalea_core::{
|
||||
game_type::{GameMode, OptionalGameType},
|
||||
position::Vec3,
|
||||
resource_location::ResourceLocation,
|
||||
tick::GameTick,
|
||||
};
|
||||
use azalea_entity::{metadata::Health, LocalEntity, Position};
|
||||
use azalea_entity::{
|
||||
metadata::{Health, PlayerMetadataBundle},
|
||||
LocalEntity,
|
||||
};
|
||||
use azalea_protocol::packets::{
|
||||
common::CommonPlayerSpawnInfo,
|
||||
config::ClientboundFinishConfiguration,
|
||||
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
|
||||
game::{ClientboundLogin, ClientboundSetHealth},
|
||||
ConnectionProtocol, Packet, ProtocolPacket,
|
||||
};
|
||||
|
@ -26,6 +28,7 @@ use bevy_app::PluginGroup;
|
|||
use bevy_ecs::{prelude::*, schedule::ExecutorKind};
|
||||
use bevy_log::{tracing_subscriber, LogPlugin};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use simdnbt::owned::{NbtCompound, NbtTag};
|
||||
use tokio::{sync::mpsc, time::sleep};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -36,6 +39,19 @@ fn test_set_health_before_login() {
|
|||
let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
|
||||
assert!(simulation.has_component::<InConfigState>());
|
||||
|
||||
simulation.receive_packet(ClientboundRegistryData {
|
||||
registry_id: ResourceLocation::new("minecraft:dimension_type"),
|
||||
entries: vec![(
|
||||
ResourceLocation::new("minecraft:overworld"),
|
||||
Some(NbtCompound::from_values(vec![
|
||||
("height".into(), NbtTag::Int(384)),
|
||||
("min_y".into(), NbtTag::Int(-64)),
|
||||
])),
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
});
|
||||
simulation.tick();
|
||||
simulation.receive_packet(ClientboundFinishConfiguration);
|
||||
simulation.tick();
|
||||
|
||||
|
@ -62,7 +78,7 @@ fn test_set_health_before_login() {
|
|||
do_limited_crafting: false,
|
||||
common: CommonPlayerSpawnInfo {
|
||||
dimension_type: DimensionType::Overworld,
|
||||
dimension: ResourceLocation::new("overworld"),
|
||||
dimension: ResourceLocation::new("minecraft:overworld"),
|
||||
seed: 0,
|
||||
game_type: GameMode::Survival,
|
||||
previous_game_type: OptionalGameType(None),
|
||||
|
@ -124,7 +140,7 @@ pub fn create_local_player_bundle(
|
|||
connection_protocol,
|
||||
};
|
||||
|
||||
let (local_player_events_sender, local_player_events_receiver) = mpsc::unbounded_channel();
|
||||
let (local_player_events_sender, _local_player_events_receiver) = mpsc::unbounded_channel();
|
||||
|
||||
let instance = Instance::default();
|
||||
let instance_holder = InstanceHolder::new(entity, Arc::new(RwLock::new(instance)));
|
||||
|
@ -135,7 +151,9 @@ pub fn create_local_player_bundle(
|
|||
game_profile: GameProfileComponent(GameProfile::new(Uuid::nil(), "azalea".to_owned())),
|
||||
client_information: ClientInformation::default(),
|
||||
instance_holder,
|
||||
metadata: PlayerMetadataBundle::default(),
|
||||
};
|
||||
|
||||
(
|
||||
local_player_bundle,
|
||||
outgoing_packets_receiver,
|
||||
|
@ -144,10 +162,6 @@ pub fn create_local_player_bundle(
|
|||
)
|
||||
}
|
||||
|
||||
fn simulation_instance_name() -> ResourceLocation {
|
||||
ResourceLocation::new("azalea:simulation")
|
||||
}
|
||||
|
||||
fn create_simulation_app() -> App {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(azalea_client::DefaultPlugins.build().disable::<LogPlugin>());
|
||||
|
@ -201,7 +215,6 @@ impl Simulation {
|
|||
pub fn receive_packet<P: ProtocolPacket + Debug>(&mut self, packet: impl Packet<P>) {
|
||||
let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap();
|
||||
self.incoming_packet_queue.lock().push(buf.into());
|
||||
println!("added to incoming_packet_queue");
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
|
@ -216,9 +229,6 @@ impl Simulation {
|
|||
pub fn has_component<T: Component>(&self) -> bool {
|
||||
self.app.world().get::<T>(self.entity).is_some()
|
||||
}
|
||||
pub fn position(&self) -> Vec3 {
|
||||
*self.component::<Position>()
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_app(app: &mut App) {
|
||||
|
|
|
@ -478,13 +478,6 @@ impl EntityBundle {
|
|||
}
|
||||
}
|
||||
|
||||
/// A bundle of the components that are always present for a player.
|
||||
#[derive(Bundle)]
|
||||
pub struct PlayerBundle {
|
||||
pub entity: EntityBundle,
|
||||
pub metadata: metadata::PlayerMetadataBundle,
|
||||
}
|
||||
|
||||
/// A marker component that signifies that this entity is "local" and shouldn't
|
||||
/// be updated by other clients.
|
||||
///
|
||||
|
|
Loading…
Add table
Reference in a new issue