Skip to main content

steel_core/behavior/blocks/redstone/
weathering_lightning_rod_block.rs

1use std::sync::Arc;
2
3use steel_macros::block_behavior;
4use steel_registry::blocks::BlockRef;
5use steel_utils::{BlockPos, BlockStateId, Direction};
6
7use crate::{
8    behavior::{
9        BlockBehavior, BlockPlaceContext,
10        blocks::{LightningRodBlock, WeatherState, WeatheringCopper},
11    },
12    entity::ai::path::PathComputationType,
13    world::{LevelReader, ScheduledTickAccess, SignalQueryContext, World},
14};
15
16/// Behavior for all weathering lightning rod type blocks
17#[block_behavior]
18pub struct WeatheringLightningRodBlock {
19    lightning_rod: LightningRodBlock,
20    #[json_arg(r#enum = "WeatherState", json = "weather_state")]
21    weathering: WeatheringCopper,
22}
23
24impl WeatheringLightningRodBlock {
25    /// Creates a new weathering lightning rod block behavior for the given block
26    #[must_use]
27    pub const fn new(block: BlockRef, weather_state: WeatherState) -> Self {
28        Self {
29            lightning_rod: LightningRodBlock::new(block),
30            weathering: WeatheringCopper::new(weather_state),
31        }
32    }
33}
34
35impl BlockBehavior for WeatheringLightningRodBlock {
36    fn random_tick(&self, state: BlockStateId, world: &Arc<World>, pos: BlockPos) {
37        self.weathering.change_over_time(state, world, pos);
38    }
39
40    fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
41        self.lightning_rod.get_state_for_placement(context)
42    }
43
44    fn update_shape(
45        &self,
46        state: BlockStateId,
47        world: &dyn ScheduledTickAccess,
48        pos: BlockPos,
49        direction: Direction,
50        neighbor_pos: BlockPos,
51        neighbor_state: BlockStateId,
52    ) -> BlockStateId {
53        self.lightning_rod
54            .update_shape(state, world, pos, direction, neighbor_pos, neighbor_state)
55    }
56
57    fn get_own_signal(
58        &self,
59        state: BlockStateId,
60        world: &dyn LevelReader,
61        pos: BlockPos,
62        context: SignalQueryContext,
63    ) -> i32 {
64        self.lightning_rod
65            .get_own_signal(state, world, pos, context)
66    }
67
68    fn get_direct_signal(
69        &self,
70        state: BlockStateId,
71        world: &dyn LevelReader,
72        pos: BlockPos,
73        direction: Direction,
74        context: SignalQueryContext,
75    ) -> i32 {
76        self.lightning_rod
77            .get_direct_signal(state, world, pos, direction, context)
78    }
79    //TODO: override onLightningStrike() once it gets implemented
80
81    fn tick(&self, state: BlockStateId, world: &Arc<World>, pos: BlockPos) {
82        self.lightning_rod.tick(state, world, pos);
83    }
84
85    fn affect_neighbors_after_removal(
86        &self,
87        state: BlockStateId,
88        world: &Arc<World>,
89        pos: BlockPos,
90        moved_by_piston: bool,
91    ) {
92        self.lightning_rod
93            .affect_neighbors_after_removal(state, world, pos, moved_by_piston);
94    }
95
96    fn on_place(
97        &self,
98        state: BlockStateId,
99        world: &Arc<World>,
100        pos: BlockPos,
101        old_state: BlockStateId,
102        moved_by_piston: bool,
103    ) {
104        self.lightning_rod
105            .on_place(state, world, pos, old_state, moved_by_piston);
106    }
107
108    fn is_signal_source(&self, state: BlockStateId, context: SignalQueryContext) -> bool {
109        self.lightning_rod.is_signal_source(state, context)
110    }
111
112    fn is_pathfindable(&self, state: BlockStateId, computation_type: PathComputationType) -> bool {
113        self.lightning_rod.is_pathfindable(state, computation_type)
114    }
115}