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.

[SOLVED] [1.6.4] Text Box Gui element not registering my click at the right spot

Featured Replies

Posted

I have made a GUI with a textbox, but when I click it, it doesn't activate! But, if I click it's location from the actual size of the window, so subtracting GuiTop and GuiLeft, it will activate. I tried adding GuiTop and left to the click but it still won't work. Any Help?

 

Code:

package skillcraft.client.interfaces;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import tileentities.TileEntityRunetable;

public class GuiRunetable extends GuiContainer
{
 int testX = 25;
 int testY = 25;

private TileEntityRunetable runetable;

GuiTextField textFieldName;

public GuiRunetable(InventoryPlayer invPlayer, TileEntityRunetable runetable)
{
	super(new ContainerRunetable(invPlayer, runetable));

	this.runetable = runetable;

	xSize = 176;
	ySize = 191;
}

@Override
public void initGui()
{
	super.initGui();
        
	textFieldName = new GuiTextField(fontRenderer, 68, 5, 100, 15);
	textFieldName.setMaxStringLength(20);
	textFieldName.setFocused(false);
}

private static final ResourceLocation texture = new ResourceLocation("skillcraft", "textures/gui/runetablegui.png");

@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
	GL11.glColor4f(1, 1, 1, 1);

	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);		
}

@Override
    public void updateScreen()
    {
        textFieldName.updateCursorCounter();
    }

@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
	fontRenderer.drawString("Rune Table", 8, 8, 0x404040);

	int[] error = runetable.runeHandler.errorCheck();
	if (error[0] == 1)
	{
		fontRenderer.drawString("You maxed out this rune!", 26, 67, 0xFF3300);
	}
	else if (error[0] == 2)
	{
		fontRenderer.drawString("Can't add this rune to this item!", 10, 67, 0xFF3300);
	}
	else if (error[0] == 3)
	{
		fontRenderer.drawString("You must have " + error[1] + " levels!", 28, 67, 0xFF3300);
	}

	textFieldName.drawTextBox();	

}

@Override
    protected void keyTyped(char key, int par2)
{
	//if (!textFieldName.isFocused())
	//{
		super.keyTyped(key, par2);
	//}

	textFieldName.textboxKeyTyped(key, par2);

	//if (runetable.getStackInSlot(2) != null)
	//{
	///	runetable.nameTool(textFieldName.getText());
	///}

	switch (key)
	{
	case 'w':
		testY--;
		break;
	case 'a':
		testX--;
		break;
	case 's':
		testY++;
		break;
	case 'd':
		testX++;
		break;
	case 'o':
		System.out.println(testX + ", " + testY);
	}
}

public void mouseClicked(int i, int j, int k)
{
	super.mouseClicked(i, j, k);

	textFieldName.mouseClicked(i, j, k);
}


}

  • Author

In the mouseClicked method. Is it because it isn't going to the server or something?

 

public void mouseClicked(int i, int j, int k)

{

super.mouseClicked(i, j, k);

 

textFieldName.mouseClicked(i + guiLeft, j + guiTop, k);

      }

 

When I do this I cannot even find where I'm supposed to click. So guiLeft and top are definately not 0

  • Author

Figured it out! Such a simple error. Instead of adding guiLeft and top onto the mouse points you have to subract them! Should of realized that. Well, thanks for your help! I really appreciated it! :)

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.