double getLineWidth(String line, int charCount) { return textRenderer .getLineMetrics( line.substring(0, math.min(charCount, line.length)), ) .width; }