Skip to main content

steel_core/behavior/blocks/redstone/
powered_block.rs

1//! Constant-strength redstone source block behavior.
2
3use steel_macros::block_behavior;
4use steel_registry::blocks::BlockRef;
5use steel_utils::{BlockPos, BlockStateId};
6
7use crate::behavior::block::BlockBehavior;
8use crate::behavior::blocks::redstone::MAX_REDSTONE_SIGNAL;
9use crate::behavior::context::BlockPlaceContext;
10use crate::world::{LevelReader, SignalQueryContext};
11
12/// Vanilla `PoweredBlock`, used by the redstone block.
13#[block_behavior]
14pub struct PoweredBlock {
15    block: BlockRef,
16}
17
18impl PoweredBlock {
19    /// Creates the constant-strength behavior for `block`.
20    #[must_use]
21    pub const fn new(block: BlockRef) -> Self {
22        Self { block }
23    }
24}
25
26impl BlockBehavior for PoweredBlock {
27    fn get_state_for_placement(&self, _context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
28        Some(self.block.default_state())
29    }
30
31    fn is_signal_source(&self, _state: BlockStateId, _context: SignalQueryContext) -> bool {
32        true
33    }
34
35    fn get_own_signal(
36        &self,
37        _state: BlockStateId,
38        _world: &dyn LevelReader,
39        _pos: BlockPos,
40        _context: SignalQueryContext,
41    ) -> i32 {
42        MAX_REDSTONE_SIGNAL
43    }
44}