Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ is breaking anyways, semantic versioning is not followed.
- Local clients now have a `TicksConnected` component. (@Kumpelinus)
- There is now a `azalea_inventory::default_components::get_default_component` function to get the default value of a component for a registry item.
- `ItemStack` now has a `get_component` function that supports default components.
- Add `Client::nearest_entity_by`.
- `Client::nearest_entity_by`.
- Sneaking/crouching.

### Changed

Expand All @@ -26,13 +27,15 @@ is breaking anyways, semantic versioning is not followed.
- `ItemStackData::components` was renamed to `component_patch`.
- The fields in `LookDirection` have been replaced with getters.
- Renamed `Client::entity_by` to `any_entity_by`, and `Client::entities_by` to `nearest_entities_by`.
- `EyeHeight` was moved into `EntityDimensions`, and `EntityDimensions` is now its own component.

### Fixed

- Fix packet order for loading (`PlayerLoaded`/`MovePlayerPos`) and sprinting (`PlayerInput`/`PlayerCommand`).
- Clients no longer send invalid look directions if the server teleports us with one.
- Look directions are now rounded based on the default Minecraft sensitivity, which may help avoid flagging anticheats.
- Movement code was updated with the changes from 1.21.5, so it no longer flags Grim.
- Clients can no longer sprint if their food level is too low.
- `azalea-chat` now handles arrays of integers in the `with` field. (@qwqawawow)
- `azalea-chat` no longer incorrectly persists styles of components in the "extra" field.
- Inventories now use the correct max stack sizes.
Expand Down
13 changes: 12 additions & 1 deletion azalea-brigadier/src/builder/argument_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl<S> Clone for ArgumentBuilderType<S> {
}

/// A node that hasn't yet been built.
#[derive(Clone)]
pub struct ArgumentBuilder<S> {
arguments: CommandNode<S>,

Expand Down Expand Up @@ -196,3 +195,15 @@ impl<S> Debug for ArgumentBuilder<S> {
.finish()
}
}
impl<S> Clone for ArgumentBuilder<S> {
fn clone(&self) -> Self {
Self {
arguments: self.arguments.clone(),
command: self.command.clone(),
requirement: self.requirement.clone(),
target: self.target.clone(),
forks: self.forks,
modifier: self.modifier.clone(),
}
}
}
21 changes: 16 additions & 5 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ use azalea_core::{
tick::GameTick,
};
use azalea_entity::{
EntityUpdateSet, EyeHeight, Position,
EntityUpdateSet, PlayerAbilities, Position,
dimensions::EntityDimensions,
indexing::{EntityIdIndex, EntityUuidIndex},
metadata::Health,
};
use azalea_physics::local_player::PhysicsState;
use azalea_protocol::{
ServerAddress,
common::client_information::ClientInformation,
Expand Down Expand Up @@ -55,9 +57,9 @@ use crate::{
interact::BlockStatePredictionHandler,
inventory::Inventory,
join::{ConnectOpts, StartJoinServerEvent},
local_player::{Hunger, InstanceHolder, PermissionLevel, PlayerAbilities, TabList},
local_player::{Hunger, InstanceHolder, PermissionLevel, TabList},
mining::{self},
movement::{LastSentLookDirection, PhysicsState},
movement::LastSentLookDirection,
packet::game::SendPacketEvent,
player::{GameProfileComponent, PlayerInfo, retroactively_add_game_profile_component},
};
Expand Down Expand Up @@ -427,12 +429,21 @@ impl Client {
)
}

/// Get the bounding box dimensions for our client, which contains our
/// width, height, and eye height.
///
/// This is a shortcut for
/// `self.component::<EntityDimensions>()`.
pub fn dimensions(&self) -> EntityDimensions {
self.component::<EntityDimensions>()
}

/// Get the position of this client's eyes.
///
/// This is a shortcut for
/// `bot.position().up(bot.component::<EyeHeight>())`.
/// `bot.position().up(bot.dimensions().eye_height)`.
pub fn eye_position(&self) -> Vec3 {
self.position().up((*self.component::<EyeHeight>()) as f64)
self.position().up(self.dimensions().eye_height as f64)
}

/// Get the health of this client.
Expand Down
5 changes: 2 additions & 3 deletions azalea-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod plugins;
pub mod test_utils;

