I am trying to make a custom minecraft start screen singleplayer button but it wont work?

huangapple go评论73阅读模式
英文:

I am trying to make a custom minecraft start screen singleplayer button but it wont work?

问题

package skink.ui;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSelectWorld;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import skink.Client;

public class MainMenu extends GuiScreen {

    public MainMenu() {

    }

    public void initGui() {

    }

    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        mc.getTextureManager().bindTexture(new ResourceLocation("Skink/background.png"));
        this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, this.width, this.height, this.width, this.height);

        this.drawRect(0, 5000, 5000, 300, 0xff162922);

        String[] buttons = { "Singleplayer", "Multiplayer", "Settings", "Language", "Quit" };

        int count = 0;
        for (String name : buttons) {
            this.drawCenteredString(mc.fontRendererObj, name, (width / buttons.length) * count + (width / buttons.length) / 2f + 8,
                    height - 20, -1);
            count++;
        }

        GlStateManager.pushMatrix();
        GlStateManager.translate(width / 2f, height / 5f, 0);
        GlStateManager.scale(3, 3, 1);
        GlStateManager.translate(-(width / 2f), -(height / 5f), 0);
        this.drawCenteredString(mc.fontRendererObj, Client.name + " Client " + Client.version, width / 2f,
                height / 5f - mc.fontRendererObj.FONT_HEIGHT / 2f, -1);
        GlStateManager.popMatrix();
    }

    public void mouseClick(int mouseX, int mouseY, int button) {
        String[] buttons = { "Singleplayer", "Multiplayer", "Settings", "Language", "Quit" };

        int count = 0;
        for (String name : buttons) {
            float x = (width / buttons.length) * count + (width / buttons.length) / 2f + 8
                    - mc.fontRendererObj.getStringWidth(name) / 2f;
            float y = height - 20;

            if (mouseX >= x && mouseY >= y && mouseX < x + mc.fontRendererObj.getStringWidth(name)
                    && mouseY < y + mc.fontRendererObj.FONT_HEIGHT) {
                switch (name) {
                    case "Singleplayer":
                        mc.displayGuiScreen(new GuiSelectWorld(this));
                        break;
                }
            }

            count++;
        }
    }

    public void onGuiClosed() {

    }

}
英文:
package skink.ui;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSelectWorld;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import skink.Client;

public class MainMenu extends GuiScreen {

	public MainMenu() {
		
	}
	
	public void initGui() {
		
	}
	
	public void drawScreen(int mouseX, int mouseY, float partialTicks) {
		mc.getTextureManager().bindTexture(new ResourceLocation(&quot;Skink/background.png&quot;));
		this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, this.width, this.height, this.width, this.height);
		
		this.drawRect(0, 5000, 5000, 300, 0xff162922);
		
		String[] buttons = { &quot;Singleplayer&quot;, &quot;Multiplayer&quot;, &quot;Settings&quot;, &quot;Language&quot;, &quot;Quit&quot;};
		
		int count = 0;
		for(String name : buttons) {
			this.drawCenteredString(mc.fontRendererObj, name, (width/buttons.length)*count + (width/buttons.length)/2f + 8, height - 20, -1);
			count++;
		}
		
		GlStateManager.pushMatrix();
		GlStateManager.translate(width/2f, height/5f, 0);
		GlStateManager.scale(3, 3, 1);
		GlStateManager.translate(-(width/2f), -(height/5f), 0);
		this.drawCenteredString(mc.fontRendererObj, Client.name + &quot; Client &quot; + Client.version, width/2f, height/5f - mc.fontRendererObj.FONT_HEIGHT/2f, -1);
		GlStateManager.popMatrix();
	}
	
	public void mouseClick(int mouseX, int mouseY, int button) {
		String[] buttons = { &quot;Singleplayer&quot;, &quot;Multiplayer&quot;, &quot;Settings&quot;, &quot;Language&quot;, &quot;Quit&quot;};
		
		int count = 0;
		for(String name : buttons) {
			float x = (width/buttons.length)*count + (width/buttons.length)/2f + 8 - mc.fontRendererObj.getStringWidth(name)/2f;
			float y =  height - 20;
			
			if(mouseX &gt;= x &amp;&amp; mouseY &gt;= y &amp;&amp; mouseX &lt; x + mc.fontRendererObj.getStringWidth(name) &amp;&amp; mouseY &lt; y + mc.fontRendererObj.FONT_HEIGHT) {
				switch(name) {
					case &quot;Singleplayer&quot;:
						mc.displayGuiScreen(new GuiSelectWorld(this));
						break;
				}
			}
			
			count++;
		}
	}
	
	public void onGuiClosed() {
		
	}
	
}

everything shows up right its just the buttons wont work, when i click singleplayer its suppost to open up the select worlds screen.

i have been working on this project for a week now and i have speant so many hours and have written thousands of lines of code to get to this point, it would mean the world to me if you spent some time to help me with this error, tysm!

Image of main menu :
Start menu

答案1

得分: 1

The mouseClicked event isn't firing when you click the spot? For 1.12.2 At least the @Override is called mouseClicked not mouseClick if you're not calling that from somewhere else. But idk what version ur on.

Also, I'm not sure about this, but I think you need to call

super.mouseClicked(i, j, k);

So if these are the coordinates of your button location --> 0, 5000, 5000, 300, it should look something like this:

@Override
protected void mouseClicked(int MouseX, int MouseY, int button) {
    super.mouseClicked(MouseX, MouseY, button);
    if (0 < MouseX && 5000 > MouseX && 5000 < MouseY && 300 > MouseY) {
        //Do stuff
    }
}
英文:

So the mouseClicked event isnt firing when you click the spot? For 1.12.2 Atleast the @Override is called mouseClicked not mouseClick if your not calling that from somewhere else. But idk what version ur on

Also im not sure about this but i think you need to call

super.mouseClicked(i, j, k);

So if these are the coordinates of your button location --> 0, 5000, 5000, 300 It should look something like this.

@Override
protected void mouseClicked(int MouseX, int MouseY, int button) {
    super.mouseClicked(MouseX, MouseY, button);
    if (0 &lt; MouseX &amp;&amp; 5000 &gt; MouseX &amp;&amp; 5000 &lt; MouseY &amp;&amp; 300 &gt; MouseY) {
        //Do stuff
	}
}

答案2

得分: 0

将以下内容从英文翻译为中文:

Change:

public void mouseClick

to:

public void onMouseClick

英文:

Change:

public void mouseClick

to:

public void onMouseClick

huangapple
  • 本文由 发表于 2020年8月1日 01:40:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63196614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定