Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

Don't call super.keyTyped.

 

It still switches over to the NEI search box every 4-5 seconds :/

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.