aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-09-11 22:58:54 -0500
committermat <git@matdoes.dev>2023-09-11 22:59:05 -0500
commitf8cca413613918a59520ac62c188e194fa27b300 (patch)
treecf15ef4426a3896c20ceeec530d66e7aa599ae5d /azalea-client/src
parentbcefa64dd192918cfeb1bba27cb4993bec6a17e3 (diff)
downloadazalea-drasl-f8cca413613918a59520ac62c188e194fa27b300.tar.xz
fix falling through blocks on spawn (and triggering anticheats)
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/client.rs5
-rw-r--r--azalea-client/src/lib.rs2
-rw-r--r--azalea-client/src/local_player.rs40
-rw-r--r--azalea-client/src/movement.rs8
-rw-r--r--azalea-client/src/packet_handling.rs24
5 files changed, 30 insertions, 49 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 517db4e9..332db1f1 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -6,8 +6,8 @@ use crate::{
interact::{CurrentSequenceNumber, InteractPlugin},
inventory::{InventoryComponent, InventoryPlugin},
local_player::{
- death_event, handle_send_packet_event, update_in_loaded_chunk, GameProfileComponent,
- Hunger, LocalPlayer, SendPacketEvent,
+ death_event, handle_send_packet_event, GameProfileComponent, Hunger, LocalPlayer,
+ SendPacketEvent,
},
mining::{self, MinePlugin},
movement::{LastSentLookDirection, PhysicsState, PlayerMovePlugin},
@@ -617,7 +617,6 @@ impl Plugin for AzaleaPlugin {
.add_systems(
Update,
(
- update_in_loaded_chunk,
// fire the Death event when the player dies.
death_event,
// add GameProfileComponent when we get an AddPlayerEvent
diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs
index 4cb1eebf..8ea2fc41 100644
--- a/azalea-client/src/lib.rs
+++ b/azalea-client/src/lib.rs
@@ -36,7 +36,7 @@ pub use client::{
TickBroadcast,
};
pub use events::Event;
-pub use local_player::{GameProfileComponent, LocalPlayer, LocalPlayerInLoadedChunk};
+pub use local_player::{GameProfileComponent, LocalPlayer};
pub use movement::{
PhysicsState, SprintDirection, StartSprintEvent, StartWalkEvent, WalkDirection,
};
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index 682fc0c9..0c89b4a7 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -1,17 +1,13 @@
use std::{io, sync::Arc};
use azalea_auth::game_profile::GameProfile;
-use azalea_core::{ChunkPos, GameMode};
-use azalea_entity::{Dead, Position};
+use azalea_core::GameMode;
+use azalea_entity::Dead;
use azalea_protocol::packets::game::ServerboundGamePacket;
-use azalea_world::{Instance, InstanceContainer, InstanceName, PartialInstance};
+use azalea_world::{Instance, PartialInstance};
use bevy_ecs::{
- component::Component,
- entity::Entity,
- event::EventReader,
- prelude::Event,
- query::Added,
- system::{Query, Res},
+ component::Component, entity::Entity, event::EventReader, prelude::Event, query::Added,
+ system::Query,
};
use derive_more::{Deref, DerefMut};
use parking_lot::RwLock;
@@ -59,11 +55,6 @@ pub struct LocalPlayer {
#[derive(Component, Clone, Debug, Deref, DerefMut)]
pub struct GameProfileComponent(pub GameProfile);
-/// Marks a [`LocalPlayer`] that's in a loaded chunk. This is updated at the
-/// beginning of every tick.
-#[derive(Component, Clone, Debug, Copy)]
-pub struct LocalPlayerInLoadedChunk;
-
/// The gamemode of a local player. For a non-local player, you can look up the
/// player in the [`TabList`].
#[derive(Component, Clone, Debug, Copy)]
@@ -134,27 +125,6 @@ impl Drop for LocalPlayer {
}
}
-/// Update the [`LocalPlayerInLoadedChunk`] component for all [`LocalPlayer`]s.
-pub fn update_in_loaded_chunk(
- mut commands: bevy_ecs::system::Commands,
- query: Query<(Entity, &InstanceName, &Position)>,
- instance_container: Res<InstanceContainer>,
-) {
- for (entity, local_player, position) in &query {
- let player_chunk_pos = ChunkPos::from(position);
- let Some(instance_lock) = instance_container.get(local_player) else {
- continue;
- };
-
- let in_loaded_chunk = instance_lock.read().chunks.get(&player_chunk_pos).is_some();
- if in_loaded_chunk {
- commands.entity(entity).insert(LocalPlayerInLoadedChunk);
- } else {
- commands.entity(entity).remove::<LocalPlayerInLoadedChunk>();
- }
- }
-}
-
/// Send the "Death" event for [`LocalPlayer`]s that died with no reason.
pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) {
for local_player_events in &query {
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index 351d91be..47cbd0ac 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -1,7 +1,7 @@
use crate::client::Client;
-use crate::local_player::{LocalPlayer, LocalPlayerInLoadedChunk};
+use crate::local_player::LocalPlayer;
use azalea_entity::{metadata::Sprinting, Attributes, Jumping};
-use azalea_entity::{LastSentPosition, LookDirection, Physics, Position};
+use azalea_entity::{InLoadedChunk, LastSentPosition, LookDirection, Physics, Position};
use azalea_physics::PhysicsSet;
use azalea_protocol::packets::game::serverbound_player_command_packet::ServerboundPlayerCommandPacket;
use azalea_protocol::packets::game::{
@@ -128,7 +128,7 @@ pub fn send_position(
&mut LastSentLookDirection,
&Sprinting,
),
- &LocalPlayerInLoadedChunk,
+ With<InLoadedChunk>,
>,
) {
for (
@@ -302,7 +302,7 @@ pub fn local_player_ai_step(
&mut Sprinting,
&mut Attributes,
),
- With<LocalPlayerInLoadedChunk>,
+ With<InLoadedChunk>,
>,
) {
for (mut physics_state, mut physics, mut sprinting, mut attributes) in query.iter_mut() {
diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs
index 605da379..c2a01659 100644
--- a/azalea-client/src/packet_handling.rs
+++ b/azalea-client/src/packet_handling.rs
@@ -709,14 +709,18 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::TeleportEntity(p) => {
let mut system_state: SystemState<(
Commands,
- Query<(&EntityIdIndex, &LocalPlayer)>,
+ Query<(&EntityIdIndex, &LocalPlayer, Option<&mut Physics>)>,
)> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs);
- let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
+ let (entity_id_index, local_player, physics) =
+ query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.id));
if let Some(entity) = entity {
+ if let Some(mut physics) = physics {
+ physics.on_ground = p.on_ground;
+ }
let new_position = p.position;
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: local_player.partial_instance.clone(),
@@ -740,14 +744,18 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::MoveEntityPos(p) => {
let mut system_state: SystemState<(
Commands,
- Query<(&EntityIdIndex, &LocalPlayer)>,
+ Query<(&EntityIdIndex, &LocalPlayer, Option<&mut Physics>)>,
)> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs);
- let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
+ let (entity_id_index, local_player, physics) =
+ query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));
if let Some(entity) = entity {
+ if let Some(mut physics) = physics {
+ physics.on_ground = p.on_ground;
+ }
let delta = p.delta.clone();
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: local_player.partial_instance.clone(),
@@ -768,14 +776,18 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::MoveEntityPosRot(p) => {
let mut system_state: SystemState<(
Commands,
- Query<(&EntityIdIndex, &LocalPlayer)>,
+ Query<(&EntityIdIndex, &LocalPlayer, Option<&mut Physics>)>,
)> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs);
- let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
+ let (entity_id_index, local_player, physics) =
+ query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));
if let Some(entity) = entity {
+ if let Some(mut physics) = physics {
+ physics.on_ground = p.on_ground;
+ }
let delta = p.delta.clone();
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: local_player.partial_instance.clone(),