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 net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.LevelReader;
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.level.block.state.properties.WoodType;
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 WallSignBlock extends SignBlock {
    public static final DirectionProperty FACING;
    private static final Map<Direction, VoxelShape> AABBS;
    
    public WallSignBlock(final Properties c, final WoodType bzs) {
        super(c, bzs);
        this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)WallSignBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)WallSignBlock.WATERLOGGED, false));
    }
    
    @Override
    public String getDescriptionId() {
        return this.asItem().getDescriptionId();
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return WallSignBlock.AABBS.get(byj.getValue((Property<Object>)WallSignBlock.FACING));
    }
    
    @Override
    public boolean canSurvive(final BlockState byj, final LevelReader bjz, final BlockPos fk) {
        return bjz.getBlockState(fk.relative(byj.<Direction>getValue((Property<Direction>)WallSignBlock.FACING).getOpposite())).getMaterial().isSolid();
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        BlockState byj3 = this.defaultBlockState();
        final FluidState coj4 = bcq.getLevel().getFluidState(bcq.getClickedPos());
        final LevelReader bjz5 = bcq.getLevel();
        final BlockPos fk6 = bcq.getClickedPos();
        final Direction[] nearestLookingDirections;
        final Direction[] arr7 = nearestLookingDirections = bcq.getNearestLookingDirections();
        for (final Direction fp11 : nearestLookingDirections) {
            if (fp11.getAxis().isHorizontal()) {
                final Direction fp12 = fp11.getOpposite();
                byj3 = ((AbstractStateHolder<O, BlockState>)byj3).<Comparable, Direction>setValue((Property<Comparable>)WallSignBlock.FACING, fp12);
                if (byj3.canSurvive(bjz5, fk6)) {
                    return ((AbstractStateHolder<O, BlockState>)byj3).<Comparable, Boolean>setValue((Property<Comparable>)WallSignBlock.WATERLOGGED, coj4.getType() == Fluids.WATER);
                }
            }
        }
        return null;
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (fp.getOpposite() == byj1.<Direction>getValue((Property<Direction>)WallSignBlock.FACING) && !byj1.canSurvive(bjx, fk5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)WallSignBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)WallSignBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return byj.rotate(bsu.getRotation(byj.<Direction>getValue((Property<Direction>)WallSignBlock.FACING)));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(WallSignBlock.FACING, WallSignBlock.WATERLOGGED);
    }
    
    static {
        FACING = HorizontalDirectionalBlock.FACING;
        AABBS = Maps.<Direction, Object>newEnumMap(ImmutableMap.<Direction, VoxelShape>of(Direction.NORTH, Block.box(0.0, 4.5, 14.0, 16.0, 12.5, 16.0), Direction.SOUTH, Block.box(0.0, 4.5, 0.0, 16.0, 12.5, 2.0), Direction.EAST, Block.box(0.0, 4.5, 0.0, 2.0, 12.5, 16.0), Direction.WEST, Block.box(14.0, 4.5, 0.0, 16.0, 12.5, 16.0)));
    }
}