pub use account::{Account, AccountOpts};
pub use azalea_physics::local_player::{PhysicsState, SprintDirection, WalkDirection};
pub use azalea_protocol::common::client_information::ClientInformation;
// Re-export bevy-tasks so plugins can make sure that they're using the same
// version.
Expand All @@ -30,7 +31,5 @@ pub use client::{
StartClientOpts, start_ecs_runner,
};
pub use events::Event;
pub use movement::{
PhysicsState, SprintDirection, StartSprintEvent, StartWalkEvent, WalkDirection,
};
pub use movement::{StartSprintEvent, StartWalkEvent};
pub use plugins::*;
38 changes: 9 additions & 29 deletions azalea-client/src/local_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};

use azalea_core::game_type::GameMode;
use azalea_protocol::packets::game::c_player_abilities::ClientboundPlayerAbilities;
use azalea_world::{Instance, PartialInstance};
use bevy_ecs::{component::Component, prelude::*};
use derive_more::{Deref, DerefMut};
Expand Down Expand Up @@ -55,34 +54,6 @@ impl From<GameMode> for LocalGameMode {
}
}

/// A component that contains the abilities the player has, like flying
/// or instantly breaking blocks. This is only present on local players.
#[derive(Clone, Debug, Component, Default)]
pub struct PlayerAbilities {
pub invulnerable: bool,
pub flying: bool,
pub can_fly: bool,
/// Whether the player can instantly break blocks and can duplicate blocks
/// in their inventory.
pub instant_break: bool,

pub flying_speed: f32,
/// Used for the fov
pub walking_speed: f32,
}
impl From<&ClientboundPlayerAbilities> for PlayerAbilities {
fn from(packet: &ClientboundPlayerAbilities) -> Self {
Self {
invulnerable: packet.flags.invulnerable,
flying: packet.flags.flying,
can_fly: packet.flags.can_fly,
instant_break: packet.flags.instant_break,
flying_speed: packet.flying_speed,
walking_speed: packet.walking_speed,
}
}
}

/// Level must be 0..=4
#[derive(Component, Clone, Default, Deref, DerefMut)]
pub struct PermissionLevel(pub u8);
Expand Down Expand Up @@ -127,6 +98,15 @@ impl Default for Hunger {
}
}
}
impl Hunger {
/// Returns true if we have enough food level to sprint.
///
/// Note that this doesn't consider our gamemode or passenger status.
pub fn is_enough_to_sprint(&self) -> bool {
// hasEnoughFoodToSprint
self.food >= 6
}
}

