- 124
- 1
- 8
Вообщем-то, создал кнопку, хочу чтобы при нажатии выводился текст в консоль. 1 раз естественно. Но при нажатии этот текст выводится не 1 раз, что мне и не нужно. Как исправить?
Класс кнопки:
Класс кнопки:
Java:
public class Button extends GuiButton {
public Button(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) {
super(buttonId, x, y, widthIn, heightIn, buttonText);
}
public static final ResourceLocation buttonTextures = new ResourceLocation(Main.MODID + ":button.png");
protected int getHoverState(boolean mouseOver)
{
int i = 1;
if (!this.enabled)
{
i = 0;
}
else if (mouseOver)
{
i = 2;
}
return i;
}
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
FontRenderer fontrenderer = mc.fontRenderer;
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int i = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
drawModalRectWithCustomSizedTexture(this.x, this.y, 0,0,this.width,this.height,this.width,this.height);
this.mouseDragged(mc, mouseX, mouseY);
int j = 14737632;
if (packedFGColour != 0)
{
j = packedFGColour;
}
else
if (!this.enabled)
{
j = 10526880;
}
else if (this.hovered)
{
j = 16777120;
}
}
}
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
}
public void mouseReleased(int mouseX, int mouseY)
{
}
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
return this.enabled && this.visible && mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
}
public boolean isMouseOver()
{
return this.hovered;
}
public void drawButtonForegroundLayer(int mouseX, int mouseY)
{
}
public void playPressSound(SoundHandler soundHandlerIn)
{
}
public int getButtonWidth()
{
return this.width;
}
public void setWidth(int width)
{
this.width = width;
}
Java:
protected void actionPerformed(GuiButton button) throws IOException {
switch (button.id) {
case 1:
System.out.println("test");
break;
}
}