Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I recently made a gui for a book. It was giving me a NullPointer so I had to change some things. I tested it and when I right clicked on it, it did this:

37NcZTc.png

And it moves with my mouse:

ODNxceN.png

I don't know what's wrong.

This is the texture I set:

qn71qR6.png

Here is my code:

 

 

The GuiScreen:

public class GuiLexicon extends GuiScreen {
    int guiWidth = 192;
    int guiHeight = 256;

    static int GUI_ID = 30;

    @Override
    public void drawScreen(int x, int y, float par3) {
        super.drawScreen(x, y, par3);

        ResourceLocation background = new ResourceLocation(SignificantAdvancements.MODID, "textures/guis/lexiconBackground.png");
        Minecraft.getMinecraft().renderEngine.bindTexture(background);

        this.drawTexturedModalRect(x, y, 0, 0, guiWidth, guiHeight);

        int stringWidth = this.fontRendererObj.getStringWidth("Lexicon of Knowledge");

        this.fontRendererObj.drawString("Lexicon of Knowledge", guiWidth - stringWidth, 50, 0, true);
    }
}

 

The GuiHandler:

public class GuiHandler implements IGuiHandler {
    @Override
    public Object getServerGuiElement ( int ID, EntityPlayer player, World world, int x, int y, int z ) {
        return null;
    }

    @Override
    public Object getClientGuiElement ( int ID, EntityPlayer player, World world, int x, int y, int z ) {
        if ( ID == GuiLexicon.GUI_ID )
            return new GuiLexicon();

        return null;
    }
}

 

 

 

If you need more code just ask. :)

The reason it moves with your mouse is because you're drawing the texture to the position of your mouse in drawScreen(). You're passing the x and y coordinates given to you by drawScreen() to drawTexturedModalRect(), but these coordinates are the coordinates of the mouse. You need to pass it the position you want the texture to be drawn to.

I'm guessing the texture can't be found because I think you need to set your mod id to lowercase when you create a ResourceLocation, but I'm not positive on that one.

Well thanks. I fixed the textures. My item for my book was that missing texture thingy. I found my resource directory was formatted weird. I'm still getting used to intelliJ IDEA. :/ But thanks for telling me about my mistake about mouse coordinates.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.