Skip to main content

yog_event/client/
control.rs

1//! This client's player doing what a player does — its own keys held, its
2//! clicks — for tours, cut scenes, bots: the host's actions (nothing on a
3//! dedicated server, nor without a player).
4
5use yog_core::{BlockPos, ClickMode, Face};
6use yog_ids as ids;
7
8actions! {
9    /// Holds the movement keys each tick till [`release`]: `forward` -1
10    /// (back) to 1, `strafe` -1 (right) to 1 (left); `use_item` raises a
11    /// shield, draws a bow, eats.
12    Drive { forward: f32, strafe: f32, jump: bool, sneak: bool, sprint: bool, use_item: bool } -> bool = ids::service_client_control::DRIVE, "YogClientOps.drive";
13    /// Gives the movement keys back to the player.
14    Release {  } -> bool = ids::service_client_control::RELEASE, "YogClientOps.release";
15    /// Turns the player to `yaw`, `pitch` (degrees).
16    Look { yaw: f32, pitch: f32 } -> bool = ids::service_client_control::LOOK, "YogClientOps.look";
17    /// Attacks entity `entity` (its uuid), or (`None`) what the crosshair is on; whether something was hit.
18    Attack { entity: Option<String> } -> bool = ids::service_client_control::ATTACK, "YogClientOps.attack";
19    /// Uses the held item, the main hand's or the off hand's.
20    UseItem { off_hand: bool } -> bool = ids::service_client_control::USE_ITEM, "YogClientOps.useItem";
21    /// Keeps breaking the block at `pos` from `face` (call each tick); whether it's still there.
22    Mine { pos: BlockPos, face: Face } -> bool = ids::service_client_control::MINE, "YogClientOps.mine";
23    /// Stops breaking a block.
24    StopMining {  } -> bool = ids::service_client_control::STOP_MINING, "YogClientOps.stopMining";
25    /// Places the held block against the block at `pos`, on `face`; whether the game took it.
26    Place { pos: BlockPos, face: Face } -> bool = ids::service_client_control::PLACE, "YogClientOps.place";
27    /// Selects hotbar slot `slot` (0–8).
28    SelectSlot { slot: u32 } -> bool = ids::service_client_control::SELECT_SLOT, "YogClientOps.selectSlot";
29    /// Clicks `slot` of the open container (`button` as the game's).
30    Click { slot: i32, button: i32, mode: ClickMode } -> bool = ids::service_client_control::CLICK, "YogClientOps.click";
31    /// Sends `text` to the chat — a command when it starts with `/`.
32    Chat { text: String } -> bool = ids::service_client_control::CHAT, "YogClientOps.chat";
33}
34
35/// Every key up: what [`Drive`] holds unless told otherwise
36/// (`Drive { forward: 1.0, ..Default::default() }`).
37impl Default for Drive {
38    fn default() -> Self {
39        Drive {
40            forward: 0.0,
41            strafe: 0.0,
42            jump: false,
43            sneak: false,
44            sprint: false,
45            use_item: false,
46        }
47    }
48}