Posted September 18, 201510 yr In my modding environment I've got NEI (Not Enough Items) installed, but when I try to type in a text box in my GUI, it switches over to the NEI one every few seconds and types in both ones; how can I prevent this? This is my code for the text box so far: public void initGui(){ super.initGui(); inputText = new GuiTextField(fontRendererObj, guiTop + 10, guiLeft + 10, 80, 12); inputText.setFocused(true); inputText.setCanLoseFocus(false); inputText.setMaxStringLength(40); } @Override public void keyTyped(char c, int i){ super.keyTyped(c, i); if(inputText.isFocused()){ inputText.textboxKeyTyped(c, i); } } public void mouseClicked(int i, int j, int k){ super.mouseClicked(i, j, k); if(inputText.isFocused()) inputText.mouseClicked(i, j, k); } protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); inputText.drawTextBox(); } Also, when pressing like e.g. 'E', it exits out of the inventory; of course, one solution to this would be something like if(i != Keyboard.KEY_E) super.keyTyped(c, i) but is there a better way?
September 18, 201510 yr Don't call super.keyTyped. It still switches over to the NEI search box every 4-5 seconds
September 18, 201510 yr You just need to check if the text field is focused and if this is true, you have to check if the char is in the valid pools. If it's not focused, you have to call super.keyTyped(c, keyCode). Here's an example how I did it: (tfFrequency is a Number-only textfield. 48 - 57 are the numbers from 0-9 and 8 is Backspace/Delete and 43,45 are +/- @Override protected void keyTyped(char c, int keyCode) { if(tfFrequency.isFocused() && (c>=48 && c<=57 || c==8 || c==45 || c==43)) { tfFrequency.textboxKeyTyped(c,keyCode); } else if(!tfName.isFocused()) { super.keyTyped(c,keyCode); } } I hope it helps, Julian
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.