content: package com.accbdd.complicated_bees.block;
  
  import com.accbdd.complicated_bees.block.entity.ApiaryBlockEntity;
  import com.accbdd.complicated_bees.screen.ApiaryMenu;
  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.LivingEntity;
  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.ItemStack;
  import net.minecraft.world.level.Level;
  import net.minecraft.world.level.block.BaseEntityBlock;
  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.entity.BlockEntityTicker;
  import net.minecraft.world.level.block.entity.BlockEntityType;
  import net.minecraft.world.level.block.state.BlockState;
  import net.minecraft.world.phys.BlockHitResult;
  import net.minecraftforge.items.IItemHandler;
  import net.minecraftforge.network.NetworkHooks;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
  
  public class ApiaryBlock extends BaseEntityBlock {
      public static final String SCREEN_APIARY = "gui.complicated_bees.apiary";
  
      public ApiaryBlock() {
          super(Properties.of()
                  .noOcclusion()
                  .requiresCorrectToolForDrops()
                  .strength(5, 6)
                  .sound(SoundType.METAL));
      }
  
      @Override
      public @NotNull RenderShape getRenderShape(BlockState state) {
          return RenderShape.MODEL;
      }
  
      @Override
      public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
          super.setPlacedBy(level, pos, state, placer, stack);
          if (!level.isClientSide) {
              BlockEntity be = level.getBlockEntity(pos);
              if (be instanceof ApiaryBlockEntity apiary && placer != null) {
                  apiary.setOwner(placer.getUUID());
              }
          }
      }
  
      @Nullable
      @Override
      public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
          return new ApiaryBlockEntity(pos, state);
      }
  
      @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 ApiaryBlockEntity) {
                  MenuProvider containerProvider = new MenuProvider() {
                      @Override
                      public Component getDisplayName() {
                          return Component.translatable(SCREEN_APIARY);
                      }
  
                      @Override
                      public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player player) {
                          return new ApiaryMenu(windowId, player, pos, ((ApiaryBlockEntity) be).getData());
                      }
                  };
                  NetworkHooks.openScreen((ServerPlayer) player, containerProvider, be.getBlockPos());
              } else {
                  throw new IllegalStateException("Our named container provider is missing!");
              }
          }
          return InteractionResult.SUCCESS;
      }
  
      @Nullable
      @Override
      public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
          if (level.isClientSide) {
              return null;
          } else {
              return (lvl, pos, st, blockEntity) -> {
                  if (blockEntity instanceof ApiaryBlockEntity be) {
                      be.tickServer();
                  }
              };
          }
      }
  
      @Override
      public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) {
          BlockEntity blockentity = pLevel.getBlockEntity(pPos);
          if (blockentity instanceof ApiaryBlockEntity apiary) {
              while (!apiary.getOutputBuffer().empty()) {
                  Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), apiary.getOutputBuffer().pop());
              }
              IItemHandler handler = apiary.getItemHandler().orElseThrow(() -> new RuntimeException("no item handler found!"));
              for (int i = 0; i < handler.getSlots(); i++) {
                  Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), handler.getStackInSlot(i));
              }
              IItemHandler frames = apiary.getFrameItemHandler().orElseThrow(() -> new RuntimeException("no item handler found!"));
              for (int i = 0; i < frames.getSlots(); i++) {
                  Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), frames.getStackInSlot(i));
              }
          }
          super.onRemove(pState, pLevel, pPos, pNewState, pMovedByPiston);
      }
  }
  