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 just finish getting my screen to load, and I am trying to have the code render buttons and the like (don't worry about the slots, I was just testing how they work). However, when the button is pressed, literally nothing happens. It is supposed to create a button for every item in the players inventory that has the tag "custombows.acceptable_heads". Here is the repo: https://github.com/bltstudios/custom_bows 

  • Author
29 minutes ago, diesieben07 said:

Where exactly do you think you are adding buttons to the screen as a result of pressing anothe rbutton?

If you are asking about on screen: Next to the first button, which I believe shows up in the corner.

If you are asking about in code:
 

	@Override
    protected void init() {
        super.init();
        this.headButton = addRenderableWidget(
                new ImageButton(ArrowWorkstationBaseMenu.TE_HEAD_SLOT_X, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_Y, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_HEIGHT, 0, 0, 0, HEAD_BUTTON_TEX, btn -> {
                    showHeads = true;
                    showBinding = false;
                    showShaft = false;
                    showFeather = false;
                    showInv = false;
                }));

        if(showHeads) {
            int x = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_X + ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH;
            int y = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_Y;
            int width = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH;
            int height = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_HEIGHT;
            for (ItemStack a: getAllOfType(ACCEPTABLE_HEAD_TAGS, pInv)) {
                renderImageButton(x, y, width, height, 0,0,0, HEAD_BUTTON_TEX, a, 0);
                x += width;
            }
        }

        this.shaftButton = addRenderableWidget(
                new ImageButton(ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_X, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_Y, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_HEIGHT, 0,0,0, SHAFT_BUTTON_TEX, btn -> {
                    showShaft = true;
                    showHeads = false;
                    showBinding = false;
                    showFeather = false;
                    showInv = false;
                }));

        if(showShaft) {
            int x = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_X + ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_WIDTH;
            int y = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_Y;
            int width = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_WIDTH;
            int height = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_HEIGHT;
            for (ItemStack a: getAllOfType(ACCEPTABLE_SHAFT_TAGS, pInv)) {
                renderImageButton(x, y, width, height, 0,0,0, SHAFT_BUTTON_TEX, a, 1);
                x += width;
            }
        }
    }

	protected ImageButton renderImageButton(int x, int y, int width, int height, int startX, int startY, int textStartY, ResourceLocation resLoc, ItemStack itemSelection, int ind) {
        return addRenderableWidget(new ImageButton(x, y, width, height, startX, startY, textStartY, resLoc, btn -> {
            menu.blockEntity.itemHandler.setStackInSlot(ind, itemSelection);
        }));
    }

    protected NonNullList<ItemStack> getAllOfType(TagKey<Item> tagKey, Inventory pInv) {
        NonNullList<ItemStack> items = null;
        for (ItemStack a: pInv.items) {
           if(a.is(tagKey)) {
               items.add(a);
           }
        }

        return items;
    }

In the ArrowWorkstationBaseScreen class

  • Author
1 minute ago, diesieben07 said:

init runs when your screen is first opened, at which point all the fields are false and no buttons are added.

init never runs again, so no buttons are ever added.

So where can I run this code?

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.