'How can i remove a title screen element with fabric in Minecraft 1.18.1

I am currently able to add elements to the title screen:

public abstract class MCEMixin extends Screen {

    protected MCEMixin(Text title) {
        super(title);
    }

    @Inject(at = @At("RETURN"), method = "initWidgetsNormal")
    private void addCustomButton(int y, int spacingY, CallbackInfo cI) {
        this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, y, 200, 20, Text.of("MCEssentials | Singleplayer"), (button) -> {
            MinecraftClient.getInstance().setScreen(new SelectWorldScreen(this));
        }));
    }
}

I want to replace the singleplayer button with mine tho and I can't figure out how.



Solution 1:[1]

Maybe you could use ci.cancel() (requires you to include CallbackInfo ci in your injected method) and copy/paste the fabric mc source to the function but just change the Singleplayer button.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P