content: package com.github.alexthe666.iceandfire.block;
  
  import com.github.alexthe666.iceandfire.IceAndFire;
  import com.github.alexthe666.iceandfire.entity.tile.TileEntityLectern;
  import net.minecraft.core.BlockPos;
  import net.minecraft.core.Direction;
  import net.minecraft.world.Containers;
  import net.minecraft.world.InteractionHand;
  import net.minecraft.world.InteractionResult;
  import net.minecraft.world.MenuProvider;
  import net.minecraft.world.entity.player.Player;
  import net.minecraft.world.item.context.BlockPlaceContext;
  import net.minecraft.world.level.BlockGetter;
  import net.minecraft.world.level.Level;
  import net.minecraft.world.level.block.*;
  import net.minecraft.world.level.block.entity.BlockEntity;
  import net.minecraft.world.level.block.entity.BlockEntityTicker;
  import net.minecraft.world.level.block.entity.BlockEntityType;
  import net.minecraft.world.level.block.state.BlockState;
  import net.minecraft.world.level.block.state.StateDefinition;
  import net.minecraft.world.level.block.state.properties.DirectionProperty;
  import net.minecraft.world.level.material.Material;
  import net.minecraft.world.phys.BlockHitResult;
  import net.minecraft.world.phys.shapes.CollisionContext;
  import net.minecraft.world.phys.shapes.VoxelShape;
  import org.jetbrains.annotations.NotNull;
  
  import javax.annotation.Nullable;
  import java.util.Random;
  
  import static com.github.alexthe666.iceandfire.entity.tile.IafTileEntityRegistry.IAF_LECTERN;
  
  public class BlockLectern extends BaseEntityBlock {
      public static final DirectionProperty FACING = DirectionProperty.create("facing", Direction.Plane.HORIZONTAL);
      protected static final VoxelShape AABB = Block.box(4, 0, 4, 12, 19, 12);
  
      public BlockLectern() {
          super(
              Properties
                  .of(Material.WOOD)
                  .noOcclusion()
                  .dynamicShape()
                  .strength(2, 5)
                  .sound(SoundType.WOOD)
          );
  
          this.registerDefaultState(this.getStateDefinition().any().setValue(FACING, Direction.NORTH));
      }
  
      @Override
      public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, @NotNull CollisionContext context) {
          return AABB;
      }
  
      @Override
      public @NotNull BlockState rotate(BlockState p_185499_1_, Rotation p_185499_2_) {
          return p_185499_1_.setValue(FACING, p_185499_2_.rotate(p_185499_1_.getValue(FACING)));
      }
  
      @Override
      public @NotNull BlockState mirror(BlockState p_185471_1_, Mirror p_185471_2_) {
          return p_185471_1_.rotate(p_185471_2_.getRotation(p_185471_1_.getValue(FACING)));
      }
  
      @Override
      public @NotNull VoxelShape getCollisionShape(@NotNull BlockState state, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, @NotNull CollisionContext context) {
          return AABB;
      }
  
  
      @Override
      public void onRemove(@NotNull BlockState state, Level worldIn, @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) {
          BlockEntity tileentity = worldIn.getBlockEntity(pos);
  
          if (tileentity instanceof TileEntityLectern) {
              Containers.dropContents(worldIn, pos, (TileEntityLectern) tileentity);
              worldIn.updateNeighbourForOutputSignal(pos, this);
          }
          super.onRemove(state, worldIn, pos, newState, isMoving);
      }
  
      public boolean canPlaceBlockAt(Level worldIn, BlockPos pos) {
          BlockState BlockState = worldIn.getBlockState(pos.below());
          Block block = BlockState.getBlock();
          return BlockState.isFaceSturdy(worldIn, pos, Direction.UP);
      }
  
  
      public void updateTick(Level worldIn, BlockPos pos, BlockState state, Random rand) {
          this.checkFall(worldIn, pos);
      }
  
      private boolean checkFall(Level worldIn, BlockPos pos) {
          if (!this.canPlaceBlockAt(worldIn, pos)) {
              worldIn.destroyBlock(pos, true);
              return false;
          } else {
              return true;
          }
      }
  
      @Nullable
      @Override
      public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153182_, @NotNull BlockState p_153183_, @NotNull BlockEntityType<T> entityType) {
          return p_153182_.isClientSide ? createTickerHelper(entityType, IAF_LECTERN.get(), TileEntityLectern::bookAnimationTick) : null;
      }
  
  
      @Override
      public BlockState getStateForPlacement(BlockPlaceContext context) {
          return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
      }
  
      @Override
      protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
          builder.add(FACING);
      }
  
      @Override
      public @NotNull RenderShape getRenderShape(@NotNull BlockState state) {
          return RenderShape.MODEL;
      }
  
      @Override
      public @NotNull InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn, @NotNull BlockPos pos, Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit) {
          if (!player.isShiftKeyDown()) {
              if (worldIn.isClientSide) {
                  IceAndFire.PROXY.setRefrencedTE(worldIn.getBlockEntity(pos));
              } else {
                  MenuProvider inamedcontainerprovider = this.getMenuProvider(state, worldIn, pos);
                  if (inamedcontainerprovider != null) {
                      player.openMenu(inamedcontainerprovider);
                  }
              }
              return InteractionResult.SUCCESS;
          }
          return InteractionResult.FAIL;
      }
  
      @Nullable
      @Override
      public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
          return new TileEntityLectern(pos, state);
      }
  }