Help with GUI

Started by abelcaron on

Topic category: Help with Minecraft modding (Java Edition)

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Help with GUI

Hello,

I want to do a custom GUI and when I run my mouse over an item or a button that show me  some informations ( text ).

Is it possible ?

@Override public void render…
Fri, 06/05/2020 - 13:54
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
    this.renderBackground();
    super.render(mouseX, mouseY, partialTicks);
    this.renderHoveredToolTip(mouseX, mouseY);
    int currentXP = ((int) new Object() {
        public double getValue(BlockPos pos, String tag) {
            TileEntity tileEntity = world.getTileEntity(pos);
            if (tileEntity != null)
                return tileEntity.getTileData().getDouble(tag);
            return 0;
        }
    }.getValue(new BlockPos((int) x, (int) y, (int) z), "XP"));
    int percentage = (currentXP * 100) / 600;
    int XposT = 120;
    int YposT = 204;
    String string = (percentage + "%");
    if (mouseX == XposT && mouseY == YposT) {
        renderTooltip(string, mouseX, mouseY);
    }
}

The code Blue steve gave me

doesnt work

he said its becuase of screen offset

but i don't think so

help?

protected void…
Fri, 06/05/2020 - 13:54
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
int k = (this.width - this.xSize) / 2; //X asis on GUI
int l = (this.height - this.ySize) / 2; //Y asis on GUI
if (mouseX > boxX && mouseX < boxX + sizeX) //Basically checking if mouse is in the correct area
{
if (mouseY > boxY && mouseY < boxY + sizeY)
{
List list = new ArrayList();
list.add("Power at lever " + powerLevel);
this.drawHoveringText(list, (int)mouseX - k, (int)mouseY - l, fontRenderer);
}
}
}

doesnt work as well

Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Your code doesn't work…
Fri, 06/05/2020 - 14:40

Your code doesn't work because fontRenderer is not valid. It needs GuiContainer but we have just Container by default.

Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes I got it work. This…
Fri, 06/05/2020 - 15:26

Yes I got it work. This picture is an example of what I did but you can change it ofc

code

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just woke up! Love to see…
Fri, 06/05/2020 - 15:45

Just woke up! Love to see what you did! Good work