    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.item.ItemStack;
    010import net.minecraft.util.Icon;
    011import net.minecraft.world.World;
    012
    013public class BlockQuartz extends Block
    014{
    015    public static final String[] quartzBlockTypes = new String[] {"default", "chiseled", "lines"};
    016    private static final String[] quartzBlockTextureTypes = new String[] {"quartzblock_side", "quartzblock_chiseled", "quartzblock_lines", null, null};
    017    @SideOnly(Side.CLIENT)
    018    private Icon[] quartzblockIcons;
    019    @SideOnly(Side.CLIENT)
    020    private Icon quartzblock_chiseled_top;
    021    @SideOnly(Side.CLIENT)
    022    private Icon quartzblock_lines_top;
    023    @SideOnly(Side.CLIENT)
    024    private Icon quartzblock_top;
    025    @SideOnly(Side.CLIENT)
    026    private Icon quartzblock_bottom;
    027
    028    public BlockQuartz(int par1)
    029    {
    030        super(par1, Material.rock);
    031        this.setCreativeTab(CreativeTabs.tabBlock);
    032    }
    033
    034    @SideOnly(Side.CLIENT)
    035
    036    /**
    037     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    038     */
    039    public Icon getIcon(int par1, int par2)
    040    {
    041        if (par2 != 2 && par2 != 3 && par2 != 4)
    042        {
    043            if (par1 != 1 && (par1 != 0 || par2 != 1))
    044            {
    045                if (par1 == 0)
    046                {
    047                    return this.quartzblock_bottom;
    048                }
    049                else
    050                {
    051                    if (par2 < 0 || par2 >= this.quartzblockIcons.length)
    052                    {
    053                        par2 = 0;
    054                    }
    055
    056                    return this.quartzblockIcons[par2];
    057                }
    058            }
    059            else
    060            {
    061                return par2 == 1 ? this.quartzblock_chiseled_top : this.quartzblock_top;
    062            }
    063        }
    064        else
    065        {
    066            return par2 == 2 && (par1 == 1 || par1 == 0) ? this.quartzblock_lines_top : (par2 == 3 && (par1 == 5 || par1 == 4) ? this.quartzblock_lines_top : (par2 == 4 && (par1 == 2 || par1 == 3) ? this.quartzblock_lines_top : this.quartzblockIcons[par2]));
    067        }
    068    }
    069
    070    /**
    071     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
    072     */
    073    public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    074    {
    075        if (par9 == 2)
    076        {
    077            switch (par5)
    078            {
    079                case 0:
    080                case 1:
    081                    par9 = 2;
    082                    break;
    083                case 2:
    084                case 3:
    085                    par9 = 4;
    086                    break;
    087                case 4:
    088                case 5:
    089                    par9 = 3;
    090            }
    091        }
    092
    093        return par9;
    094    }
    095
    096    /**
    097     * Determines the damage on the item the block drops. Used in cloth and wood.
    098     */
    099    public int damageDropped(int par1)
    100    {
    101        return par1 != 3 && par1 != 4 ? par1 : 2;
    102    }
    103
    104    /**
    105     * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
    106     * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
    107     */
    108    protected ItemStack createStackedBlock(int par1)
    109    {
    110        return par1 != 3 && par1 != 4 ? super.createStackedBlock(par1) : new ItemStack(this.blockID, 1, 2);
    111    }
    112
    113    /**
    114     * The type of render function that is called for this block
    115     */
    116    public int getRenderType()
    117    {
    118        return 39;
    119    }
    120
    121    @SideOnly(Side.CLIENT)
    122
    123    /**
    124     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
    125     */
    126    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    127    {
    128        par3List.add(new ItemStack(par1, 1, 0));
    129        par3List.add(new ItemStack(par1, 1, 1));
    130        par3List.add(new ItemStack(par1, 1, 2));
    131    }
    132
    133    @SideOnly(Side.CLIENT)
    134
    135    /**
    136     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
    137     * is the only chance you get to register icons.
    138     */
    139    public void registerIcons(IconRegister par1IconRegister)
    140    {
    141        this.quartzblockIcons = new Icon[quartzBlockTextureTypes.length];
    142
    143        for (int i = 0; i < this.quartzblockIcons.length; ++i)
    144        {
    145            if (quartzBlockTextureTypes[i] == null)
    146            {
    147                this.quartzblockIcons[i] = this.quartzblockIcons[i - 1];
    148            }
    149            else
    150            {
    151                this.quartzblockIcons[i] = par1IconRegister.registerIcon(quartzBlockTextureTypes[i]);
    152            }
    153        }
    154
    155        this.quartzblock_top = par1IconRegister.registerIcon("quartzblock_top");
    156        this.quartzblock_chiseled_top = par1IconRegister.registerIcon("quartzblock_chiseled_top");
    157        this.quartzblock_lines_top = par1IconRegister.registerIcon("quartzblock_lines_top");
    158        this.quartzblock_bottom = par1IconRegister.registerIcon("quartzblock_bottom");
    159    }
    160}