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 theIcon; 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.blockIcon : this.theIcon; 027 } 028 029 @SideOnly(Side.CLIENT) 030 031 /** 032 * When this method is called, your block should register all the icons it needs with the given IconRegister. This 033 * is the only chance you get to register icons. 034 */ 035 public void registerIcons(IconRegister par1IconRegister) 036 { 037 super.registerIcons(par1IconRegister); 038 this.theIcon = par1IconRegister.registerIcon(this.getUnlocalizedName2() + "_powered"); 039 } 040 041 protected boolean func_94360_a(World par1World, int par2, int par3, int par4, int par5, boolean par6, int par7) 042 { 043 if (par7 >= 8) 044 { 045 return false; 046 } 047 else 048 { 049 int j1 = par5 & 7; 050 boolean flag1 = true; 051 052 switch (j1) 053 { 054 case 0: 055 if (par6) 056 { 057 ++par4; 058 } 059 else 060 { 061 --par4; 062 } 063 064 break; 065 case 1: 066 if (par6) 067 { 068 --par2; 069 } 070 else 071 { 072 ++par2; 073 } 074 075 break; 076 case 2: 077 if (par6) 078 { 079 --par2; 080 } 081 else 082 { 083 ++par2; 084 ++par3; 085 flag1 = false; 086 } 087 088 j1 = 1; 089 break; 090 case 3: 091 if (par6) 092 { 093 --par2; 094 ++par3; 095 flag1 = false; 096 } 097 else 098 { 099 ++par2; 100 } 101 102 j1 = 1; 103 break; 104 case 4: 105 if (par6) 106 { 107 ++par4; 108 } 109 else 110 { 111 --par4; 112 ++par3; 113 flag1 = false; 114 } 115 116 j1 = 0; 117 break; 118 case 5: 119 if (par6) 120 { 121 ++par4; 122 ++par3; 123 flag1 = false; 124 } 125 else 126 { 127 --par4; 128 } 129 130 j1 = 0; 131 } 132 133 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); 134 } 135 } 136 137 protected boolean func_94361_a(World par1World, int par2, int par3, int par4, boolean par5, int par6, int par7) 138 { 139 int j1 = par1World.getBlockId(par2, par3, par4); 140 141 if (j1 == this.blockID) 142 { 143 int k1 = par1World.getBlockMetadata(par2, par3, par4); 144 int l1 = k1 & 7; 145 146 if (par7 == 1 && (l1 == 0 || l1 == 4 || l1 == 5)) 147 { 148 return false; 149 } 150 151 if (par7 == 0 && (l1 == 1 || l1 == 2 || l1 == 3)) 152 { 153 return false; 154 } 155 156 if ((k1 & 8) != 0) 157 { 158 if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) 159 { 160 return true; 161 } 162 163 return this.func_94360_a(par1World, par2, par3, par4, k1, par5, par6 + 1); 164 } 165 } 166 167 return false; 168 } 169 170 protected void func_94358_a(World par1World, int par2, int par3, int par4, int par5, int par6, int par7) 171 { 172 boolean flag = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4); 173 flag = flag || this.func_94360_a(par1World, par2, par3, par4, par5, true, 0) || this.func_94360_a(par1World, par2, par3, par4, par5, false, 0); 174 boolean flag1 = false; 175 176 if (flag && (par5 & 8) == 0) 177 { 178 par1World.setBlockMetadataWithNotify(par2, par3, par4, par6 | 8, 3); 179 flag1 = true; 180 } 181 else if (!flag && (par5 & 8) != 0) 182 { 183 par1World.setBlockMetadataWithNotify(par2, par3, par4, par6, 3); 184 flag1 = true; 185 } 186 187 if (flag1) 188 { 189 par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID); 190 191 if (par6 == 2 || par6 == 3 || par6 == 4 || par6 == 5) 192 { 193 par1World.notifyBlocksOfNeighborChange(par2, par3 + 1, par4, this.blockID); 194 } 195 } 196 } 197}