How to add a button to the title screen in 1.21.10 #5171
Description(There are like no tutorials for this, there is one from 5 years ago which im pretty sure is dated) package net.shashi93.resourcescreening.mixin;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
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.CallbackInfoReturnable;
@Mixin(TitleScreen.class)
public class TitleScreen extends Screen {
protected TitleScreen(Text title) {
super(title);
}
@Inject(at = @At("RETURN"), method = "addNormalWidgets")
private int addModsButton(int y, int spacingY) {
this.addDrawableChild(ButtonWidget.builder(Text.translatable("modname.customButton"), (button) -> {
this.client.setScreen(new SelectWorldScreen(this));
}).dimensions(this.width / 2 - 200 +252, y, 50, 200).build());}
}I copied this code off of this forum: https://github.com/orgs/FabricMC/discussions/1795, and i edited it in IntelliJ to fix some problems using it's suggestion. Clearly, it did not work. If you need any more info, I am more than willing to provide it |
Answered by
unatried
Feb 8, 2026
Replies: 1 comment 5 replies
|
You don't need a mixin to add simple button. Use the |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just did this: