    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                for (int var5 = 0; var5 < 1000; ++var5)
    095                {
    096                    int var6 = par2 + par1World.rand.nextInt(16) - par1World.rand.nextInt(16);
    097                    int var7 = par3 + par1World.rand.nextInt(8) - par1World.rand.nextInt(8);
    098                    int var8 = par4 + par1World.rand.nextInt(16) - par1World.rand.nextInt(16);
    099
    100                    if (par1World.getBlockId(var6, var7, var8) == 0)
    101                    {
    102                        if (!par1World.isRemote)
    103                        {
    104                            par1World.setBlockAndMetadataWithNotify(var6, var7, var8, this.blockID, par1World.getBlockMetadata(par2, par3, par4));
    105                            par1World.setBlockWithNotify(par2, par3, par4, 0);
    106                        }
    107                        else
    108                        {
    109                            short var9 = 128;
    110
    111                            for (int var10 = 0; var10 < var9; ++var10)
    112                            {
    113                                double var11 = par1World.rand.nextDouble();
    114                                float var13 = (par1World.rand.nextFloat() - 0.5F) * 0.2F;
    115                                float var14 = (par1World.rand.nextFloat() - 0.5F) * 0.2F;
    116                                float var15 = (par1World.rand.nextFloat() - 0.5F) * 0.2F;
    117                                double var16 = (double)var6 + (double)(par2 - var6) * var11 + (par1World.rand.nextDouble() - 0.5D) * 1.0D + 0.5D;
    118                                double var18 = (double)var7 + (double)(par3 - var7) * var11 + par1World.rand.nextDouble() * 1.0D - 0.5D;
    119                                double var20 = (double)var8 + (double)(par4 - var8) * var11 + (par1World.rand.nextDouble() - 0.5D) * 1.0D + 0.5D;
    120                                par1World.spawnParticle("portal", var16, var18, var20, (double)var13, (double)var14, (double)var15);
    121                            }
    122                        }
    123
    124                        return;
    125                    }
    126                }
    127            }
    128        }
    129
    130        /**
    131         * How many world ticks before ticking
    132         */
    133        public int tickRate()
    134        {
    135            return 5;
    136        }
    137
    138        /**
    139         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    140         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    141         */
    142        public boolean isOpaqueCube()
    143        {
    144            return false;
    145        }
    146
    147        /**
    148         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    149         */
    150        public boolean renderAsNormalBlock()
    151        {
    152            return false;
    153        }
    154
    155        @SideOnly(Side.CLIENT)
    156
    157        /**
    158         * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
    159         * coordinates.  Args: blockAccess, x, y, z, side
    160         */
    161        public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    162        {
    163            return true;
    164        }
    165
    166        /**
    167         * The type of render function that is called for this block
    168         */
    169        public int getRenderType()
    170        {
    171            return 27;
    172        }
    173
    174        @SideOnly(Side.CLIENT)
    175
    176        /**
    177         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    178         */
    179        public int idPicked(World par1World, int par2, int par3, int par4)
    180        {
    181            return 0;
    182        }
    183    }