package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.core.Direction;
import java.util.Map;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

public class BaseCoralWallFanBlock extends BaseCoralFanBlock {
    public static final DirectionProperty FACING;
    private static final Map<Direction, VoxelShape> SHAPES;
    
    protected BaseCoralWallFanBlock(final Properties c) {
        super(c);
        this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)BaseCoralWallFanBlock.WATERLOGGED, true));
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return BaseCoralWallFanBlock.SHAPES.get(byj.getValue((Property<Object>)BaseCoralWallFanBlock.FACING));
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return byj.rotate(bsu.getRotation(byj.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING)));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(BaseCoralWallFanBlock.FACING, BaseCoralWallFanBlock.WATERLOGGED);
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (byj1.<Boolean>getValue((Property<Boolean>)BaseCoralWallFanBlock.WATERLOGGED)) {
            bjx.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bjx));
        }
        if (fp.getOpposite() == byj1.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING) && !byj1.canSurvive(bjx, fk5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return byj1;
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        final Direction fp5 = byj.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING);
        final BlockPos fk2 = fk.relative(fp5.getOpposite());
        final BlockState byj2 = bjz.getBlockState(fk2);
        return byj2.isFaceSturdy(bjz, fk2, fp5);
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        BlockState byj3 = super.getStateForPlacement(bcq);
        final LevelReader bjz4 = bcq.getLevel();
        final BlockPos fk5 = bcq.getClickedPos();
        final Direction[] nearestLookingDirections;
        final Direction[] arr6 = nearestLookingDirections = bcq.getNearestLookingDirections();
        for (final Direction fp10 : nearestLookingDirections) {
            if (fp10.getAxis().isHorizontal()) {
                byj3 = ((AbstractStateHolder<O, BlockState>)byj3).<Comparable, Direction>setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, fp10.getOpposite());
                if (byj3.canSurvive(bjz4, fk5)) {
                    return byj3;
                }
            }
        }
        return null;
    }
    
    static {
        FACING = HorizontalDirectionalBlock.FACING;
        SHAPES = Maps.<Direction, Object>newEnumMap(ImmutableMap.<Direction, VoxelShape>of(Direction.NORTH, Block.box(0.0, 4.0, 5.0, 16.0, 12.0, 16.0), Direction.SOUTH, Block.box(0.0, 4.0, 0.0, 16.0, 12.0, 11.0), Direction.WEST, Block.box(5.0, 4.0, 0.0, 16.0, 12.0, 16.0), Direction.EAST, Block.box(0.0, 4.0, 0.0, 11.0, 12.0, 16.0)));
    }
}
