Buggy code:
public class ElementTextField extends ElementBase { public int borderColor = new GuiColor ( 55 , 55 , 55 ) . getColor ( ) ; public int backgroundColor = new GuiColor ( 139 , 139 , 139 ) . getColor ( ) ; public int disabledColor = new GuiColor ( 198 , 198 , 198 ) . getColor ( ) ; public int selectedLineColor = new GuiColor ( 160 , 160 , 224 ) . getColor ( ) ; public int textColor = new GuiColor ( 224 , 224 , 224 ) . getColor ( ) ; public int selectedTextColor = new GuiColor ( 224 , 224 , 224 ) . getColor ( ) ; public int defaultCaretColor = new GuiColor ( 255 , 255 , 255 ) . getColor ( ) ; protected char [ ] text ; protected int textLength ; protected int selectionStart ; protected int selectionEnd ; protected int renderStart ; protected int caret ; private boolean isFocused ; private boolean canFocusChange = true ; private boolean selecting ; private byte caretCounter ; protected boolean caretInsert ; protected boolean enableStencil = true ; protected boolean smartCaret = true ; protected boolean smartCaretCase = true ; public ElementTextField ( GuiBase gui , int posX , int posY , int width , int height ) { } public ElementTextField ( GuiBase gui , int posX , int posY , int width , int height , short limit ) { } public ElementTextField setTextColor ( Number textColor , Number selectedTextColor ) { } public ElementTextField setSelectionColor ( Number selectedLineColor , Number defaultCaretColor ) { } public ElementTextField setBackgroundColor ( Number backgroundColor , Number disabledColor , Number borderColor ) { } public ElementTextField setFocusable ( boolean focusable ) { } public ElementTextField setFocused ( boolean focused ) { } public ElementTextField setText ( String text ) { } public ElementTextField setMaxLength ( short limit ) { } public int getMaxStringLength ( ) { } public boolean isFocused ( ) { } public boolean isFocusable ( ) { } public String getText ( ) { } public String getSelectedText ( ) { } public void writeText ( String text ) { } protected boolean isAllowedCharacter ( char charTyped ) { } protected boolean insertCharacter ( char charTyped ) { } protected void findRenderStart ( ) { } protected void clearSelection ( ) { } protected final int seekNextCaretLocation ( int pos ) { } protected final int seekNextCaretLocation ( int pos , boolean forward ) { } @ Override public boolean onKeyTyped ( char charTyped , int keyTyped ) { } @ Override public boolean onMousePressed ( int mouseX , int mouseY , int mouseButton ) { } @ Override public void update ( int mouseX , int mouseY ) { } @ Override public void onMouseReleased ( int mouseX , int mouseY ) { } @ Override public void drawBackground ( int mouseX , int mouseY , float gameTicks ) { } @ Override public void drawForeground ( int mouseX , int mouseY ) { if ( enableStencil ) { glEnable ( GL_STENCIL_TEST ) ; glClear ( GL_STENCIL_BUFFER_BIT ) ; drawStencil ( ( ( posX ) + 1 ) , ( ( posY ) + 1 ) , ( ( ( posX ) + ( sizeX ) ) - 1 ) , ( ( ( posY ) + ( sizeY ) ) - 1 ) , 1 ) ; } FontRenderer font = getFontRenderer ( ) ; char [ ] text = this . text ; int startX = ( posX ) + 1 ; int endX = ( sizeX ) - 1 ; int startY = ( posY ) + 1 ; int endY = startY + ( font . FONT_HEIGHT ) ; for ( int i = renderStart , width = 0 ; i <= ( textLength ) ; ++ i ) { boolean end = i == ( textLength ) ; int charW = 2 ; if ( ! end ) { charW = font . getCharWidth ( text [ i ] ) ; if ( ( ! ( enableStencil ) ) && ( ( width + charW ) > endX ) ) break ; } boolean drawCaret = ( ( i == ( caret ) ) && ( ( caretCounter %= 24 ) < 12 ) ) && ( isFocused ( ) ) ; if ( drawCaret ) { int caretEnd = width + 2 ; if ( caretInsert ) caretEnd = width + charW ; <START_BUG> drawModalRect ( ( startX + width ) , ( startY - 1 ) , ( startX + caretEnd ) , endY , ( ( - 16777216 & ( defaultCaretColor ) ) | ( ~ ( ( defaultCaretColor ) & 16777215 ) ) ) ) ; <END_BUG> } if ( ! end ) { boolean selected = ( i >= ( selectionStart ) ) & ( i < ( selectionEnd ) ) ; if ( selected ) drawModalRect ( ( startX + width ) , startY , ( ( startX + width ) + charW ) , endY , selectedLineColor ) ; font . drawString ( String . valueOf ( text [ i ] ) , ( startX + width ) , startY , ( selected ? selectedTextColor : textColor ) ) ; } if ( drawCaret ) { int caretEnd = width + 2 ; if ( caretInsert ) caretEnd = width + charW ; GL11 . glEnable ( GL_BLEND ) ; GL11 . glBlendFunc ( GL_ONE_MINUS_DST_COLOR , GL_ZERO ) ; gui . drawSizedRect ( ( startX + width ) , ( startY - 1 ) , ( startX + caretEnd ) , endY , ( - 1 ) ) ; GL11 . glDisable ( GL_BLEND ) ; } width += charW ; if ( width > endX ) break ; } if ( enableStencil ) glDisable ( GL_STENCIL_TEST ) ; } }

Fix:
drawModalRect ( ( startX + width ) , ( startY - 1 ) , ( startX + caretEnd ) , endY , ( ( - 16777216 & ( defaultCaretColor ) ) | ( ( ~ ( defaultCaretColor ) ) & 16777215 ) ) ) ;