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.tags.FluidTags;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.core.Direction;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.phys.shapes.Shapes;
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.StateDefinition;
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.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.block.state.properties.EnumProperty;

public class SlabBlock extends Block implements SimpleWaterloggedBlock {
    public static final EnumProperty<SlabType> TYPE;
    public static final BooleanProperty WATERLOGGED;
    protected static final VoxelShape BOTTOM_AABB;
    protected static final VoxelShape TOP_AABB;
    
    public SlabBlock(final Properties c) {
        super(c);
        this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue(SlabBlock.TYPE, SlabType.BOTTOM)).<Comparable, Boolean>setValue((Property<Comparable>)SlabBlock.WATERLOGGED, false));
    }
    
    @Override
    public boolean useShapeForLightOcclusion(final BlockState byj) {
        return byj.<SlabType>getValue(SlabBlock.TYPE) != SlabType.DOUBLE;
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(SlabBlock.TYPE, SlabBlock.WATERLOGGED);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        final SlabType bzp6 = byj.<SlabType>getValue(SlabBlock.TYPE);
        switch (bzp6) {
            case DOUBLE: {
                return Shapes.block();
            }
            case TOP: {
                return SlabBlock.TOP_AABB;
            }
            default: {
                return SlabBlock.BOTTOM_AABB;
            }
        }
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final BlockPos fk3 = bcq.getClickedPos();
        final BlockState byj4 = bcq.getLevel().getBlockState(fk3);
        if (byj4.getBlock() == this) {
            return (((AbstractStateHolder<O, BlockState>)byj4).setValue(SlabBlock.TYPE, SlabType.DOUBLE)).<Comparable, Boolean>setValue((Property<Comparable>)SlabBlock.WATERLOGGED, false);
        }
        final FluidState coj5 = bcq.getLevel().getFluidState(fk3);
        final BlockState byj5 = (((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue(SlabBlock.TYPE, SlabType.BOTTOM)).<Comparable, Boolean>setValue((Property<Comparable>)SlabBlock.WATERLOGGED, coj5.getType() == Fluids.WATER);
        final Direction fp7 = bcq.getClickedFace();
        if (fp7 == Direction.DOWN || (fp7 != Direction.UP && bcq.getClickLocation().y - fk3.getY() > 0.5)) {
            return ((AbstractStateHolder<O, BlockState>)byj5).<SlabType, SlabType>setValue(SlabBlock.TYPE, SlabType.TOP);
        }
        return byj5;
    }
    
    @Override
    public boolean canBeReplaced(final BlockState byj, final BlockPlaceContext bcq) {
        final ItemStack ben4 = bcq.getItemInHand();
        final SlabType bzp5 = byj.<SlabType>getValue(SlabBlock.TYPE);
        if (bzp5 == SlabType.DOUBLE || ben4.getItem() != this.asItem()) {
            return false;
        }
        if (!bcq.replacingClickedOnBlock()) {
            return true;
        }
        final boolean boolean6 = bcq.getClickLocation().y - bcq.getClickedPos().getY() > 0.5;
        final Direction fp7 = bcq.getClickedFace();
        if (bzp5 == SlabType.BOTTOM) {
            return fp7 == Direction.UP || (boolean6 && fp7.getAxis().isHorizontal());
        }
        return fp7 == Direction.DOWN || (!boolean6 && fp7.getAxis().isHorizontal());
    }
    
    @Override
    public FluidState getFluidState(final BlockState byj) {
        if (byj.<Boolean>getValue((Property<Boolean>)SlabBlock.WATERLOGGED)) {
            return Fluids.WATER.getSource(false);
        }
        return super.getFluidState(byj);
    }
    
    @Override
    public boolean placeLiquid(final LevelAccessor bjx, final BlockPos fk, final BlockState byj, final FluidState coj) {
        return byj.<SlabType>getValue(SlabBlock.TYPE) != SlabType.DOUBLE && super.placeLiquid(bjx, fk, byj, coj);
    }
    
    @Override
    public boolean canPlaceLiquid(final BlockGetter bjg, final BlockPos fk, final BlockState byj, final Fluid coi) {
        return byj.<SlabType>getValue(SlabBlock.TYPE) != SlabType.DOUBLE && super.canPlaceLiquid(bjg, fk, byj, coi);
    }
    
    @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>)SlabBlock.WATERLOGGED)) {
            bjx.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bjx));
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        switch (cqr) {
            case LAND: {
                return false;
            }
            case WATER: {
                return bjg.getFluidState(fk).is(FluidTags.WATER);
            }
            case AIR: {
                return false;
            }
            default: {
                return false;
            }
        }
    }
    
    static {
        TYPE = BlockStateProperties.SLAB_TYPE;
        WATERLOGGED = BlockStateProperties.WATERLOGGED;
        BOTTOM_AABB = Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0);
        TOP_AABB = Block.box(0.0, 8.0, 0.0, 16.0, 16.0, 16.0);
    }
}
