package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.util.Mth;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
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.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.IntegerProperty;

public class StandingSignBlock extends SignBlock {
    public static final IntegerProperty ROTATION;
    
    public StandingSignBlock(final Properties c, final WoodType cgs) {
        super(c, cgs);
        this.registerDefaultState((((StateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)StandingSignBlock.ROTATION, 0)).<Comparable, Boolean>setValue((Property<Comparable>)StandingSignBlock.WATERLOGGED, false));
    }
    
    @Override
    public boolean canSurvive(final BlockState cfj, final LevelReader bqd, final BlockPos fu) {
        return bqd.getBlockState(fu.below()).getMaterial().isSolid();
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        final FluidState cxa3 = bin.getLevel().getFluidState(bin.getClickedPos());
        return (((StateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)StandingSignBlock.ROTATION, Mth.floor((180.0f + bin.getRotation()) * 16.0f / 360.0f + 0.5) & 0xF)).<Comparable, Boolean>setValue((Property<Comparable>)StandingSignBlock.WATERLOGGED, cxa3.getType() == Fluids.WATER);
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (fz == Direction.DOWN && !this.canSurvive(cfj1, bqc, fu5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public BlockState rotate(final BlockState cfj, final Rotation cap) {
        return ((StateHolder<O, BlockState>)cfj).<Comparable, Integer>setValue((Property<Comparable>)StandingSignBlock.ROTATION, cap.rotate(cfj.<Integer>getValue((Property<Integer>)StandingSignBlock.ROTATION), 16));
    }
    
    @Override
    public BlockState mirror(final BlockState cfj, final Mirror bzj) {
        return ((StateHolder<O, BlockState>)cfj).<Comparable, Integer>setValue((Property<Comparable>)StandingSignBlock.ROTATION, bzj.mirror(cfj.<Integer>getValue((Property<Integer>)StandingSignBlock.ROTATION), 16));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(StandingSignBlock.ROTATION, StandingSignBlock.WATERLOGGED);
    }
    
    static {
        ROTATION = BlockStateProperties.ROTATION_16;
    }
}
