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, February 23 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

IntentScarab    0

IntentScarab

IntentScarab    0

  • Tree Puncher
  • IntentScarab
  • Members
  • 0
  • 10 posts
Posted February 23

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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted February 23

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
  • 10 posts
Posted February 23

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

    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 5 minutes ago

      Hello, I am having issues registering my tile entity. Here is my code as well as a link to the code in my github. The IDE is complaining that 'TileEntityType.Builder.create' has invalid arguments   // Tiles public static final DeferredRegister<TileEntityType<?>> TILE_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, GOCurrency.MODID); public static final RegistryObject<TileEntityType<VendingTile>> TILE_VENDING = TILE_ENTITY_TYPES.register("vending_te", () -> TileEntityType.Builder.create(VendingTile::new, BLOCK_VENDING.get()).build(null));   https://github.com/Beardlessbrady/Currency-Mod/blob/95230ca4ee2d290b3e5f3ef81810a27f73137625/src/main/java/com/beardlessbrady/gocurrency/handlers/CommonRegistry.java#L42-L43
    • ThisIsNotOriginal
      Error at load_registries event phase

      By ThisIsNotOriginal · Posted 59 minutes ago

      The pastebin for the log and Registry Event is posted below this text.   https://pastebin.com/KEzJvRgG https://pastebin.com/VUrXR94k
    • PlasmaPig13
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By PlasmaPig13 · Posted 1 hour ago

      Here's the crash report and the loglatest.log crash-2021-03-02_19.33.58-client.txt
    • PlasmaPig13
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By PlasmaPig13 · Posted 1 hour ago

      I'm using 1.14.4 forge version 28.2.23 and the game crashes with the title's error message. Also, I'm new here; how do I paste the log? 
    • LexManos
      The vanilla tag system isnt suitable for ore dictionary

      By LexManos · Posted 1 hour ago

      You can also use conditionals, However empty tags are probably the best way to go. Data gens make any argument of being hard to use moot. So there is nothing we need to do in this reguard.
  • Topics

    • BeardlessBrady
      0
      [1.16.4] Tile Registration

      By BeardlessBrady
      Started 6 minutes ago

    • ThisIsNotOriginal
      0
      Error at load_registries event phase

      By ThisIsNotOriginal
      Started 59 minutes ago

    • PlasmaPig13
      1
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By PlasmaPig13
      Started 1 hour ago

    • EnderiumSmith
      3
      The vanilla tag system isnt suitable for ore dictionary

      By EnderiumSmith
      Started 14 hours ago

    • Ilikecheese
      0
      forge 1.16.5 wont show up

      By Ilikecheese
      Started 1 hour ago

  • Who's Online (See full list)

    • BeardlessBrady
    • ThisIsNotOriginal
    • ehbean
    • Beethoven92
    • Jeldrik
    • That_Tallone
    • squidlex
    • Lyon
    • Draco18s
    • Radical
  • 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