Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Gui button won't click.


Recommended Posts

None of my gui's buttons will click at all. No errors, it's just not happening.

I have a bunch of system printouts throughout the code and it's like the actionPerformed method isn't even being called?

 

 

public class TravellerShopOtherworld extends GuiContainer

{

 

public TravellerShopOtherworld(Container container)

{

super(container);

}

 

private static final ResourceLocation texture = new ResourceLocation(Main.modid + ":textures/gui/stretchedIcons/" + "guiShop.png");

 

protected void drawGuiContainerBackgroundLayer(float f, int x, int y)

{

 

int posX = (this.width) /2;

int posY = (this.height) /2;

 

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

 

this.mc.renderEngine.bindTexture(texture);

int xSize=196;

int ySize=128;

int k = (this.width - xSize) / 2;

int l = (this.height - ySize) / 2;

this.drawTexturedModalRect(k, l, 0, 0, xSize, ySize);

 

 

 

}

 

protected void mouseClicked(int par1, int par2, int par3)

{

Tools.printcon("Mouse was clicked");

super.mouseClicked(par1, par2, par3);

 

}

 

public void updateScreen()

{

int posX = (this.width) /2;

int posY = (this.height) /2;

 

}

 

protected void keyTyped(char par1, int par2)

{

 

if (par2 != 28 && par2 != 156)

{

if (par2 == 1)

{

this.mc.displayGuiScreen((GuiScreen)null);

}

}

 

}

 

protected void drawGuiContainerForegroundLayer(int par1, int par2)

{

int posX = (this.width) /2;

int posY = (this.height) /2;

 

this.fontRendererObj.drawString("Halo of the Sun: " + "$1500", posX+(-85), posY+(-55), 0x000000);

this.fontRendererObj.drawString("Throwing Knife: " + "$50", posX+(-85), posY+(-27), 0x000000);

this.fontRendererObj.drawString("Mining Helmet: " + "$750", posX+(-85), posY+(1), 0x000000);

this.fontRendererObj.drawString("Backpack: " + "$750", posX+(-85), posY+(29), 0x000000);

 

}

 

public void onGuiClosed()

{

Keyboard.enableRepeatEvents(false);

}

 

public void initGui(){

Keyboard.enableRepeatEvents(true);

this.buttonList.clear();

int posX = (this.width) / 2;

int posY = (this.height) / 2;

 

this.buttonList.add(new GuiButton(0, posX+(50), posY+(-59), 36, 20, "Buy"));

this.buttonList.add(new GuiButton(1, posX+(50), posY+(-31), 36, 20, "Buy"));

this.buttonList.add(new GuiButton(2, posX+(50), posY+(-3), 36, 20, "Buy"));

this.buttonList.add(new GuiButton(3, posX+(50), posY+(25), 36, 20, "Buy"));

 

}

 

protected void actionPerformed(GuiButton button)

{

Tools.printcon("Button clicked");

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

int i = (int)player.posX;

int j = (int)player.posY;

int k = (int)player.posZ;

 

if (button.id == 0)

{

Tools.printcon("Sending packet for purchase #1");

IMessage message = new APacketPurchase.PurchaseMessage(1);

}

if (button.id == 1)

{

Tools.printcon("Sending packet for purchase #2");

IMessage message = new APacketPurchase.PurchaseMessage(2);

}

if (button.id == 2)

{

Tools.printcon("Sending packet for purchase #3");

IMessage message = new APacketPurchase.PurchaseMessage(3);

}

if (button.id == 3)

{

Tools.printcon("Sending packet for purchase #4");

IMessage message = new APacketPurchase.PurchaseMessage(4);

}

}

 

public boolean doesGuiPauseGame()

{

return false;

}

 

}

 

Link to post
Share on other sites

Have you tried to change

IMessage message = new APacketPurchase.PurchaseMessage(4);

 

into something like this?

YourMessageHandler.sendToServer(new [your packet name + variables etc.])

 

Otherwise the packet is made, but the send methode is never called

(and so the debug messages are never printed)

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to post
Share on other sites

I have a bunch of system printouts throughout the code and it's like the actionPerformed method isn't even being called?

protected void actionPerformed(GuiButton button)
{
	Tools.printcon("Button clicked");

There are two printouts BEFORE the packet sending that are never printed.

 

@N247S - Learn to read, it can't have anything to do with packets :) (#noHate)

 

Ms_Raven - tried to find something but really couldn't. Few tips for future tho:

When you put @Override over method that is being overriden your IDE will correct you if you make mistake - ensures you won't write different method name or something.

 

As to problem - is your constructor called? Maybe you have two classes with same name? Anything like that?

1.7.10 is no longer supported by forge, you are on your own.

Link to post
Share on other sites

Ernio is right, Im sorry to misunderstand your question. Nevertheless it is still a thing you might want to change.

 

Anyway, on to the problem, you are adding the buttons to the buttonlist. but Im not sure if thats the correct list to be honest. I used controlList.add(), maybe that will give the buttons acces to actionPerformed().

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to post
Share on other sites

A quick scan over the code and it looks correct. Like Ernio says, you should definitely enable @Override verification in your IDE to ensure your methods are the right ones, but they do look correct as well.

 

You should put a console statement in every method to see which ones are being called. Especially the initGui().

 

The one thing I wonder about is that you've made it a GuiContainer but haven't added any inventory slots. I don't know that that would cause a problem, but it might. What happens if you make it extend GuiScreen instead? I realize you'll want it to be GuiContainer when your finished, but it might be instructive to see if it works as a GuiScreen.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to post
Share on other sites

Ernio is right, Im sorry to misunderstand your question. Nevertheless it is still a thing you might want to change.

 

Anyway, on to the problem, you are adding the buttons to the buttonlist. but Im not sure if thats the correct list to be honest. I used controlList.add(), maybe that will give the buttons acces to actionPerformed().

 

This man is correct. buttonList is deprecated. use controlList instead.

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to post
Share on other sites

I am sorry, but where did you get "controlList" field?

 

She's on 1.7.10, I am on 1.8, there is not such field as this. Also buttonList is not deprecated (in my Forge version, which might be quite old but STILL it's newer than any 1.7.10, so how can something be deprecated?)

 

