    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.renderer.texture.IconRegister;
    006import net.minecraft.util.Icon;
    007import net.minecraft.world.World;
    008
    009public class BlockRailPowered extends BlockRailBase
    010{
    011    @SideOnly(Side.CLIENT)
    012    protected Icon field_94362_b;
    013
    014    protected BlockRailPowered(int par1)
    015    {
    016        super(par1, true);
    017    }
    018
    019    @SideOnly(Side.CLIENT)
    020
    021    /**
    022     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    023     */
    024    public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
    025    {
    026        return (par2 & 8) == 0 ? this.field_94336_cN : this.field_94362_b;
    027    }
    028
    029    @SideOnly(Side.CLIENT)
    030    public void func_94332_a(IconRegister par1IconRegister)
    031    {
    032        super.func_94332_a(par1IconRegister);
    033        this.field_94362_b = par1IconRegister.func_94245_a(this.func_94330_A() + "_powered");
    034    }
    035
    036    protected boolean func_94360_a(World par1World, int par2, int par3, int par4, int par5, boolean par6, int par7)
    037    {
    038        if (par7 >= 8)
    039        {
    040            return false;
    041        }
    042        else
    043        {
    044            int j1 = par5 & 7;
    045            boolean flag1 = true;
    046
    047            switch (j1)
    048            {
    049                case 0:
    050                    if (par6)
    051                    {
    052                        ++par4;
    053                    }
    054                    else
    055                    {
    056                        --par4;
    057                    }
    058
    059                    break;
    060                case 1:
    061                    if (par6)
    062                    {
    063                        --par2;
    064                    }
    065                    else
    066                    {
    067                        ++par2;
    068                    }
    069
    070                    break;
    071                case 2:
    072                    if (par6)
    073                    {
    074                        --par2;
    075                    }
    076                    else
    077                    {
    078                        ++par2;
    079                        ++par3;
    080                        flag1 = false;
    081                    }
    082
    083                    j1 = 1;
    084                    break;
    085                case 3:
    086                    if (par6)
    087                    {
    088                        --par2;
    089                        ++par3;
    090                        flag1 = false;
    091                    }
    092                    else
    093                    {
    094                        ++par2;
    095                    }
    096
    097                    j1 = 1;
    098                    break;
    099                case 4:
    100                    if (par6)
    101                    {
    102                        ++par4;
    103                    }
    104                    else
    105                    {
    106                        --par4;
    107                        ++par3;
    108                        flag1 = false;
    109                    }
    110
    111                    j1 = 0;
    112                    break;
    113                case 5:
    114                    if (par6)
    115                    {
    116                        ++par4;
    117                        ++par3;
    118                        flag1 = false;
    119                    }
    120                    else
    121                    {
    122                        --par4;
    123                    }
    124
    125                    j1 = 0;
    126            }
    127
    128            return this.func_94361_a(par1World, par2, par3, par4, par6, par7, j1) ? true : flag1 && this.func_94361_a(par1World, par2, par3 - 1, par4, par6, par7, j1);
    129        }
    130    }
    131
    132    protected boolean func_94361_a(World par1World, int par2, int par3, int par4, boolean par5, int par6, int par7)
    133    {
    134        int j1 = par1World.getBlockId(par2, par3, par4);
    135
    136        if (j1 == this.blockID)
    137        {
    138            int k1 = par1World.getBlockMetadata(par2, par3, par4);
    139            int l1 = k1 & 7;
    140
    141            if (par7 == 1 && (l1 == 0 || l1 == 4 || l1 == 5))
    142            {
    143                return false;
    144            }
    145
    146            if (par7 == 0 && (l1 == 1 || l1 == 2 || l1 == 3))
    147            {
    148                return false;
    149            }
    150
    151            if ((k1 & 8) != 0)
    152            {
    153                if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
    154                {
    155                    return true;
    156                }
    157
    158                return this.func_94360_a(par1World, par2, par3, par4, k1, par5, par6 + 1);
    159            }
    160        }
    161
    162        return false;
    163    }
    164
    165    protected void func_94358_a(World par1World, int par2, int par3, int par4, int par5, int par6, int par7)
    166    {
    167        boolean flag = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4);
    168        flag = flag || this.func_94360_a(par1World, par2, par3, par4, par5, true, 0) || this.func_94360_a(par1World, par2, par3, par4, par5, false, 0);
    169        boolean flag1 = false;
    170
    171        if (flag && (par5 & 8) == 0)
    172        {
    173            par1World.setBlockMetadataWithNotify(par2, par3, par4, par6 | 8, 3);
    174            flag1 = true;
    175        }
    176        else if (!flag && (par5 & 8) != 0)
    177        {
    178            par1World.setBlockMetadataWithNotify(par2, par3, par4, par6, 3);
    179            flag1 = true;
    180        }
    181
    182        if (flag1)
    183        {
    184            par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
    185
    186            if (par6 == 2 || par6 == 3 || par6 == 4 || par6 == 5)
    187            {
    188                par1World.notifyBlocksOfNeighborChange(par2, par3 + 1, par4, this.blockID);
    189            }
    190        }
    191    }
    192}