package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
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.properties.IntegerProperty;

public class StandingSignBlock extends SignBlock {
    public static final IntegerProperty ROTATION;
    
    public StandingSignBlock(final Properties c, final WoodType bzs) {
        super(c, bzs);
        this.registerDefaultState((((AbstractStateHolder<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 byj, final LevelReader bjz, final BlockPos fk) {
        return bjz.getBlockState(fk.below()).getMaterial().isSolid();
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final FluidState coj3 = bcq.getLevel().getFluidState(bcq.getClickedPos());
        return (((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)StandingSignBlock.ROTATION, Mth.floor((180.0f + bcq.getRotation()) * 16.0f / 360.0f + 0.5) & 0xF)).<Comparable, Boolean>setValue((Property<Comparable>)StandingSignBlock.WATERLOGGED, coj3.getType() == Fluids.WATER);
    }
    
    @Override
    public BlockState updateShape(final BlockState byj1, final Direction fp, final BlockState byj3, final LevelAccessor bjx, final BlockPos fk5, final BlockPos fk6) {
        if (fp == Direction.DOWN && !this.canSurvive(byj1, 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, Integer>setValue((Property<Comparable>)StandingSignBlock.ROTATION, btu.rotate(byj.<Integer>getValue((Property<Integer>)StandingSignBlock.ROTATION), 16));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Integer>setValue((Property<Comparable>)StandingSignBlock.ROTATION, bsu.mirror(byj.<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;
    }
}
