mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use azalea_client::{InConfigState, test_simulation::*};
|
|
use azalea_core::resource_location::ResourceLocation;
|
|
use azalea_entity::{LocalEntity, metadata::Health};
|
|
use azalea_protocol::packets::{
|
|
ConnectionProtocol,
|
|
config::{ClientboundFinishConfiguration, ClientboundRegistryData},
|
|
game::ClientboundSetHealth,
|
|
};
|
|
use azalea_registry::{DataRegistry, DimensionType};
|
|
use bevy_log::tracing_subscriber;
|
|
use simdnbt::owned::{NbtCompound, NbtTag};
|
|
|
|
#[test]
|
|
fn test_set_health_before_login() {
|
|
let _ = tracing_subscriber::fmt::try_init();
|
|
|
|
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();
|
|
|
|
assert!(!simulation.has_component::<InConfigState>());
|
|
assert!(simulation.has_component::<LocalEntity>());
|
|
|
|
simulation.receive_packet(ClientboundSetHealth {
|
|
health: 15.,
|
|
food: 20,
|
|
saturation: 20.,
|
|
});
|
|
simulation.tick();
|
|
assert_eq!(*simulation.component::<Health>(), 15.);
|
|
|
|
simulation.receive_packet(make_basic_login_packet(
|
|
DimensionType::new_raw(0), // overworld
|
|
ResourceLocation::new("minecraft:overworld"),
|
|
));
|
|
simulation.tick();
|
|
|
|
// health should stay the same
|
|
assert_eq!(*simulation.component::<Health>(), 15.);
|
|
}
|