diff --git a/gradle.properties b/gradle.properties index 5255d95..4a73767 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ authors=ModFest contributors=Prospector, Sisby folk, acikek license=MIT # Mod Version -baseVersion=0.5.0 +baseVersion=0.5.1 # Branch Metadata branch=1.21 tagBranch=1.21 diff --git a/src/main/java/net/modfest/ballotbox/BallotBoxConfig.java b/src/main/java/net/modfest/ballotbox/BallotBoxConfig.java index fe8a153..7e0601e 100644 --- a/src/main/java/net/modfest/ballotbox/BallotBoxConfig.java +++ b/src/main/java/net/modfest/ballotbox/BallotBoxConfig.java @@ -13,6 +13,12 @@ public class BallotBoxConfig extends ReflectiveConfig { public final TrackedValue bug_text = value("Modfest Discord"); @Comment("The link to use to replace the bug report button") public final TrackedValue bug_url = value("https://discord.gg/gn543Ee"); + @Comment("Whether to replace the realms button on the title screen with a credits button") + public final TrackedValue replace_realms_credits = value(true); + @Comment("Whether to replace the player reporting button on the pause screen with a credits button") + public final TrackedValue replace_reporting_credits = value(true); + @Comment("The text to use for replacement credits but tons button") + public final TrackedValue credits_text = value("Modpack Credits"); @Comment("The number of top results to show when displaying voting results") public final TrackedValue awardLimit = value(8); @Comment("The closing date, as an ISO local date time - or an empty string for none") diff --git a/src/main/java/net/modfest/ballotbox/mixin/client/GameMenuScreenMixin.java b/src/main/java/net/modfest/ballotbox/mixin/client/GameMenuScreenMixin.java index 6865adb..ba87887 100644 --- a/src/main/java/net/modfest/ballotbox/mixin/client/GameMenuScreenMixin.java +++ b/src/main/java/net/modfest/ballotbox/mixin/client/GameMenuScreenMixin.java @@ -6,6 +6,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ConfirmLinkScreen; +import net.minecraft.client.gui.screen.CreditsScreen; import net.minecraft.client.gui.screen.GameMenuScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.tooltip.Tooltip; @@ -28,20 +29,26 @@ public class GameMenuScreenMixin { private static ButtonWidget ballotbox$voteButton = null; @WrapOperation(method = "addFeedbackAndBugsButtons", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;", ordinal = 0)) - private static Widget replaceSendFeedback(GridWidget.Adder instance, Widget widget, Operation original, Screen parentScreen, GridWidget.Adder gridAdder) { + private static Widget replaceSendFeedback(GridWidget.Adder instance, Widget widget, Operation original, Screen parentScreen) { if (!BallotBox.CONFIG.replace_feedback.value() || !BallotBoxClient.isEnabled(MinecraftClient.getInstance())) return original.call(instance, widget); ballotbox$voteButton = ButtonWidget.builder(Text.of("Submission Voting"), b -> { MinecraftClient.getInstance().setScreen(new VotingScreen()); ClientPlayNetworking.send(new OpenVoteScreen()); }).width(98).tooltip(BallotBoxClient.isOpen() ? null : Tooltip.of(Text.literal("Closed %s.".formatted(BallotBox.relativeTime(BallotBoxClient.closingTime))).formatted(Formatting.GRAY))).build(); ballotbox$voteButton.active = BallotBoxClient.isOpen(); - return gridAdder.add(ballotbox$voteButton); + return instance.add(ballotbox$voteButton); } @WrapOperation(method = "addFeedbackAndBugsButtons", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;", ordinal = 1)) - private static Widget replaceReportBugs(GridWidget.Adder instance, Widget widget, Operation original, Screen parentScreen, GridWidget.Adder gridAdder) { + private static Widget replaceReportBugs(GridWidget.Adder instance, Widget widget, Operation original, Screen parentScreen) { if (!BallotBox.CONFIG.replace_bugs.value() || !BallotBoxClient.isEnabled(MinecraftClient.getInstance())) return original.call(instance, widget); - return gridAdder.add(ButtonWidget.builder(Text.of(BallotBox.CONFIG.bug_text.value()), ConfirmLinkScreen.opening(parentScreen, BallotBox.CONFIG.bug_url.value())).width(98).build()); + return instance.add(ButtonWidget.builder(Text.of(BallotBox.CONFIG.bug_text.value()), ConfirmLinkScreen.opening(parentScreen, BallotBox.CONFIG.bug_url.value())).width(98).build()); + } + + @WrapOperation(method = "initWidgets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;", ordinal = 6)) + private Widget replacePlayerReporting(GridWidget.Adder instance, Widget widget, Operation original) { + if (!BallotBox.CONFIG.replace_reporting_credits.value()) return original.call(instance, widget); + return instance.add(ButtonWidget.builder(Text.of(BallotBox.CONFIG.credits_text.value()), b -> MinecraftClient.getInstance().setScreen(new CreditsScreen(false, () -> MinecraftClient.getInstance().setScreen((GameMenuScreen) (Object) this)))).width(98).build()); } @Inject(method = "render", at = @At("TAIL")) diff --git a/src/main/java/net/modfest/ballotbox/mixin/client/TitleScreenMixin.java b/src/main/java/net/modfest/ballotbox/mixin/client/TitleScreenMixin.java new file mode 100644 index 0000000..07f6c04 --- /dev/null +++ b/src/main/java/net/modfest/ballotbox/mixin/client/TitleScreenMixin.java @@ -0,0 +1,30 @@ +package net.modfest.ballotbox.mixin.client; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.screen.CreditsScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.TitleScreen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.text.Text; +import net.modfest.ballotbox.BallotBox; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(TitleScreen.class) +public abstract class TitleScreenMixin extends Screen { + protected TitleScreenMixin(Text title) { + super(title); + } + + @WrapOperation(method = "initWidgetsNormal", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/TitleScreen;addDrawableChild(Lnet/minecraft/client/gui/Element;)Lnet/minecraft/client/gui/Element;", ordinal = 2)) + private Element replaceRealms(TitleScreen instance, Element element, Operation original, int y, int spacingY) { + if (!BallotBox.CONFIG.replace_realms_credits.value()) return original.call(instance, element); + return addDrawableChild(ButtonWidget.builder(Text.of(BallotBox.CONFIG.credits_text.value()), b -> MinecraftClient.getInstance().setScreen(new CreditsScreen(false, () -> MinecraftClient.getInstance().setScreen((TitleScreen) (Object) this)))) + .dimensions(this.width / 2 - 100, y + spacingY * 2, 200, 20) + .build() + ); + } +} diff --git a/src/main/resources/ballotbox.mixins.json b/src/main/resources/ballotbox.mixins.json index e17fac1..c6bd7ee 100644 --- a/src/main/resources/ballotbox.mixins.json +++ b/src/main/resources/ballotbox.mixins.json @@ -3,10 +3,9 @@ "minVersion": "0.8", "package": "net.modfest.ballotbox.mixin", "compatibilityLevel": "JAVA_21", - "mixins": [ - ], "client": [ "client.GameMenuScreenMixin", + "client.TitleScreenMixin", "client.OptionEntryAccessor" ], "injectors": {