public static String wordWrap(String towrap, TextRenderer tr, float width){
        String[] lines = towrap.split("\n");
        StringBuilder sb2 = new StringBuilder();
        
        for(String line : lines){
            StringBuffer sb = new StringBuffer();
            String[] words = line.split(" ");
            
            for(String word : words){
                if(sb.length() != 0){
                    sb.append(" ");
                    sb.append(word);
                    if(tr.getWidth(sb.toString()) > width){
                        sb.delete(sb.length() - word.length() - 1, sb.length());
                        if(sb2.length() > 0){
                            sb2.append("\n");
                        }
                        sb2.append(sb.toString());
                        sb = new StringBuffer();
                        sb.append(word);
                    }
                }else{
                    sb.append(word);
                }
            }
            if(sb2.length() > 0 && sb.length() > 0){
                sb2.append("\n");
                sb2.append(sb);
            }
        }
        return sb2.toString();
    }