001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.List; 006import java.util.Random; 007import net.minecraft.block.material.Material; 008import net.minecraft.client.renderer.texture.IconRegister; 009import net.minecraft.entity.Entity; 010import net.minecraft.util.AxisAlignedBB; 011import net.minecraft.util.Facing; 012import net.minecraft.util.Icon; 013import net.minecraft.world.IBlockAccess; 014import net.minecraft.world.World; 015 016public class BlockPistonExtension extends Block 017{ 018 /** The texture for the 'head' of the piston. Sticky or normal. */ 019 private Icon headTexture = null; 020 021 public BlockPistonExtension(int par1) 022 { 023 super(par1, Material.piston); 024 this.setStepSound(soundStoneFootstep); 025 this.setHardness(0.5F); 026 } 027 028 @SideOnly(Side.CLIENT) 029 public void setHeadTexture(Icon par1Icon) 030 { 031 this.headTexture = par1Icon; 032 } 033 034 /** 035 * ejects contained items into the world, and notifies neighbours of an update, as appropriate 036 */ 037 public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) 038 { 039 super.breakBlock(par1World, par2, par3, par4, par5, par6); 040 int j1 = Facing.faceToSide[getDirectionMeta(par6)]; 041 par2 += Facing.offsetsXForSide[j1]; 042 par3 += Facing.offsetsYForSide[j1]; 043 par4 += Facing.offsetsZForSide[j1]; 044 int k1 = par1World.getBlockId(par2, par3, par4); 045 046 if (k1 == Block.pistonBase.blockID || k1 == Block.pistonStickyBase.blockID) 047 { 048 par6 = par1World.getBlockMetadata(par2, par3, par4); 049 050 if (BlockPistonBase.isExtended(par6)) 051 { 052 Block.blocksList[k1].dropBlockAsItem(par1World, par2, par3, par4, par6, 0); 053 par1World.func_94571_i(par2, par3, par4); 054 } 055 } 056 } 057 058 @SideOnly(Side.CLIENT) 059 public void clearHeadTexture() 060 { 061 this.headTexture = null; 062 } 063 064 @SideOnly(Side.CLIENT) 065 066 /** 067 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 068 */ 069 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 070 { 071 int k = getDirectionMeta(par2); 072 return par1 == k ? (this.headTexture != null ? this.headTexture : ((par2 & 8) != 0 ? BlockPistonBase.func_94496_b("piston_top_sticky") : BlockPistonBase.func_94496_b("piston_top"))) : (k < 6 && par1 == Facing.faceToSide[k] ? BlockPistonBase.func_94496_b("piston_top") : BlockPistonBase.func_94496_b("piston_side")); 073 } 074 075 @SideOnly(Side.CLIENT) 076 public void func_94332_a(IconRegister par1IconRegister) {} 077 078 /** 079 * The type of render function that is called for this block 080 */ 081 public int getRenderType() 082 { 083 return 17; 084 } 085 086 /** 087 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 088 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 089 */ 090 public boolean isOpaqueCube() 091 { 092 return false; 093 } 094 095 /** 096 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 097 */ 098 public boolean renderAsNormalBlock() 099 { 100 return false; 101 } 102 103 /** 104 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 105 */ 106 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 107 { 108 return false; 109 } 110 111 /** 112 * checks to see if you can place this block can be placed on that side of a block: BlockLever overrides 113 */ 114 public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5) 115 { 116 return false; 117 } 118 119 /** 120 * Returns the quantity of items to drop on block destruction. 121 */ 122 public int quantityDropped(Random par1Random) 123 { 124 return 0; 125 } 126 127 /** 128 * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the 129 * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity 130 */ 131 public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) 132 { 133 int l = par1World.getBlockMetadata(par2, par3, par4); 134 135 switch (getDirectionMeta(l)) 136 { 137 case 0: 138 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F); 139 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 140 this.setBlockBounds(0.375F, 0.25F, 0.375F, 0.625F, 1.0F, 0.625F); 141 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 142 break; 143 case 1: 144 this.setBlockBounds(0.0F, 0.75F, 0.0F, 1.0F, 1.0F, 1.0F); 145 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 146 this.setBlockBounds(0.375F, 0.0F, 0.375F, 0.625F, 0.75F, 0.625F); 147 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 148 break; 149 case 2: 150 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.25F); 151 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 152 this.setBlockBounds(0.25F, 0.375F, 0.25F, 0.75F, 0.625F, 1.0F); 153 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 154 break; 155 case 3: 156 this.setBlockBounds(0.0F, 0.0F, 0.75F, 1.0F, 1.0F, 1.0F); 157 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 158 this.setBlockBounds(0.25F, 0.375F, 0.0F, 0.75F, 0.625F, 0.75F); 159 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 160 break; 161 case 4: 162 this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.25F, 1.0F, 1.0F); 163 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 164 this.setBlockBounds(0.375F, 0.25F, 0.25F, 0.625F, 0.75F, 1.0F); 165 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 166 break; 167 case 5: 168 this.setBlockBounds(0.75F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 169 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 170 this.setBlockBounds(0.0F, 0.375F, 0.25F, 0.75F, 0.625F, 0.75F); 171 super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity); 172 } 173 174 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 175 } 176 177 /** 178 * Updates the blocks bounds based on its current state. Args: world, x, y, z 179 */ 180 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 181 { 182 int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4); 183 184 switch (getDirectionMeta(l)) 185 { 186 case 0: 187 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F); 188 break; 189 case 1: 190 this.setBlockBounds(0.0F, 0.75F, 0.0F, 1.0F, 1.0F, 1.0F); 191 break; 192 case 2: 193 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.25F); 194 break; 195 case 3: 196 this.setBlockBounds(0.0F, 0.0F, 0.75F, 1.0F, 1.0F, 1.0F); 197 break; 198 case 4: 199 this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.25F, 1.0F, 1.0F); 200 break; 201 case 5: 202 this.setBlockBounds(0.75F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); 203 } 204 } 205 206 /** 207 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 208 * their own) Args: x, y, z, neighbor blockID 209 */ 210 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 211 { 212 int i1 = getDirectionMeta(par1World.getBlockMetadata(par2, par3, par4)); 213 int j1 = par1World.getBlockId(par2 - Facing.offsetsXForSide[i1], par3 - Facing.offsetsYForSide[i1], par4 - Facing.offsetsZForSide[i1]); 214 215 if (j1 != Block.pistonBase.blockID && j1 != Block.pistonStickyBase.blockID) 216 { 217 par1World.func_94571_i(par2, par3, par4); 218 } 219 else 220 { 221 Block.blocksList[j1].onNeighborBlockChange(par1World, par2 - Facing.offsetsXForSide[i1], par3 - Facing.offsetsYForSide[i1], par4 - Facing.offsetsZForSide[i1], par5); 222 } 223 } 224 225 public static int getDirectionMeta(int par0) 226 { 227 return par0 & 7; 228 } 229 230 @SideOnly(Side.CLIENT) 231 232 /** 233 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 234 */ 235 public int idPicked(World par1World, int par2, int par3, int par4) 236 { 237 return 0; 238 } 239}