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.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.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((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH)).<Comparable, Boolean>setValue((Property<Comparable>)PoweredRailBlock.POWERED, false));
    }
    
    protected boolean findPoweredRailSignal(final Level bjw, final BlockPos fk, final BlockState byj, final boolean boolean4, final int integer) {
        if (integer >= 8) {
            return false;
        }
        int integer2 = fk.getX();
        int integer3 = fk.getY();
        int integer4 = fk.getZ();
        boolean boolean5 = true;
        RailShape bzn11 = byj.<RailShape>getValue(PoweredRailBlock.SHAPE);
        switch (bzn11) {
            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;
                }
                bzn11 = RailShape.EAST_WEST;
                break;
            }
            case ASCENDING_WEST: {
                if (boolean4) {
                    --integer2;
                    ++integer3;
                    boolean5 = false;
                }
                else {
                    ++integer2;
                }
                bzn11 = RailShape.EAST_WEST;
                break;
            }
            case ASCENDING_NORTH: {
                if (boolean4) {
                    ++integer4;
                }
                else {
                    --integer4;
                    ++integer3;
                    boolean5 = false;
                }
                bzn11 = RailShape.NORTH_SOUTH;
                break;
            }
            case ASCENDING_SOUTH: {
                if (boolean4) {
                    ++integer4;
                    ++integer3;
                    boolean5 = false;
                }
                else {
                    --integer4;
                }
                bzn11 = RailShape.NORTH_SOUTH;
                break;
            }
        }
        return this.isSameRailWithPower(bjw, new BlockPos(integer2, integer3, integer4), boolean4, integer, bzn11) || (boolean5 && this.isSameRailWithPower(bjw, new BlockPos(integer2, integer3 - 1, integer4), boolean4, integer, bzn11));
    }
    
    protected boolean isSameRailWithPower(final Level bjw, final BlockPos fk, final boolean boolean3, final int integer, final RailShape bzn) {
        final BlockState byj7 = bjw.getBlockState(fk);
        if (byj7.getBlock() != this) {
            return false;
        }
        final RailShape bzn2 = byj7.<RailShape>getValue(PoweredRailBlock.SHAPE);
        return (bzn != RailShape.EAST_WEST || (bzn2 != RailShape.NORTH_SOUTH && bzn2 != RailShape.ASCENDING_NORTH && bzn2 != RailShape.ASCENDING_SOUTH)) && (bzn != RailShape.NORTH_SOUTH || (bzn2 != RailShape.EAST_WEST && bzn2 != RailShape.ASCENDING_EAST && bzn2 != RailShape.ASCENDING_WEST)) && byj7.<Boolean>getValue((Property<Boolean>)PoweredRailBlock.POWERED) && (bjw.hasNeighborSignal(fk) || this.findPoweredRailSignal(bjw, fk, byj7, boolean3, integer + 1));
    }
    
    @Override
    protected void updateState(final BlockState byj, final Level bjw, final BlockPos fk, final Block bph) {
        final boolean boolean6 = byj.<Boolean>getValue((Property<Boolean>)PoweredRailBlock.POWERED);
        final boolean boolean7 = bjw.hasNeighborSignal(fk) || this.findPoweredRailSignal(bjw, fk, byj, true, 0) || this.findPoweredRailSignal(bjw, fk, byj, false, 0);
        if (boolean7 != boolean6) {
            bjw.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Boolean>setValue((Property<Comparable>)PoweredRailBlock.POWERED, boolean7), 3);
            bjw.updateNeighborsAt(fk.below(), this);
            if (byj.<RailShape>getValue(PoweredRailBlock.SHAPE).isAscending()) {
                bjw.updateNeighborsAt(fk.above(), this);
            }
        }
    }
    
    @Override
    public Property<RailShape> getShapeProperty() {
        return PoweredRailBlock.SHAPE;
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        Label_0424: {
            switch (btu) {
                case CLOCKWISE_180: {
                    switch (byj.<RailShape>getValue(PoweredRailBlock.SHAPE)) {
                        case ASCENDING_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case ASCENDING_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case ASCENDING_NORTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_SOUTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case SOUTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        case SOUTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case NORTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        case NORTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        default: {
                            break Label_0424;
                        }
                    }
                    break;
                }
                case COUNTERCLOCKWISE_90: {
                    switch (byj.<RailShape>getValue(PoweredRailBlock.SHAPE)) {
                        case NORTH_SOUTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
                        }
                        case EAST_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
                        }
                        case ASCENDING_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case ASCENDING_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_NORTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case ASCENDING_SOUTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case SOUTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case SOUTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        case NORTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case NORTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        default: {
                            break Label_0424;
                        }
                    }
                    break;
                }
                case CLOCKWISE_90: {
                    switch (byj.<RailShape>getValue(PoweredRailBlock.SHAPE)) {
                        case NORTH_SOUTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.EAST_WEST);
                        }
                        case EAST_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_SOUTH);
                        }
                        case ASCENDING_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case ASCENDING_NORTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case ASCENDING_SOUTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case SOUTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case SOUTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        case NORTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case NORTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        default: {
                            break Label_0424;
                        }
                    }
                    break;
                }
            }
        }
        return byj;
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        final RailShape bzn4 = byj.<RailShape>getValue(PoweredRailBlock.SHAPE);
        Label_0319: {
            switch (bsu) {
                case LEFT_RIGHT: {
                    switch (bzn4) {
                        case ASCENDING_NORTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_SOUTH);
                        }
                        case ASCENDING_SOUTH: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_NORTH);
                        }
                        case SOUTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case SOUTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        case NORTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case NORTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        default: {
                            break Label_0319;
                        }
                    }
                    break;
                }
                case FRONT_BACK: {
                    switch (bzn4) {
                        case ASCENDING_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_WEST);
                        }
                        case ASCENDING_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.ASCENDING_EAST);
                        }
                        case SOUTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_WEST);
                        }
                        case SOUTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.SOUTH_EAST);
                        }
                        case NORTH_WEST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_EAST);
                        }
                        case NORTH_EAST: {
                            return ((AbstractStateHolder<O, BlockState>)byj).<RailShape, RailShape>setValue(PoweredRailBlock.SHAPE, RailShape.NORTH_WEST);
                        }
                        default: {
                            break Label_0319;
                        }
                    }
                    break;
                }
            }
        }
        return super.mirror(byj, bsu);
    }
    
    @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;
    }
}
