diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-12-10 00:08:08 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-10 00:08:08 -0600 |
| commit | 348c71b97b2dfc45d7412ec33f6131e20592bb14 (patch) | |
| tree | 2490f6fe8e4d8181a526b66e0397ceea96ec8961 /azalea-entity/src/plugin | |
| parent | f15f0325c0a9d62f10ea22b891ab7134391b04fb (diff) | |
| download | azalea-drasl-348c71b97b2dfc45d7412ec33f6131e20592bb14.tar.xz | |
Climbing (#121)
* start implementing climbing
* fix tests
* fix bots running at lower tick rate
Diffstat (limited to 'azalea-entity/src/plugin')
| -rw-r--r-- | azalea-entity/src/plugin/mod.rs | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index 9950e6ba..4b6d9979 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -3,6 +3,7 @@ mod relative_updates; use std::collections::HashSet; +use azalea_block::BlockState; use azalea_core::position::{BlockPos, ChunkPos, Vec3}; use azalea_world::{InstanceContainer, InstanceName, MinecraftEntityId}; use bevy_app::{App, Plugin, PreUpdate, Update}; @@ -11,7 +12,8 @@ use derive_more::{Deref, DerefMut}; use tracing::debug; use crate::{ - metadata::Health, Dead, EyeHeight, FluidOnEyes, LocalEntity, LookDirection, Physics, Position, + metadata::Health, Dead, EyeHeight, FluidOnEyes, LocalEntity, LookDirection, OnClimbable, + Physics, Position, }; use indexing::EntityUuidIndex; @@ -48,6 +50,7 @@ impl Plugin for EntityPlugin { add_dead, clamp_look_direction, update_fluid_on_eyes, + update_on_climbable, ), ), ) @@ -106,6 +109,72 @@ pub fn update_fluid_on_eyes( } } +pub fn update_on_climbable( + mut query: Query<(&mut OnClimbable, &Position, &InstanceName)>, + instance_container: Res<InstanceContainer>, +) { + for (mut on_climbable, position, instance_name) in query.iter_mut() { + // TODO: there's currently no gamemode component that can be accessed from here, + // maybe LocalGameMode should be replaced with two components, maybe called + // EntityGameMode and PreviousGameMode? + + // if game_mode == GameMode::Spectator { + // continue; + // } + + let Some(instance) = instance_container.get(instance_name) else { + continue; + }; + + let instance = instance.read(); + + let block_pos = BlockPos::from(position); + let block_state_at_feet = instance.get_block_state(&block_pos).unwrap_or_default(); + let block_at_feet = Box::<dyn azalea_block::Block>::from(block_state_at_feet); + let registry_block_at_feet = block_at_feet.as_registry_block(); + + **on_climbable = azalea_registry::tags::blocks::CLIMBABLE.contains(®istry_block_at_feet) + || (azalea_registry::tags::blocks::TRAPDOORS.contains(®istry_block_at_feet) + && is_trapdoor_useable_as_ladder(block_state_at_feet, block_pos, &instance)); + } +} + +fn is_trapdoor_useable_as_ladder( + block_state: BlockState, + block_pos: BlockPos, + instance: &azalea_world::Instance, +) -> bool { + // trapdoor must be open + if !block_state + .property::<azalea_block::properties::Open>() + .unwrap_or_default() + { + return false; + } + + // block below must be a ladder + let block_below = instance + .get_block_state(&block_pos.down(1)) + .unwrap_or_default(); + let registry_block_below = + Box::<dyn azalea_block::Block>::from(block_below).as_registry_block(); + if registry_block_below != azalea_registry::Block::Ladder { + return false; + } + // and the ladder must be facing the same direction as the trapdoor + let ladder_facing = block_below + .property::<azalea_block::properties::Facing>() + .expect("ladder block must have facing property"); + let trapdoor_facing = block_state + .property::<azalea_block::properties::Facing>() + .expect("trapdoor block must have facing property"); + if ladder_facing != trapdoor_facing { + return false; + } + + true +} + /// A component that lists all the local player entities that have this entity /// loaded. If this is empty, the entity will be removed from the ECS. #[derive(Component, Clone, Deref, DerefMut)] |
