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.world.level.block.state.StateDefinition;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
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.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.RailShape;
import net.minecraft.world.level.block.state.properties.EnumProperty;

public class PoweredRailBlock extends BaseRailBlock {
    public static final EnumProperty<RailShape> SHAPE;
    public static final BooleanProperty POWERED;
    
    protected PoweredRailBlock(final Properties c) {
        super(true, c);
        this.registerDefaultState((((StateHolder<O, BlockState>)this.stateDefinition.any()).setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH)).<Comparable, Boolean>setValue((Property<Comparable>)PoweredRailBlock.POWERED, false));
    }
    
    protected boolean findPoweredRailSignal(final Level bqb, final BlockPos fu, final BlockState cfj, final boolean boolean4, final int integer) {
        if (integer >= 8) {
            return false;
        }
        int integer2 = fu.getX();
        int integer3 = fu.getY();
        int integer4 = fu.getZ();
        boolean boolean5 = true;
        RailShape cgm11 = cfj.<RailShape>getValue(PoweredRailBlock.SHAPE);
        switch (cgm11) {
            case NORTH_SOUTH: {
                if (boolean4) {
                    ++integer4;
                    break;
                }
                --integer4;
                break;
            }
            case EAST_WEST: {
                if (boolean4) {
                    --integer2;
                    break;
                }
                ++integer2;
                break;
            }
            case ASCENDING_EAST: {
                if (boolean4) {
                    --integer2;
                }
                else {
                    ++integer2;
                    ++integer3;
                    boolean5 = false;
                }
                cgm11 = RailShape.EAST_WEST;
                break;
            }
            case ASCENDING_WEST: {
                if (boolean4) {
                    --integer2;
                    ++integer3;
                    boolean5 = false;
                }
                else {
                    ++integer2;
                }
                cgm11 = RailShape.EAST_WEST;
                break;
            }
            case ASCENDING_NORTH: {
                if (boolean4) {
                    ++integer4;
                }
                else {
                    --integer4;
                    ++integer3;
                    boolean5 = false;
                }
                cgm11 = RailShape.NORTH_SOUTH;
                break;
            }
            case ASCENDING_SOUTH: {
                if (boolean4) {
                    ++integer4;
                    ++integer3;
                    boolean5 = false;
                }
                else {
                    --integer4;
                }
                cgm11 = RailShape.NORTH_SOUTH;
                break;
            }
        }
        return this.isSameRailWithPower(bqb, new BlockPos(integer2, integer3, integer4), boolean4, integer, cgm11) || (boolean5 && this.isSameRailWithPower(bqb, new BlockPos(integer2, integer3 - 1, integer4), boolean4, integer, cgm11));
    }
    
    protected boolean isSameRailWithPower(final Level bqb, final BlockPos fu, final boolean boolean3, final int integer, final RailShape cgm) {
        final BlockState cfj7 = bqb.getBlockState(fu);
        if (!cfj7.is(this)) {
            return false;
        }
        final RailShape cgm2 = cfj7.<RailShape>getValue(PoweredRailBlock.SHAPE);
        return (cgm != RailShape.EAST_WEST || (cgm2 != RailShape.NORTH_SOUTH && cgm2 != RailShape.ASCENDING_NORTH && cgm2 != RailShape.ASCENDING_SOUTH)) && (cgm != RailShape.NORTH_SOUTH || (cgm2 != RailShape.EAST_WEST && cgm2 != RailShape.ASCENDING_EAST && cgm2 != RailShape.ASCENDING_WEST)) && cfj7.<Boolean>getValue((Property<Boolean>)PoweredRailBlock.POWERED) && (bqb.hasNeighborSignal(fu) || this.findPoweredRailSignal(bqb, fu, cfj7, boolean3, integer + 1));
    }
    
    @Override
    protected void updateState(final BlockState cfj, final Level bqb, final BlockPos fu, final Block bvr) {
        final boolean boolean6 = cfj.<Boolean>getValue((Property<Boolean>)PoweredRailBlock.POWERED);
        final boolean boolean7 = bqb.hasNeighborSignal(fu) || this.findPoweredRailSignal(bqb, fu, cfj, true, 0) || this.findPoweredRailSignal(bqb, fu, cfj, false, 0);
        if (boolean7 != boolean6) {
            bqb.setBlock(fu, ((StateHolder<O, BlockState>)cfj).<Comparable, Boolean>setValue((Property<Comparable>)PoweredRailBlock.POWERED, boolean7), 3);
            bqb.updateNeighborsAt(fu.below(), this);
            if (cfj.<RailShape>getValue(PoweredRailBlock.SHAPE).isAscending()) {
                bqb.updateNeighborsAt(fu.above(), this);
            }
        }
    }
    
    @Override
    public Property<RailShape> getShapeProperty() {
        return PoweredRailBlock.SHAPE;
    }
    
    @Override
    public BlockState rotate(final BlockState cfj, final Rotation cap) {
        Label_0424: {
            switch (cap) {
                case CLOCKWISE_180: {
                    switch (cfj.<RailShape>getValue(PoweredRailBlock.SHAPE)) {
                        case ASCENDING_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case ASCENDING_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case ASCENDING_NORTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_SOUTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case SOUTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        case SOUTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case NORTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        case NORTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        default: {
                            break Label_0424;
                        }
                    }
                    break;
                }
                case COUNTERCLOCKWISE_90: {
                    switch (cfj.<RailShape>getValue(PoweredRailBlock.SHAPE)) {
                        case NORTH_SOUTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
                        }
                        case EAST_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
                        }
                        case ASCENDING_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case ASCENDING_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_NORTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case ASCENDING_SOUTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case SOUTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case SOUTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        case NORTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case NORTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        default: {
                            break Label_0424;
                        }
                    }
                    break;
                }
                case CLOCKWISE_90: {
                    switch (cfj.<RailShape>getValue(PoweredRailBlock.SHAPE)) {
                        case NORTH_SOUTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
                        }
                        case EAST_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
                        }
                        case ASCENDING_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case ASCENDING_NORTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case ASCENDING_SOUTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case SOUTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case SOUTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        case NORTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case NORTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        default: {
                            break Label_0424;
                        }
                    }
                    break;
                }
            }
        }
        return cfj;
    }
    
    @Override
    public BlockState mirror(final BlockState cfj, final Mirror bzj) {
        final RailShape cgm4 = cfj.<RailShape>getValue(PoweredRailBlock.SHAPE);
        Label_0319: {
            switch (bzj) {
                case LEFT_RIGHT: {
                    switch (cgm4) {
                        case ASCENDING_NORTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_SOUTH: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case SOUTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case SOUTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        case NORTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case NORTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        default: {
                            break Label_0319;
                        }
                    }
                    break;
                }
                case FRONT_BACK: {
                    switch (cgm4) {
                        case ASCENDING_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case ASCENDING_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case SOUTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case SOUTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        case NORTH_WEST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case NORTH_EAST: {
                            return ((StateHolder<O, BlockState>)cfj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        default: {
                            break Label_0319;
                        }
                    }
                    break;
                }
            }
        }
        return super.mirror(cfj, bzj);
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(PoweredRailBlock.SHAPE, PoweredRailBlock.POWERED);
    }
    
    static {
        SHAPE = BlockStateProperties.RAIL_SHAPE_STRAIGHT;
        POWERED = BlockStateProperties.POWERED;
    }
}
