001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import java.util.List;
006    import java.util.Random;
007    
008    public abstract class BlockHalfSlab extends Block
009    {
010        private final boolean isDoubleSlab;
011    
012        public BlockHalfSlab(int par1, boolean par2, Material par3Material)
013        {
014            super(par1, 6, par3Material);
015            this.isDoubleSlab = par2;
016    
017            if (par2)
018            {
019                opaqueCubeLookup[par1] = true;
020            }
021            else
022            {
023                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
024            }
025    
026            this.setLightOpacity(255);
027        }
028    
029        /**
030         * Updates the blocks bounds based on its current state. Args: world, x, y, z
031         */
032        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
033        {
034            if (this.isDoubleSlab)
035            {
036                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
037            }
038            else
039            {
040                boolean var5 = (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 8) != 0;
041    
042                if (var5)
043                {
044                    this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F);
045                }
046                else
047                {
048                    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
049                }
050            }
051        }
052    
053        /**
054         * Sets the block's bounds for rendering it as an item
055         */
056        public void setBlockBoundsForItemRender()
057        {
058            if (this.isDoubleSlab)
059            {
060                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
061            }
062            else
063            {
064                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
065            }
066        }
067    
068        /**
069         * if the specified block is in the given AABB, add its collision bounding box to the given list
070         */
071        public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
072        {
073            this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
074            super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
075        }
076    
077        /**
078         * Returns the block texture based on the side being looked at.  Args: side
079         */
080        public int getBlockTextureFromSide(int par1)
081        {
082            return this.getBlockTextureFromSideAndMetadata(par1, 0);
083        }
084    
085        /**
086         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
087         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
088         */
089        public boolean isOpaqueCube()
090        {
091            return this.isDoubleSlab;
092        }
093    
094        public int func_85104_a(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
095        {
096            return this.isDoubleSlab ? 0 : (par5 != 0 && (par5 == 1 || (double)par7 <= 0.5D) ? par9 : par9 | 8);
097        }
098    
099        /**
100         * Returns the quantity of items to drop on block destruction.
101         */
102        public int quantityDropped(Random par1Random)
103        {
104            return this.isDoubleSlab ? 2 : 1;
105        }
106    
107        /**
108         * Determines the damage on the item the block drops. Used in cloth and wood.
109         */
110        public int damageDropped(int par1)
111        {
112            return par1 & 7;
113        }
114    
115        /**
116         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
117         */
118        public boolean renderAsNormalBlock()
119        {
120            return this.isDoubleSlab;
121        }
122    
123        @SideOnly(Side.CLIENT)
124    
125        /**
126         * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
127         * coordinates.  Args: blockAccess, x, y, z, side
128         */
129        public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
130        {
131            if (this.isDoubleSlab)
132            {
133                return super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
134            }
135            else if (par5 != 1 && par5 != 0 && !super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5))
136            {
137                return false;
138            }
139            else
140            {
141                int var6 = par2 + Facing.offsetsXForSide[Facing.faceToSide[par5]];
142                int var7 = par3 + Facing.offsetsYForSide[Facing.faceToSide[par5]];
143                int var8 = par4 + Facing.offsetsZForSide[Facing.faceToSide[par5]];
144                boolean var9 = (par1IBlockAccess.getBlockMetadata(var6, var7, var8) & 8) != 0;
145                return var9 ? (par5 == 0 ? true : (par5 == 1 && super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1IBlockAccess.getBlockId(par2, par3, par4)) || (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 8) == 0)) : (par5 == 1 ? true : (par5 == 0 && super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1IBlockAccess.getBlockId(par2, par3, par4)) || (par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 8) != 0));
146            }
147        }
148    
149        @SideOnly(Side.CLIENT)
150    
151        /**
152         * Takes a block ID, returns true if it's the same as the ID for a stone or wooden single slab.
153         */
154        private static boolean isBlockSingleSlab(int par0)
155        {
156            return par0 == Block.stoneSingleSlab.blockID || par0 == Block.woodSingleSlab.blockID;
157        }
158    
159        /**
160         * Returns the slab block name with step type.
161         */
162        public abstract String getFullSlabName(int var1);
163    }