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