    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.entity.Entity;
    011import net.minecraft.item.ItemStack;
    012import net.minecraft.util.AxisAlignedBB;
    013import net.minecraft.util.Icon;
    014import net.minecraft.world.IBlockAccess;
    015import net.minecraft.world.World;
    016
    017public class BlockPane extends Block
    018{
    019    /**
    020     * Holds the texture index of the side of the pane (the thin lateral side)
    021     */
    022    private final String sideTextureIndex;
    023
    024    /**
    025     * If this field is true, the pane block drops itself when destroyed (like the iron fences), otherwise, it's just
    026     * destroyed (like glass panes)
    027     */
    028    private final boolean canDropItself;
    029    private final String field_94402_c;
    030    @SideOnly(Side.CLIENT)
    031    private Icon field_94401_cO;
    032
    033    protected BlockPane(int par1, String par2Str, String par3Str, Material par4Material, boolean par5)
    034    {
    035        super(par1, par4Material);
    036        this.sideTextureIndex = par3Str;
    037        this.canDropItself = par5;
    038        this.field_94402_c = par2Str;
    039        this.setCreativeTab(CreativeTabs.tabDecorations);
    040    }
    041
    042    /**
    043     * Returns the ID of the items to drop on destruction.
    044     */
    045    public int idDropped(int par1, Random par2Random, int par3)
    046    {
    047        return !this.canDropItself ? 0 : super.idDropped(par1, par2Random, par3);
    048    }
    049
    050    /**
    051     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    052     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    053     */
    054    public boolean isOpaqueCube()
    055    {
    056        return false;
    057    }
    058
    059    /**
    060     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    061     */
    062    public boolean renderAsNormalBlock()
    063    {
    064        return false;
    065    }
    066
    067    /**
    068     * The type of render function that is called for this block
    069     */
    070    public int getRenderType()
    071    {
    072        return 18;
    073    }
    074
    075    @SideOnly(Side.CLIENT)
    076
    077    /**
    078     * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
    079     * coordinates.  Args: blockAccess, x, y, z, side
    080     */
    081    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    082    {
    083        int i1 = par1IBlockAccess.getBlockId(par2, par3, par4);
    084        return i1 == this.blockID ? false : super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
    085    }
    086
    087    /**
    088     * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
    089     * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
    090     */
    091    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
    092    {
    093        boolean flag = this.canThisPaneConnectToThisBlockID(par1World.getBlockId(par2, par3, par4 - 1));
    094        boolean flag1 = this.canThisPaneConnectToThisBlockID(par1World.getBlockId(par2, par3, par4 + 1));
    095        boolean flag2 = this.canThisPaneConnectToThisBlockID(par1World.getBlockId(par2 - 1, par3, par4));
    096        boolean flag3 = this.canThisPaneConnectToThisBlockID(par1World.getBlockId(par2 + 1, par3, par4));
    097
    098        if ((!flag2 || !flag3) && (flag2 || flag3 || flag || flag1))
    099        {
    100            if (flag2 && !flag3)
    101            {
    102                this.setBlockBounds(0.0F, 0.0F, 0.4375F, 0.5F, 1.0F, 0.5625F);
    103                super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    104            }
    105            else if (!flag2 && flag3)
    106            {
    107                this.setBlockBounds(0.5F, 0.0F, 0.4375F, 1.0F, 1.0F, 0.5625F);
    108                super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    109            }
    110        }
    111        else
    112        {
    113            this.setBlockBounds(0.0F, 0.0F, 0.4375F, 1.0F, 1.0F, 0.5625F);
    114            super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    115        }
    116
    117        if ((!flag || !flag1) && (flag2 || flag3 || flag || flag1))
    118        {
    119            if (flag && !flag1)
    120            {
    121                this.setBlockBounds(0.4375F, 0.0F, 0.0F, 0.5625F, 1.0F, 0.5F);
    122                super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    123            }
    124            else if (!flag && flag1)
    125            {
    126                this.setBlockBounds(0.4375F, 0.0F, 0.5F, 0.5625F, 1.0F, 1.0F);
    127                super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    128            }
    129        }
    130        else
    131        {
    132            this.setBlockBounds(0.4375F, 0.0F, 0.0F, 0.5625F, 1.0F, 1.0F);
    133            super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    134        }
    135    }
    136
    137    /**
    138     * Sets the block's bounds for rendering it as an item
    139     */
    140    public void setBlockBoundsForItemRender()
    141    {
    142        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    143    }
    144
    145    /**
    146     * Updates the blocks bounds based on its current state. Args: world, x, y, z
    147     */
    148    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    149    {
    150        float f = 0.4375F;
    151        float f1 = 0.5625F;
    152        float f2 = 0.4375F;
    153        float f3 = 0.5625F;
    154        boolean flag = this.canThisPaneConnectToThisBlockID(par1IBlockAccess.getBlockId(par2, par3, par4 - 1));
    155        boolean flag1 = this.canThisPaneConnectToThisBlockID(par1IBlockAccess.getBlockId(par2, par3, par4 + 1));
    156        boolean flag2 = this.canThisPaneConnectToThisBlockID(par1IBlockAccess.getBlockId(par2 - 1, par3, par4));
    157        boolean flag3 = this.canThisPaneConnectToThisBlockID(par1IBlockAccess.getBlockId(par2 + 1, par3, par4));
    158
    159        if ((!flag2 || !flag3) && (flag2 || flag3 || flag || flag1))
    160        {
    161            if (flag2 && !flag3)
    162            {
    163                f = 0.0F;
    164            }
    165            else if (!flag2 && flag3)
    166            {
    167                f1 = 1.0F;
    168            }
    169        }
    170        else
    171        {
    172            f = 0.0F;
    173            f1 = 1.0F;
    174        }
    175
    176        if ((!flag || !flag1) && (flag2 || flag3 || flag || flag1))
    177        {
    178            if (flag && !flag1)
    179            {
    180                f2 = 0.0F;
    181            }
    182            else if (!flag && flag1)
    183            {
    184                f3 = 1.0F;
    185            }
    186        }
    187        else
    188        {
    189            f2 = 0.0F;
    190            f3 = 1.0F;
    191        }
    192
    193        this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
    194    }
    195
    196    @SideOnly(Side.CLIENT)
    197
    198    /**
    199     * Returns the texture index of the thin side of the pane.
    200     */
    201    public Icon getSideTextureIndex()
    202    {
    203        return this.field_94401_cO;
    204    }
    205
    206    /**
    207     * Gets passed in the blockID of the block adjacent and supposed to return true if its allowed to connect to the
    208     * type of blockID passed in. Args: blockID
    209     */
    210    public final boolean canThisPaneConnectToThisBlockID(int par1)
    211    {
    212        return Block.opaqueCubeLookup[par1] || par1 == this.blockID || par1 == Block.glass.blockID;
    213    }
    214
    215    /**
    216     * Return true if a player with Silk Touch can harvest this block directly, and not its normal drops.
    217     */
    218    protected boolean canSilkHarvest()
    219    {
    220        return true;
    221    }
    222
    223    /**
    224     * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
    225     * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
    226     */
    227    protected ItemStack createStackedBlock(int par1)
    228    {
    229        return new ItemStack(this.blockID, 1, par1);
    230    }
    231
    232    @SideOnly(Side.CLIENT)
    233    public void func_94332_a(IconRegister par1IconRegister)
    234    {
    235        this.field_94336_cN = par1IconRegister.func_94245_a(this.field_94402_c);
    236        this.field_94401_cO = par1IconRegister.func_94245_a(this.sideTextureIndex);
    237    }
    238}