content: package com.accbdd.complicated_bees.block;
  
  import com.accbdd.complicated_bees.block.entity.MicroscopeBlockEntity;
  import com.accbdd.complicated_bees.screen.MicroscopeMenu;
  import net.minecraft.core.BlockPos;
  import net.minecraft.core.Direction;
  import net.minecraft.network.chat.Component;
  import net.minecraft.server.level.ServerPlayer;
  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.Inventory;
  import net.minecraft.world.entity.player.Player;
  import net.minecraft.world.inventory.AbstractContainerMenu;
  import net.minecraft.world.item.context.BlockPlaceContext;
  import net.minecraft.world.level.BlockGetter;
  import net.minecraft.world.level.Level;
  import net.minecraft.world.level.LevelAccessor;
  import net.minecraft.world.level.block.BaseEntityBlock;
  import net.minecraft.world.level.block.Block;
  import net.minecraft.world.level.block.RenderShape;
  import net.minecraft.world.level.block.Rotation;
  import net.minecraft.world.level.block.entity.BlockEntity;
  import net.minecraft.world.level.block.state.BlockState;
  import net.minecraft.world.level.block.state.StateDefinition;
  import net.minecraft.world.level.block.state.properties.BlockStateProperties;
  import net.minecraft.world.phys.BlockHitResult;
  import net.minecraft.world.phys.shapes.CollisionContext;
  import net.minecraft.world.phys.shapes.VoxelShape;
  import net.minecraftforge.network.NetworkHooks;
  import org.jetbrains.annotations.Nullable;
  
  public class MicroscopeBlock extends BaseEntityBlock {
      public MicroscopeBlock() {
          super(Properties.of().noOcclusion());
      }
  
      @Nullable
      @Override
      public BlockState getStateForPlacement(BlockPlaceContext context) {
          return this.defaultBlockState()
                  .setValue(BlockStateProperties.HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite());
      }
  
      @Override
      protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
          super.createBlockStateDefinition(builder);
          builder.add(BlockStateProperties.HORIZONTAL_FACING);
      }
  
      @Override
      public BlockState rotate(BlockState state, LevelAccessor level, BlockPos pos, Rotation direction) {
          return state.setValue(BlockStateProperties.HORIZONTAL_FACING, direction.rotate(state.getValue(BlockStateProperties.HORIZONTAL_FACING)));
      }
  
      @Override
      public VoxelShape getShape(BlockState state, BlockGetter getter, BlockPos pos, CollisionContext collisionContext) {
          if (state.getValue(BlockStateProperties.HORIZONTAL_FACING) == Direction.WEST || state.getValue(BlockStateProperties.HORIZONTAL_FACING) == Direction.EAST)
              return Block.box(3, 0, 5, 13, 13, 11);
          else
              return Block.box(5, 0, 3, 11, 13, 13);
      }
  
      @Override
      public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
          if (!level.isClientSide) {
              BlockEntity be = level.getBlockEntity(pos);
              if (be instanceof MicroscopeBlockEntity microscope) {
                  if (microscope.isLocked()) {
                      player.displayClientMessage(Component.translatable("gui.complicated_bees.microscope.locked"), true);
                      return InteractionResult.CONSUME;
                  }
                  MenuProvider containerProvider = new MenuProvider() {
                      @Override
                      public Component getDisplayName() {
                          return Component.translatable("block.complicated_bees.microscope");
                      }
  
                      @Override
                      public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player playerEntity) {
                          return new MicroscopeMenu(windowId, playerEntity, pos);
                      }
                  };
                  NetworkHooks.openScreen((ServerPlayer) player, containerProvider, be.getBlockPos());
              } else {
                  throw new IllegalStateException("Our named container provider is missing!");
              }
          }
          return InteractionResult.SUCCESS;
      }
  
      @Override
      public RenderShape getRenderShape(BlockState p_49232_) {
          return RenderShape.MODEL;
      }
  
      @Override
      public void onRemove(BlockState oldState, Level level, BlockPos pos, BlockState newState, boolean p_60519_) {
          if (!oldState.is(newState.getBlock())) {
              BlockEntity be = level.getBlockEntity(pos);
              if (be instanceof MicroscopeBlockEntity microscope) {
                  for (int i = 0; i < microscope.getItems().getSlots(); i++) {
                      Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), microscope.getItems().getStackInSlot(i));
                  }
              }
              super.onRemove(oldState, level, pos, newState, p_60519_);
          }
      }
  
      @Nullable
      @Override
      public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
          return new MicroscopeBlockEntity(pos, state);
      }
  }
  