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