001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.List; 006import net.minecraft.block.material.Material; 007import net.minecraft.client.renderer.texture.IconRegister; 008import net.minecraft.creativetab.CreativeTabs; 009import net.minecraft.entity.EntityLiving; 010import net.minecraft.entity.item.EntityFallingSand; 011import net.minecraft.entity.player.EntityPlayer; 012import net.minecraft.item.ItemStack; 013import net.minecraft.util.Icon; 014import net.minecraft.util.MathHelper; 015import net.minecraft.world.IBlockAccess; 016import net.minecraft.world.World; 017 018public class BlockAnvil extends BlockSand 019{ 020 /** List of types/statues the Anvil can be in. */ 021 public static final String[] statuses = new String[] {"intact", "slightlyDamaged", "veryDamaged"}; 022 private static final String[] field_94431_cO = new String[] {"anvil_top", "anvil_top_damaged_1", "anvil_top_damaged_2"}; 023 public int field_82521_b = 0; 024 @SideOnly(Side.CLIENT) 025 private Icon[] field_94432_cP; 026 027 protected BlockAnvil(int par1) 028 { 029 super(par1, Material.anvil); 030 this.setLightOpacity(0); 031 this.setCreativeTab(CreativeTabs.tabDecorations); 032 } 033 034 /** 035 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 036 */ 037 public boolean renderAsNormalBlock() 038 { 039 return false; 040 } 041 042 /** 043 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 044 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 045 */ 046 public boolean isOpaqueCube() 047 { 048 return false; 049 } 050 051 @SideOnly(Side.CLIENT) 052 053 /** 054 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 055 */ 056 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 057 { 058 if (this.field_82521_b == 3 && par1 == 1) 059 { 060 int k = (par2 >> 2) % this.field_94432_cP.length; 061 return this.field_94432_cP[k]; 062 } 063 else 064 { 065 return this.field_94336_cN; 066 } 067 } 068 069 @SideOnly(Side.CLIENT) 070 public void func_94332_a(IconRegister par1IconRegister) 071 { 072 this.field_94336_cN = par1IconRegister.func_94245_a("anvil_base"); 073 this.field_94432_cP = new Icon[field_94431_cO.length]; 074 075 for (int i = 0; i < this.field_94432_cP.length; ++i) 076 { 077 this.field_94432_cP[i] = par1IconRegister.func_94245_a(field_94431_cO[i]); 078 } 079 } 080 081 /** 082 * Called when the block is placed in the world. 083 */ 084 public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack) 085 { 086 int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; 087 int i1 = par1World.getBlockMetadata(par2, par3, par4) >> 2; 088 ++l; 089 l %= 4; 090 091 if (l == 0) 092 { 093 par1World.setBlockMetadataWithNotify(par2, par3, par4, 2 | i1 << 2, 2); 094 } 095 096 if (l == 1) 097 { 098 par1World.setBlockMetadataWithNotify(par2, par3, par4, 3 | i1 << 2, 2); 099 } 100 101 if (l == 2) 102 { 103 par1World.setBlockMetadataWithNotify(par2, par3, par4, 0 | i1 << 2, 2); 104 } 105 106 if (l == 3) 107 { 108 par1World.setBlockMetadataWithNotify(par2, par3, par4, 1 | i1 << 2, 2); 109 } 110 } 111 112 /** 113 * Called upon block activation (right click on the block.) 114 */ 115 public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) 116 { 117 if (par1World.isRemote) 118 { 119 return true; 120 } 121 else 122 { 123 par5EntityPlayer.displayGUIAnvil(par2, par3, par4); 124 return true; 125 } 126 } 127 128 /** 129 * The type of render function that is called for this block 130 */ 131 public int getRenderType() 132 { 133 return 35; 134 } 135 136 /** 137 * Determines the damage on the item the block drops. Used in cloth and wood. 138 */ 139 public int damageDropped(int par1) 140 { 141 return par1 >> 2; 142 } 143 144 /** 145 * Updates the blocks bounds based on its current state. Args: world, x, y, z 146 */ 147 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 148 { 149 int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 3; 150 151 if (l != 3 && l != 1) 152 { 153 this.setBlockBounds(0.125F, 0.0F, 0.0F, 0.875F, 1.0F, 1.0F); 154 } 155 else 156 { 157 this.setBlockBounds(0.0F, 0.0F, 0.125F, 1.0F, 1.0F, 0.875F); 158 } 159 } 160 161 @SideOnly(Side.CLIENT) 162 163 /** 164 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) 165 */ 166 public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) 167 { 168 par3List.add(new ItemStack(par1, 1, 0)); 169 par3List.add(new ItemStack(par1, 1, 1)); 170 par3List.add(new ItemStack(par1, 1, 2)); 171 } 172 173 /** 174 * Called when the falling block entity for this block is created 175 */ 176 protected void onStartFalling(EntityFallingSand par1EntityFallingSand) 177 { 178 par1EntityFallingSand.setIsAnvil(true); 179 } 180 181 /** 182 * Called when the falling block entity for this block hits the ground and turns back into a block 183 */ 184 public void onFinishFalling(World par1World, int par2, int par3, int par4, int par5) 185 { 186 par1World.playAuxSFX(1022, par2, par3, par4, 0); 187 } 188 189 @SideOnly(Side.CLIENT) 190 191 /** 192 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 193 * coordinates. Args: blockAccess, x, y, z, side 194 */ 195 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 196 { 197 return true; 198 } 199}