use DhScreenUtil.setScreen when possible

This commit is contained in:
James Seibel
2026-05-15 22:28:25 -05:00
parent 09289e72a1
commit 206e492e7c
8 changed files with 17 additions and 28 deletions
@@ -87,7 +87,7 @@ public class DhUpdateScreenBase
versionId
));
#else
DhScreenUtil.showScreen(new UpdateModScreen(
DhScreenUtil.setScreen(new UpdateModScreen(
new TitleScreen(false),
versionId
));
@@ -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);
@@ -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
@@ -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());
}
@@ -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
}
@@ -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
}
@@ -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
@@ -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"));