    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.creativetab.CreativeTabs;
    010import net.minecraft.item.ItemStack;
    011import net.minecraft.util.Icon;
    012import net.minecraft.world.World;
    013
    014public class BlockLog extends Block
    015{
    016    /** The type of tree this log came from. */
    017    public static final String[] woodType = new String[] {"oak", "spruce", "birch", "jungle"};
    018    public static final String[] treeTextureTypes = new String[] {"tree_side", "tree_spruce", "tree_birch", "tree_jungle"};
    019    @SideOnly(Side.CLIENT)
    020    private Icon[] iconArray;
    021    @SideOnly(Side.CLIENT)
    022    private Icon tree_top;
    023
    024    protected BlockLog(int par1)
    025    {
    026        super(par1, Material.wood);
    027        this.setCreativeTab(CreativeTabs.tabBlock);
    028    }
    029
    030    /**
    031     * The type of render function that is called for this block
    032     */
    033    public int getRenderType()
    034    {
    035        return 31;
    036    }
    037
    038    /**
    039     * Returns the quantity of items to drop on block destruction.
    040     */
    041    public int quantityDropped(Random par1Random)
    042    {
    043        return 1;
    044    }
    045
    046    /**
    047     * Returns the ID of the items to drop on destruction.
    048     */
    049    public int idDropped(int par1, Random par2Random, int par3)
    050    {
    051        return Block.wood.blockID;
    052    }
    053
    054    /**
    055     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    056     */
    057    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    058    {
    059        byte b0 = 4;
    060        int j1 = b0 + 1;
    061
    062        if (par1World.checkChunksExist(par2 - j1, par3 - j1, par4 - j1, par2 + j1, par3 + j1, par4 + j1))
    063        {
    064            for (int k1 = -b0; k1 <= b0; ++k1)
    065            {
    066                for (int l1 = -b0; l1 <= b0; ++l1)
    067                {
    068                    for (int i2 = -b0; i2 <= b0; ++i2)
    069                    {
    070                        int j2 = par1World.getBlockId(par2 + k1, par3 + l1, par4 + i2);
    071
    072                        if (Block.blocksList[j2] != null)
    073                        {
    074                            Block.blocksList[j2].beginLeavesDecay(par1World, par2 + k1, par3 + l1, par4 + i2);
    075                        }
    076                    }
    077                }
    078            }
    079        }
    080    }
    081
    082    /**
    083     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
    084     */
    085    public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    086    {
    087        int j1 = par9 & 3;
    088        byte b0 = 0;
    089
    090        switch (par5)
    091        {
    092            case 0:
    093            case 1:
    094                b0 = 0;
    095                break;
    096            case 2:
    097            case 3:
    098                b0 = 8;
    099                break;
    100            case 4:
    101            case 5:
    102                b0 = 4;
    103        }
    104
    105        return j1 | b0;
    106    }
    107
    108    @SideOnly(Side.CLIENT)
    109
    110    /**
    111     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    112     */
    113    public Icon getIcon(int par1, int par2)
    114    {
    115        int k = par2 & 12;
    116        int l = par2 & 3;
    117        return k == 0 && (par1 == 1 || par1 == 0) ? this.tree_top : (k == 4 && (par1 == 5 || par1 == 4) ? this.tree_top : (k == 8 && (par1 == 2 || par1 == 3) ? this.tree_top : this.iconArray[l]));
    118    }
    119
    120    /**
    121     * Determines the damage on the item the block drops. Used in cloth and wood.
    122     */
    123    public int damageDropped(int par1)
    124    {
    125        return par1 & 3;
    126    }
    127
    128    /**
    129     * returns a number between 0 and 3
    130     */
    131    public static int limitToValidMetadata(int par0)
    132    {
    133        return par0 & 3;
    134    }
    135
    136    @SideOnly(Side.CLIENT)
    137
    138    /**
    139     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
    140     */
    141    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    142    {
    143        par3List.add(new ItemStack(par1, 1, 0));
    144        par3List.add(new ItemStack(par1, 1, 1));
    145        par3List.add(new ItemStack(par1, 1, 2));
    146        par3List.add(new ItemStack(par1, 1, 3));
    147    }
    148
    149    /**
    150     * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
    151     * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
    152     */
    153    protected ItemStack createStackedBlock(int par1)
    154    {
    155        return new ItemStack(this.blockID, 1, limitToValidMetadata(par1));
    156    }
    157
    158    @SideOnly(Side.CLIENT)
    159
    160    /**
    161     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
    162     * is the only chance you get to register icons.
    163     */
    164    public void registerIcons(IconRegister par1IconRegister)
    165    {
    166        this.tree_top = par1IconRegister.registerIcon("tree_top");
    167        this.iconArray = new Icon[treeTextureTypes.length];
    168
    169        for (int i = 0; i < this.iconArray.length; ++i)
    170        {
    171            this.iconArray[i] = par1IconRegister.registerIcon(treeTextureTypes[i]);
    172        }
    173    }
    174
    175    @Override
    176    public boolean canSustainLeaves(World world, int x, int y, int z)
    177    {
    178        return true;
    179    }
    180
    181    @Override
    182    public boolean isWood(World world, int x, int y, int z)
    183    {
    184        return true;
    185    }
    186}