From 206e492e7ceffc56581615071b17961a9e05e0f9 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 15 May 2026 22:28:25 -0500 Subject: [PATCH] use DhScreenUtil.setScreen when possible --- .../commonMixins/DhUpdateScreenBase.java | 2 +- .../common/wrappers/gui/DhScreenUtil.java | 6 +++-- .../common/wrappers/gui/MinecraftScreen.java | 2 +- .../gui/classicConfig/DhConfigScreen.java | 23 ++++++------------- .../wrappers/gui/updater/ChangelogScreen.java | 2 +- .../wrappers/gui/updater/UpdateModScreen.java | 6 ++--- .../minecraft/MinecraftRenderWrapper.java | 1 - .../mixins/client/MixinOptionsScreen.java | 3 +-- 8 files changed, 17 insertions(+), 28 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/DhUpdateScreenBase.java b/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/DhUpdateScreenBase.java index 300a29f1d..d188144e4 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/DhUpdateScreenBase.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/DhUpdateScreenBase.java @@ -87,7 +87,7 @@ public class DhUpdateScreenBase versionId )); #else - DhScreenUtil.showScreen(new UpdateModScreen( + DhScreenUtil.setScreen(new UpdateModScreen( new TitleScreen(false), versionId )); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/DhScreenUtil.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/DhScreenUtil.java index 5ef482c21..18fc8db07 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/DhScreenUtil.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/DhScreenUtil.java @@ -12,9 +12,11 @@ public class DhScreenUtil //================// //region - public static void showScreen(Screen screen) + public static void setScreen(Screen screen) { - #if MC_VER <= MC_26_1_2 + #if MC_VER <= MC_1_12_2 + Objects.requireNonNull(Minecraft.getMinecraft()).displayGuiScreen(screen); + #elif MC_VER <= MC_26_1_2 Objects.requireNonNull(Minecraft.getInstance()).setScreen(screen); #else Objects.requireNonNull(Minecraft.getInstance()).setScreenAndShow(screen); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/MinecraftScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/MinecraftScreen.java index cd44a28f3..079f8e259 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/MinecraftScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/MinecraftScreen.java @@ -238,7 +238,7 @@ public class MinecraftScreen #endif { this.screen.onClose(); // Close our screen - DhScreenUtil.showScreen(this.parent); // Goto the parent screen + DhScreenUtil.setScreen(this.parent); // Goto the parent screen } #if MC_VER > MC_1_12_2 diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java index c5c4a110a..3d5069a24 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java @@ -3,16 +3,15 @@ package com.seibel.distanthorizons.common.wrappers.gui.classicConfig; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Pattern; import com.seibel.distanthorizons.api.enums.config.DisallowSelectingViaConfigGui; import com.seibel.distanthorizons.common.wrappers.gui.DhScreen; +import com.seibel.distanthorizons.common.wrappers.gui.DhScreenUtil; import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget; import com.seibel.distanthorizons.common.wrappers.gui.config.ConfigGuiInfo; import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper; @@ -21,27 +20,20 @@ import com.seibel.distanthorizons.core.config.ConfigHandler; import com.seibel.distanthorizons.core.config.types.*; import com.seibel.distanthorizons.common.wrappers.gui.updater.ChangelogScreen; -import com.seibel.distanthorizons.core.config.types.enums.EConfigCommentTextPosition; import com.seibel.distanthorizons.core.config.types.enums.EConfigValidity; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.jar.updater.SelfUpdater; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.util.AnnotationUtil; -import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui; import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper; import com.seibel.distanthorizons.coreapi.ModInfo; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.ContainerObjectSelectionList; import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import com.seibel.distanthorizons.core.logging.DhLogger; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,7 +47,6 @@ import net.minecraft.client.gui.GuiGraphicsExtractor; #endif #if MC_VER >= MC_1_17_1 -import net.minecraft.client.gui.narration.NarratableEntry; #endif #if MC_VER <= MC_1_21_10 @@ -150,7 +141,7 @@ class DhConfigScreen extends DhScreen ChangelogScreen changelogScreen = new ChangelogScreen(this); if (changelogScreen.usable) { - Objects.requireNonNull(this.minecraft).setScreen(changelogScreen); + DhScreenUtil.setScreen(changelogScreen); } else { @@ -170,7 +161,7 @@ class DhConfigScreen extends DhScreen (button) -> { ConfigHandler.INSTANCE.configFileHandler.loadFromFile(); - Objects.requireNonNull(this.minecraft).setScreen(this.parent); + DhScreenUtil.setScreen(this.parent); })); // done/close button @@ -181,7 +172,7 @@ class DhConfigScreen extends DhScreen (button) -> { ConfigHandler.INSTANCE.configFileHandler.saveToFile(); - Objects.requireNonNull(this.minecraft).setScreen(this.parent); + DhScreenUtil.setScreen(this.parent); })); this.configListWidget = new ClassicConfigGUI.ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, 32, 25); @@ -464,7 +455,7 @@ class DhConfigScreen extends DhScreen { configEntry.uiSetWithoutSaving(configEntry.getDefaultValue()); this.reload = true; - Objects.requireNonNull(this.minecraft).setScreen(this); + DhScreenUtil.setScreen(this); }; int resetButtonPosX = this.width @@ -574,7 +565,7 @@ class DhConfigScreen extends DhScreen ((button) -> { ConfigHandler.INSTANCE.configFileHandler.saveToFile(); - Objects.requireNonNull(this.minecraft).setScreen(ClassicConfigGUI.getScreen(this, configCategory.getDestination())); + DhScreenUtil.setScreen(ClassicConfigGUI.getScreen(this, configCategory.getDestination())); })); this.configListWidget.addButton(this, configType, widget, null, null, null); @@ -790,7 +781,7 @@ class DhConfigScreen extends DhScreen public void onClose() { ConfigHandler.INSTANCE.configFileHandler.saveToFile(); - Objects.requireNonNull(this.minecraft).setScreen(this.parent); + DhScreenUtil.setScreen(this.parent); ClassicConfigGUI.CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run()); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java index d67700173..f3e06b5cd 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java @@ -287,7 +287,7 @@ public class ChangelogScreen extends DhScreen #if MC_VER <= MC_1_12_2 // Handled by button to avoid recursive loop #else - DhScreenUtil.showScreen(this.parent); + DhScreenUtil.setScreen(this.parent); #endif } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java index 6ec14a0ff..0662b5d6c 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java @@ -35,8 +35,6 @@ import net.minecraft.resources.Identifier; import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*; -import java.util.*; - /** * The screen that pops up if the mod has an update. * @@ -174,7 +172,7 @@ public class UpdateModScreen extends DhScreen 20, 20, // Create the button and tell it where to go #if MC_VER > MC_1_12_2 - (buttonWidget) -> DhScreenUtil.showScreen(new ChangelogScreen(this, this.newVersionID)), + (buttonWidget) -> DhScreenUtil.setScreen(new ChangelogScreen(this, this.newVersionID)), #endif // Add a title to the button #if MC_VER <= MC_1_12_2 @@ -296,7 +294,7 @@ public class UpdateModScreen extends DhScreen #if MC_VER <= MC_1_12_2 // Handled by button to avoid recursive loop #else - DhScreenUtil.showScreen(this.parent); // Go to the parent screen + DhScreenUtil.setScreen(this.parent); // Go to the parent screen #endif } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java index 209571a88..e369a4901 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -217,7 +217,6 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper Vec3 projectedView = camera.position(); #endif return new Vec3d(projectedView.x, projectedView.y, projectedView.z); - #endif } @Override diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java index 0d3615055..6cc70af21 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java @@ -35,7 +35,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; #if MC_VER >= MC_1_20_6 @@ -148,7 +147,7 @@ public class MixinOptionsScreen extends Screen 20, ICON_TEXTURE, 20, 40, // Create the button and tell it where to go // For now it goes to the client option by default - (buttonWidget) -> DhScreenUtil.showScreen(GetConfigScreen.getScreen(this)), + (buttonWidget) -> DhScreenUtil.setScreen(GetConfigScreen.getScreen(this)), // Add a title to the button #if MC_VER < MC_1_19_2 new TranslatableComponent(ModInfo.ID + ".title"));