Posted May 3, 201510 yr 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; } }
May 3, 201510 yr You are creating IMessages(packets) correctly, but they dont get send anywhere (at least I dont see it). So I think its better to use the sendToServer(new IMessage) methode instead.(If this is how you write it ) Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
May 3, 201510 yr Author There are two printouts BEFORE the packet sending that are never printed. It's not getting even that far.
May 3, 201510 yr 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
May 3, 201510 yr 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.
May 3, 201510 yr 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
May 3, 201510 yr 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/
May 3, 201510 yr 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]
May 3, 201510 yr 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.
May 3, 201510 yr Author I have a dozen other GUIs that use the same code for buttons that work perfectly fine... A button list or overriding the method isn't the problem...
May 4, 201510 yr 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/
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.