Skip to content

Commit

Permalink
credit button replacers
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Nov 30, 2024
1 parent 066e1bb commit 252eec0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/modfest/ballotbox/BallotBoxConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public class BallotBoxConfig extends ReflectiveConfig {
public final TrackedValue<String> bug_text = value("Modfest Discord");
@Comment("The link to use to replace the bug report button")
public final TrackedValue<String> 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<Boolean> replace_realms_credits = value(true);
@Comment("Whether to replace the player reporting button on the pause screen with a credits button")
public final TrackedValue<Boolean> replace_reporting_credits = value(true);
@Comment("The text to use for replacement credits but tons button")
public final TrackedValue<String> credits_text = value("Modpack Credits");
@Comment("The number of top results to show when displaying voting results")
public final TrackedValue<Integer> awardLimit = value(8);
@Comment("The closing date, as an ISO local date time - or an empty string for none")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Widget> original, Screen parentScreen, GridWidget.Adder gridAdder) {
private static Widget replaceSendFeedback(GridWidget.Adder instance, Widget widget, Operation<Widget> 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<Widget> original, Screen parentScreen, GridWidget.Adder gridAdder) {
private static Widget replaceReportBugs(GridWidget.Adder instance, Widget widget, Operation<Widget> 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<Widget> 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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Element> 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()
);
}
}
3 changes: 1 addition & 2 deletions src/main/resources/ballotbox.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"minVersion": "0.8",
"package": "net.modfest.ballotbox.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
],
"client": [
"client.GameMenuScreenMixin",
"client.TitleScreenMixin",
"client.OptionEntryAccessor"
],
"injectors": {
Expand Down

0 comments on commit 252eec0

Please sign in to comment.