Ensure NetworkConstants is loaded before mod construction (#10407)

This commit is contained in:
Jonathing 2025-02-06 13:49:59 -05:00 committed by GitHub
parent 59979642e9
commit fa109380f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 2 deletions

View file

@ -1,10 +1,15 @@
--- a/net/minecraft/server/Bootstrap.java
+++ b/net/minecraft/server/Bootstrap.java
@@ -54,6 +_,8 @@
@@ -54,6 +_,13 @@
CauldronInteraction.m_175649_();
BuiltInRegistries.m_257498_();
CreativeModeTabs.m_280019_();
+ net.minecraftforge.registries.GameData.vanillaSnapshot();
+ // Forge: Hacky fix to ensure that NetworkConstants is loaded before mods are constructed.
+ // Many older mods use network internals that shouldn't be used, yet are exposed so they get used anyways.
+ // This can cause class-loading issues with ForgeMod loading NetworkConstants and HandshakeResolver.
+ // To ensure that doesn't happen, we load it here and now. This is not an issue in 1.20.2 and newer.
+ net.minecraftforge.network.NetworkHooks.init();
+ if (false) // skip redirectOutputToLog, Forge already redirects stdout and stderr output to log so that they print with more context
m_135890_();
f_285608_.set(Duration.between(instant, Instant.now()).toMillis());

View file

@ -426,7 +426,6 @@ public class ForgeMod
return uuid.toString();
});
LOGGER.debug(FORGEMOD, "Loading Network data for FML net version: {}", NetworkConstants.init());
CrashReportCallables.registerCrashCallable("FML", ForgeVersion::getSpec);
CrashReportCallables.registerCrashCallable("Forge", ()->ForgeVersion.getGroup()+":"+ForgeVersion.getVersion());

View file

@ -47,6 +47,11 @@ public class NetworkHooks
{
private static final Logger LOGGER = LogManager.getLogger();
public static void init()
{
LOGGER.debug("Loading Network data for FML net version: {}", NetworkConstants.init());
}
public static String getFMLVersion(final String ip)
{
return ip.contains("\0") ? Objects.equals(ip.split("\0")[1], NetworkConstants.NETVERSION) ? NetworkConstants.NETVERSION : ip.split("\0")[1] : NetworkConstants.NOVERSION;