From 1b60c66eecc6444c6baeeff2ecdda4c8c05e0a07 Mon Sep 17 00:00:00 2001 From: coolGi Date: Mon, 22 May 2023 23:51:19 +0930 Subject: [PATCH] Only use the Modrinth api if the user clicks the changelog menu instead of when the config is opened --- .../common/wrappers/gui/ClassicConfigGUI.java | 6 +----- .../wrappers/gui/updater/ChangelogScreen.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java index 6ec9bdde2..e68ad8ecf 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java @@ -219,8 +219,6 @@ public abstract class ClassicConfigGUI { // Changelog button if (Config.Client.AutoUpdater.enableAutoUpdater.get()) { - if (!ModrinthGetter.initted) - ModrinthGetter.init(); this.addBtn(new TexturedButtonWidget( // Where the button is on the screen this.width - 28, this.height - 28, @@ -231,9 +229,7 @@ public abstract class ClassicConfigGUI { // Some textuary stuff 0, new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"), 20, 20, // Create the button and tell it where to go - (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this, - ModrinthGetter.getLatestIDForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion()) - )), + (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this)), // Add a title to the button #if PRE_MC_1_19 new TranslatableComponent(ModInfo.ID + ".updater.title") diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java index 0695af77a..b1dba7415 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java @@ -1,6 +1,8 @@ package com.seibel.lod.common.wrappers.gui.updater; import com.mojang.blaze3d.vertex.PoseStack; +import com.seibel.lod.core.dependencyInjection.SingletonInjector; +import com.seibel.lod.core.wrapperInterfaces.IVersionConstants; import com.seibel.lod.coreapi.ModInfo; import com.seibel.lod.core.jar.installer.MarkdownFormatter; import com.seibel.lod.core.jar.installer.ModrinthGetter; @@ -31,12 +33,27 @@ public class ChangelogScreen extends Screen { private List changelog; private TextArea changelogArea; + public ChangelogScreen(Screen parent) { + this(parent, null); + + if (!ModrinthGetter.initted) // Make sure the modrinth stuff is initted + ModrinthGetter.init(); + if (!ModrinthGetter.initted) // If its not initted the just close the screen + onClose(); + + setupChangelog(ModrinthGetter.getLatestIDForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion())); + } public ChangelogScreen(Screen parent, String versionID) { super(translate(ModInfo.ID + ".updater.title")); this.parent = parent; this.versionID = versionID; + if (versionID != null) + setupChangelog(versionID); + } + + private void setupChangelog(String versionID) { this.changelog = new ArrayList<>(); // Put the new version name at the very top of the change log @@ -59,6 +76,8 @@ public class ChangelogScreen extends Screen { // System.out.println(this.changelog); } + + @Override protected void init() { super.init();