    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 BlockDragonEgg extends Block
    008    {
    009        public BlockDragonEgg(int par1, int par2)
    010        {
    011            super(par1, par2, Material.dragonEgg);
    012        }
    013
    014        /**
    015         * Called whenever the block is added into the world. Args: world, x, y, z
    016         */
    017        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    018        {
    019            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    020        }
    021
    022        /**
    023         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    024         * their own) Args: x, y, z, neighbor blockID
    025         */
    026        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    027        {
    028            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    029        }
    030
    031        /**
    032         * Ticks the block if it's been scheduled
    033         */
    034        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    035        {
    036            this.fallIfPossible(par1World, par2, par3, par4);
    037        }
    038
    039        /**
    040         * Checks if the dragon egg can fall down, and if so, makes it fall.
    041         */
    042        private void fallIfPossible(World par1World, int par2, int par3, int par4)
    043        {
    044            if (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0)
    045            {
    046                byte var5 = 32;
    047
    048                if (!BlockSand.fallInstantly && par1World.checkChunksExist(par2 - var5, par3 - var5, par4 - var5, par2 + var5, par3 + var5, par4 + var5))
    049                {
    050                    EntityFallingSand var6 = new EntityFallingSand(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), this.blockID);
    051                    par1World.spawnEntityInWorld(var6);
    052                }
    053                else
    054                {
    055                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    056
    057                    while (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0)
    058                    {
    059                        --par3;
    060                    }
    061
    062                    if (par3 > 0)
    063                    {
    064                        par1World.setBlockWithNotify(par2, par3, par4, this.blockID);
    065                    }
    066                }
    067            }
    068        }
    069
    070        /**
    071         * Called upon block activation (right click on the block.)
    072         */
    073        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    074        {
    075            this.teleportNearby(par1World, par2, par3, par4);
    076            return true;
    077        }
    078
    079        /**
    080         * Called when the block is clicked by a player. Args: x, y, z, entityPlayer
    081         */
    082        public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    083        {
    084            this.teleportNearby(par1World, par2, par3, par4);
    085        }
    086
    087        /**
    088         * Teleports the dragon egg somewhere else in a 31x19x31 area centered on the egg.
    089         */
    090        private void teleportNearby(World par1World, int par2, int par3, int par4)
    091        {
    092            if (par1World.getBlockId(par2, par3, par4) == this.blockID)
    093            {
    094                if (!par1World.isRemote)
    095                {
    096                    for (int var5 = 0; var5 < 1000; ++var5)
    097                    {
    098                        int var6 = par2 + par1World.rand.nextInt(16) - par1World.rand.nextInt(16);
    099                        int var7 = par3 + par1World.rand.nextInt(8) - par1World.rand.nextInt(8);
    100                        int var8 = par4 + par1World.rand.nextInt(16) - par1World.rand.nextInt(16);
    101
    102                        if (par1World.getBlockId(var6, var7, var8) == 0)
    103                        {
    104                            par1World.setBlockAndMetadataWithNotify(var6, var7, var8, this.blockID, par1World.getBlockMetadata(par2, par3, par4));
    105                            par1World.setBlockWithNotify(par2, par3, par4, 0);
    106                            short var9 = 128;
    107
    108                            for (int var10 = 0; var10 < var9; ++var10)
    109                            {
    110                                double var11 = par1World.rand.nextDouble();
    111                                float var13 = (par1World.rand.nextFloat() - 0.5F) * 0.2F;
    112                                float var14 = (par1World.rand.nextFloat() - 0.5F) * 0.2F;
    113                                float var15 = (par1World.rand.nextFloat() - 0.5F) * 0.2F;
    114                                double var16 = (double)var6 + (double)(par2 - var6) * var11 + (par1World.rand.nextDouble() - 0.5D) * 1.0D + 0.5D;
    115                                double var18 = (double)var7 + (double)(par3 - var7) * var11 + par1World.rand.nextDouble() * 1.0D - 0.5D;
    116                                double var20 = (double)var8 + (double)(par4 - var8) * var11 + (par1World.rand.nextDouble() - 0.5D) * 1.0D + 0.5D;
    117                                par1World.spawnParticle("portal", var16, var18, var20, (double)var13, (double)var14, (double)var15);
    118                            }
    119
    120                            return;
    121                        }
    122                    }
    123                }
    124            }
    125        }
    126
    127        /**
    128         * How many world ticks before ticking
    129         */
    130        public int tickRate()
    131        {
    132            return 3;
    133        }
    134
    135        /**
    136         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    137         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    138         */
    139        public boolean isOpaqueCube()
    140        {
    141            return false;
    142        }
    143
    144        /**
    145         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    146         */
    147        public boolean renderAsNormalBlock()
    148        {
    149            return false;
    150        }
    151
    152        /**
    153         * The type of render function that is called for this block
    154         */
    155        public int getRenderType()
    156        {
    157            return 27;
    158        }
    159
    160        @SideOnly(Side.CLIENT)
    161
    162        /**
    163         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    164         */
    165        public int idPicked(World par1World, int par2, int par3, int par4)
    166        {
    167            return 0;
    168        }
    169    }