steel_core/behavior/blocks/decoration/skull/
skull_block.rs1use crate::behavior::blocks::decoration::skull::abstract_skull_block::AbstractSkullBlock;
2use crate::behavior::{BlockBehavior, BlockEntityCreation, BlockLootContext, BlockPlaceContext};
3use crate::block_entity::SharedBlockEntity;
4use crate::entity::ai::path::PathComputationType;
5use crate::world::World;
6use std::sync::{Arc, Weak};
7use steel_macros::block_behavior;
8use steel_math::convert_to_rotation_segment;
9use steel_registry::blocks::BlockRef;
10use steel_registry::blocks::block_state_ext::BlockStateExt;
11use steel_registry::blocks::properties::{BlockStateProperties, IntProperty};
12use steel_registry::item_stack::ItemStack;
13use steel_utils::{BlockPos, BlockStateId};
14
15const ROTATION_16: &IntProperty = &BlockStateProperties::ROTATION_16;
16
17#[block_behavior]
19pub struct SkullBlock {
20 block: BlockRef,
21}
22
23impl SkullBlock {
24 pub const fn new(block: BlockRef) -> Self {
26 Self { block }
27 }
28}
29
30impl BlockBehavior for SkullBlock {
31 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
32 self.default_state_for_placement(context)
33 }
34
35 fn handle_neighbor_changed(
36 &self,
37 state: BlockStateId,
38 world: &Arc<World>,
39 pos: BlockPos,
40 source_block: BlockRef,
41 moved_by_piston: bool,
42 ) {
43 self.default_handle_neighbor_changed(state, world, pos, source_block, moved_by_piston);
44 }
45
46 fn is_pathfindable(&self, state: BlockStateId, computation_type: PathComputationType) -> bool {
47 self.default_is_pathfindable(state, computation_type)
48 }
49
50 fn new_block_entity(
51 &self,
52 level: Weak<World>,
53 pos: BlockPos,
54 state: BlockStateId,
55 ) -> BlockEntityCreation {
56 self.new_skull_block_entity(level, pos, state)
57 }
58
59 fn get_clone_item_stack(
60 &self,
61 block: BlockRef,
62 state: BlockStateId,
63 block_entity: Option<SharedBlockEntity>,
64 include_data: bool,
65 ) -> Option<ItemStack> {
66 self.default_get_clone_item_stack(block, state, block_entity, include_data)
67 }
68
69 fn get_drops(
70 &self,
71 state: BlockStateId,
72 context: &BlockLootContext<'_>,
73 ) -> Option<Vec<ItemStack>> {
74 self.default_get_drops(state, context)
75 }
76}
77
78impl AbstractSkullBlock for SkullBlock {
79 fn state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
80 let rotation = convert_to_rotation_segment(context.rotation());
81 Some(self.block.default_state().set_value(ROTATION_16, rotation))
82 }
83}