Welp, 1.7.10 still gets updates - which might be cause of my "outdateness" - what versions are you on guys?

1.7.10 is no longer supported by forge, you are on your own.

Link to post
Share on other sites

Again you need to be meticulous in your debugging. You should put a console statement to confirm that the gui constructor is called, that the init is called, etc.

 

For example, maybe you'll find that you copied the GUI class to work on it and you're never actually constructing this one but an older copy of it. Sometimes I have multiple workspaces open and think I'm working in one project but actually working in another. Most bugs are dumb mistakes or typos, the rest are logic bugs. In either case when debugging you  should trust nothing so need to very every step of logic to get to the result you want.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I'm reworking vanilla enchanting mechanics for my mod, and need to completely replace the functionality of vanilla enchanting tables and anvils. I have 2 new tile entity blocks set up, and I'm working on their functionality at the moment. When they're done, how would I replace the vanilla blocks with them? Alternatively, how would I replace the tile entity of the vanilla blocks with my own tile entities?
    • This is the crash report  Description: Initializing game java.lang.NoClassDefFoundError: slimeknights/tconstruct/library/client/MaterialRenderInfo     at lucraft.mods.lucraftcore.LCConfig$Materials.<init>(LCConfig.java:108)     at lucraft.mods.lucraftcore.LCConfig.<clinit>(LCConfig.java:36)     at lucraft.mods.lucraftcore.addonpacks.AddonPackHandler.getAddonPacksDir(AddonPackHandler.java:61)     at lucraft.mods.lucraftcore.core.LCClientHooks.insertAddonPackResourcePacks(LCClientHooks.java:37)     at net.minecraft.client.Minecraft.func_110436_a(Minecraft.java:789)     at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:247)     at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)     at net.minecraft.client.main.Main.main(SourceFile:123)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Caused by: java.lang.ClassNotFoundException: slimeknights.tconstruct.library.client.MaterialRenderInfo     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 15 more Caused by: java.lang.NullPointerException A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace:     at lucraft.mods.lucraftcore.LCConfig$Materials.<init>(LCConfig.java:108)     at lucraft.mods.lucraftcore.LCConfig.<clinit>(LCConfig.java:36)     at lucraft.mods.lucraftcore.addonpacks.AddonPackHandler.getAddonPacksDir(AddonPackHandler.java:61)     at lucraft.mods.lucraftcore.core.LCClientHooks.insertAddonPackResourcePacks(LCClientHooks.java:37)     at net.minecraft.client.Minecraft.func_110436_a(Minecraft.java:789)     at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:247)     at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467) -- Initialization -- Details: Stacktrace:     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)     at net.minecraft.client.main.Main.main(SourceFile:123)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    • So I started my mods and this error popped up  The game crashed whilst initializing game Error: java.lang.NoClassDefFoundError: slimeknights/tconstruct/library/client/MaterialRenderInfo Exit Code: -1 which is weird since I don't have tinkers construct installed or is that something else and how do I fix this.
    • I want to use an old mod for some reason, but the forge-1.12.2-14.23.4.2764 installer does not work with the following error. java.net.preferIPv4Stack=true Exception in thread "main" java.lang.reflect.InvocationTargetException     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     at net.minecraftforge.installer.Java6Gate.main(Java6Gate.java:48) Caused by: java.lang.ExceptionInInitializerError     at net.minecraftforge.installer.ClientInstall.getSponsorMessage(ClientInstall.java:401)     at net.minecraftforge.installer.InstallerAction.getSponsorMessage(InstallerAction.java:60)     at net.minecraftforge.installer.InstallerPanel.updateFilePath(InstallerPanel.java:334)     at net.minecraftforge.installer.InstallerPanel.<init>(InstallerPanel.java:315)     at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:167)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:54)     ... 5 more Caused by: java.lang.ArrayIndexOutOfBoundsException: 1     at net.minecraftforge.installer.MirrorData.buildMirrorList(MirrorData.java:84)     at net.minecraftforge.installer.MirrorData.<init>(MirrorData.java:63)     at net.minecraftforge.installer.MirrorData.<clinit>(MirrorData.java:17)     ... 11 more Is there a way to install this version other than the installer? The method of copying and overwriting the version of the .minecraft folder according to the explanation site on the net did not work. I don't want such an answer [1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.]
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.