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