Skip to main content

steel_core/world/game_event/
context.rs

1//! The context for game events
2use steel_utils::BlockStateId;
3
4use crate::entity::Entity;
5
6/// The context for a game event
7#[derive(Clone, Default)]
8pub struct GameEventContext<'a> {
9    /// The entity that caused the game event
10    source_entity: Option<&'a dyn Entity>,
11    /// The block state involved in the game event
12    affected_state: Option<BlockStateId>,
13}
14
15impl<'a> GameEventContext<'a> {
16    /// Creates a new `GameEventContext`
17    #[must_use]
18    pub fn new(
19        source_entity: Option<&'a dyn Entity>,
20        affected_state: Option<BlockStateId>,
21    ) -> Self {
22        Self {
23            source_entity,
24            affected_state,
25        }
26    }
27
28    /// Returns the entity that caused the game event.
29    #[must_use]
30    pub fn source_entity(&self) -> Option<&'a dyn Entity> {
31        self.source_entity
32    }
33
34    /// Returns the block state involved in the game event.
35    #[must_use]
36    pub const fn affected_state(&self) -> Option<BlockStateId> {
37        self.affected_state
38    }
39}