Jump to content

[1.7.10] [Solved] Gui wierdness. :/


Recommended Posts

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

Posted

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.

Posted

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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