|
|
|
@ -4,17 +4,12 @@ use std::{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crate::utils::get_death_message;
|
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
use valence::bevy_ecs;
|
|
|
|
|
use valence::{
|
|
|
|
|
entity::{living::Health, player::PlayerEntityBundle, EntityId},
|
|
|
|
|
packet::WritePacket,
|
|
|
|
|
prelude::{event::PerformRespawn, *},
|
|
|
|
|
};
|
|
|
|
|
use valence::{bevy_ecs, client::misc::Respawn};
|
|
|
|
|
use valence::{entity::living::Health, packet::WritePacket, prelude::*};
|
|
|
|
|
use valence_protocol::{
|
|
|
|
|
packet::s2c::play::{
|
|
|
|
|
synchronize_tags::{Tag, TagGroup},
|
|
|
|
|
ChunkRenderDistanceCenterS2c, SynchronizeTagsS2c,
|
|
|
|
|
ChunkRenderDistanceCenterS2c, DamageTiltS2c, SynchronizeTagsS2c,
|
|
|
|
|
},
|
|
|
|
|
var_int::VarInt,
|
|
|
|
|
Encode,
|
|
|
|
@ -33,37 +28,32 @@ pub fn init_clients(
|
|
|
|
|
(
|
|
|
|
|
&mut Position,
|
|
|
|
|
Entity,
|
|
|
|
|
&UniqueId,
|
|
|
|
|
&mut Client,
|
|
|
|
|
&mut GameMode,
|
|
|
|
|
&Username,
|
|
|
|
|
&mut HasRespawnScreen,
|
|
|
|
|
&mut Location,
|
|
|
|
|
),
|
|
|
|
|
Added<Client>,
|
|
|
|
|
>,
|
|
|
|
|
instances: Query<Entity, With<Instance>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
for (_pos, entity, uuid, mut client, mut game_mode, username, mut has_respawn_screen) in
|
|
|
|
|
for (mut pos, entity, mut client, mut game_mode, username, mut has_respawn_screen, mut loc) in
|
|
|
|
|
&mut new_clients
|
|
|
|
|
{
|
|
|
|
|
// initialize client
|
|
|
|
|
has_respawn_screen.0 = true;
|
|
|
|
|
*game_mode = GameMode::Creative;
|
|
|
|
|
commands.entity(entity).insert((
|
|
|
|
|
OldHeight(-1.0),
|
|
|
|
|
Alive(true),
|
|
|
|
|
PlayerEntityBundle {
|
|
|
|
|
location: Location(instances.single()),
|
|
|
|
|
position: Position(DVec3 {
|
|
|
|
|
x: -214.0,
|
|
|
|
|
y: 83.0,
|
|
|
|
|
z: 276.0,
|
|
|
|
|
}),
|
|
|
|
|
uuid: *uuid,
|
|
|
|
|
..Default::default()
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
loc.0 = instances.single();
|
|
|
|
|
pos.set(DVec3 {
|
|
|
|
|
x: -214.0,
|
|
|
|
|
y: 83.0,
|
|
|
|
|
z: 276.0,
|
|
|
|
|
});
|
|
|
|
|
commands
|
|
|
|
|
.entity(entity)
|
|
|
|
|
.insert((OldHeight(-1.0), Alive(true)));
|
|
|
|
|
|
|
|
|
|
// send packet that magically fixes chunks
|
|
|
|
|
// TODO: make this configurable as different maps will have different chunks we need to force load
|
|
|
|
@ -107,6 +97,13 @@ pub fn init_clients(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn apply_damage_tilt(mut client: Mut<Client>) {
|
|
|
|
|
client.write_packet(&DamageTiltS2c {
|
|
|
|
|
entity_id: VarInt(0),
|
|
|
|
|
yaw: 0.0,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn fall_damage(
|
|
|
|
|
mut clients: Query<
|
|
|
|
|
(
|
|
|
|
@ -122,8 +119,7 @@ pub fn fall_damage(
|
|
|
|
|
instances: Query<&Instance>,
|
|
|
|
|
) {
|
|
|
|
|
let instance = instances.single();
|
|
|
|
|
for (_client, on_ground, mut health, gamemode, position, mut historical_position) in
|
|
|
|
|
&mut clients
|
|
|
|
|
for (client, on_ground, mut health, gamemode, position, mut historical_position) in &mut clients
|
|
|
|
|
{
|
|
|
|
|
let current_block = instance
|
|
|
|
|
.block(BlockPos {
|
|
|
|
@ -146,6 +142,7 @@ pub fn fall_damage(
|
|
|
|
|
if on_ground.0 {
|
|
|
|
|
if delta_y > 3.0 {
|
|
|
|
|
health.0 -= (delta_y - 3.0) as f32;
|
|
|
|
|
apply_damage_tilt(client);
|
|
|
|
|
}
|
|
|
|
|
historical_position.0 = position.0.y;
|
|
|
|
|
} else if delta_y < 0.0 {
|
|
|
|
@ -199,7 +196,7 @@ pub fn respawn(
|
|
|
|
|
&mut Health,
|
|
|
|
|
&mut Alive,
|
|
|
|
|
)>,
|
|
|
|
|
mut events: EventReader<PerformRespawn>,
|
|
|
|
|
mut events: EventReader<Respawn>,
|
|
|
|
|
instances: Query<Entity, With<Instance>>,
|
|
|
|
|
) {
|
|
|
|
|
for event in events.iter() {
|
|
|
|
|