steel_core/behavior/blocks/vegetation/
nether_roots_block.rs1use steel_macros::block_behavior;
2use steel_registry::{vanilla_block_tags::BlockTag, vanilla_blocks};
3use steel_utils::{BlockPos, BlockStateId, Direction};
4
5use crate::behavior::block::BlockBehavior;
6use crate::behavior::context::BlockPlaceContext;
7use crate::world::{LevelReader, ScheduledTickAccess};
8
9use super::{
10 BlockRef, default_surviving_state, survives_on_tag, vegetation_block::survival_update_shape,
11};
12
13#[block_behavior]
15pub struct NetherRootsBlock {
16 block: BlockRef,
17}
18
19impl NetherRootsBlock {
20 #[must_use]
22 pub const fn new(block: BlockRef) -> Self {
23 Self { block }
24 }
25
26 fn support_tag(&self) -> steel_utils::Identifier {
27 if self.block == &vanilla_blocks::WARPED_ROOTS {
28 BlockTag::SUPPORTS_WARPED_ROOTS
29 } else {
30 BlockTag::SUPPORTS_CRIMSON_ROOTS
31 }
32 }
33}
34
35impl BlockBehavior for NetherRootsBlock {
36 fn update_shape(
37 &self,
38 state: BlockStateId,
39 world: &dyn ScheduledTickAccess,
40 pos: BlockPos,
41 _direction: Direction,
42 _neighbor_pos: BlockPos,
43 _neighbor_state: BlockStateId,
44 ) -> BlockStateId {
45 survival_update_shape(self, state, world, pos)
46 }
47
48 fn can_survive(&self, _state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
49 let support_tag = self.support_tag();
50 survives_on_tag(world, pos, &support_tag)
51 }
52
53 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
54 default_surviving_state(self.block, self, context)
55 }
56}