Jump to content

Button Widget not working


Hypericats

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

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"); });
        }
    }

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.

Link to comment
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.
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a structure, and sometimes several mobs spawn there. This is a boss and must spawn alone. Here is the code for spawning entities in the structure { "type": "minecraft:jigsaw", "start_pool": "egyptcraft:boss_pyramid/start_pool", "size": 5, "max_distance_from_center": 80, "biomes": "#egyptcraft:has_structure/boss_pyramid", "step": "surface_structures", "start_height": { "absolute": 0 }, "project_start_to_heightmap": "WORLD_SURFACE_WG", "use_expansion_hack": false, "spawn_overrides": { "monster": { "bounding_box": "full", "spawns": [ { "type": "egyptcraft:anubis", "maxCount": 1, "minCount": 1, "weight": 100 } ] } } } Maybe it's something else?
    • I have OreGenEvent.GenerateMinable event, I need to get a chance to spawn (generate) every ore that is processed in this event. Also e.getType().name().toString() is name this is the same block name by which it can be entered in the Block.getByID?  forge 1.12.2 59(recommended)
    • Hello everybody! Out of nowhere my minecraft doesn't allow me to play on forge 1.19.2 I tried to reinstall minecraft, doesn't have any mod right now on the forge version. Tried the newest version of forge, tried recommended version as well. I have the newest version of Java as well...   I dont know why it stopped working but it just stopped completly out of nowhere...   Thank you so much for your help guys ❤️
    • Hello, my world is crashing at 0% loaded and I don't know why. (Forge 43.2.14, 1.19.2) I have two worlds that I play on, and one works and the other doesn't, even with the same mod list. Here's the crash report: https://pastebin.com/AUbRwkGj
    • Minecraft 1.12.2 Very frustrating error. only ever occurs on one device. Started yesterday without prompting (maybe java updated or something?) Says things that have been imported actually arent when running client Reinstalled Intellij, cleared cache, cleaned and rebuilt gradle, redownloaded the entire file from git. Nothing works. (I believe I have the right plugins installed, dependencies OK, and am using corretto 1.8).   One thing I did for more of the below errors was just to explicitly import them, which was working up until this little guy who literally does not exist in forge to import. the class inhereting something inhereting it refers to import net.minecraftforge.registries.IForgeRegistryEntry.Impl, not net.minecraftforge.registries.IForgeRegistryEntry$Impl as the output implies. also I didn't even have to manually import these things for it to work on my other device. (which is just importing the minecraft package that contains them), but here I did have to just to get rid of a few errors--not even make anything work?? I dont know. (edited) here's the aforementioned "below error" (one of many like it): error: cannot access net.minecraftforge.registries.IForgeRegistryEntry.Impl public class BlockBase extends Block {        ^   class file for net.minecraftforge.registries.IForgeRegistryEntry$Impl not found Here's the class BlockBase:   package com.quantum.exodus.common.blocks; import com.quantum.exodus.ExodusMod; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraftforge.registries.IForgeRegistryEntry.Impl; public class BlockBase extends Block { protected String name; public BlockBase(Material material, String name) { super(material); this.name = name; setTranslationKey(name); setRegistryName(name); } public void registerItemModel(Item itemBlock) { ExodusMod.proxy.registerItemRenderer(itemBlock, 0, name); } public Item createItemBlock() { return new ItemBlock(this).setRegistryName(getRegistryName()); } @Override public BlockBase setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } }
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.