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, so I am new to modding and I have been making my first mod with some basic hacks like fly. However, while trying to add button widgets to the Save and exit/disconnect screen the Button Widget is highlighted red and gives me an error.ย  There is not much information about why but I have spent 5 hours trying to fix this and I don't know what to do anymore. I think it once said something about the ButtonWidget class being protected but that didn't really help me. I was using a tutorial to learn to do this and I think I had the exact same code (With different names) I followed it word for word and checked everything. I'm using fabric 1.19.3.

package net.hypericats.hyperionclient.mixin;


import net.hypericats.hyperionclient.HyperionClientModuleScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


@Mixin(GameMenuScreen.class)
public abstract class GameMenuButtonsMixin extends Screen {
    protected GameMenuButtonsMixin(Text text) { super(text); }

    @Inject(at = @At("HEAD"), method = "initWidgets", require = 1)
    void initWidgets(CallbackInfo ci) {
        assert this.client != null;
        this.addDrawableChild(new ButtonWidget(10, 10, 90, 20, Text.literal("Hyperion Client Modules"),
                btn -> {this.client.setScreen(new HyperionClientModuleScreen(this, this.client.options));
        }));
    }
}

This is my Mixin class for the buttons

package net.hypericats.hyperionclient;

import net.hypericats.hyperionclient.event.KeyInputHandler;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;


public class HyperionClientModuleScreen extends Screen {

    private final Screen parent;
    private final GameOptions settings;

    public HyperionClientModuleScreen(Screen parent, GameOptions gameOptions) {
        super(Text.literal("Hyperion Client Modules"));
        this.parent = parent;
        this.settings = gameOptions;
    }

    Text flyHackText() {
       if(KeyInputHandler.FlyHax) {
           return Text.literal("Flying is enabled");
       } else {
           return Text.literal("Flying is disabled");
       }
    }

        protected void init() {

            assert this.client != null;
            this.addDrawableChild(new ButtonWidget(10, 10, 90, 20, flyHackText(), (btn) -> {
                KeyInputHandler.FlyHax = !KeyInputHandler.FlyHax;
                btn.setMessage(flyHackText());
            }));

            this.addDrawableChild(new ButtonWidget(10, this.height - 10, 90, 20, ScreenTexts.BACK, (btn) -> this.client.setScreen(this.parent)));
        }
}

And this is the screen referenced in the mixin.

Also while running the client I get this error:

ย class ButtonWidget cannot be applied to given types;
ย  ย  ย  ย  ย  ย  this.addDrawableChild(new ButtonWidget(10, 10, 90, 20, flyHackText(), (btn) -> {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ^
ย  required: int,int,int,int,Text,PressAction,NarrationSupplier
ย  found: ย  ย int,int,int,int,Text,(btn)->{ K[...])); }
ย  reason: actual and formal argument lists differ in length

I looked it up and it seems I missing something (Narraration supplier?) but I think that's not needed. I also tried adding some in but it didn't work, unless I did it wrong?

Neither mixins or your version of minecraft is supported in these forums.

ย 

But there is another way (the following shows adding a button to the inventory screen inย  modern supported versions of minecraft)

https://forums.minecraftforge.net/topic/117992-tooltip-depth/#comment-519260

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.comย  You should also read the support forum sticky post.

  • 3 weeks later...

You're a hero, Warjort...again.

I was having a similar problem with the Button class and could not find anything about the CreateNarration parameter that the compiled was complaining of as missing.

I take it back - it still doesn't work for me.

ย 

Using Minecraft 1.19.3 and the equivalent Forge, and this code:

        addRenderableWidget(new Button((m_slider_x + SLIDER_WIDTH - SPEND_WIDTH),
                                       (grid_y + (ROW_HEIGHT * (PlayerData.STAT_COUNT + 1))),
                                       SPEND_WIDTH,
                                       SPEND_HEIGHT,
                                       Component.translatable("stats_and_skills.spend_label"),
                                       this::onSpend));

I get this error:

ย ย ย  constructor Button.Button(int,int,int,int,Component,OnPress,CreateNarration) is not applicable

ย 

What is "CreateNarration" exactly? The Button constructor seems to need another parameter that is a Lamda/function that returns a MutableComponent, but I cannot figure out the parameter list for the lambda.

Oh this is painful. This compiles, not sure if it works yet:

ย 

        addRenderableWidget(new SpendButton((m_slider_x + SLIDER_WIDTH - SPEND_WIDTH),
                                            (grid_y + (ROW_HEIGHT * (PlayerData.STAT_COUNT + 1)))));

...

    public class SpendButton extends Button
    {
        public SpendButton(int x, int y)
        {
            super(x,
                  y,
                  SPEND_WIDTH,
                  SPEND_HEIGHT,
                  Component.translatable("stats_and_skills.spend_label"),
                  (button) -> { onSpend(); },
                  (button) -> { return Component.translatable("stats_and_skills.spend_label"); });
        }
    }

ย 

  • Author

@Jontom Xireย I noticed something similar where it asked for the narration but I couldnโ€™t find what to put there. I still havenโ€™t figured it out but I saw that apparently there was a another version of the function that didnโ€™t have any narration but the compiler didnโ€™t seem to know it existed. Lmk if the addRenderableWidget worked or if you found another solution.

  • 4 weeks later...
  • 2 weeks later...
  • Author

Hi, I managed to figure it out. I didnโ€™t end up using Jontomโ€™s code, I used a simpler method. I hadnโ€™t realized this at first but my solution was just to go in minecraftโ€™s code and read how the button widget was implemented. For any future readers, you can probably copy and paste the code from minecraftโ€™s code in the options file under the gui. The code was similar to what I first posted but used something like โ€œ.builderโ€ and โ€œbuild()โ€ at the end. This was the solution for minecraft 1.19.3 fabric but you could probably use the same steps for future versions.

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.