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

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"));
	}
}
}

  • Author

Why do you add the button every 50 frames? :o

Use initGui.

 

As I already said, it acts the same way, I was just putting it there to see if it made a difference.

  • Author

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);
}
}

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.

  • Author

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

 

Wow, I had no idea about that one. Thanks a ton! I will definitely hold onto this page for future reference.

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.