diff --git a/patches/minecraft/net/minecraft/network/NetworkSystem.java.patch b/patches/minecraft/net/minecraft/network/NetworkSystem.java.patch index 76ca4cff80..cf3967d0bb 100644 --- a/patches/minecraft/net/minecraft/network/NetworkSystem.java.patch +++ b/patches/minecraft/net/minecraft/network/NetworkSystem.java.patch @@ -1,5 +1,30 @@ --- ../src-base/minecraft/net/minecraft/network/NetworkSystem.java +++ ../src-work/minecraft/net/minecraft/network/NetworkSystem.java +@@ -50,21 +50,21 @@ + { + protected NioEventLoopGroup func_179280_b() + { +- return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build()); ++ return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).setThreadFactory(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER).build()); + } + }; + public static final LazyLoadBase field_181141_b = new LazyLoadBase() + { + protected EpollEventLoopGroup func_179280_b() + { +- return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).build()); ++ return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).setThreadFactory(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER).build()); + } + }; + public static final LazyLoadBase field_180232_b = new LazyLoadBase() + { + protected LocalEventLoopGroup func_179280_b() + { +- return new LocalEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Server IO #%d").setDaemon(true).build()); ++ return new LocalEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Server IO #%d").setDaemon(true).setThreadFactory(net.minecraftforge.fml.common.thread.SidedThreadGroups.CLIENT).build()); + } + }; + private final MinecraftServer field_151273_d; @@ -111,7 +111,7 @@ ; } diff --git a/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch b/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch index d75bd10251..e29541c4a7 100644 --- a/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch +++ b/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch @@ -243,14 +243,16 @@ this.field_71304_b.func_76318_c("connection"); this.func_147137_ag().func_151269_c(); this.field_71304_b.func_76318_c("players"); -@@ -758,6 +760,7 @@ +@@ -758,7 +760,8 @@ public void func_71256_s() { +- this.field_175590_aa = new Thread(this, "Server thread"); + net.minecraftforge.fml.common.StartupQuery.reset(); - this.field_175590_aa = new Thread(this, "Server thread"); ++ this.field_175590_aa = new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, this, "Server thread"); this.field_175590_aa.start(); } + @@ -774,7 +777,13 @@ public WorldServer func_71218_a(int p_71218_1_) diff --git a/patches/minecraft/net/minecraft/server/network/NetHandlerLoginServer.java.patch b/patches/minecraft/net/minecraft/server/network/NetHandlerLoginServer.java.patch index e4992a0e06..d872daa1d1 100644 --- a/patches/minecraft/net/minecraft/server/network/NetHandlerLoginServer.java.patch +++ b/patches/minecraft/net/minecraft/server/network/NetHandlerLoginServer.java.patch @@ -18,3 +18,12 @@ } } } +@@ -179,7 +179,7 @@ + this.field_147335_k = p_147315_1_.func_149300_a(privatekey); + this.field_147328_g = NetHandlerLoginServer.LoginState.AUTHENTICATING; + this.field_147333_a.func_150727_a(this.field_147335_k); +- (new Thread("User Authenticator #" + field_147331_b.incrementAndGet()) ++ (new Thread(net.minecraftforge.fml.common.thread.SidedThreadGroups.SERVER, "User Authenticator #" + field_147331_b.incrementAndGet()) + { + public void run() + { diff --git a/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java b/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java index fb5fc44fb5..92f85a0a39 100644 --- a/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java +++ b/src/main/java/net/minecraftforge/fml/common/FMLCommonHandler.java @@ -64,6 +64,8 @@ import net.minecraftforge.fml.common.gameevent.PlayerEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.thread.SidedThreadGroup; +import net.minecraftforge.fml.common.thread.SidedThreadGroups; import net.minecraftforge.fml.relauncher.CoreModManager; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.server.FMLServerHandler; @@ -201,13 +203,8 @@ public class FMLCommonHandler */ public Side getEffectiveSide() { - Thread thr = Thread.currentThread(); - if (thr.getName().equals("Server thread") || thr.getName().startsWith("Netty Server IO")) - { - return Side.SERVER; - } - - return Side.CLIENT; + final ThreadGroup group = Thread.currentThread().getThreadGroup(); + return group instanceof SidedThreadGroup ? ((SidedThreadGroup) group).getSide() : Side.CLIENT; } /** * Raise an exception diff --git a/src/main/java/net/minecraftforge/fml/common/thread/SidedThreadGroup.java b/src/main/java/net/minecraftforge/fml/common/thread/SidedThreadGroup.java new file mode 100644 index 0000000000..a66efe422b --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/thread/SidedThreadGroup.java @@ -0,0 +1,56 @@ +/* + * Minecraft Forge + * Copyright (c) 2016. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.fml.common.thread; + +import net.minecraftforge.fml.relauncher.Side; + +import java.util.concurrent.ThreadFactory; + +import javax.annotation.Nonnull; + +/** + * A thread group and factory combination which belongs to a {@link Side}. + */ +public final class SidedThreadGroup extends ThreadGroup implements ThreadFactory +{ + private final Side side; + + SidedThreadGroup(final Side side) + { + super(side.name()); + this.side = side; + } + + /** + * Gets the side this sided thread group belongs to. + * + * @return the side + */ + public Side getSide() + { + return this.side; + } + + @Override + public Thread newThread(@Nonnull final Runnable runnable) + { + return new Thread(this, runnable); + } +} diff --git a/src/main/java/net/minecraftforge/fml/common/thread/SidedThreadGroups.java b/src/main/java/net/minecraftforge/fml/common/thread/SidedThreadGroups.java new file mode 100644 index 0000000000..bc10aa4f83 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/thread/SidedThreadGroups.java @@ -0,0 +1,31 @@ +/* + * Minecraft Forge + * Copyright (c) 2016. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.fml.common.thread; + +import net.minecraftforge.fml.relauncher.Side; + +public final class SidedThreadGroups +{ + public static final SidedThreadGroup CLIENT = new SidedThreadGroup(Side.CLIENT); + public static final SidedThreadGroup SERVER = new SidedThreadGroup(Side.SERVER); + + private SidedThreadGroups() { + } +}