    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005
    006    public class ItemSlab extends ItemBlock
    007    {
    008        private final boolean field_77891_a;
    009
    010        /** Instance of BlockHalfSlab. */
    011        private final BlockHalfSlab theHalfSlab;
    012
    013        /** Instance of BlockHalfSlab. */
    014        private final BlockHalfSlab theHalfSlab2;
    015
    016        public ItemSlab(int par1, BlockHalfSlab par2BlockHalfSlab, BlockHalfSlab par3BlockHalfSlab, boolean par4)
    017        {
    018            super(par1);
    019            this.theHalfSlab = par2BlockHalfSlab;
    020            this.theHalfSlab2 = par3BlockHalfSlab;
    021            this.field_77891_a = par4;
    022            this.setMaxDamage(0);
    023            this.setHasSubtypes(true);
    024        }
    025
    026        @SideOnly(Side.CLIENT)
    027
    028        /**
    029         * Gets an icon index based on an item's damage value
    030         */
    031        public int getIconFromDamage(int par1)
    032        {
    033            return Block.blocksList[this.shiftedIndex].getBlockTextureFromSideAndMetadata(2, par1);
    034        }
    035
    036        /**
    037         * Returns the metadata of the block which this Item (ItemBlock) can place
    038         */
    039        public int getMetadata(int par1)
    040        {
    041            return par1;
    042        }
    043
    044        public String getItemNameIS(ItemStack par1ItemStack)
    045        {
    046            return this.theHalfSlab.getFullSlabName(par1ItemStack.getItemDamage());
    047        }
    048
    049        /**
    050         * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    051         * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    052         */
    053        public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    054        {
    055            if (this.field_77891_a)
    056            {
    057                return super.onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
    058            }
    059            else if (par1ItemStack.stackSize == 0)
    060            {
    061                return false;
    062            }
    063            else if (!par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack))
    064            {
    065                return false;
    066            }
    067            else
    068            {
    069                int var11 = par3World.getBlockId(par4, par5, par6);
    070                int var12 = par3World.getBlockMetadata(par4, par5, par6);
    071                int var13 = var12 & 7;
    072                boolean var14 = (var12 & 8) != 0;
    073
    074                if ((par7 == 1 && !var14 || par7 == 0 && var14) && var11 == this.theHalfSlab.blockID && var13 == par1ItemStack.getItemDamage())
    075                {
    076                    if (par3World.checkIfAABBIsClear(this.theHalfSlab2.getCollisionBoundingBoxFromPool(par3World, par4, par5, par6)) && par3World.setBlockAndMetadataWithNotify(par4, par5, par6, this.theHalfSlab2.blockID, var13))
    077                    {
    078                        par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), this.theHalfSlab2.stepSound.getPlaceSound(), (this.theHalfSlab2.stepSound.getVolume() + 1.0F) / 2.0F, this.theHalfSlab2.stepSound.getPitch() * 0.8F);
    079                        --par1ItemStack.stackSize;
    080                    }
    081
    082                    return true;
    083                }
    084                else
    085                {
    086                    return this.func_77888_a(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7) ? true : super.onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
    087                }
    088            }
    089        }
    090
    091        @SideOnly(Side.CLIENT)
    092
    093        /**
    094         * Returns true if the given ItemBlock can be placed on the given side of the given block position.
    095         */
    096        public boolean canPlaceItemBlockOnSide(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer, ItemStack par7ItemStack)
    097        {
    098            int var8 = par2;
    099            int var9 = par3;
    100            int var10 = par4;
    101            int var11 = par1World.getBlockId(par2, par3, par4);
    102            int var12 = par1World.getBlockMetadata(par2, par3, par4);
    103            int var13 = var12 & 7;
    104            boolean var14 = (var12 & 8) != 0;
    105
    106            if ((par5 == 1 && !var14 || par5 == 0 && var14) && var11 == this.theHalfSlab.blockID && var13 == par7ItemStack.getItemDamage())
    107            {
    108                return true;
    109            }
    110            else
    111            {
    112                if (par5 == 0)
    113                {
    114                    --par3;
    115                }
    116
    117                if (par5 == 1)
    118                {
    119                    ++par3;
    120                }
    121
    122                if (par5 == 2)
    123                {
    124                    --par4;
    125                }
    126
    127                if (par5 == 3)
    128                {
    129                    ++par4;
    130                }
    131
    132                if (par5 == 4)
    133                {
    134                    --par2;
    135                }
    136
    137                if (par5 == 5)
    138                {
    139                    ++par2;
    140                }
    141
    142                var11 = par1World.getBlockId(par2, par3, par4);
    143                var12 = par1World.getBlockMetadata(par2, par3, par4);
    144                var13 = var12 & 7;
    145                var14 = (var12 & 8) != 0;
    146                return var11 == this.theHalfSlab.blockID && var13 == par7ItemStack.getItemDamage() ? true : super.canPlaceItemBlockOnSide(par1World, var8, var9, var10, par5, par6EntityPlayer, par7ItemStack);
    147            }
    148        }
    149
    150        private boolean func_77888_a(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7)
    151        {
    152            if (par7 == 0)
    153            {
    154                --par5;
    155            }
    156
    157            if (par7 == 1)
    158            {
    159                ++par5;
    160            }
    161
    162            if (par7 == 2)
    163            {
    164                --par6;
    165            }
    166
    167            if (par7 == 3)
    168            {
    169                ++par6;
    170            }
    171
    172            if (par7 == 4)
    173            {
    174                --par4;
    175            }
    176
    177            if (par7 == 5)
    178            {
    179                ++par4;
    180            }
    181
    182            int var8 = par3World.getBlockId(par4, par5, par6);
    183            int var9 = par3World.getBlockMetadata(par4, par5, par6);
    184            int var10 = var9 & 7;
    185
    186            if (var8 == this.theHalfSlab.blockID && var10 == par1ItemStack.getItemDamage())
    187            {
    188                if (par3World.checkIfAABBIsClear(this.theHalfSlab2.getCollisionBoundingBoxFromPool(par3World, par4, par5, par6)) && par3World.setBlockAndMetadataWithNotify(par4, par5, par6, this.theHalfSlab2.blockID, var10))
    189                {
    190                    par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), this.theHalfSlab2.stepSound.getPlaceSound(), (this.theHalfSlab2.stepSound.getVolume() + 1.0F) / 2.0F, this.theHalfSlab2.stepSound.getPitch() * 0.8F);
    191                    --par1ItemStack.stackSize;
    192                }
    193
    194                return true;
    195            }
    196            else
    197            {
    198                return false;
    199            }
    200        }
    201    }