Simplify Title Screen Brandings (#10287)

This commit is contained in:
Jonathing authored and GitHub committed 2025-01-02 14:31:05 -08:00
1 parent 3024ef7707
commit 5d4825ac4b
3 files changed
+60 -9

No files matched your search

@@ -352,7 +352,10 @@ public class ForgeHooksClient {
return LazyInit.INSTANCE;
}
// NO-OP method, kept for bin-compat. Used in TitleScreen.java
@Deprecated(forRemoval = true, since = "1.21.4")
public static void renderMainMenu(TitleScreen gui, GuiGraphics graphics, Font font, int width, int height, int alpha) {
/*
VersionChecker.Status status = getForgeVersionStatus();
if (status == VersionChecker.Status.BETA || status == VersionChecker.Status.BETA_OUTDATED) {
@@ -362,6 +365,7 @@ public class ForgeHooksClient {
line = Component.translatable("forge.update.beta.2");
graphics.drawCenteredString(font, line, width / 2, 4 + (font.lineHeight + 1), 0xFFFFFF | alpha);
}
*/
}
public static String forgeStatusLine;
@@ -5,6 +5,7 @@
package net.minecraftforge.internal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.ObjIntConsumer;
@@ -17,6 +18,9 @@ import net.minecraftforge.fml.ModList;
import net.minecraftforge.versions.forge.ForgeVersion;
import net.minecraftforge.versions.mcp.MCPVersion;
/**
* Controls the title screen brandings for the game.
*/
public final class BrandingControl {
private BrandingControl() {}
@@ -25,13 +29,29 @@ public final class BrandingControl {
private static void computeBranding() {
if (brandings == null) {
brandings = List.of(
"Forge " + ForgeVersion.getVersion(),
"Minecraft " + MCPVersion.getMCVersion(),
"MCP " + MCPVersion.getMCPVersion(),
ForgeI18n.parseMessage("fml.menu.loadingmods", ModList.get().size())
);
brandingsNoMC = brandings.subList(1, brandings.size());
var list = new ArrayList<String>();
// Forge
var forge = ForgeVersion.getVersion().split("-", 2);
// I don't want to use VersionChecker to check for this, so I'm just going to use the version string.
// We only have Forge Betas on the "XX.0.XX" versions anyways.
boolean beta = "0".equals(forge[0].split("\\.")[1]);
var name = beta ? "§eForge Beta§f " : "Forge ";
list.add(name + forge[0] + " (" + ForgeI18n.parseMessage("fml.menu.loadingmods", ModList.get().size()) + ")");
// Extra forge version info (like branch)
if (forge.length > 1) list.add("Branch " + forge[1]);
// TODO [Forge][FML] When FML is rewritten, add its version here behind a config value to show it (debugBrandingVersions)
// this is how to check if we are in ForgeDev:
// FMLLoader.launcherHandlerName().startsWith("forge_dev")
// Minecraft
list.add("Minecraft " + MCPVersion.getMCVersion());
brandings = List.copyOf(list);
brandingsNoMC = brandings.subList(0, brandings.size() - 1);
}
}
@@ -43,6 +63,11 @@ public final class BrandingControl {
return reverse ? brandingsNoMC.reversed() : brandingsNoMC;
}
/**
* Gets the branding lines to display over the copyright line. This is usually a message when Forge has an update.
*
* @return The branding lines to display
*/
public static List<String> getOverCopyrightBrandings() {
final class LazyInit {
private static final List<String> INSTANCE = ForgeHooksClient.forgeStatusLine == null
@@ -55,22 +80,46 @@ public final class BrandingControl {
return LazyInit.INSTANCE;
}
/**
* Iterates over each branding line, passing the line and its index to the consumer.
*
* @param includeMC Whether to include the Minecraft version line
* @param reverse Whether to iterate in reverse order
* @param lineConsumer The consumer to accept each line and its index
*/
public static void forEachLine(boolean includeMC, boolean reverse, ObjIntConsumer<String> lineConsumer) {
var brandings = getBrandings(includeMC, reverse);
for (int idx = 0; idx < brandings.size(); idx++)
lineConsumer.accept(brandings.get(idx), idx);
}
/**
* Iterates over each branding line that should be displayed above the copyright line, passing the line and its
* index to the consumer.
*
* @param lineConsumer The consumer to accept each line and its index
*/
public static void forEachAboveCopyrightLine(ObjIntConsumer<String> lineConsumer) {
var overCopyrightBrandings = getOverCopyrightBrandings();
for (int idx = 0; idx < overCopyrightBrandings.size(); idx++)
lineConsumer.accept(overCopyrightBrandings.get(idx), idx);
}
/**
* Gets the branding to use in place of the default {@code "vanilla"} branding.
*
* @return The branding to use
*/
public static String getBranding() {
return "forge";
}
/**
* The reload listener for the branding control. On reload, the brandings are recomputed in
* {@link #computeBranding()}.
*
* @return The reload listener
*/
public static ResourceManagerReloadListener resourceManagerReloadListener() {
return BrandingControl::onResourceManagerReload;
}