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.tags.Tag;
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.level.block.state.BlockBehaviour;
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((((StateHolder<O, BlockState>)this.defaultBlockState()).setValue(SlabBlock.TYPE, SlabType.BOTTOM)).<Comparable, Boolean>setValue((Property<Comparable>)SlabBlock.WATERLOGGED, false));
    }
    
    @Override
    public boolean useShapeForLightOcclusion(final BlockState cfj) {
        return cfj.<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 cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        final SlabType cgo6 = cfj.<SlabType>getValue(SlabBlock.TYPE);
        switch (cgo6) {
            case DOUBLE: {
                return Shapes.block();
            }
            case TOP: {
                return SlabBlock.TOP_AABB;
            }
            default: {
                return SlabBlock.BOTTOM_AABB;
            }
        }
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bin) {
        final BlockPos fu3 = bin.getClickedPos();
        final BlockState cfj4 = bin.getLevel().getBlockState(fu3);
        if (cfj4.is(this)) {
            return (((StateHolder<O, BlockState>)cfj4).setValue(SlabBlock.TYPE, SlabType.DOUBLE)).<Comparable, Boolean>setValue((Property<Comparable>)SlabBlock.WATERLOGGED, false);
        }
        final FluidState cxa5 = bin.getLevel().getFluidState(fu3);
        final BlockState cfj5 = (((StateHolder<O, BlockState>)this.defaultBlockState()).setValue(SlabBlock.TYPE, SlabType.BOTTOM)).<Comparable, Boolean>setValue((Property<Comparable>)SlabBlock.WATERLOGGED, cxa5.getType() == Fluids.WATER);
        final Direction fz7 = bin.getClickedFace();
        if (fz7 == Direction.DOWN || (fz7 != Direction.UP && bin.getClickLocation().y - fu3.getY() > 0.5)) {
            return ((StateHolder<O, BlockState>)cfj5).<SlabType, SlabType>setValue(SlabBlock.TYPE, SlabType.TOP);
        }
        return cfj5;
    }
    
    @Override
    public boolean canBeReplaced(final BlockState cfj, final BlockPlaceContext bin) {
        final ItemStack bki4 = bin.getItemInHand();
        final SlabType cgo5 = cfj.<SlabType>getValue(SlabBlock.TYPE);
        if (cgo5 == SlabType.DOUBLE || bki4.getItem() != this.asItem()) {
            return false;
        }
        if (!bin.replacingClickedOnBlock()) {
            return true;
        }
        final boolean boolean6 = bin.getClickLocation().y - bin.getClickedPos().getY() > 0.5;
        final Direction fz7 = bin.getClickedFace();
        if (cgo5 == SlabType.BOTTOM) {
            return fz7 == Direction.UP || (boolean6 && fz7.getAxis().isHorizontal());
        }
        return fz7 == Direction.DOWN || (!boolean6 && fz7.getAxis().isHorizontal());
    }
    
    @Override
    public FluidState getFluidState(final BlockState cfj) {
        if (cfj.<Boolean>getValue((Property<Boolean>)SlabBlock.WATERLOGGED)) {
            return Fluids.WATER.getSource(false);
        }
        return super.getFluidState(cfj);
    }
    
    @Override
    public boolean placeLiquid(final LevelAccessor bqc, final BlockPos fu, final BlockState cfj, final FluidState cxa) {
        return cfj.<SlabType>getValue(SlabBlock.TYPE) != SlabType.DOUBLE && super.placeLiquid(bqc, fu, cfj, cxa);
    }
    
    @Override
    public boolean canPlaceLiquid(final BlockGetter bpg, final BlockPos fu, final BlockState cfj, final Fluid cwz) {
        return cfj.<SlabType>getValue(SlabBlock.TYPE) != SlabType.DOUBLE && super.canPlaceLiquid(bpg, fu, cfj, cwz);
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (cfj1.<Boolean>getValue((Property<Boolean>)SlabBlock.WATERLOGGED)) {
            bqc.getLiquidTicks().scheduleTick(fu5, Fluids.WATER, Fluids.WATER.getTickDelay(bqc));
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        switch (czg) {
            case LAND: {
                return false;
            }
            case WATER: {
                return bpg.getFluidState(fu).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);
    }
}
