コード例 #1
0
        public virtual bool FindExitLocation(net.minecraft.src.World world, net.minecraft.src.Entity
                                             entity)
        {
            short  c  = 128;          // '\200';
            double d  = -1D;
            int    i  = 0;
            int    j  = 0;
            int    k  = 0;
            int    l  = net.minecraft.src.MathHelper.Floor_double(entity.posX);
            int    i1 = net.minecraft.src.MathHelper.Floor_double(entity.posZ);

            for (int j1 = l - c; j1 <= l + c; j1++)
            {
                double d1 = ((double)j1 + 0.5D) - entity.posX;
                for (int j2 = i1 - c; j2 <= i1 + c; j2++)
                {
                    double d3 = ((double)j2 + 0.5D) - entity.posZ;
                    for (int k2 = 127; k2 >= 0; k2--)
                    {
                        if (world.GetBlockId(j1, k2, j2) != net.minecraft.src.Block.PORTAL.ID)
                        {
                            continue;
                        }
                        for (; world.GetBlockId(j1, k2 - 1, j2) == net.minecraft.src.Block.PORTAL.ID
                             ; k2--)
                        {
                        }
                        double d5 = ((double)k2 + 0.5D) - entity.posY;
                        double d7 = d1 * d1 + d5 * d5 + d3 * d3;
                        if (d < 0.0D || d7 < d)
                        {
                            d = d7;
                            i = j1;
                            j = k2;
                            k = j2;
                        }
                    }
                }
            }
            if (d >= 0.0D)
            {
                int    k1 = i;
                int    l1 = j;
                int    i2 = k;
                double d2 = (double)k1 + 0.5D;
                double d4 = (double)l1 + 0.5D;
                double d6 = (double)i2 + 0.5D;
                if (world.GetBlockId(k1 - 1, l1, i2) == net.minecraft.src.Block.PORTAL.ID)
                {
                    d2 -= 0.5D;
                }
                if (world.GetBlockId(k1 + 1, l1, i2) == net.minecraft.src.Block.PORTAL.ID)
                {
                    d2 += 0.5D;
                }
                if (world.GetBlockId(k1, l1, i2 - 1) == net.minecraft.src.Block.PORTAL.ID)
                {
                    d6 -= 0.5D;
                }
                if (world.GetBlockId(k1, l1, i2 + 1) == net.minecraft.src.Block.PORTAL.ID)
                {
                    d6 += 0.5D;
                }
                entity.SetLocationAndAngles(d2, d4, d6, entity.rotationYaw, 0.0F);
                entity.motionX = entity.motionY = entity.motionZ = 0.0D;
                return(true);
            }
            else
            {
                return(false);
            }
        }