    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.AxisAlignedBB;
    011import net.minecraft.util.Icon;
    012import net.minecraft.world.IBlockAccess;
    013import net.minecraft.world.World;
    014
    015public class BlockWall extends Block
    016{
    017    /** The types of the wall. */
    018    public static final String[] types = new String[] {"normal", "mossy"};
    019
    020    public BlockWall(int par1, Block par2Block)
    021    {
    022        super(par1, par2Block.blockMaterial);
    023        this.setHardness(par2Block.blockHardness);
    024        this.setResistance(par2Block.blockResistance / 3.0F);
    025        this.setStepSound(par2Block.stepSound);
    026        this.setCreativeTab(CreativeTabs.tabBlock);
    027    }
    028
    029    @SideOnly(Side.CLIENT)
    030
    031    /**
    032     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    033     */
    034    public Icon getIcon(int par1, int par2)
    035    {
    036        return par2 == 1 ? Block.cobblestoneMossy.getBlockTextureFromSide(par1) : Block.cobblestone.getBlockTextureFromSide(par1);
    037    }
    038
    039    /**
    040     * The type of render function that is called for this block
    041     */
    042    public int getRenderType()
    043    {
    044        return 32;
    045    }
    046
    047    /**
    048     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    049     */
    050    public boolean renderAsNormalBlock()
    051    {
    052        return false;
    053    }
    054
    055    public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    056    {
    057        return false;
    058    }
    059
    060    /**
    061     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    062     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    063     */
    064    public boolean isOpaqueCube()
    065    {
    066        return false;
    067    }
    068
    069    /**
    070     * Updates the blocks bounds based on its current state. Args: world, x, y, z
    071     */
    072    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    073    {
    074        boolean flag = this.canConnectWallTo(par1IBlockAccess, par2, par3, par4 - 1);
    075        boolean flag1 = this.canConnectWallTo(par1IBlockAccess, par2, par3, par4 + 1);
    076        boolean flag2 = this.canConnectWallTo(par1IBlockAccess, par2 - 1, par3, par4);
    077        boolean flag3 = this.canConnectWallTo(par1IBlockAccess, par2 + 1, par3, par4);
    078        float f = 0.25F;
    079        float f1 = 0.75F;
    080        float f2 = 0.25F;
    081        float f3 = 0.75F;
    082        float f4 = 1.0F;
    083
    084        if (flag)
    085        {
    086            f2 = 0.0F;
    087        }
    088
    089        if (flag1)
    090        {
    091            f3 = 1.0F;
    092        }
    093
    094        if (flag2)
    095        {
    096            f = 0.0F;
    097        }
    098
    099        if (flag3)
    100        {
    101            f1 = 1.0F;
    102        }
    103
    104        if (flag && flag1 && !flag2 && !flag3)
    105        {
    106            f4 = 0.8125F;
    107            f = 0.3125F;
    108            f1 = 0.6875F;
    109        }
    110        else if (!flag && !flag1 && flag2 && flag3)
    111        {
    112            f4 = 0.8125F;
    113            f2 = 0.3125F;
    114            f3 = 0.6875F;
    115        }
    116
    117        this.setBlockBounds(f, 0.0F, f2, f1, f4, f3);
    118    }
    119
    120    /**
    121     * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    122     * cleared to be reused)
    123     */
    124    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    125    {
    126        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
    127        this.maxY = 1.5D;
    128        return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
    129    }
    130
    131    /**
    132     * Return whether an adjacent block can connect to a wall.
    133     */
    134    public boolean canConnectWallTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    135    {
    136        int l = par1IBlockAccess.getBlockId(par2, par3, par4);
    137
    138        if (l != this.blockID && l != Block.fenceGate.blockID)
    139        {
    140            Block block = Block.blocksList[l];
    141            return block != null && block.blockMaterial.isOpaque() && block.renderAsNormalBlock() ? block.blockMaterial != Material.pumpkin : false;
    142        }
    143        else
    144        {
    145            return true;
    146        }
    147    }
    148
    149    @SideOnly(Side.CLIENT)
    150
    151    /**
    152     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
    153     */
    154    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    155    {
    156        par3List.add(new ItemStack(par1, 1, 0));
    157        par3List.add(new ItemStack(par1, 1, 1));
    158    }
    159
    160    /**
    161     * Determines the damage on the item the block drops. Used in cloth and wood.
    162     */
    163    public int damageDropped(int par1)
    164    {
    165        return par1;
    166    }
    167
    168    @SideOnly(Side.CLIENT)
    169
    170    /**
    171     * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
    172     * coordinates.  Args: blockAccess, x, y, z, side
    173     */
    174    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    175    {
    176        return par5 == 0 ? super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) : true;
    177    }
    178
    179    @SideOnly(Side.CLIENT)
    180
    181    /**
    182     * When this method is called, your block should register all the icons it needs with the given IconRegister. This
    183     * is the only chance you get to register icons.
    184     */
    185    public void registerIcons(IconRegister par1IconRegister) {}
    186}