英文:
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("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() {
}
}
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 < MouseX && 5000 > MouseX && 5000 < MouseY && 300 > MouseY) {
//Do stuff
}
}
答案2
得分: 0
将以下内容从英文翻译为中文:
Change:
public void mouseClick
to:
public void onMouseClick
英文:
Change:
public void mouseClick
to:
public void onMouseClick
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论