From f8cca413613918a59520ac62c188e194fa27b300 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 11 Sep 2023 22:58:54 -0500 Subject: fix falling through blocks on spawn (and triggering anticheats) --- azalea-entity/src/plugin/mod.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'azalea-entity/src/plugin') diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index 94e8e79d..6153ac17 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -3,9 +3,9 @@ mod relative_updates; use std::collections::HashSet; -use azalea_core::{BlockPos, Vec3}; +use azalea_core::{BlockPos, ChunkPos, Vec3}; use azalea_world::{InstanceContainer, InstanceName, MinecraftEntityId}; -use bevy_app::{App, Plugin, PostUpdate, PreUpdate, Update}; +use bevy_app::{App, FixedUpdate, Plugin, PostUpdate, PreUpdate, Update}; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; use log::debug; @@ -68,6 +68,7 @@ impl Plugin for EntityPlugin { ), ) .add_systems(Update, update_bounding_box) + .add_systems(FixedUpdate, update_in_loaded_chunk) .init_resource::(); } } @@ -144,3 +145,29 @@ pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed

, + instance_container: Res, +) { + for (entity, instance_name, position) in &query { + let player_chunk_pos = ChunkPos::from(position); + let Some(instance_lock) = instance_container.get(instance_name) else { + continue; + }; + + let in_loaded_chunk = instance_lock.read().chunks.get(&player_chunk_pos).is_some(); + if in_loaded_chunk { + commands.entity(entity).insert(InLoadedChunk); + } else { + commands.entity(entity).remove::(); + } + } +} -- cgit v1.2.3