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.world.level.material.FluidState;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.tags.BlockTags;
import net.minecraft.core.Direction;
import net.minecraft.world.level.pathfinder.PathComputationType;
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.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class WallBlock extends CrossCollisionBlock {
    public static final BooleanProperty UP;
    private final VoxelShape[] shapeWithPostByIndex;
    private final VoxelShape[] collisionShapeWithPostByIndex;
    
    public WallBlock(final Properties c) {
        super(0.0f, 3.0f, 0.0f, 14.0f, 24.0f, c);
        this.registerDefaultState((((((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)WallBlock.UP, true)).setValue((Property<Comparable>)WallBlock.NORTH, false)).setValue((Property<Comparable>)WallBlock.EAST, false)).setValue((Property<Comparable>)WallBlock.SOUTH, false)).setValue((Property<Comparable>)WallBlock.WEST, false)).<Comparable, Boolean>setValue((Property<Comparable>)WallBlock.WATERLOGGED, false));
        this.shapeWithPostByIndex = this.makeShapes(4.0f, 3.0f, 16.0f, 0.0f, 14.0f);
        this.collisionShapeWithPostByIndex = this.makeShapes(4.0f, 3.0f, 24.0f, 0.0f, 24.0f);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        if (byj.<Boolean>getValue((Property<Boolean>)WallBlock.UP)) {
            return this.shapeWithPostByIndex[this.getAABBIndex(byj)];
        }
        return super.getShape(byj, bjg, fk, cvq);
    }
    
    @Override
    public VoxelShape getCollisionShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        if (byj.<Boolean>getValue((Property<Boolean>)WallBlock.UP)) {
            return this.collisionShapeWithPostByIndex[this.getAABBIndex(byj)];
        }
        return super.getCollisionShape(byj, bjg, fk, cvq);
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    private boolean connectsTo(final BlockState byj, final boolean boolean2, final Direction fp) {
        final Block bph5 = byj.getBlock();
        final boolean boolean3 = bph5.is(BlockTags.WALLS) || (bph5 instanceof FenceGateBlock && FenceGateBlock.connectsToDirection(byj, fp));
        return (!Block.isExceptionForConnection(bph5) && boolean2) || boolean3;
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final LevelReader bjz3 = bcq.getLevel();
        final BlockPos fk4 = bcq.getClickedPos();
        final FluidState coj5 = bcq.getLevel().getFluidState(bcq.getClickedPos());
        final BlockPos fk5 = fk4.north();
        final BlockPos fk6 = fk4.east();
        final BlockPos fk7 = fk4.south();
        final BlockPos fk8 = fk4.west();
        final BlockState byj10 = bjz3.getBlockState(fk5);
        final BlockState byj11 = bjz3.getBlockState(fk6);
        final BlockState byj12 = bjz3.getBlockState(fk7);
        final BlockState byj13 = bjz3.getBlockState(fk8);
        final boolean boolean14 = this.connectsTo(byj10, byj10.isFaceSturdy(bjz3, fk5, Direction.SOUTH), Direction.SOUTH);
        final boolean boolean15 = this.connectsTo(byj11, byj11.isFaceSturdy(bjz3, fk6, Direction.WEST), Direction.WEST);
        final boolean boolean16 = this.connectsTo(byj12, byj12.isFaceSturdy(bjz3, fk7, Direction.NORTH), Direction.NORTH);
        final boolean boolean17 = this.connectsTo(byj13, byj13.isFaceSturdy(bjz3, fk8, Direction.EAST), Direction.EAST);
        final boolean boolean18 = (!boolean14 || boolean15 || !boolean16 || boolean17) && (boolean14 || !boolean15 || boolean16 || !boolean17);
        return (((((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)WallBlock.UP, boolean18 || !bjz3.isEmptyBlock(fk4.above()))).setValue((Property<Comparable>)WallBlock.NORTH, boolean14)).setValue((Property<Comparable>)WallBlock.EAST, boolean15)).setValue((Property<Comparable>)WallBlock.SOUTH, boolean16)).setValue((Property<Comparable>)WallBlock.WEST, boolean17)).<Comparable, Boolean>setValue((Property<Comparable>)WallBlock.WATERLOGGED, coj5.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 (byj1.<Boolean>getValue((Property<Boolean>)WallBlock.WATERLOGGED)) {
            bjx.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bjx));
        }
        if (fp == Direction.DOWN) {
            return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
        }
        final Direction fp2 = fp.getOpposite();
        final boolean boolean9 = (fp == Direction.NORTH) ? this.connectsTo(byj3, byj3.isFaceSturdy(bjx, fk6, fp2), fp2) : byj1.<Boolean>getValue((Property<Boolean>)WallBlock.NORTH);
        final boolean boolean10 = (fp == Direction.EAST) ? this.connectsTo(byj3, byj3.isFaceSturdy(bjx, fk6, fp2), fp2) : byj1.<Boolean>getValue((Property<Boolean>)WallBlock.EAST);
        final boolean boolean11 = (fp == Direction.SOUTH) ? this.connectsTo(byj3, byj3.isFaceSturdy(bjx, fk6, fp2), fp2) : byj1.<Boolean>getValue((Property<Boolean>)WallBlock.SOUTH);
        final boolean boolean12 = (fp == Direction.WEST) ? this.connectsTo(byj3, byj3.isFaceSturdy(bjx, fk6, fp2), fp2) : byj1.<Boolean>getValue((Property<Boolean>)WallBlock.WEST);
        final boolean boolean13 = (!boolean9 || boolean10 || !boolean11 || boolean12) && (boolean9 || !boolean10 || boolean11 || !boolean12);
        return ((((((AbstractStateHolder<O, BlockState>)byj1).setValue((Property<Comparable>)WallBlock.UP, boolean13 || !bjx.isEmptyBlock(fk5.above()))).setValue((Property<Comparable>)WallBlock.NORTH, boolean9)).setValue((Property<Comparable>)WallBlock.EAST, boolean10)).setValue((Property<Comparable>)WallBlock.SOUTH, boolean11)).<Comparable, Boolean>setValue((Property<Comparable>)WallBlock.WEST, boolean12);
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(WallBlock.UP, WallBlock.NORTH, WallBlock.EAST, WallBlock.WEST, WallBlock.SOUTH, WallBlock.WATERLOGGED);
    }
    
    static {
        UP = BlockStateProperties.UP;
    }
}
