Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] Button is created but texture isn't added
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
IntentScarab

[1.16.4] Button is created but texture isn't added

By IntentScarab, Tuesday at 05:36 PM in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

IntentScarab    0

IntentScarab

IntentScarab    0

  • Tree Puncher
  • IntentScarab
  • Members
  • 0
  • 6 posts
Posted Tuesday at 05:36 PM

Hello, I am having a problem with creating a button for my gui. The button actually does get created and gets added to the screen, the problem is that it has no texture.

I have double-triple checked the coords of the texture from my file, and I've looked at other modders code and I'm not seeing what they have done that I haven't relating to this issue.

 

The BlockScreen code:

public class ExperienceBlockScreen extends ContainerScreen<BaseContainer> {

    private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Constants.MOD_ID,
            "textures/gui/experience_block_gui.png");

    // Coords for the graphical elements of the gui
    // Arrow Coords
    // B/G
    final static int ARROW_BAR_XPOS = 199;
    final static int ARROW_BAR_YPOS = 4;


    // Exp Bar Coords
    // B/G
    final static int EXP_BAR_XPOS = 8;
    final static int EXP_BAR_YPOS = 78;

    // Width and Height
    final static int EXP_BAR_SPACING_X = 21;
    final static int EXP_BAR_SPACING_Y = 72;

    // F/G
    final static int EXP_BAR_TEX_U = 177;
    final static int EXP_BAR_TEX_V = 75;


    // Buttons
    // Single Plus
    final static int SINGLE_PLUS_BUTTON_XPOS = 115;
    final static int SINGLE_PLUS_BUTTON_YPOS = 28;

    // Double Plus
    final static int DOUBLE_PLUS_BUTTON_XPOS = 129;
    final static int DOUBLE_PLUS_BUTTON_YPOS = 28;

    // Single Minus
    final static int SINGLE_MINUS_BUTTON_XPOS = 115;
    final static int SINGLE_MINUS_BUTTON_YPOS = 40;

    // Double Minus
    final static int DOUBLE_MINUS_BUTTON_XPOS = 129;
    final static int DOUBLE_MINUS_BUTTON_YPOS = 41;

    // Button Spacings
    final static int SINGLE_SPACING_X = 11;
    final static int SINGLE_SPACING_Y = 11;

    final static int DOUBLE_SPACING_X = 17;
    final static int DOUBLE_SPACING_Y = 9;



    public ExperienceBlockScreen(BaseContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);

        xSize = 176;
        ySize = 166;
    }

//    @Override
//    protected void init() {
//
//        super.init();
//
//        //this.buttons.clear();
//
//    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(matrixStack);
        super.render(matrixStack, mouseX, mouseY, partialTicks);
        this.renderHoveredTooltip(matrixStack, mouseX, mouseY);

    }

    @Override
    protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) {

//        final float LABEL_XPOS = 5;
//        final float FONT_Y_SPACING = 12;
//        final float EXP_BLOCK_LABEL_YPOS = ExperienceBlockContainer.TILE_INV_YPOS - FONT_Y_SPACING;
//        this.font.func_243248_b(matrixStack, this.title, LABEL_XPOS, EXP_BLOCK_LABEL_YPOS, Color.darkGray.getRGB());
//
//        final float PLAYER_INV_LABEL_YPOS = ExperienceBlockContainer.PLAYER_INV_YPOS - FONT_Y_SPACING;
//        this.font.func_243248_b(matrixStack, this.playerInventory.getDisplayName(), LABEL_XPOS, PLAYER_INV_LABEL_YPOS, Color.darkGray.getRGB());


    }



    @Override
    protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {

        this.minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
        RenderSystem.color4f(1.0f, 1.0f,1.0f,1.0f);

        int edgeSpacingX = (this.width - this.xSize)/2;
        int edgeSpacingY = (this.height - this.ySize)/2;

        // Drawing the main gui element
        this.blit(matrixStack, edgeSpacingX, edgeSpacingY, 0, 0, this.xSize, this.ySize);

        // Drawing the button for single minus
        // (x,y) this can be the (0,0) of the gui element, then the offsets to get the texture, then the width and height
//        this.blit(matrixStack, edgeSpacingX + SINGLE_MINUS_BUTTON_XPOS,  edgeSpacingY + SINGLE_MINUS_BUTTON_YPOS,
//                SINGLE_MINUS_BUTTON_XPOS, SINGLE_MINUS_BUTTON_YPOS,
//                SINGLE_SPACING_X, SINGLE_SPACING_Y);


        this.addButton(new SingleMinusButton(guiLeft + SINGLE_MINUS_BUTTON_XPOS,  guiTop + SINGLE_MINUS_BUTTON_YPOS,
                new TranslationTextComponent(""), (press)->{}));


        // Drawing the ExpBar
        this.blit(matrixStack, edgeSpacingX + EXP_BAR_XPOS, edgeSpacingY + EXP_BAR_YPOS - 17,
                EXP_BAR_TEX_U, EXP_BAR_TEX_V - 17, EXP_BAR_SPACING_X, EXP_BAR_SPACING_Y);




    }

}

 

And the SingleMinusButton code:

public class SingleMinusButton extends Button {

