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