package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.core.Direction;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;

public class IronBarsBlock extends CrossCollisionBlock {
    protected IronBarsBlock(final Properties c) {
        super(1.0f, 1.0f, 16.0f, 16.0f, 16.0f, c);
        this.registerDefaultState(((((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)IronBarsBlock.NORTH, false)).setValue((Property<Comparable>)IronBarsBlock.EAST, false)).setValue((Property<Comparable>)IronBarsBlock.SOUTH, false)).setValue((Property<Comparable>)IronBarsBlock.WEST, false)).<Comparable, Boolean>setValue((Property<Comparable>)IronBarsBlock.WATERLOGGED, false));
    }
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        final BlockGetter bjg3 = bcq.getLevel();
        final BlockPos fk4 = bcq.getClickedPos();
        final FluidState coj5 = bcq.getLevel().getFluidState(bcq.getClickedPos());
        final BlockPos fk5 = fk4.north();
        final BlockPos fk6 = fk4.south();
        final BlockPos fk7 = fk4.west();
        final BlockPos fk8 = fk4.east();
        final BlockState byj10 = bjg3.getBlockState(fk5);
        final BlockState byj11 = bjg3.getBlockState(fk6);
        final BlockState byj12 = bjg3.getBlockState(fk7);
        final BlockState byj13 = bjg3.getBlockState(fk8);
        return ((((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)IronBarsBlock.NORTH, this.attachsTo(byj10, byj10.isFaceSturdy(bjg3, fk5, Direction.SOUTH)))).setValue((Property<Comparable>)IronBarsBlock.SOUTH, this.attachsTo(byj11, byj11.isFaceSturdy(bjg3, fk6, Direction.NORTH)))).setValue((Property<Comparable>)IronBarsBlock.WEST, this.attachsTo(byj12, byj12.isFaceSturdy(bjg3, fk7, Direction.EAST)))).setValue((Property<Comparable>)IronBarsBlock.EAST, this.attachsTo(byj13, byj13.isFaceSturdy(bjg3, fk8, Direction.WEST)))).<Comparable, Boolean>setValue((Property<Comparable>)IronBarsBlock.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>)IronBarsBlock.WATERLOGGED)) {
            bjx.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bjx));
        }
        if (fp.getAxis().isHorizontal()) {
            return ((AbstractStateHolder<O, BlockState>)byj1).<Comparable, Boolean>setValue((Property<Comparable>)IronBarsBlock.PROPERTY_BY_DIRECTION.get(fp), this.attachsTo(byj3, byj3.isFaceSturdy(bjx, fk6, fp.getOpposite())));
        }
        return super.updateShape(byj1, fp, byj3, bjx, fk5, fk6);
    }
    
    @Override
    public boolean skipRendering(final BlockState byj1, final BlockState byj2, final Direction fp) {
        if (byj2.getBlock() == this) {
            if (!fp.getAxis().isHorizontal()) {
                return true;
            }
            if (byj1.<Boolean>getValue((Property<Boolean>)IronBarsBlock.PROPERTY_BY_DIRECTION.get(fp)) && byj2.<Boolean>getValue((Property<Boolean>)IronBarsBlock.PROPERTY_BY_DIRECTION.get(fp.getOpposite()))) {
                return true;
            }
        }
        return super.skipRendering(byj1, byj2, fp);
    }
    
    public final boolean attachsTo(final BlockState byj, final boolean boolean2) {
        final Block bph4 = byj.getBlock();
        return (!Block.isExceptionForConnection(bph4) && boolean2) || bph4 instanceof IronBarsBlock;
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(IronBarsBlock.NORTH, IronBarsBlock.EAST, IronBarsBlock.WEST, IronBarsBlock.SOUTH, IronBarsBlock.WATERLOGGED);
    }
}
