use interfaces::types::BlockLocation;
use swarm_bot_packets::types::UUID;
use crate::{
bootstrap::BotConnection,
client::{
pathfind::moves::CardinalDirection, processor::InterfaceIn,
state::local::inventory::ItemStack,
},
types::{Direction, Location},
};
pub mod v340;
mod encrypt;
mod io;
mod transform;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(clippy::missing_docs_in_private_items)]
pub enum Mine {
Start,
#[allow(unused)]
Cancel,
Finished,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
#[allow(clippy::missing_docs_in_private_items)]
pub enum Face {
NegY,
PosY,
NegZ,
PosZ,
NegX,
PosX,
}
impl From<CardinalDirection> for Face {
fn from(dir: CardinalDirection) -> Self {
match dir {
CardinalDirection::North => Self::PosX,
CardinalDirection::South => Self::NegX,
CardinalDirection::West => Self::PosZ,
CardinalDirection::East => Self::NegZ,
}
}
}
impl Face {
#[allow(unused)]
pub const fn is_x(self) -> bool {
matches!(self, Self::PosX | Self::NegX)
}
#[allow(unused)]
pub const fn is_y(self) -> bool {
matches!(self, Self::PosY | Self::NegY)
}
#[allow(unused)]
pub const fn is_z(self) -> bool {
matches!(self, Self::PosZ | Self::NegZ)
}
pub fn unit_location(self) -> BlockLocation {
match self {
Self::NegY => BlockLocation::new(0, -1, 0),
Self::PosY => BlockLocation::new(0, 1, 0),
Self::NegZ => BlockLocation::new(0, 0, -1),
Self::PosZ => BlockLocation::new(0, 0, 1),
Self::NegX => BlockLocation::new(-1, 0, 0),
Self::PosX => BlockLocation::new(1, 0, 0),
}
}
}
impl From<u8> for Face {
#[allow(clippy::panic)]
fn from(elem: u8) -> Self {
match elem {
0 => Self::NegY,
1 => Self::PosY,
2 => Self::NegZ,
3 => Self::PosZ,
4 => Self::NegX,
5 => Self::PosX,
_ => panic!("invalid"),
}
}
}
#[derive(Copy, Clone, Debug)]
pub enum MouseButton {
Left,
Right,
}
impl From<MouseButton> for u8 {
fn from(button: MouseButton) -> Self {
match button {
MouseButton::Left => 0,
MouseButton::Right => 1,
}
}
}
pub enum InvAction {
#[allow(unused)]
Q(u16),
CtrlQ(u16),
#[allow(unused)]
Click(u16, MouseButton, ItemStack),
#[allow(unused)]
ShiftClick(u16, MouseButton, ItemStack),
}
pub trait InterfaceOut {
fn place_block(&mut self, against: BlockLocation, face: Face);
fn attack_entity(&mut self, id: u32);
fn send_chat(&mut self, message: &str);
fn inventory_action(&mut self, action: InvAction);
fn swing_arm(&mut self);
fn finish_eating(&mut self);
fn use_item(&mut self);
fn change_slot(&mut self, number: u8);
fn mine(&mut self, location: BlockLocation, mine: Mine, face: Face);
fn respawn(&mut self);
fn teleport(&mut self, location: Location);
fn look(&mut self, direction: Direction);
fn teleport_and_look(&mut self, location: Location, direction: Direction, on_ground: bool);
}
pub trait Minecraft: Sized {
type Queue: EventQueue;
type Interface: InterfaceOut;
async fn login(conn: BotConnection) -> anyhow::Result<Login<Self::Queue, Self::Interface>>;
}
pub trait EventQueue {
fn flush(&mut self, processor: &mut impl InterfaceIn);
}
#[derive(Debug)]
pub struct ClientInfo {
pub username: String,
pub uuid: UUID,
pub entity_id: u32,
}
pub struct Login<E: EventQueue, I: InterfaceOut> {
pub queue: E,
pub out: I,
pub info: ClientInfo,
}