use serde::Serialize;
use serde_json::{Value, json};
use yog_ids::client_op as op;
use crate::client::op::{ask, call};
#[derive(Serialize, Debug, Clone, Copy, PartialEq, Default)]
pub struct Drive {
pub forward: f32,
pub strafe: f32,
pub jump: bool,
pub sneak: bool,
pub sprint: bool,
pub use_item: bool,
}
pub fn drive(keys: Drive) {
call(op::DRIVE, json!(keys));
}
pub fn release() {
call(op::RELEASE, Value::Null);
}
pub fn look(yaw: f32, pitch: f32) {
call(op::LOOK, json!({ "yaw": yaw, "pitch": pitch }));
}
pub fn attack(uuid: Option<&str>) {
call(op::ATTACK, json!({ "entity": uuid }));
}
pub fn use_item(off_hand: bool) {
call(op::USE, json!({ "off_hand": off_hand }));
}
#[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Face {
Down,
Up,
North,
South,
West,
East,
}
pub fn mine(pos: [i32; 3], face: Face) -> bool {
ask(op::MINE, json!({ "x": pos[0], "y": pos[1], "z": pos[2], "face": face })).unwrap_or(false)
}
pub fn stop_mining() {
call(op::MINE, json!({ "stop": true }));
}
pub fn place(pos: [i32; 3], face: Face) -> bool {
ask(op::PLACE, json!({ "x": pos[0], "y": pos[1], "z": pos[2], "face": face })).unwrap_or(false)
}
pub fn select_slot(slot: u8) {
call(op::SLOT, json!({ "slot": slot }));
}
pub fn click(slot: i32, button: i32, mode: &str) {
call(op::CLICK, json!({ "slot": slot, "button": button, "mode": mode }));
}
pub fn chat(text: &str) {
call(op::CHAT, json!({ "text": text }));
}