diff --git a/patches/minecraft/net/minecraft/client/server/LanServerPinger.java.patch b/patches/minecraft/net/minecraft/client/server/LanServerPinger.java.patch index e89de40562..ed1cb082ba 100644 --- a/patches/minecraft/net/minecraft/client/server/LanServerPinger.java.patch +++ b/patches/minecraft/net/minecraft/client/server/LanServerPinger.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/client/server/LanServerPinger.java +++ b/net/minecraft/client/server/LanServerPinger.java -@@ -16,7 +_,7 @@ +@@ -13,7 +_,7 @@ public class LanServerPinger extends Thread { private static final AtomicInteger f_120101_ = new AtomicInteger(0); private static final Logger f_120102_ = LogUtils.getLogger(); @@ -9,7 +9,7 @@ public static final int f_174975_ = 4445; private static final long f_174976_ = 1500L; private final String f_120103_; -@@ -39,7 +_,7 @@ +@@ -36,7 +_,7 @@ while(!this.isInterrupted() && this.f_120105_) { try { diff --git a/patches/minecraft/net/minecraft/server/dedicated/DedicatedServer.java.patch b/patches/minecraft/net/minecraft/server/dedicated/DedicatedServer.java.patch index 2df09cffbd..c02078a5f3 100644 --- a/patches/minecraft/net/minecraft/server/dedicated/DedicatedServer.java.patch +++ b/patches/minecraft/net/minecraft/server/dedicated/DedicatedServer.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java +@@ -68,6 +_,8 @@ + private MinecraftServerGui f_139605_; + @Nullable + private final TextFilterClient f_139606_; ++ @Nullable ++ private net.minecraft.client.server.LanServerPinger dediLanPinger; + + public DedicatedServer(Thread p_214789_, LevelStorageSource.LevelStorageAccess p_214790_, PackRepository p_214791_, WorldStem p_214792_, DedicatedServerSettings p_214793_, DataFixer p_214794_, Services p_214795_, ChunkProgressListenerFactory p_214796_) { + super(p_214789_, p_214790_, p_214791_, p_214792_, Proxy.NO_PROXY, p_214794_, p_214795_, p_214796_); @@ -79,6 +_,7 @@ public boolean m_7038_() throws IOException { Thread thread = new Thread("Server console handler") { @@ -22,26 +31,41 @@ if (dedicatedserverproperties.f_139744_ != null) { this.m_129900_().m_46170_(GameRules.f_46153_).m_46246_(dedicatedserverproperties.f_139744_, this); } -@@ -183,12 +_,13 @@ - thread1.start(); - } - -+ // <3 you Grum for this, saves us ~30 patch files! --^ - if (dedicatedserverproperties.f_139721_) { - MinecraftServerStatistics.m_18328_(this); +@@ -188,7 +_,12 @@ f_139598_.info("JMX monitoring enabled"); } - return true; ++ if (net.minecraftforge.common.ForgeConfig.SERVER.advertiseDedicatedServerToLan.get()) { ++ this.dediLanPinger = new net.minecraft.client.server.LanServerPinger(this.m_129916_(), String.valueOf(this.m_7448_())); ++ this.dediLanPinger.start(); ++ } ++ + return net.minecraftforge.server.ServerLifecycleHooks.handleServerStarting(this); } } -@@ -492,6 +_,7 @@ +@@ -263,6 +_,10 @@ + this.f_139601_.m_7530_(); + } + ++ if (this.dediLanPinger != null) { ++ this.dediLanPinger.interrupt(); ++ this.dediLanPinger = null; ++ } + } + + public void m_5703_(BooleanSupplier p_139661_) { +@@ -492,7 +_,12 @@ } public void m_7041_() { + net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.GameShuttingDownEvent()); super.m_7041_(); ++ if (this.dediLanPinger != null) { ++ this.dediLanPinger.interrupt(); ++ this.dediLanPinger = null; ++ } Util.m_137580_(); SkullBlockEntity.m_196704_(); + } diff --git a/src/main/java/net/minecraftforge/common/ForgeConfig.java b/src/main/java/net/minecraftforge/common/ForgeConfig.java index 32fc104c90..22121279ea 100644 --- a/src/main/java/net/minecraftforge/common/ForgeConfig.java +++ b/src/main/java/net/minecraftforge/common/ForgeConfig.java @@ -30,6 +30,8 @@ public class ForgeConfig { public final ConfigValue permissionHandler; + public final BooleanValue advertiseDedicatedServerToLan; + Server(ForgeConfigSpec.Builder builder) { builder.comment("Server configuration settings") .push("server"); @@ -69,6 +71,11 @@ public class ForgeConfig { .translation("forge.configgui.permissionHandler") .define("permissionHandler", "forge:default_handler"); + advertiseDedicatedServerToLan = builder + .comment("Set this to true to enable advertising the dedicated server to local LAN clients so that it shows up in the Multiplayer screen automatically.") + .translation("forge.configgui.advertiseDedicatedServerToLan") + .define("advertiseDedicatedServerToLan", true); + builder.pop(); } } diff --git a/src/main/resources/forge.sas b/src/main/resources/forge.sas index e9a3db032a..14b42c20a5 100644 --- a/src/main/resources/forge.sas +++ b/src/main/resources/forge.sas @@ -4,4 +4,6 @@ # checkAndFixSAS will populate all overrides as nessasary. Prefixing added lines with \t # checkAndFixSAS also supports names using . so simplest way to find the correct line to add is to get the AT line from the bot # and remove the access modifier. -#================================================================================================================================== \ No newline at end of file +# You need to run the setup task again after running checkAndFixSAS for genPatches to pick up the changes. +#================================================================================================================================== +net/minecraft/client/server/LanServerPinger \ No newline at end of file