    private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Constants.MOD_ID,
            "textures/gui/experience_block_gui.png");

    private int xSize;
    private int ySize;


    public SingleMinusButton(int x, int y, ITextComponent title, IPressable pressedAction) {
        super(x, y, 11, 11, title, pressedAction);

        xSize = 176;
        ySize = 166;

    }

    @Override
    public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {

        int textureX = (this.width - xSize) / 2;
        int textureY = (this.height - ySize) / 2;

        // Where the button should be on the gui
        final int SINGLE_MINUS_BUTTON_XPOS = 115;
        final int SINGLE_MINUS_BUTTON_YPOS = 40;

        //Coords to base button
        final int SINGLE_MINUS_BUTTON_BASE_U = 216;
        final int SINGLE_MINUS_BUTTON_BASE_V = 68;

        // Coords to the texture of hovered button texture
        final int SINGLE_MINUS_BUTTON_HOV_U = 216;
        final int SINGLE_MINUS_BUTTON_HOV_V = 17;

        // Coords to the texture of the selected button texture
        final int SINGLE_MINUS_BUTTON_SEL_U = 216;
        final int SINGLE_MINUS_BUTTON_SEL_V = 42;


        Minecraft minecraft = Minecraft.getInstance();
        minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
        RenderSystem.color4f(1.0f, 1.0f,1.0f,1.0f);

        this.blit(matrixStack,
                textureX + SINGLE_MINUS_BUTTON_XPOS, textureY + SINGLE_MINUS_BUTTON_YPOS,
                SINGLE_MINUS_BUTTON_BASE_U, SINGLE_MINUS_BUTTON_BASE_V,
                width, height);
    }

    private static boolean inBounds(int x, int y, int xSize, int ySize, double mouseX, double mouseY) {
        return ((mouseX >= x && mouseX <= x + xSize) && (mouseY >= y && mouseY <= y + ySize));
    }


}

 

If there's a call to a method that I'm missing, then the help would be wonderful.

The issue I think is with the actual texture file if the button is being created, but it works for the main gui so I don't understand.

 

Thank you for the help in advance.

problem.png

experience_block_gui.png

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56306 posts
Posted Tuesday at 06:02 PM

Why are you hardcoding screen coordinates in the button class? Look at how the default button gets positioned.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

IntentScarab    0

IntentScarab

IntentScarab    0

  • Tree Puncher
  • IntentScarab
  • Members
  • 0
  • 6 posts
Posted Tuesday at 06:12 PM

That's me being stupid and not thinking stuff through. That actually fixed it tho, so thank you very much.

Updated code in case someone in the future needs it:

public class SingleMinusButton extends Button {

    private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Constants.MOD_ID,
            "textures/gui/experience_block_gui.png");


    public SingleMinusButton(int x, int y, ITextComponent title, IPressable pressedAction) {
        super(x, y, 11, 11, title, pressedAction);

    }

    @Override
    public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {

        //Coords to base button
        final int SINGLE_MINUS_BUTTON_BASE_U = 216;
        final int SINGLE_MINUS_BUTTON_BASE_V = 68;

        // Coords to the texture of hovered button texture
        final int SINGLE_MINUS_BUTTON_HOV_U = 216;
        final int SINGLE_MINUS_BUTTON_HOV_V = 17;

        // Coords to the texture of the selected button texture
        final int SINGLE_MINUS_BUTTON_SEL_U = 216;
        final int SINGLE_MINUS_BUTTON_SEL_V = 42;


        Minecraft minecraft = Minecraft.getInstance();
        minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
        RenderSystem.color4f(1.0f, 1.0f,1.0f,1.0f);

        this.blit(matrixStack,
                x, y,
                SINGLE_MINUS_BUTTON_BASE_U, SINGLE_MINUS_BUTTON_BASE_V,
                width, height);
    }

    private static boolean inBounds(int x, int y, int xSize, int ySize, double mouseX, double mouseY) {
        return ((mouseX >= x && mouseX <= x + xSize) && (mouseY >= y && mouseY <= y + ySize));
    }


}

 

Is there anything else I'm being stupid on btw? Might help me next time

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      The game crashed whilst rendering overlay

      By diesieben07 · Posted 1 hour ago

      In the future please make your own thread instead of posting in an old, unrelated thread.   Delete this file.
    • FactionsFire
      Exit code 0 Sorry for inconvenience

      By FactionsFire · Posted 1 hour ago

      I am trying to lanuch 1.8.9 forge and i get "An unexpected issue happened and the game has crashed exit sorry for inconvenience exit code 0"" And this has happened for about a week. 
    • Merken
      The game crashed whilst rendering overlay

      By Merken · Posted 1 hour ago

      The game crashed whilst rendering overlay Error: net.minecraftforge.fml.config.ConfigFileTypeHandler$ConfigLoadingException: Failed loading config file forge-client.toml of type CLIENT for modid forge Exit Code: -1
    • Merken
      The game crashed whilst rendering overlay

      By Merken · Posted 1 hour ago

      The game crashed whilst rendering overlay Error: net.minecraftforge.fml.config.ConfigFileTypeHandler$ConfigLoadingException: Failed loading config file forge-client.toml of type CLIENT for modid forge Exit Code: -1
    • diesieben07
      My game keeps crashing

      By diesieben07 · Posted 2 hours ago

      You do not. In the future please make your own thread instead of posting in some random thread that looks vaguely similar.   Your Optifine version is outdated and not listed as compatible with your version of Forge. Refer to the Optifine downloads page regarding compatibility with Forge.
  • Topics

    • Merken
      2
      The game crashed whilst rendering overlay

      By Merken
      Started 1 hour ago

    • FactionsFire
      0
      Exit code 0 Sorry for inconvenience

      By FactionsFire
      Started 1 hour ago

    • seekR4621
      1
      My game keeps crashing

      By seekR4621
      Started 3 hours ago

    • NorthWestWind
      2
      [1.16.x] Stop Held Item blobbing in Hand

      By NorthWestWind
      Started 3 hours ago

    • ehbean
      1
      1.16.x Custom Furnace/Brewing Stand

      By ehbean
      Started 12 hours ago

  • Who's Online (See full list)

    • diesieben07
    • Nanook
    • NorthWestWind
    • Ginge
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] Button is created but texture isn't added
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community