    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[] anvilIconNames = 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[] iconArray;
    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 getIcon(int par1, int par2)
    057    {
    058        if (this.field_82521_b == 3 && par1 == 1)
    059        {
    060            int k = (par2 >> 2) % this.iconArray.length;
    061            return this.iconArray[k];
    062        }
    063        else
    064        {
    065            return this.blockIcon;
    066        }
    067    }
    068
    069    @SideOnly(Side.CLIENT)
    070
    071    /**
    072     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
    073     * is the only chance you get to register icons.
    074     */
    075    public void registerIcons(IconRegister par1IconRegister)
    076    {
    077        this.blockIcon = par1IconRegister.registerIcon("anvil_base");
    078        this.iconArray = new Icon[anvilIconNames.length];
    079
    080        for (int i = 0; i < this.iconArray.length; ++i)
    081        {
    082            this.iconArray[i] = par1IconRegister.registerIcon(anvilIconNames[i]);
    083        }
    084    }
    085
    086    /**
    087     * Called when the block is placed in the world.
    088     */
    089    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
    090    {
    091        int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
    092        int i1 = par1World.getBlockMetadata(par2, par3, par4) >> 2;
    093        ++l;
    094        l %= 4;
    095
    096        if (l == 0)
    097        {
    098            par1World.setBlockMetadataWithNotify(par2, par3, par4, 2 | i1 << 2, 2);
    099        }
    100
    101        if (l == 1)
    102        {
    103            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3 | i1 << 2, 2);
    104        }
    105
    106        if (l == 2)
    107        {
    108            par1World.setBlockMetadataWithNotify(par2, par3, par4, 0 | i1 << 2, 2);
    109        }
    110
    111        if (l == 3)
    112        {
    113            par1World.setBlockMetadataWithNotify(par2, par3, par4, 1 | i1 << 2, 2);
    114        }
    115    }
    116
    117    /**
    118     * Called upon block activation (right click on the block.)
    119     */
    120    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    121    {
    122        if (par1World.isRemote)
    123        {
    124            return true;
    125        }
    126        else
    127        {
    128            par5EntityPlayer.displayGUIAnvil(par2, par3, par4);
    129            return true;
    130        }
    131    }
    132
    133    /**
    134     * The type of render function that is called for this block
    135     */
    136    public int getRenderType()
    137    {
    138        return 35;
    139    }
    140
    141    /**
    142     * Determines the damage on the item the block drops. Used in cloth and wood.
    143     */
    144    public int damageDropped(int par1)
    145    {
    146        return par1 >> 2;
    147    }
    148
    149    /**
    150     * Updates the blocks bounds based on its current state. Args: world, x, y, z
    151     */
    152    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    153    {
    154        int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 3;
    155
    156        if (l != 3 && l != 1)
    157        {
    158            this.setBlockBounds(0.125F, 0.0F, 0.0F, 0.875F, 1.0F, 1.0F);
    159        }
    160        else
    161        {
    162            this.setBlockBounds(0.0F, 0.0F, 0.125F, 1.0F, 1.0F, 0.875F);
    163        }
    164    }
    165
    166    @SideOnly(Side.CLIENT)
    167
    168    /**
    169     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
    170     */
    171    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    172    {
    173        par3List.add(new ItemStack(par1, 1, 0));
    174        par3List.add(new ItemStack(par1, 1, 1));
    175        par3List.add(new ItemStack(par1, 1, 2));
    176    }
    177
    178    /**
    179     * Called when the falling block entity for this block is created
    180     */
    181    protected void onStartFalling(EntityFallingSand par1EntityFallingSand)
    182    {
    183        par1EntityFallingSand.setIsAnvil(true);
    184    }
    185
    186    /**
    187     * Called when the falling block entity for this block hits the ground and turns back into a block
    188     */
    189    public void onFinishFalling(World par1World, int par2, int par3, int par4, int par5)
    190    {
    191        par1World.playAuxSFX(1022, par2, par3, par4, 0);
    192    }
    193
    194    @SideOnly(Side.CLIENT)
    195
    196    /**
    197     * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
    198     * coordinates.  Args: blockAccess, x, y, z, side
    199     */
    200    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    201    {
    202        return true;
    203    }
    204}