Jump to content

Adding Button to menu without editing base classes?


Guru_Fraser

Recommended Posts

If you really want to do this without becoming a coremod and doing it with ASM (the proper way), you need to make a Client-Side tick handler that checks the buttonList of the currently open gui if it contains your button, and if not, add it.

Thanks, but looking in minecraft.currentScreen there is no way to add buttons to the button list, or even check when the button is clicked, how would I handle that?

Link to comment
Share on other sites

mc.currentScreen.buttonList is the list that contains all Buttons of a Gui.

Its protected, but if you don't want to use reflection just make an accessor class in the net.minecraft.client.gui package.

and to make your button do something make a new subclass of GuiButton and in there override mousePressed.

Then do something like this:

if (super.mousePressed(*params*)) {
    // perfom action when button is pressed
}

Thanks I'll look into that! Since you seem to be very good at this; you don't happen to know how to get the correct health and max health of a player when on a bukkit server? I am using minecraft methods and they're returning health as 0.0 always and max as 20.0 always :S.

Link to comment
Share on other sites

I seem to have confused you, I am referring to client side here, on the server the max health can exceed 20; I want my client to track the health AND max health correctly, but instead it just reads 0.0 and 20. When actually my health is like 200 / 300. I can code bukkit, thats easy, I'm very new to forge coding,

Heres my code that I'm trying:

String s = mod_dungeonrealms.formatExp(mc.thePlayer.func_110139_bj(), mc.thePlayer.func_110138_aP()) + " / " + mc.thePlayer.func_110138_aP();

public static String formatExp(float f, float f2) {
	if((f >= ((f2 / 3) * 2))) {
		return " \u00A7a " + f;
	} else if(f >= ((f2 / 3))) {
		return " \u00A76 " + f;
	} else {
		return " \u00A7c " + f;
	}
}

 

Link to comment
Share on other sites

org.bukkit.entity.Damageable.getHealth()

org.bukkit.entity.Damageable.getMaxHealth()

Javadocs are your friend: http://jd.bukkit.org/rb/apidocs/org/bukkit/entity/Damageable.html

Also is this what you meant?

package net.minecraft.client.gui;

import net.minecraft.client.gui.achievement.GuiAchievements;
import net.minecraft.client.gui.achievement.GuiStats;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.resources.I18n;
import net.minecraft.stats.StatList;

public class DungeonRealmButtonAdder extends GuiIngameMenu {

public void init(){
	this.buttonList.add(new GuiButton(10, this.width - 100, this.height - 22, 98, 20, "Dungeon Realms"));
}

@Override
protected void actionPerformed(GuiButton par1GuiButton) {
        switch (par1GuiButton.id)
        {
            case 0:
                this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
                break;
            case 1:
                par1GuiButton.enabled = false;
                this.mc.statFileWriter.readStat(StatList.leaveGameStat, 1);
                this.mc.theWorld.sendQuittingDisconnectingPacket();
                this.mc.loadWorld((WorldClient)null);
                this.mc.displayGuiScreen(new GuiMainMenu());
            case 2:
            case 3:
            default:
                break;
            case 4:
                this.mc.displayGuiScreen((GuiScreen)null);
                this.mc.setIngameFocus();
                this.mc.sndManager.resumeAllSounds();
                break;
            case 5:
                this.mc.displayGuiScreen(new GuiAchievements(this.mc.statFileWriter));
                break;
            case 6:
                this.mc.displayGuiScreen(new GuiStats(this, this.mc.statFileWriter));
                break;
            case 7:
                this.mc.displayGuiScreen(new GuiShareToLan(this));
                break;
            case 10:
            	new GuiDungeonControls();
            	
        }
}

}

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.