aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src/plugins')
-rw-r--r--azalea-client/src/plugins/attack.rs45
-rw-r--r--azalea-client/src/plugins/chat/mod.rs48
-rw-r--r--azalea-client/src/plugins/client_information.rs37
-rw-r--r--azalea-client/src/plugins/interact/mod.rs47
-rw-r--r--azalea-client/src/plugins/inventory/mod.rs41
-rw-r--r--azalea-client/src/plugins/mining.rs26
-rw-r--r--azalea-client/src/plugins/mod.rs2
-rw-r--r--azalea-client/src/plugins/movement.rs101
-rw-r--r--azalea-client/src/plugins/tick_broadcast.rs50
-rw-r--r--azalea-client/src/plugins/tick_counter.rs10
10 files changed, 8 insertions, 399 deletions
diff --git a/azalea-client/src/plugins/attack.rs b/azalea-client/src/plugins/attack.rs
index baab4333..41ce114d 100644
--- a/azalea-client/src/plugins/attack.rs
+++ b/azalea-client/src/plugins/attack.rs
@@ -12,7 +12,7 @@ use tracing::warn;
use super::packet::game::SendGamePacketEvent;
use crate::{
- Client, interact::SwingArmEvent, local_player::LocalGameMode, movement::MoveEventsSystems,
+ interact::SwingArmEvent, local_player::LocalGameMode, movement::MoveEventsSystems,
respawn::perform_respawn,
};
@@ -43,49 +43,6 @@ impl Plugin for AttackPlugin {
}
}
-impl Client {
- /// Attack an entity in the world.
- ///
- /// This doesn't automatically look at the entity or perform any
- /// range/visibility checks, so it might trigger anticheats.
- pub fn attack(&self, entity: Entity) {
- self.ecs.lock().write_message(AttackEvent {
- entity: self.entity,
- target: entity,
- });
- }
-
- /// Whether the player has an attack cooldown.
- ///
- /// Also see [`Client::attack_cooldown_remaining_ticks`].
- pub fn has_attack_cooldown(&self) -> bool {
- let Some(attack_strength_scale) = self.get_component::<AttackStrengthScale>() else {
- // they don't even have an AttackStrengthScale so they probably can't even
- // attack? whatever, just return false
- return false;
- };
- *attack_strength_scale < 1.0
- }
-
- /// Returns the number of ticks until we can attack at full strength again.
- ///
- /// Also see [`Client::has_attack_cooldown`].
- pub fn attack_cooldown_remaining_ticks(&self) -> usize {
- let mut ecs = self.ecs.lock();
- let Ok((attributes, ticks_since_last_attack)) = ecs
- .query::<(&Attributes, &TicksSinceLastAttack)>()
- .get(&ecs, self.entity)
- else {
- return 0;
- };
-
- let attack_strength_delay = get_attack_strength_delay(attributes);
- let remaining_ticks = attack_strength_delay - **ticks_since_last_attack as f32;
-
- remaining_ticks.max(0.).ceil() as usize
- }
-}
-
/// A component that indicates that this client will be attacking the given
/// entity next tick.
#[derive(Clone, Component, Debug)]
diff --git a/azalea-client/src/plugins/chat/mod.rs b/azalea-client/src/plugins/chat/mod.rs
index bd90a8d6..11ad742c 100644
--- a/azalea-client/src/plugins/chat/mod.rs
+++ b/azalea-client/src/plugins/chat/mod.rs
@@ -14,8 +14,6 @@ use bevy_ecs::prelude::*;
use handler::{SendChatKindEvent, handle_send_chat_kind_event};
use uuid::Uuid;
-use crate::client::Client;
-
pub struct ChatPlugin;
impl Plugin for ChatPlugin {
fn build(&self, app: &mut App) {
@@ -187,52 +185,6 @@ impl ChatPacket {
}
}
-impl Client {
- /// Send a chat message to the server.
- ///
- /// This only sends the chat packet and not the command packet, which means
- /// on some servers you can use this to send chat messages that start
- /// with a `/`. The [`Client::chat`] function handles checking whether
- /// the message is a command and using the proper packet for you, so you
- /// should use that instead.
- pub fn write_chat_packet(&self, message: &str) {
- self.ecs.lock().write_message(SendChatKindEvent {
- entity: self.entity,
- content: message.to_owned(),
- kind: ChatKind::Message,
- });
- }
-
- /// Send a command packet to the server. The `command` argument should not
- /// include the slash at the front.
- ///
- /// You can also just use [`Client::chat`] and start your message with a `/`
- /// to send a command.
- pub fn write_command_packet(&self, command: &str) {
- self.ecs.lock().write_message(SendChatKindEvent {
- entity: self.entity,
- content: command.to_owned(),
- kind: ChatKind::Command,
- });
- }
-
- /// Send a message in chat.
- ///
- /// ```rust,no_run
- /// # use azalea_client::Client;
- /// # async fn example(bot: Client) -> anyhow::Result<()> {
- /// bot.chat("Hello, world!");
- /// # Ok(())
- /// # }
- /// ```
- pub fn chat(&self, content: impl Into<String>) {
- self.ecs.lock().write_message(SendChatEvent {
- entity: self.entity,
- content: content.into(),
- });
- }
-}
-
/// A client received a chat message packet.
#[derive(Clone, Debug, Message)]
pub struct ChatReceivedEvent {
diff --git a/azalea-client/src/plugins/client_information.rs b/azalea-client/src/plugins/client_information.rs
index 98f69a2d..92b4f70a 100644
--- a/azalea-client/src/plugins/client_information.rs
+++ b/azalea-client/src/plugins/client_information.rs
@@ -1,13 +1,13 @@
use azalea_protocol::{
common::client_information::ClientInformation,
- packets::{config::s_client_information::ServerboundClientInformation, game},
+ packets::config::s_client_information::ServerboundClientInformation,
};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use tracing::{debug, warn};
use super::packet::config::SendConfigPacketEvent;
-use crate::{Client, brand::send_brand, packet::login::InLoginState};
+use crate::{brand::send_brand, packet::login::InLoginState};
/// Send [`ServerboundClientInformation`] on join.
pub struct ClientInformationPlugin;
@@ -42,36 +42,3 @@ pub fn send_client_information(
));
}
}
-
-impl Client {
- /// Tell the server we changed our game options (i.e. render distance, main
- /// hand).
- ///
- /// If this is not set before the login packet, the default will be sent.
- ///
- /// ```rust,no_run
- /// # use azalea_client::{Client, ClientInformation};
- /// # async fn example(bot: Client) -> Result<(), Box<dyn std::error::Error>> {
- /// bot.set_client_information(ClientInformation {
- /// view_distance: 2,
- /// ..Default::default()
- /// });
- /// # Ok(())
- /// # }
- /// ```
- pub fn set_client_information(&self, client_information: ClientInformation) {
- self.query_self::<&mut ClientInformation, _>(|mut ci| {
- *ci = client_information.clone();
- });
-
- if self.logged_in() {
- debug!(
- "Sending client information (already logged in): {:?}",
- client_information
- );
- self.write_packet(game::s_client_information::ServerboundClientInformation {
- client_information,
- });
- }
- }
-}
diff --git a/azalea-client/src/plugins/interact/mod.rs b/azalea-client/src/plugins/interact/mod.rs
index df614b8a..d2a4ef44 100644
--- a/azalea-client/src/plugins/interact/mod.rs
+++ b/azalea-client/src/plugins/interact/mod.rs
@@ -38,7 +38,6 @@ use tracing::warn;
use super::mining::Mining;
use crate::{
- Client,
attack::handle_attack_event,
interact::pick::{HitResultComponent, update_hit_result_component},
inventory::InventorySystems,
@@ -85,52 +84,6 @@ impl Plugin for InteractPlugin {
#[derive(Clone, Debug, Eq, Hash, PartialEq, SystemSet)]
pub struct UpdateAttributesSystems;
-impl Client {
- /// Right-click a block.
- ///
- /// The behavior of this depends on the target block,
- /// and it'll either place the block you're holding in your hand or use the
- /// block you clicked (like toggling a lever).
- ///
- /// Note that this may trigger anticheats as it doesn't take into account
- /// whether you're actually looking at the block.
- pub fn block_interact(&self, position: BlockPos) {
- self.ecs.lock().write_message(StartUseItemEvent {
- entity: self.entity,
- hand: InteractionHand::MainHand,
- force_block: Some(position),
- });
- }
-
- /// Right-click an entity.
- ///
- /// This can click through walls, which may trigger anticheats. If that
- /// behavior isn't desired, consider using [`Client::start_use_item`]
- /// instead.
- pub fn entity_interact(&self, entity: Entity) {
- self.ecs.lock().trigger(EntityInteractEvent {
- client: self.entity,
- target: entity,
- location: None,
- });
- }
-
- /// Right-click the currently held item.
- ///
- /// If the item is consumable, then it'll act as if right-click was held
- /// until the item finishes being consumed. You can use this to eat food.
- ///
- /// If we're looking at a block or entity, then it will be clicked. Also see
- /// [`Client::block_interact`] and [`Client::entity_interact`].
- pub fn start_use_item(&self) {
- self.ecs.lock().write_message(StartUseItemEvent {
- entity: self.entity,
- hand: InteractionHand::MainHand,
- force_block: None,
- });
- }
-}
-
/// A component that contains information about our local block state
/// predictions.
#[derive(Clone, Component, Debug, Default)]
diff --git a/azalea-client/src/plugins/inventory/mod.rs b/azalea-client/src/plugins/inventory/mod.rs
index 09c0d78f..740decb1 100644
--- a/azalea-client/src/plugins/inventory/mod.rs
+++ b/azalea-client/src/plugins/inventory/mod.rs
@@ -18,7 +18,6 @@ use indexmap::IndexMap;
use tracing::{error, warn};
use crate::{
- Client,
inventory::equipment_effects::{collect_equipment_changes, handle_equipment_changes},
packet::game::SendGamePacketEvent,
};
@@ -56,46 +55,6 @@ impl Plugin for InventoryPlugin {
#[derive(Clone, Debug, Eq, Hash, PartialEq, SystemSet)]
pub struct InventorySystems;
-impl Client {
- /// Return the menu that is currently open, or the player's inventory if no
- /// menu is open.
- pub fn menu(&self) -> Menu {
- self.query_self::<&Inv, _>(|inv| inv.menu().clone())
- }
-
- /// Returns the index of the hotbar slot that's currently selected.
- ///
- /// If you want to access the actual held item, you can get the current menu
- /// with [`Client::menu`] and then get the slot index by offsetting from
- /// the start of [`azalea_inventory::Menu::hotbar_slots_range`].
- ///
- /// You can use [`Self::set_selected_hotbar_slot`] to change it.
- pub fn selected_hotbar_slot(&self) -> u8 {
- self.query_self::<&Inv, _>(|inv| inv.selected_hotbar_slot)
- }
-
- /// Update the selected hotbar slot index.
- ///
- /// This will run next `Update`, so you might want to call
- /// `bot.wait_updates(1)` after calling this if you're using `azalea`.
- ///
- /// # Panics
- ///
- /// This will panic if `new_hotbar_slot_index` is not in the range 0..=8.
- pub fn set_selected_hotbar_slot(&self, new_hotbar_slot_index: u8) {
- assert!(
- new_hotbar_slot_index < 9,
- "Hotbar slot index must be in the range 0..=8"
- );
-
- let mut ecs = self.ecs.lock();
- ecs.trigger(SetSelectedHotbarSlotEvent {
- entity: self.entity,
- slot: new_hotbar_slot_index,
- });
- }
-}
-
/// A Bevy trigger that's fired when our client should show a new screen (like a
/// chest or crafting table).
///
diff --git a/azalea-client/src/plugins/mining.rs b/azalea-client/src/plugins/mining.rs
index 56136362..e9dcbe59 100644
--- a/azalea-client/src/plugins/mining.rs
+++ b/azalea-client/src/plugins/mining.rs
@@ -15,7 +15,6 @@ use derive_more::{Deref, DerefMut};
use tracing::{debug, trace, warn};
use crate::{
- Client,
interact::{
BlockStatePredictionHandler, SwingArmEvent, can_use_game_master_blocks,
check_is_interaction_restricted, pick::HitResultComponent,
@@ -71,31 +70,6 @@ impl Plugin for MiningPlugin {
#[derive(Clone, Debug, Eq, Hash, PartialEq, SystemSet)]
pub struct MiningSystems;
-impl Client {
- pub fn start_mining(&self, position: BlockPos) {
- let mut ecs = self.ecs.lock();
-
- ecs.write_message(StartMiningBlockEvent {
- entity: self.entity,
- position,
- force: true,
- });
- }
-
- /// When enabled, the bot will mine any block that it is looking at if it is
- /// reachable.
- pub fn left_click_mine(&self, enabled: bool) {
- let mut ecs = self.ecs.lock();
- let mut entity_mut = ecs.entity_mut(self.entity);
-
- if enabled {
- entity_mut.insert(LeftClickMine);
- } else {
- entity_mut.remove::<LeftClickMine>();
- }
- }
-}
-
/// A component that simulates the client holding down left click to mine the
/// block that it's facing, but this only interacts with blocks and not
/// entities.
diff --git a/azalea-client/src/plugins/mod.rs b/azalea-client/src/plugins/mod.rs
index 2ccbb3cc..a4aec19f 100644
--- a/azalea-client/src/plugins/mod.rs
+++ b/azalea-client/src/plugins/mod.rs
@@ -24,7 +24,6 @@ pub mod packet;
pub mod pong;
pub mod respawn;
pub mod task_pool;
-pub mod tick_broadcast;
pub mod tick_counter;
pub mod tick_end;
@@ -58,7 +57,6 @@ impl PluginGroup for DefaultPlugins {
.add(loading::PlayerLoadedPlugin)
.add(brand::BrandPlugin)
.add(client_information::ClientInformationPlugin)
- .add(tick_broadcast::TickBroadcastPlugin)
.add(tick_counter::TickCounterPlugin)
.add(pong::PongPlugin)
.add(connection::ConnectionPlugin)
diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs
index c4409722..c9473ebf 100644
--- a/azalea-client/src/plugins/movement.rs
+++ b/azalea-client/src/plugins/movement.rs
@@ -35,7 +35,6 @@ use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use crate::{
- client::Client,
local_player::{Hunger, InstanceHolder, LocalGameMode},
packet::game::SendGamePacketEvent,
};
@@ -77,55 +76,6 @@ impl Plugin for MovementPlugin {
#[derive(Clone, Debug, Eq, Hash, PartialEq, SystemSet)]
pub struct MoveEventsSystems;
-impl Client {
- /// Set whether we're jumping. This acts as if you held space in
- /// vanilla.
- ///
- /// If you want to jump once, use the `jump` function in `azalea`.
- ///
- /// If you're making a realistic client, calling this function every tick is
- /// recommended.
- pub fn set_jumping(&self, jumping: bool) {
- self.query_self::<&mut Jumping, _>(|mut j| **j = jumping);
- }
-
- /// Returns whether the player will try to jump next tick.
- pub fn jumping(&self) -> bool {
- *self.component::<Jumping>()
- }
-
- pub fn set_crouching(&self, crouching: bool) {
- self.query_self::<&mut PhysicsState, _>(|mut p| p.trying_to_crouch = crouching);
- }
-
- /// Whether the client is currently trying to sneak.
- ///
- /// You may want to check the [`Pose`] instead.
- pub fn crouching(&self) -> bool {
- self.query_self::<&PhysicsState, _>(|p| p.trying_to_crouch)
- }
-
- /// Sets the direction the client is looking.
- ///
- /// `y_rot` is yaw (looking to the side, between -180 to 180), and `x_rot`
- /// is pitch (looking up and down, between -90 to 90).
- ///
- /// You can get these numbers from the vanilla f3 screen.
- pub fn set_direction(&self, y_rot: f32, x_rot: f32) {
- self.query_self::<&mut LookDirection, _>(|mut ld| {
- ld.update(LookDirection::new(y_rot, x_rot));
- });
- }
-
- /// Returns the direction the client is looking.
- ///
- /// See [`Self::set_direction`] for more details.
- pub fn direction(&self) -> (f32, f32) {
- let look_direction: LookDirection = self.component::<LookDirection>();
- (look_direction.y_rot(), look_direction.x_rot())
- }
-}
-
/// A component that contains the look direction that was last sent over the
/// network.
#[derive(Clone, Component, Debug, Default)]
@@ -515,57 +465,6 @@ fn distance_to_unit_square(v: Vec2) -> f32 {
(1. + ratio * ratio).sqrt()
}
-impl Client {
- /// Start walking in the given direction.
- ///
- /// To sprint, use [`Client::sprint`]. To stop walking, call walk with
- /// [`WalkDirection::None`].
- ///
- /// # Example
- ///
- /// ```rust,no_run
- /// # use azalea_client::{Client, WalkDirection};
- /// # use std::time::Duration;
- /// # async fn example(mut bot: Client) {
- /// // walk for one second
- /// bot.walk(WalkDirection::Forward);
- /// tokio::time::sleep(Duration::from_secs(1)).await;
- /// bot.walk(WalkDirection::None);
- /// # }
- /// ```
- pub fn walk(&self, direction: WalkDirection) {
- let mut ecs = self.ecs.lock();
- ecs.write_message(StartWalkEvent {
- entity: self.entity,
- direction,
- });
- }
-
- /// Start sprinting in the given direction.
- ///
- /// o stop moving, call [`bot.walk(WalkDirection::None)`](Self::walk)
- ///
- /// # Example
- ///
- /// ```rust,no_run
- /// # use azalea_client::{Client, WalkDirection, SprintDirection};
- /// # use std::time::Duration;
- /// # async fn example(mut bot: Client) {
- /// // sprint for one second
- /// bot.sprint(SprintDirection::Forward);
- /// tokio::time::sleep(Duration::from_secs(1)).await;
- /// bot.walk(WalkDirection::None);
- /// # }
- /// ```
- pub fn sprint(&self, direction: SprintDirection) {
- let mut ecs = self.ecs.lock();
- ecs.write_message(StartSprintEvent {
- entity: self.entity,
- direction,
- });
- }
-}
-
/// An event sent when the client starts walking.
///
/// This does not get sent for non-local entities.
diff --git a/azalea-client/src/plugins/tick_broadcast.rs b/azalea-client/src/plugins/tick_broadcast.rs
deleted file mode 100644
index e51716cc..00000000
--- a/azalea-client/src/plugins/tick_broadcast.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-use azalea_core::tick::GameTick;
-use bevy_app::prelude::*;
-use bevy_ecs::prelude::*;
-use derive_more::Deref;
-use tokio::sync::broadcast;
-
-/// A resource that contains a [`broadcast::Sender`] that will be sent every
-/// Minecraft tick.
-///
-/// This is useful for running code every schedule from async user code.
-///
-/// ```
-/// use azalea_client::tick_broadcast::TickBroadcast;
-/// # async fn example(client: azalea_client::Client) {
-/// let mut receiver = {
-/// let ecs = client.ecs.lock();
-/// let tick_broadcast = ecs.resource::<TickBroadcast>();
-/// tick_broadcast.subscribe()
-/// };
-/// while receiver.recv().await.is_ok() {
-/// // do something
-/// }
-/// # }
-/// ```
-#[derive(Deref, Resource)]
-pub struct TickBroadcast(broadcast::Sender<()>);
-/// A resource that contains a [`broadcast::Sender`] that will be sent every
-/// Azalea ECS Update.
-///
-/// Also see [`TickBroadcast`].
-#[derive(Deref, Resource)]
-pub struct UpdateBroadcast(broadcast::Sender<()>);
-
-pub fn send_tick_broadcast(tick_broadcast: ResMut<TickBroadcast>) {
- let _ = tick_broadcast.0.send(());
-}
-pub fn send_update_broadcast(update_broadcast: ResMut<UpdateBroadcast>) {
- let _ = update_broadcast.0.send(());
-}
-/// A plugin that makes the [`UpdateBroadcast`] and [`TickBroadcast`] resources
-/// available.
-pub struct TickBroadcastPlugin;
-impl Plugin for TickBroadcastPlugin {
- fn build(&self, app: &mut App) {
- app.insert_resource(TickBroadcast(broadcast::channel(1).0))
- .insert_resource(UpdateBroadcast(broadcast::channel(1).0))
- .add_systems(GameTick, send_tick_broadcast)
- .add_systems(Update, send_update_broadcast);
- }
-}
diff --git a/azalea-client/src/plugins/tick_counter.rs b/azalea-client/src/plugins/tick_counter.rs
index 2f4086a0..e4b5f0a4 100644
--- a/azalea-client/src/plugins/tick_counter.rs
+++ b/azalea-client/src/plugins/tick_counter.rs
@@ -4,7 +4,7 @@ use azalea_world::InstanceName;
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
-use crate::{mining::MiningSystems, movement::send_position, tick_broadcast::send_tick_broadcast};
+use crate::{mining::MiningSystems, movement::send_position};
/// Counts the number of game ticks elapsed on the **local client** since the
/// `login` packet was received.
@@ -22,14 +22,14 @@ impl Plugin for TickCounterPlugin {
increment_counter
.before(PhysicsSystems)
.before(MiningSystems)
- .before(send_position)
- .before(send_tick_broadcast),
+ .before(send_position),
);
}
}
-/// Increment the [`GameTickCounter`] on every entity that lives in an instance.
-fn increment_counter(mut query: Query<&mut TicksConnected, With<InstanceName>>) {
+/// Increment the [`TicksConnected`] component on every entity
+/// that lives in an instance.
+pub fn increment_counter(mut query: Query<&mut TicksConnected, With<InstanceName>>) {
for mut counter in &mut query {
counter.0 += 1;
}