pub struct Client {
pub read_conn: Arc<Mutex<ReadConnection<ClientboundGamePacket>>>,
pub write_conn: Arc<Mutex<WriteConnection<ServerboundGamePacket>>>,
pub player: Arc<Mutex<RawMutex, Player>>,
pub dimension: Arc<Mutex<RawMutex, Dimension>>,
pub physics_state: Arc<Mutex<RawMutex, PhysicsState>>,
pub client_information: Arc<RwLock<RawRwLock, ServerboundClientInformationPacket>>,
/* private fields */
}
Expand description
A player that you control that is currently in a Minecraft server.
Fields
read_conn: Arc<Mutex<ReadConnection<ClientboundGamePacket>>>
write_conn: Arc<Mutex<WriteConnection<ServerboundGamePacket>>>
player: Arc<Mutex<RawMutex, Player>>
dimension: Arc<Mutex<RawMutex, Dimension>>
physics_state: Arc<Mutex<RawMutex, PhysicsState>>
client_information: Arc<RwLock<RawRwLock, ServerboundClientInformationPacket>>
Implementations
sourceimpl Client
impl Client
sourcepub async fn send_chat_packet(
&self,
message: &str
) -> impl Future<Output = Result<(), Error>>
pub async fn send_chat_packet(
&self,
message: &str
) -> impl Future<Output = Result<(), Error>>
Sends chat message to the server. This only sends the chat packet and
not the command packet. 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.
sourceimpl Client
impl Client
sourcepub async fn join(
account: &Account,
address: impl TryInto<ServerAddress>
) -> impl Future<Output = Result<(Client, UnboundedReceiver<Event>), JoinError>>
pub async fn join(
account: &Account,
address: impl TryInto<ServerAddress>
) -> impl Future<Output = Result<(Client, UnboundedReceiver<Event>), JoinError>>
Connect to a Minecraft server.
To change the render distance and other settings, use Client::set_client_information
.
Examples
use azalea_client::Client;
#[tokio::main]
async fn main() -> Box<dyn std::error::Error> {
let account = Account::offline("bot");
let client = Client::join(&account, "localhost").await?;
client.chat("Hello, world!").await?;
client.shutdown().await?;
}
sourcepub async fn write_packet(
&self,
packet: ServerboundGamePacket
) -> impl Future<Output = Result<(), Error>>
pub async fn write_packet(
&self,
packet: ServerboundGamePacket
) -> impl Future<Output = Result<(), Error>>
Write a packet directly to the server.
sourcepub async fn shutdown(self) -> impl Future<Output = Result<(), Error>>
pub async fn shutdown(self) -> impl Future<Output = Result<(), Error>>
Disconnect from the server, ending all tasks.
sourcepub fn entity_mut(&self, dimension: &'d mut Dimension) -> EntityMut<'d>
pub fn entity_mut(&self, dimension: &'d mut Dimension) -> EntityMut<'d>
Returns the entity associated to the player.
sourcepub fn entity(&self, dimension: &'d Dimension) -> EntityRef<'d>
pub fn entity(&self, dimension: &'d Dimension) -> EntityRef<'d>
Returns the entity associated to the player.
sourcepub async fn set_client_information(
&self,
client_information: ServerboundClientInformationPacket
) -> impl Future<Output = Result<(), Error>>
pub async fn set_client_information(
&self,
client_information: ServerboundClientInformationPacket
) -> impl Future<Output = Result<(), Error>>
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.
sourceimpl Client
impl Client
sourcepub async fn send_position(
&mut self
) -> impl Future<Output = Result<(), MovePlayerError>>
pub async fn send_position(
&mut self
) -> impl Future<Output = Result<(), MovePlayerError>>
This gets called every tick.
pub async fn set_pos(
&mut self,
new_pos: Vec3
) -> impl Future<Output = Result<(), MovePlayerError>>
pub async fn move_entity(
&mut self,
movement: &Vec3
) -> impl Future<Output = Result<(), MovePlayerError>>
sourcepub fn ai_step(&mut self)
pub fn ai_step(&mut self)
Makes the bot do one physics tick. Note that this is already handled automatically by the client.
sourcepub fn walk(&mut self, direction: MoveDirection)
pub fn walk(&mut self, direction: MoveDirection)
Start walking in the given direction.
sourcepub fn set_jumping(&mut self, jumping: bool)
pub fn set_jumping(&mut self, jumping: bool)
Toggle whether we’re jumping. This acts as if you held space in
vanilla. If you want to jump once, use the jump
function.
If you’re making a realistic client, calling this function every tick is recommended.