content: package com.github.alexthe666.iceandfire.block;
  
  import net.minecraft.core.BlockPos;
  import net.minecraft.core.Direction;
  import net.minecraft.world.InteractionHand;
  import net.minecraft.world.InteractionResult;
  import net.minecraft.world.entity.Entity;
  import net.minecraft.world.entity.player.Player;
  import net.minecraft.world.item.Item;
  import net.minecraft.world.item.ItemStack;
  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.LevelReader;
  import net.minecraft.world.level.block.Block;
  import net.minecraft.world.level.block.Blocks;
  import net.minecraft.world.level.block.state.BlockState;
  import net.minecraft.world.level.block.state.StateDefinition;
  import net.minecraft.world.level.block.state.properties.IntegerProperty;
  import net.minecraft.world.level.material.Material;
  import net.minecraft.world.level.pathfinder.PathComputationType;
  import net.minecraft.world.phys.BlockHitResult;
  import net.minecraft.world.phys.shapes.CollisionContext;
  import net.minecraft.world.phys.shapes.Shapes;
  import net.minecraft.world.phys.shapes.VoxelShape;
  import org.jetbrains.annotations.NotNull;
  
  import javax.annotation.Nullable;
  
  public class BlockGoldPile extends Block {
      public static final IntegerProperty LAYERS = IntegerProperty.create("layers", 1, 8);
      protected static final VoxelShape[] SHAPES = new VoxelShape[]{Shapes.empty(), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};
      public Item itemBlock;
  
      public BlockGoldPile() {
          super(
              Properties
                  .of(Material.DIRT)
                  .strength(0.3F, 1)
                  .randomTicks()
                  .sound(IafBlockRegistry.SOUND_TYPE_GOLD)
          );
  
          this.registerDefaultState(this.stateDefinition.any().setValue(LAYERS, 1));
      }
  
      @Override
      public boolean isPathfindable(@NotNull BlockState state, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, PathComputationType type) {
          switch (type) {
              case LAND:
                  return state.getValue(LAYERS) < 5;
              case WATER:
                  return false;
              case AIR:
                  return false;
              default:
                  return false;
          }
      }
  
      @Override
      public @NotNull VoxelShape getShape(BlockState state, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, @NotNull CollisionContext context) {
          return SHAPES[state.getValue(LAYERS)];
      }
  
      @Override
      public @NotNull VoxelShape getCollisionShape(BlockState state, @NotNull BlockGetter worldIn, @NotNull BlockPos pos, @NotNull CollisionContext context) {
          return SHAPES[state.getValue(LAYERS) - 1];
      }
  
      @Override
      public boolean useShapeForLightOcclusion(@NotNull BlockState state) {
          return true;
      }
  
      @Override
      public boolean canSurvive(@NotNull BlockState state, LevelReader worldIn, BlockPos pos) {
          BlockState blockstate = worldIn.getBlockState(pos.below());
          Block block = blockstate.getBlock();
          if (block != Blocks.ICE && block != Blocks.PACKED_ICE && block != Blocks.BARRIER) {
              if (block != Blocks.HONEY_BLOCK && block != Blocks.SOUL_SAND) {
                  return Block.isFaceFull(blockstate.getCollisionShape(worldIn, pos.below()), Direction.UP) || block instanceof BlockGoldPile && blockstate.getValue(LAYERS) == 8;
              } else {
                  return true;
              }
          } else {
              return false;
          }
      }
  
      @Deprecated
      public boolean canEntitySpawn(BlockState state, Entity entityIn) {
          return false;
      }
  
      @Override
      public @NotNull BlockState updateShape(BlockState stateIn, @NotNull Direction facing, @NotNull BlockState facingState, @NotNull LevelAccessor worldIn, @NotNull BlockPos currentPos, @NotNull BlockPos facingPos) {
          return !stateIn.canSurvive(worldIn, currentPos) ? Blocks.AIR.defaultBlockState() : super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos);
      }
  
  
      @Override
      @Nullable
      public BlockState getStateForPlacement(BlockPlaceContext context) {
          BlockState blockstate = context.getLevel().getBlockState(context.getClickedPos());
          if (blockstate.getBlock() == this) {
              int i = blockstate.getValue(LAYERS);
              return blockstate.setValue(LAYERS, Math.min(8, i + 1));
          } else {
              return super.getStateForPlacement(context);
          }
      }
  
      @Override
      protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
          builder.add(LAYERS);
      }
  
      @Override
      public @NotNull InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn, @NotNull BlockPos pos, Player playerIn, @NotNull InteractionHand handIn, @NotNull BlockHitResult resultIn) {
          ItemStack item = playerIn.getInventory().getSelected();
  
          if (!item.isEmpty()) {
              if (item.getItem() != null) {
                  if (item.getItem() == this.asItem()) {
                      if (!item.isEmpty()) {
                          if (state.getValue(LAYERS) < 8) {
                              worldIn.setBlock(pos, state.setValue(LAYERS, state.getValue(LAYERS) + 1), 3);
                              if (!playerIn.isCreative()) {
                                  item.shrink(1);
  
                                  if (item.isEmpty()) {
                                      playerIn.getInventory().setItem(playerIn.getInventory().selected, ItemStack.EMPTY);
                                  } else {
                                      playerIn.getInventory().setItem(playerIn.getInventory().selected, item);
                                  }
                              }
                              return InteractionResult.SUCCESS;
                          }
                      }
                  }
              }
          }
          return InteractionResult.PASS;
      }
  }