Jump to content

Recommended Posts

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?

Posted

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

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