I need help with adding a button to the main menu #1795
|
I'm trying to put a button on the title screen but i get an error message back claiming that the string can't be converted to text (the text I'm trying to display inside the button): C:\Users\Jones\Desktop\mystery-mod-1.17.1\src\main\java\net\mystery\mod\mixin\TitleScreenMixin.java:23: error: incompatible types: String cannot be converted to Text this.addButton(new ButtonWidget(this.width / 2 - 100 + 205, y, 50, 20, "bruh", (buttonWidget) -> { package net.mystery.mod.mixin; I used this tutorial and I my code looks exactly the same (apart from the value of the string) but it doesn't work for me. Please help! |
Replies: 4 comments 4 replies
|
You need to use a Minecraft
(there are other types of Also, you can use Fabric API (fabric-screen-api-v1 to be specific) to add buttons to screens without mixins. See the |
|
Do this: package pack1.pack2.pack3;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
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 HomeScreen extends Screen {
protected HomeScreen(Text title) {
super(title);
}
@Inject(at = @At("RETURN"), method = "addNormalWidgets")
private void addModsButton(int y, int spacingY, CallbackInfoReturnable<Integer> cir) {
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());
}
}Inside of your resources folder (there where you have assets, the mixin file and the fabric.mod.json file) add the file: {
"modname.customButton": "ButtonText"
} |
|
You do not need a mixin to do this, you can use the |

Do this: