yog_event/events.rs
1//! Event types passed from Minecraft (through the Java host) into Rust mods.
2
3use yog_core::BlockPos;
4
5/// Whether a handler is running before or after the action.
6///
7/// In `Pre` phase the handler's return value may cancel the action.
8/// In `Post` phase the return value is ignored.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum EventPhase { Pre, Post }
11
12/// Fired when a player breaks a block (server side).
13#[derive(Debug, Clone)]
14pub struct BlockBreakEvent {
15 pub player_name: String,
16 /// Registry id of the block, e.g. `minecraft:stone`.
17 pub block_id: String,
18 pub pos: BlockPos,
19}
20
21/// Fired when a player sends a chat message.
22#[derive(Debug, Clone)]
23pub struct ChatEvent {
24 pub player_name: String,
25 pub message: String,
26}
27
28/// Fired when a player joins the server.
29#[derive(Debug, Clone)]
30pub struct PlayerJoinEvent {
31 pub player_name: String,
32 /// Player UUID as a string, e.g. `069a79f4-44e9-4726-a5be-fca90e38aaf5`.
33 pub uuid: String,
34}
35
36/// Fired when a player leaves the server.
37#[derive(Debug, Clone)]
38pub struct PlayerLeaveEvent {
39 pub player_name: String,
40 pub uuid: String,
41}
42
43/// Fired when a player right-clicks with an item (server side).
44#[derive(Debug, Clone)]
45pub struct UseItemEvent {
46 pub player_name: String,
47 /// Registry id of the held item, e.g. `minecraft:stick`.
48 pub item_id: String,
49}
50
51/// Fired when a player right-clicks a block (server side).
52#[derive(Debug, Clone)]
53pub struct UseBlockEvent {
54 pub player_name: String,
55 /// Registry id of the targeted block, e.g. `minecraft:chest`.
56 pub block_id: String,
57 pub pos: BlockPos,
58}
59
60/// Fired when a player attacks (left-clicks) an entity (server side).
61#[derive(Debug, Clone)]
62pub struct AttackEntityEvent {
63 pub player_name: String,
64 /// Registry id of the target, e.g. `minecraft:zombie`.
65 pub target_type: String,
66 /// Target entity UUID as a string.
67 pub target_uuid: String,
68}
69
70/// Fired after a living entity takes damage (server side).
71#[derive(Debug, Clone)]
72pub struct EntityDamageEvent {
73 /// Registry id of the entity, e.g. `minecraft:zombie`.
74 pub entity_type: String,
75 pub uuid: String,
76 /// Amount of damage dealt (hit points).
77 pub amount: f32,
78 /// Identifier of the damage source, e.g. `minecraft:player`, `fall`.
79 pub source: String,
80}
81
82/// Fired after a living entity dies (server side).
83#[derive(Debug, Clone)]
84pub struct EntityDeathEvent {
85 /// Registry id of the entity, e.g. `minecraft:zombie`.
86 pub entity_type: String,
87 pub uuid: String,
88 /// Identifier of the killing damage source, e.g. `minecraft:player`.
89 pub source: String,
90}
91
92/// Fired when a player places a block (server side).
93///
94/// Passed to handlers registered via `Registry::on_player_place_block` with an
95/// [`EventPhase`] argument:
96/// - `Pre` — fires before placement; return `false` to cancel.
97/// - `Post` — fires after placement (requires mixin support; not yet wired).
98#[derive(Debug, Clone)]
99pub struct PlaceBlockEvent {
100 pub player_name: String,
101 /// Registry id of the block being placed, e.g. `minecraft:stone`.
102 pub block_id: String,
103 pub pos: BlockPos,
104}
105
106/// Fired when any entity is loaded into a world (server side).
107///
108/// Also used for `on_entity_spawn_pre` (cancellable): return `false` to
109/// discard the entity immediately after loading (effective spawn cancellation).
110#[derive(Debug, Clone)]
111pub struct EntitySpawnEvent {
112 /// Registry id of the entity, e.g. `minecraft:zombie`.
113 pub entity_type: String,
114 pub uuid: String,
115 /// Dimension the entity was added to, e.g. `minecraft:overworld`.
116 pub dimension: String,
117}
118
119/// Fired when a player dies.
120///
121/// - `Pre` — fires before death is processed; return `false` to prevent death
122/// (entity survives at 0.5 HP).
123/// - `Post` — fires after the player has died.
124#[derive(Debug, Clone)]
125pub struct PlayerDeathEvent {
126 pub player_name: String,
127 pub uuid: String,
128 /// Damage source identifier, e.g. `"player"`, `"fall"`.
129 pub source: String,
130}
131
132/// Fired when a player respawns after death (Post only).
133#[derive(Debug, Clone)]
134pub struct PlayerRespawnEvent {
135 pub player_name: String,
136 pub uuid: String,
137 /// True if respawning at a bed or respawn anchor; false for world spawn.
138 pub at_anchor: bool,
139}
140
141/// Fired when a player earns an advancement (Post only).
142#[derive(Debug, Clone)]
143pub struct AdvancementEvent {
144 pub player_name: String,
145 pub uuid: String,
146 /// Namespaced id of the advancement, e.g. `"minecraft:story/mine_stone"`.
147 pub advancement_id: String,
148}
149
150/// Fired when a player right-clicks (interacts with) an entity (server side).
151///
152/// - `Pre` — fires before the interaction; return `false` to cancel.
153/// - `Post` — fires after the interaction.
154#[derive(Debug, Clone)]
155pub struct EntityInteractEvent {
156 pub player_name: String,
157 pub player_uuid: String,
158 /// Registry id of the interacted entity, e.g. `"minecraft:villager"`.
159 pub entity_type: String,
160 pub entity_uuid: String,
161 /// `"main_hand"` or `"off_hand"`.
162 pub hand: String,
163}
164
165/// Fired when a player takes a crafted item from a crafting output slot (Post only).
166#[derive(Debug, Clone)]
167pub struct CraftEvent {
168 pub player_name: String,
169 pub player_uuid: String,
170 /// Registry id of the crafted item, e.g. `"minecraft:stick"`.
171 pub result_item: String,
172 pub result_count: u32,
173}
174
175/// Fired when an explosion occurs in a world.
176///
177/// - `Pre` — fires before block destruction; return `false` to cancel
178/// (blocks and entities are unaffected).
179/// - `Post` — fires after the explosion has taken effect.
180#[derive(Debug, Clone)]
181pub struct ExplosionEvent {
182 pub dimension: String,
183 pub x: f64,
184 pub y: f64,
185 pub z: f64,
186 pub power: f32,
187 /// UUID of the entity that caused the explosion, or empty string if none.
188 pub cause_uuid: String,
189}
190
191// ── ABI minor 9 event types ───────────────────────────────────────────────────
192
193/// Fired when a player picks up an item entity.
194///
195/// - `Pre` — return `false` to prevent the pickup.
196/// - `Post` — item was successfully picked up.
197#[derive(Debug, Clone)]
198pub struct ItemPickupEvent {
199 pub player_name: String,
200 pub player_uuid: String,
201 /// Registry id of the item, e.g. `"minecraft:diamond"`.
202 pub item_id: String,
203 pub item_count: u32,
204 /// UUID of the item entity that was picked up.
205 pub entity_uuid: String,
206}
207
208/// Fired every time a player sends a movement packet (very high frequency).
209///
210/// Post-phase only. The fields reflect the *new* position the client claims.
211#[derive(Debug, Clone)]
212pub struct PlayerMoveEvent {
213 pub player_name: String,
214 pub player_uuid: String,
215 pub x: f64,
216 pub y: f64,
217 pub z: f64,
218 pub yaw: f32,
219 pub pitch: f32,
220}
221
222/// Fired when a player opens a container screen.
223///
224/// - `Pre` — return `false` to prevent the screen from opening.
225/// - `Post` — screen opened; `container_type` is set.
226#[derive(Debug, Clone)]
227pub struct ContainerOpenEvent {
228 pub player_name: String,
229 pub player_uuid: String,
230 /// Screen handler registry id, e.g. `"minecraft:chest"`.
231 /// Empty string for screens not in the registry (e.g. the player inventory).
232 pub container_type: String,
233}
234
235/// Fired when a player closes a container screen (Post only).
236#[derive(Debug, Clone)]
237pub struct ContainerCloseEvent {
238 pub player_name: String,
239 pub player_uuid: String,
240}
241
242// ── ABI minor 10 — client-side events ────────────────────────────────────────
243
244/// Fired every client tick on the render thread.
245#[derive(Debug, Clone)]
246pub struct ClientTickEvent {}
247
248/// Fired every frame when the HUD is rendered.
249/// `delta_tick` is the partial-tick interpolation factor (0.0–1.0).
250#[derive(Debug, Clone)]
251pub struct HudRenderEvent {
252 pub delta_tick: f32,
253}
254
255/// Fired on every key press, release, or repeat (client-side).
256///
257/// Return `false` in the handler to prevent Minecraft from processing the key.
258#[derive(Debug, Clone)]
259pub struct KeyPressEvent {
260 /// GLFW key code (e.g. 69 = E). See `org.lwjgl.glfw.GLFW`.
261 pub key_code: i32,
262 pub scan_code: i32,
263 /// 0 = release, 1 = press, 2 = repeat.
264 pub action: i32,
265 /// Modifier bitmask: 1=Shift, 2=Ctrl, 4=Alt, 8=Super.
266 pub modifiers: i32,
267}
268
269/// Fired when a GUI screen opens or closes.
270#[derive(Debug, Clone)]
271pub struct ScreenEvent {
272 /// Simple class name of the screen, e.g. `"InventoryScreen"`, `"ChestScreen"`.
273 pub screen_class: String,
274}
275
276/// Fired when a persistent projectile (arrow, trident, etc.) hits a target.
277///
278/// - `Pre` — return `false` to cancel the hit (projectile passes through).
279/// - `Post` — hit was processed.
280#[derive(Debug, Clone)]
281pub struct ProjectileHitEvent {
282 /// Registry id of the projectile, e.g. `"minecraft:arrow"`.
283 pub projectile_type: String,
284 pub projectile_uuid: String,
285 /// UUID of the entity that fired the projectile, or empty string.
286 pub shooter_uuid: String,
287 /// `"block"` or `"entity"`.
288 pub hit_type: String,
289 /// UUID of the entity that was hit (empty for block hits).
290 pub hit_entity_uuid: String,
291 pub x: f64,
292 pub y: f64,
293 pub z: f64,
294 pub dimension: String,
295}