yog_event/block.rs
1//! What happens to blocks.
2
3use yog_core::BlockPos;
4use yog_data::Schema;
5
6/// Fired when a player breaks a block (server side).
7#[derive(Debug, Clone, Schema)]
8pub struct Break {
9 pub player_name: String,
10 /// Registry id of the block, e.g. `minecraft:stone`.
11 pub block_id: String,
12 pub pos: BlockPos,
13 /// Dimension the block was broken in, e.g. `minecraft:overworld`.
14 pub dimension: String,
15}
16
17/// Fired when a player places a block (server side).
18///
19/// Passed to handlers registered via `Registry::on_player_place_block` with an
20/// [`EventPhase`] argument:
21/// - `Pre` — fires before placement; return `false` to cancel.
22/// - `Post` — fires after the block has been placed.
23#[derive(Debug, Clone, Schema)]
24pub struct Place {
25 pub player_name: String,
26 /// Registry id of the block being placed, e.g. `minecraft:stone`.
27 pub block_id: String,
28 pub pos: BlockPos,
29 pub dimension: String,
30 /// Whether the player was sneaking (shift).
31 pub sneaking: bool,
32}
33
34/// Fired when a player right-clicks a block (server side).
35#[derive(Debug, Clone, Schema)]
36pub struct Use {
37 pub player_name: String,
38 /// Registry id of the targeted block, e.g. `minecraft:chest`.
39 pub block_id: String,
40 pub pos: BlockPos,
41 pub dimension: String,
42 /// Whether the player was sneaking (shift).
43 pub sneaking: bool,
44}
45
46/// A hopper or dropper offers an item to a block that accepts items
47/// (`block.accepts_items`): a service each such block provides (keyed by
48/// its id), answering whether it takes the item.
49#[derive(Debug, Clone, Schema)]
50pub struct Insert {
51 /// Registry id of the block.
52 pub block_id: String,
53 pub pos: BlockPos,
54 pub dimension: String,
55 pub item_id: String,
56 pub count: u32,
57 /// The item's data as SNBT (`{}` for none).
58 pub nbt: String,
59 /// Only whether it would take it — nothing changes yet; else it takes it.
60 pub simulate: bool,
61}
62
63mod actions;
64pub use actions::*;