    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.Random;
    006
    007    public class BlockSkull extends BlockContainer
    008    {
    009        protected BlockSkull(int par1)
    010        {
    011            super(par1, Material.circuits);
    012            this.blockIndexInTexture = 104;
    013            this.setBlockBounds(0.25F, 0.0F, 0.25F, 0.75F, 0.5F, 0.75F);
    014        }
    015
    016        /**
    017         * The type of render function that is called for this block
    018         */
    019        public int getRenderType()
    020        {
    021            return -1;
    022        }
    023
    024        /**
    025         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    026         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    027         */
    028        public boolean isOpaqueCube()
    029        {
    030            return false;
    031        }
    032
    033        /**
    034         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    035         */
    036        public boolean renderAsNormalBlock()
    037        {
    038            return false;
    039        }
    040
    041        /**
    042         * Updates the blocks bounds based on its current state. Args: world, x, y, z
    043         */
    044        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    045        {
    046            int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 7;
    047
    048            switch (var5)
    049            {
    050                case 1:
    051                default:
    052                    this.setBlockBounds(0.25F, 0.0F, 0.25F, 0.75F, 0.5F, 0.75F);
    053                    break;
    054                case 2:
    055                    this.setBlockBounds(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F);
    056                    break;
    057                case 3:
    058                    this.setBlockBounds(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F);
    059                    break;
    060                case 4:
    061                    this.setBlockBounds(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F);
    062                    break;
    063                case 5:
    064                    this.setBlockBounds(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F);
    065            }
    066        }
    067
    068        /**
    069         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    070         * cleared to be reused)
    071         */
    072        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    073        {
    074            this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
    075            return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
    076        }
    077
    078        /**
    079         * Called when the block is placed in the world.
    080         */
    081        public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
    082        {
    083            int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
    084            par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
    085        }
    086
    087        /**
    088         * Returns a new instance of a block's tile entity class. Called on placing the block.
    089         */
    090        public TileEntity createNewTileEntity(World par1World)
    091        {
    092            return new TileEntitySkull();
    093        }
    094
    095        @SideOnly(Side.CLIENT)
    096
    097        /**
    098         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    099         */
    100        public int idPicked(World par1World, int par2, int par3, int par4)
    101        {
    102            return Item.skull.shiftedIndex;
    103        }
    104
    105        /**
    106         * Get the block's damage value (for use with pick block).
    107         */
    108        public int getDamageValue(World par1World, int par2, int par3, int par4)
    109        {
    110            TileEntity var5 = par1World.getBlockTileEntity(par2, par3, par4);
    111            return var5 != null && var5 instanceof TileEntitySkull ? ((TileEntitySkull)var5).func_82117_a() : super.getDamageValue(par1World, par2, par3, par4);
    112        }
    113
    114        /**
    115         * Determines the damage on the item the block drops. Used in cloth and wood.
    116         */
    117        public int damageDropped(int par1)
    118        {
    119            return par1;
    120        }
    121
    122        /**
    123         * Drops the block items with a specified chance of dropping the specified items
    124         */
    125        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) {}
    126
    127        /**
    128         * Called when the block is attempted to be harvested
    129         */
    130        public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer)
    131        {
    132            if (par6EntityPlayer.capabilities.isCreativeMode)
    133            {
    134                par5 |= 8;
    135                par1World.setBlockMetadataWithNotify(par2, par3, par4, par5);
    136            }
    137
    138            super.onBlockHarvested(par1World, par2, par3, par4, par5, par6EntityPlayer);
    139        }
    140
    141        /**
    142         * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    143         */
    144        public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    145        {
    146            if (!par1World.isRemote)
    147            {
    148                if ((par6 & 8) == 0)
    149                {
    150                    this.dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(Item.skull.shiftedIndex, 1, this.getDamageValue(par1World, par2, par3, par4)));
    151                }
    152
    153                super.breakBlock(par1World, par2, par3, par4, par5, par6);
    154            }
    155        }
    156
    157        /**
    158         * Returns the ID of the items to drop on destruction.
    159         */
    160        public int idDropped(int par1, Random par2Random, int par3)
    161        {
    162            return Item.skull.shiftedIndex;
    163        }
    164
    165        public void func_82529_a(World par1World, int par2, int par3, int par4, TileEntitySkull par5TileEntitySkull)
    166        {
    167            if (par5TileEntitySkull.func_82117_a() == 1 && par3 >= 2)
    168            {
    169                int var6 = Block.slowSand.blockID;
    170                int var7;
    171                EntityWither var8;
    172                int var9;
    173
    174                for (var7 = -2; var7 <= 0; ++var7)
    175                {
    176                    if (par1World.getBlockId(par2, par3 - 1, par4 + var7) == var6 && par1World.getBlockId(par2, par3 - 1, par4 + var7 + 1) == var6 && par1World.getBlockId(par2, par3 - 2, par4 + var7 + 1) == var6 && par1World.getBlockId(par2, par3 - 1, par4 + var7 + 2) == var6 && this.func_82528_d(par1World, par2, par3, par4 + var7, 1) && this.func_82528_d(par1World, par2, par3, par4 + var7 + 1, 1) && this.func_82528_d(par1World, par2, par3, par4 + var7 + 2, 1))
    177                    {
    178                        par1World.setBlockMetadata(par2, par3, par4 + var7, 8);
    179                        par1World.setBlockMetadata(par2, par3, par4 + var7 + 1, 8);
    180                        par1World.setBlockMetadata(par2, par3, par4 + var7 + 2, 8);
    181                        par1World.setBlock(par2, par3, par4 + var7, 0);
    182                        par1World.setBlock(par2, par3, par4 + var7 + 1, 0);
    183                        par1World.setBlock(par2, par3, par4 + var7 + 2, 0);
    184                        par1World.setBlock(par2, par3 - 1, par4 + var7, 0);
    185                        par1World.setBlock(par2, par3 - 1, par4 + var7 + 1, 0);
    186                        par1World.setBlock(par2, par3 - 1, par4 + var7 + 2, 0);
    187                        par1World.setBlock(par2, par3 - 2, par4 + var7 + 1, 0);
    188
    189                        if (!par1World.isRemote)
    190                        {
    191                            var8 = new EntityWither(par1World);
    192                            var8.setLocationAndAngles((double)par2 + 0.5D, (double)par3 - 1.45D, (double)(par4 + var7) + 1.5D, 90.0F, 0.0F);
    193                            var8.renderYawOffset = 90.0F;
    194                            var8.func_82206_m();
    195                            par1World.spawnEntityInWorld(var8);
    196                        }
    197
    198                        for (var9 = 0; var9 < 120; ++var9)
    199                        {
    200                            par1World.spawnParticle("snowballpoof", (double)par2 + par1World.rand.nextDouble(), (double)(par3 - 2) + par1World.rand.nextDouble() * 3.9D, (double)(par4 + var7 + 1) + par1World.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
    201                        }
    202
    203                        par1World.notifyBlockChange(par2, par3, par4 + var7, 0);
    204                        par1World.notifyBlockChange(par2, par3, par4 + var7 + 1, 0);
    205                        par1World.notifyBlockChange(par2, par3, par4 + var7 + 2, 0);
    206                        par1World.notifyBlockChange(par2, par3 - 1, par4 + var7, 0);
    207                        par1World.notifyBlockChange(par2, par3 - 1, par4 + var7 + 1, 0);
    208                        par1World.notifyBlockChange(par2, par3 - 1, par4 + var7 + 2, 0);
    209                        par1World.notifyBlockChange(par2, par3 - 2, par4 + var7 + 1, 0);
    210                        return;
    211                    }
    212                }
    213
    214                for (var7 = -2; var7 <= 0; ++var7)
    215                {
    216                    if (par1World.getBlockId(par2 + var7, par3 - 1, par4) == var6 && par1World.getBlockId(par2 + var7 + 1, par3 - 1, par4) == var6 && par1World.getBlockId(par2 + var7 + 1, par3 - 2, par4) == var6 && par1World.getBlockId(par2 + var7 + 2, par3 - 1, par4) == var6 && this.func_82528_d(par1World, par2 + var7, par3, par4, 1) && this.func_82528_d(par1World, par2 + var7 + 1, par3, par4, 1) && this.func_82528_d(par1World, par2 + var7 + 2, par3, par4, 1))
    217                    {
    218                        par1World.setBlockMetadata(par2 + var7, par3, par4, 8);
    219                        par1World.setBlockMetadata(par2 + var7 + 1, par3, par4, 8);
    220                        par1World.setBlockMetadata(par2 + var7 + 2, par3, par4, 8);
    221                        par1World.setBlock(par2 + var7, par3, par4, 0);
    222                        par1World.setBlock(par2 + var7 + 1, par3, par4, 0);
    223                        par1World.setBlock(par2 + var7 + 2, par3, par4, 0);
    224                        par1World.setBlock(par2 + var7, par3 - 1, par4, 0);
    225                        par1World.setBlock(par2 + var7 + 1, par3 - 1, par4, 0);
    226                        par1World.setBlock(par2 + var7 + 2, par3 - 1, par4, 0);
    227                        par1World.setBlock(par2 + var7 + 1, par3 - 2, par4, 0);
    228
    229                        if (!par1World.isRemote)
    230                        {
    231                            var8 = new EntityWither(par1World);
    232                            var8.setLocationAndAngles((double)(par2 + var7) + 1.5D, (double)par3 - 1.45D, (double)par4 + 0.5D, 0.0F, 0.0F);
    233                            var8.func_82206_m();
    234                            par1World.spawnEntityInWorld(var8);
    235                        }
    236
    237                        for (var9 = 0; var9 < 120; ++var9)
    238                        {
    239                            par1World.spawnParticle("snowballpoof", (double)(par2 + var7 + 1) + par1World.rand.nextDouble(), (double)(par3 - 2) + par1World.rand.nextDouble() * 3.9D, (double)par4 + par1World.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
    240                        }
    241
    242                        par1World.notifyBlockChange(par2 + var7, par3, par4, 0);
    243                        par1World.notifyBlockChange(par2 + var7 + 1, par3, par4, 0);
    244                        par1World.notifyBlockChange(par2 + var7 + 2, par3, par4, 0);
    245                        par1World.notifyBlockChange(par2 + var7, par3 - 1, par4, 0);
    246                        par1World.notifyBlockChange(par2 + var7 + 1, par3 - 1, par4, 0);
    247                        par1World.notifyBlockChange(par2 + var7 + 2, par3 - 1, par4, 0);
    248                        par1World.notifyBlockChange(par2 + var7 + 1, par3 - 2, par4, 0);
    249                        return;
    250                    }
    251                }
    252            }
    253        }
    254
    255        private boolean func_82528_d(World par1World, int par2, int par3, int par4, int par5)
    256        {
    257            if (par1World.getBlockId(par2, par3, par4) != this.blockID)
    258            {
    259                return false;
    260            }
    261            else
    262            {
    263                TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4);
    264                return var6 != null && var6 instanceof TileEntitySkull ? ((TileEntitySkull)var6).func_82117_a() == par5 : false;
    265            }
    266        }
    267    }