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

Hi all,

I've been updating my mod from 1.18 to 1.19 and so far I've been able to fix the changes regarding literal/translatable Components and other minor changes, but the Button class' constructor seems to have changed, and I don't know how to update it.

Here is my working constructor for 1.18:
 

public BuySellButton(int x, int y, String buyText, String sellText, boolean isBuy, OnPress listener) {
        super(x, y, 50, 12, new TextComponent((isBuy ? buyText : sellText)), listener);
        this.isBuy = isBuy;
    }

Simply changing the component does not work:

public BuySellButton(int x, int y, String buyText, String sellText, boolean isBuy, OnPress listener) {
        super(x, y, 50, 12, Component.literal((isBuy ? buyText : sellText)), listener);
        this.isBuy = isBuy;
    }

Cannot resolve method 'super(int, int, int, int, MutableComponent, OnPress)'

Here are the available constructors/builders from the Button class:

public static Button.Builder builder(Component p_254439_, Button.OnPress p_254567_) {
      return new Button.Builder(p_254439_, p_254567_);
   }

   protected Button(int p_259075_, int p_259271_, int p_260232_, int p_260028_, Component p_259351_, Button.OnPress p_260152_, Button.CreateNarration p_259552_) {
      super(p_259075_, p_259271_, p_260232_, p_260028_, p_259351_);
      this.onPress = p_260152_;
      this.createNarration = p_259552_;
   }

   protected Button(Builder builder) {
      this(builder.x, builder.y, builder.width, builder.height, builder.message, builder.onPress, builder.createNarration);
      setTooltip(builder.tooltip); // Forge: Make use of the Builder tooltip
   }

Can someone please help me understand how to update my Button constructor?

  • Author

Replying to myself with the answer, you just have to switch to using a builder:

public BuySellButton(int x, int y, String buyText, String sellText, boolean isBuy, OnPress listener) {
        super(Button.builder(Component.literal(isBuy ? buyText : sellText), listener)
                .pos(x, y)
                .size(50, 12));
        this.isBuy = isBuy;
    }

 

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.