Jump to content

[SOLVED][1.7.10]Gui Button not working properly?


deadrecon98

Recommended Posts

Hello. I am currently trying to create a mod but I seem to be stuck on the GUI. For some reason the button that I add to it doesn't actually show up (but retains function). Any help would be greatly appreciated!

 

 

Here is the code for the GUI. (I realize that the button is in the wrong place, same thing when it is in the right spot)

package com.Cyphereion.Endurance.GUI;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import com.Cyphereion.API.Config.ConfigManager;

public class GUIClassChoose extends GuiScreen{

public GUIClassChoose(){
	super();
}

private static int tick = 0;

@Override
public void actionPerformed(GuiButton button){
	switch(button.id){
	default:
		break;
	case 0:
		System.out.println("Mage!");
		break;
	}
}

@Override
public void drawScreen(int x, int y, float f){
	tick ++;
	Minecraft mc = Minecraft.getMinecraft();
	EntityPlayer player = mc.thePlayer;

	int posX = (this.width) / 2;
	int posY = (this.height) / 2;

	this.drawString(this.mc.fontRenderer, EnumChatFormatting.LIGHT_PURPLE  + "Mage", posX - 150, posY - 75, 200);
	this.drawString(this.mc.fontRenderer, EnumChatFormatting.YELLOW + "" + EnumChatFormatting.BOLD + "Choose your class!", posX - 50, posY - 110, 200);

	if(tick >= 50){
		tick = 0;			
		this.buttonList.add(new GuiButton(0, posX - 150, posY - 75, 25, 75, "Mage"));
	}
}
}

Link to comment
Share on other sites

Derp, I could have seen that. You need to call super.drawScreen.

Hmm... It still doesn't seem to have any effect on it. I have tried placing it in both my initGui Method and my main class method. I've put it before it loads the button and after but with the same results.

 

Here is my class now, tell me if you see anything wrong.

package com.Cyphereion.Endurance.GUI;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import com.Cyphereion.API.Config.ConfigManager;

public class GUIClassChoose extends GuiScreen{

public GUIClassChoose(){
	super();
}

@Override
public void actionPerformed(GuiButton button){
	switch(button.id){
	default:
		break;
	case 0:
		System.out.println("Mage!");
		break;
	}
}

@Override
public void initGui(){
	super.initGui();
	super.drawScreen(0, 0, 0);
	int posX = (this.width) / 2;
	int posY = (this.height) / 2;
	this.buttonList.add(new GuiButton(0, posX - 150, posY - 75, 25, 25, "Mage"));

}

@Override
public void drawScreen(int x, int y, float f){
	Minecraft mc = Minecraft.getMinecraft();
	EntityPlayer player = mc.thePlayer;

	int posX = (this.width) / 2;
	int posY = (this.height) / 2;

	this.drawString(this.mc.fontRenderer, EnumChatFormatting.LIGHT_PURPLE  + "Mage", posX - 150, posY - 75, 200);
	this.drawString(this.mc.fontRenderer, EnumChatFormatting.YELLOW + "" + EnumChatFormatting.BOLD + "Choose your class!", posX - 50, posY - 110, 200);
}
}

Link to comment
Share on other sites

You need to call super.drawScreen within your drawScreen (preferably in last place). The drawScreen from GuiScreen actually renders the buttons.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
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.
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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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