    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        /**
    095         * called before onBlockPlacedBy by ItemBlock and ItemReed
    096         */
    097        public void updateBlockMetadata(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8)
    098        {
    099            if (!this.isDoubleSlab)
    100            {
    101                if (par5 == 0 || par5 != 1 && (double)par7 > 0.5D)
    102                {
    103                    int var9 = par1World.getBlockMetadata(par2, par3, par4) & 7;
    104                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var9 | 8);
    105                }
    106            }
    107        }
    108
    109        /**
    110         * Returns the quantity of items to drop on block destruction.
    111         */
    112        public int quantityDropped(Random par1Random)
    113        {
    114            return this.isDoubleSlab ? 2 : 1;
    115        }
    116
    117        /**
    118         * Determines the damage on the item the block drops. Used in cloth and wood.
    119         */
    120        public int damageDropped(int par1)
    121        {
    122            return par1 & 7;
    123        }
    124
    125        /**
    126         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    127         */
    128        public boolean renderAsNormalBlock()
    129        {
    130            return this.isDoubleSlab;
    131        }
    132
    133        @SideOnly(Side.CLIENT)
    134
    135        /**
    136         * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
    137         * coordinates.  Args: blockAccess, x, y, z, side
    138         */
    139        public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    140        {
    141            if (this.isDoubleSlab)
    142            {
    143                return super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
    144            }
    145            else if (par5 != 1 && par5 != 0 && !super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5))
    146            {
    147                return false;
    148            }
    149            else
    150            {
    151                int var6 = par2 + Facing.offsetsXForSide[Facing.faceToSide[par5]];
    152                int var7 = par3 + Facing.offsetsYForSide[Facing.faceToSide[par5]];
    153                int var8 = par4 + Facing.offsetsZForSide[Facing.faceToSide[par5]];
    154                boolean var9 = (par1IBlockAccess.getBlockMetadata(var6, var7, var8) & 8) != 0;
    155                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));
    156            }
    157        }
    158
    159        @SideOnly(Side.CLIENT)
    160
    161        /**
    162         * Takes a block ID, returns true if it's the same as the ID for a stone or wooden single slab.
    163         */
    164        private static boolean isBlockSingleSlab(int par0)
    165        {
    166            return par0 == Block.stoneSingleSlab.blockID || par0 == Block.woodSingleSlab.blockID;
    167        }
    168
    169        /**
    170         * Returns the slab block name with step type.
    171         */
    172        public abstract String getFullSlabName(int var1);
    173    }