package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.tags.Tag;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.CollisionContext;
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;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class IronBarsBlock extends CrossCollisionBlock {
    protected IronBarsBlock(final Properties c) {
        super(1.0f, 1.0f, 16.0f, 16.0f, 16.0f, c);
        this.registerDefaultState(((((((StateHolder<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 bin) {
        final BlockGetter bpg3 = bin.getLevel();
        final BlockPos fu4 = bin.getClickedPos();
        final FluidState cxa5 = bin.getLevel().getFluidState(bin.getClickedPos());
        final BlockPos fu5 = fu4.north();
        final BlockPos fu6 = fu4.south();
        final BlockPos fu7 = fu4.west();
        final BlockPos fu8 = fu4.east();
        final BlockState cfj10 = bpg3.getBlockState(fu5);
        final BlockState cfj11 = bpg3.getBlockState(fu6);
        final BlockState cfj12 = bpg3.getBlockState(fu7);
        final BlockState cfj13 = bpg3.getBlockState(fu8);
        return ((((((StateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)IronBarsBlock.NORTH, this.attachsTo(cfj10, cfj10.isFaceSturdy(bpg3, fu5, Direction.SOUTH)))).setValue((Property<Comparable>)IronBarsBlock.SOUTH, this.attachsTo(cfj11, cfj11.isFaceSturdy(bpg3, fu6, Direction.NORTH)))).setValue((Property<Comparable>)IronBarsBlock.WEST, this.attachsTo(cfj12, cfj12.isFaceSturdy(bpg3, fu7, Direction.EAST)))).setValue((Property<Comparable>)IronBarsBlock.EAST, this.attachsTo(cfj13, cfj13.isFaceSturdy(bpg3, fu8, Direction.WEST)))).<Comparable, Boolean>setValue((Property<Comparable>)IronBarsBlock.WATERLOGGED, cxa5.getType() == Fluids.WATER);
    }
    
    @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>)IronBarsBlock.WATERLOGGED)) {
            bqc.getLiquidTicks().scheduleTick(fu5, Fluids.WATER, Fluids.WATER.getTickDelay(bqc));
        }
        if (fz.getAxis().isHorizontal()) {
            return ((StateHolder<O, BlockState>)cfj1).<Comparable, Boolean>setValue((Property<Comparable>)IronBarsBlock.PROPERTY_BY_DIRECTION.get(fz), this.attachsTo(cfj3, cfj3.isFaceSturdy(bqc, fu6, fz.getOpposite())));
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    @Override
    public VoxelShape getVisualShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return Shapes.empty();
    }
    
    @Override
    public boolean skipRendering(final BlockState cfj1, final BlockState cfj2, final Direction fz) {
        if (cfj2.is(this)) {
            if (!fz.getAxis().isHorizontal()) {
                return true;
            }
            if (cfj1.<Boolean>getValue((Property<Boolean>)IronBarsBlock.PROPERTY_BY_DIRECTION.get(fz)) && cfj2.<Boolean>getValue((Property<Boolean>)IronBarsBlock.PROPERTY_BY_DIRECTION.get(fz.getOpposite()))) {
                return true;
            }
        }
        return super.skipRendering(cfj1, cfj2, fz);
    }
    
    public final boolean attachsTo(final BlockState cfj, final boolean boolean2) {
        final Block bvr4 = cfj.getBlock();
        return (!Block.isExceptionForConnection(bvr4) && boolean2) || bvr4 instanceof IronBarsBlock || bvr4.is(BlockTags.WALLS);
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(IronBarsBlock.NORTH, IronBarsBlock.EAST, IronBarsBlock.WEST, IronBarsBlock.SOUTH, IronBarsBlock.WATERLOGGED);
    }
}
