    001    package net.minecraft.src;
    002
    003    public class ItemEnderEye extends Item
    004    {
    005        public ItemEnderEye(int par1)
    006        {
    007            super(par1);
    008            this.setCreativeTab(CreativeTabs.tabMisc);
    009        }
    010
    011        /**
    012         * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    013         * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    014         */
    015        public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    016        {
    017            int var11 = par3World.getBlockId(par4, par5, par6);
    018            int var12 = par3World.getBlockMetadata(par4, par5, par6);
    019
    020            if (par2EntityPlayer.canPlayerEdit(par4, par5, par6) && var11 == Block.endPortalFrame.blockID && !BlockEndPortalFrame.isEnderEyeInserted(var12))
    021            {
    022                if (par3World.isRemote)
    023                {
    024                    return true;
    025                }
    026                else
    027                {
    028                    par3World.setBlockMetadataWithNotify(par4, par5, par6, var12 + 4);
    029                    --par1ItemStack.stackSize;
    030                    int var13;
    031
    032                    for (var13 = 0; var13 < 16; ++var13)
    033                    {
    034                        double var14 = (double)((float)par4 + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
    035                        double var16 = (double)((float)par5 + 0.8125F);
    036                        double var18 = (double)((float)par6 + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
    037                        double var20 = 0.0D;
    038                        double var22 = 0.0D;
    039                        double var24 = 0.0D;
    040                        par3World.spawnParticle("smoke", var14, var16, var18, var20, var22, var24);
    041                    }
    042
    043                    var13 = var12 & 3;
    044                    int var26 = 0;
    045                    int var15 = 0;
    046                    boolean var27 = false;
    047                    boolean var17 = true;
    048                    int var28 = Direction.enderEyeMetaToDirection[var13];
    049                    int var19;
    050                    int var21;
    051                    int var23;
    052                    int var29;
    053                    int var30;
    054
    055                    for (var19 = -2; var19 <= 2; ++var19)
    056                    {
    057                        var29 = par4 + Direction.offsetX[var28] * var19;
    058                        var21 = par6 + Direction.offsetZ[var28] * var19;
    059                        var30 = par3World.getBlockId(var29, par5, var21);
    060
    061                        if (var30 == Block.endPortalFrame.blockID)
    062                        {
    063                            var23 = par3World.getBlockMetadata(var29, par5, var21);
    064
    065                            if (!BlockEndPortalFrame.isEnderEyeInserted(var23))
    066                            {
    067                                var17 = false;
    068                                break;
    069                            }
    070
    071                            var15 = var19;
    072
    073                            if (!var27)
    074                            {
    075                                var26 = var19;
    076                                var27 = true;
    077                            }
    078                        }
    079                    }
    080
    081                    if (var17 && var15 == var26 + 2)
    082                    {
    083                        for (var19 = var26; var19 <= var15; ++var19)
    084                        {
    085                            var29 = par4 + Direction.offsetX[var28] * var19;
    086                            var21 = par6 + Direction.offsetZ[var28] * var19;
    087                            var29 += Direction.offsetX[var13] * 4;
    088                            var21 += Direction.offsetZ[var13] * 4;
    089                            var30 = par3World.getBlockId(var29, par5, var21);
    090                            var23 = par3World.getBlockMetadata(var29, par5, var21);
    091
    092                            if (var30 != Block.endPortalFrame.blockID || !BlockEndPortalFrame.isEnderEyeInserted(var23))
    093                            {
    094                                var17 = false;
    095                                break;
    096                            }
    097                        }
    098
    099                        for (var19 = var26 - 1; var19 <= var15 + 1; var19 += 4)
    100                        {
    101                            for (var29 = 1; var29 <= 3; ++var29)
    102                            {
    103                                var21 = par4 + Direction.offsetX[var28] * var19;
    104                                var30 = par6 + Direction.offsetZ[var28] * var19;
    105                                var21 += Direction.offsetX[var13] * var29;
    106                                var30 += Direction.offsetZ[var13] * var29;
    107                                var23 = par3World.getBlockId(var21, par5, var30);
    108                                int var31 = par3World.getBlockMetadata(var21, par5, var30);
    109
    110                                if (var23 != Block.endPortalFrame.blockID || !BlockEndPortalFrame.isEnderEyeInserted(var31))
    111                                {
    112                                    var17 = false;
    113                                    break;
    114                                }
    115                            }
    116                        }
    117
    118                        if (var17)
    119                        {
    120                            for (var19 = var26; var19 <= var15; ++var19)
    121                            {
    122                                for (var29 = 1; var29 <= 3; ++var29)
    123                                {
    124                                    var21 = par4 + Direction.offsetX[var28] * var19;
    125                                    var30 = par6 + Direction.offsetZ[var28] * var19;
    126                                    var21 += Direction.offsetX[var13] * var29;
    127                                    var30 += Direction.offsetZ[var13] * var29;
    128                                    par3World.setBlockWithNotify(var21, par5, var30, Block.endPortal.blockID);
    129                                }
    130                            }
    131                        }
    132                    }
    133
    134                    return true;
    135                }
    136            }
    137            else
    138            {
    139                return false;
    140            }
    141        }
    142
    143        /**
    144         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    145         */
    146        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    147        {
    148            MovingObjectPosition var4 = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, false);
    149
    150            if (var4 != null && var4.typeOfHit == EnumMovingObjectType.TILE)
    151            {
    152                int var5 = par2World.getBlockId(var4.blockX, var4.blockY, var4.blockZ);
    153
    154                if (var5 == Block.endPortalFrame.blockID)
    155                {
    156                    return par1ItemStack;
    157                }
    158            }
    159
    160            if (!par2World.isRemote)
    161            {
    162                ChunkPosition var7 = par2World.findClosestStructure("Stronghold", (int)par3EntityPlayer.posX, (int)par3EntityPlayer.posY, (int)par3EntityPlayer.posZ);
    163
    164                if (var7 != null)
    165                {
    166                    EntityEnderEye var6 = new EntityEnderEye(par2World, par3EntityPlayer.posX, par3EntityPlayer.posY + 1.62D - (double)par3EntityPlayer.yOffset, par3EntityPlayer.posZ);
    167                    var6.moveTowards((double)var7.x, var7.y, (double)var7.z);
    168                    par2World.spawnEntityInWorld(var6);
    169                    par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
    170                    par2World.playAuxSFXAtEntity((EntityPlayer)null, 1002, (int)par3EntityPlayer.posX, (int)par3EntityPlayer.posY, (int)par3EntityPlayer.posZ, 0);
    171
    172                    if (!par3EntityPlayer.capabilities.isCreativeMode)
    173                    {
    174                        --par1ItemStack.stackSize;
    175                    }
    176                }
    177            }
    178
    179            return par1ItemStack;
    180        }
    181    }