steel_core/behavior/blocks/falling/
sand_block.rs1use std::sync::Arc;
2
3use steel_macros::block_behavior;
4use steel_registry::blocks::BlockRef;
5use steel_registry::blocks::properties::Direction;
6use steel_utils::{BlockPos, BlockStateId};
7
8use crate::behavior::{BlockBehavior, BlockPlaceContext, Fallable};
9use crate::world::{ScheduledTickAccess, World};
10
11use super::FallingBlock;
12
13#[block_behavior]
17pub struct SandBlock {
18 falling: FallingBlock,
19}
20
21impl SandBlock {
22 #[must_use]
24 pub const fn new(block: BlockRef) -> Self {
25 Self {
26 falling: FallingBlock::new(block),
27 }
28 }
29}
30
31impl Fallable for SandBlock {}
32
33impl BlockBehavior for SandBlock {
34 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
35 self.falling.get_state_for_placement(context)
36 }
37
38 fn on_place(
39 &self,
40 _state: BlockStateId,
41 world: &Arc<World>,
42 pos: BlockPos,
43 _old_state: BlockStateId,
44 _moved_by_piston: bool,
45 ) {
46 self.falling.on_place(world, pos);
47 }
48
49 fn update_shape(
50 &self,
51 state: BlockStateId,
52 ticks: &dyn ScheduledTickAccess,
53 pos: BlockPos,
54 _direction: Direction,
55 _neighbor_pos: BlockPos,
56 _neighbor_state: BlockStateId,
57 ) -> BlockStateId {
58 self.falling.update_shape(state, ticks, pos)
59 }
60
61 fn tick(&self, state: BlockStateId, world: &Arc<World>, pos: BlockPos) {
62 BlockBehavior::tick(&self.falling, state, world, pos);
63 }
64
65 fn as_fallable(&self) -> Option<&dyn Fallable> {
66 Some(self)
67 }
68}