Skip to main content

steel_core/behavior/blocks/building/
rotated_pillar_block.rs

1//! Rotated pillar block behavior implementation.
2//!
3//! Pillar blocks (like logs) have an axis property that determines their orientation.
4
5use steel_macros::block_behavior;
6use steel_registry::blocks::BlockRef;
7use steel_registry::blocks::block_state_ext::BlockStateExt;
8use steel_registry::blocks::properties::{BlockStateProperties, EnumProperty};
9use steel_utils::BlockStateId;
10use steel_utils::axis::Axis;
11
12use crate::behavior::block::BlockBehavior;
13use crate::behavior::context::BlockPlaceContext;
14
15/// Behavior for rotated pillar blocks (logs, pillars, etc.).
16///
17/// These blocks have an axis property that is set based on which face
18/// was clicked during placement.
19#[block_behavior]
20pub struct RotatedPillarBlock {
21    block: BlockRef,
22}
23
24impl RotatedPillarBlock {
25    /// Axis property for the pillar orientation.
26    pub const AXIS: EnumProperty<Axis> = BlockStateProperties::AXIS;
27
28    /// Creates a new rotated pillar block behavior for the given block.
29    #[must_use]
30    pub const fn new(block: BlockRef) -> Self {
31        Self { block }
32    }
33
34    /// Returns the vanilla placement state for a rotated pillar class.
35    #[must_use]
36    pub(super) fn placement_state(
37        block: BlockRef,
38        context: &BlockPlaceContext<'_>,
39    ) -> BlockStateId {
40        block
41            .default_state()
42            .set_value(&Self::AXIS, context.clicked_face().get_axis())
43    }
44}
45
46impl BlockBehavior for RotatedPillarBlock {
47    fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
48        Some(Self::placement_state(self.block, context))
49    }
50}