content: package com.accbdd.complicated_bees.block;
  
  import com.accbdd.complicated_bees.block.entity.AutolyzerBlockEntity;
  import com.accbdd.complicated_bees.screen.AutolyzerMenu;
  import net.minecraft.core.BlockPos;
  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.Level;
  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.SoundType;
  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.minecraftforge.items.IItemHandler;
  import net.minecraftforge.items.ItemStackHandler;
  import net.minecraftforge.network.NetworkHooks;
  import org.jetbrains.annotations.Nullable;
  
  public class AutolyzerBlock extends BaseEntityBlock {
      public AutolyzerBlock() {
          super(Properties.of()
                  .strength(3.5F)
                  .requiresCorrectToolForDrops()
                  .sound(SoundType.METAL));
      }
  
      @Nullable
      @Override
      public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
          return new AutolyzerBlockEntity(pPos, pState);
      }
  
      @Override
      public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
          if (!level.isClientSide) {
              BlockEntity be = level.getBlockEntity(pos);
              if (be instanceof AutolyzerBlockEntity) {
                  MenuProvider containerProvider = new MenuProvider() {
                      @Override
                      public Component getDisplayName() {
                          return Component.empty();
                      }
  
                      @Override
                      public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player playerEntity) {
                          return new AutolyzerMenu(windowId, playerEntity, be.getBlockPos());
                      }
                  };
                  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 pState) {
          return RenderShape.MODEL;
      }
  
      @Override
      public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) {
          BlockEntity blockentity = pLevel.getBlockEntity(pPos);
          if (blockentity instanceof AutolyzerBlockEntity autolyzer && !pNewState.is(this)) {
              IItemHandler handler = autolyzer.getItemHandler().resolve().orElse(new ItemStackHandler());
              for (int i = 0; i < handler.getSlots(); i++) {
                  Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), handler.getStackInSlot(i));
              }
          }
          super.onRemove(pState, pLevel, pPos, pNewState, pMovedByPiston);
      }
  
      @Nullable
      @Override
      public BlockState getStateForPlacement(BlockPlaceContext pContext) {
          return this.defaultBlockState()
                  .setValue(BlockStateProperties.FACING, pContext.getHorizontalDirection().getOpposite());
      }
  
      @Override
      protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
          super.createBlockStateDefinition(pBuilder);
          pBuilder.add(BlockStateProperties.FACING);
      }
  }
  