impl InstanceHolder {
/// Create a new `InstanceHolder` for the given entity.
Expand Down
10 changes: 4 additions & 6 deletions azalea-client/src/plugins/attack.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use azalea_core::{game_type::GameMode, tick::GameTick};
use azalea_entity::{
Attributes, Physics,
indexing::EntityIdIndex,
metadata::{ShiftKeyDown, Sprinting},
Attributes, Crouching, Physics, indexing::EntityIdIndex, metadata::Sprinting,
update_bounding_box,
};
use azalea_physics::PhysicsSet;
Expand Down Expand Up @@ -100,7 +98,7 @@ pub fn handle_attack_queued(
&mut Sprinting,
&AttackQueued,
&LocalGameMode,
&ShiftKeyDown,
&Crouching,
&EntityIdIndex,
)>,
) {
Expand All @@ -111,7 +109,7 @@ pub fn handle_attack_queued(
mut sprinting,
attack_queued,
game_mode,
sneaking,
crouching,
entity_id_index,
) in &mut query
{
Expand All @@ -128,7 +126,7 @@ pub fn handle_attack_queued(
ServerboundInteract {
entity_id: target_entity_id,
action: s_interact::ActionType::Attack,
using_secondary_action: **sneaking,
using_secondary_action: **crouching,
},
));
commands.trigger(SwingArmEvent {
Expand Down
19 changes: 13 additions & 6 deletions azalea-client/src/plugins/interact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use azalea_core::{
tick::GameTick,
};
use azalea_entity::{
Attributes, LocalEntity, LookDirection,
Attributes, Crouching, LocalEntity, LookDirection, PlayerAbilities,
attributes::{
creative_block_interaction_range_modifier, creative_entity_interaction_range_modifier,
},
Expand All @@ -36,7 +36,7 @@ use crate::{
attack::handle_attack_event,
interact::pick::{HitResultComponent, update_hit_result_component},
inventory::{Inventory, InventorySet},
local_player::{LocalGameMode, PermissionLevel, PlayerAbilities},
local_player::{LocalGameMode, PermissionLevel},
movement::MoveEventsSet,
packet::game::SendPacketEvent,
respawn::perform_respawn,
Expand Down Expand Up @@ -250,12 +250,20 @@ pub fn handle_start_use_item_queued(
&mut BlockStatePredictionHandler,
&HitResultComponent,
&LookDirection,
&Crouching,
Option<&Mining>,
)>,
entity_id_query: Query<&MinecraftEntityId>,
) {
for (entity, start_use_item, mut prediction_handler, hit_result, look_direction, mining) in
query
for (
entity,
start_use_item,
mut prediction_handler,
hit_result,
look_direction,
crouching,
mining,
) in query
{
commands.entity(entity).remove::<StartUseItemQueued>();

Expand Down Expand Up @@ -332,8 +340,7 @@ pub fn handle_start_use_item_queued(
location: r.location,
hand: InteractionHand::MainHand,
},
// TODO: sneaking
using_secondary_action: false,
using_secondary_action: **crouching,
},
));
}
Expand Down
9 changes: 5 additions & 4 deletions azalea-client/src/plugins/interact/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use azalea_core::{
position::Vec3,
};
use azalea_entity::{
Attributes, Dead, EyeHeight, LocalEntity, LookDirection, Physics, Position,
Attributes, Dead, LocalEntity, LookDirection, Physics, Position,
dimensions::EntityDimensions,
metadata::{ArmorStandMarker, Marker},
view_vector,
};
Expand All @@ -31,7 +32,7 @@ pub fn update_hit_result_component(
Entity,
Option<&mut HitResultComponent>,
&Position,
&EyeHeight,
&EntityDimensions,
&LookDirection,
&InstanceName,
&Physics,
Expand All @@ -47,7 +48,7 @@ pub fn update_hit_result_component(
entity,
hit_result_ref,
position,
eye_height,
dimensions,
look_direction,
world_name,
physics,
Expand All @@ -57,7 +58,7 @@ pub fn update_hit_result_component(
let block_pick_range = attributes.block_interaction_range.calculate();
let entity_pick_range = attributes.entity_interaction_range.calculate();

let eye_position = position.up(eye_height.into());
let eye_position = position.up(dimensions.eye_height.into());

let Some(world_lock) = instance_container.get(world_name) else {
continue;
Expand Down
5 changes: 2 additions & 3 deletions azalea-client/src/plugins/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
};

use azalea_chat::FormattedText;
use azalea_entity::PlayerAbilities;
pub use azalea_inventory::*;
use azalea_inventory::{
item::MaxStackSizeExt,
Expand All @@ -23,9 +24,7 @@ use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use tracing::{error, warn};

use crate::{
Client, local_player::PlayerAbilities, packet::game::SendPacketEvent, respawn::perform_respawn,
};
use crate::{Client, packet::game::SendPacketEvent, respawn::perform_respawn};

pub struct InventoryPlugin;
impl Plugin for InventoryPlugin {
Expand Down
5 changes: 2 additions & 3 deletions azalea-client/src/plugins/mining.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use azalea_block::{BlockState, BlockTrait, fluid_state::FluidState};
use azalea_core::{direction::Direction, game_type::GameMode, position::BlockPos, tick::GameTick};
use azalea_entity::{FluidOnEyes, Physics, Position, mining::get_mine_progress};
use azalea_entity::{FluidOnEyes, Physics, PlayerAbilities, Position, mining::get_mine_progress};
use azalea_inventory::ItemStack;
use azalea_physics::{PhysicsSet, collision::BlockWithShape};
use azalea_protocol::packets::game::s_player_action::{self, ServerboundPlayerAction};
Expand All @@ -17,7 +17,7 @@ use crate::{
check_is_interaction_restricted, pick::HitResultComponent,
},
inventory::{Inventory, InventorySet},
local_player::{InstanceHolder, LocalGameMode, PermissionLevel, PlayerAbilities},
local_player::{InstanceHolder, LocalGameMode, PermissionLevel},
movement::MoveEventsSet,
packet::game::SendPacketEvent,
};
Expand Down Expand Up @@ -55,7 +55,6 @@ impl Plugin for MiningPlugin {
.in_set(MiningSet)
.after(InventorySet)
.after(MoveEventsSet)
.before(azalea_entity::update_bounding_box)
.after(azalea_entity::update_fluid_on_eyes)
.after(crate::interact::pick::update_hit_result_component)
.after(crate::attack::handle_attack_event)
Expand Down
Loading
Loading