diff --git a/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java b/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java index 15bf5deff..5c96301e5 100644 --- a/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java +++ b/fml/client/cpw/mods/fml/client/modloader/ModLoaderClientHelper.java @@ -12,6 +12,9 @@ import net.minecraft.src.Entity; import net.minecraft.src.EntityClientPlayerMP; import net.minecraft.src.EntityPlayer; import net.minecraft.src.KeyBinding; +import net.minecraft.src.NetClientHandler; +import net.minecraft.src.NetHandler; +import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.Render; import net.minecraft.src.RenderManager; @@ -23,6 +26,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import com.google.common.collect.MapDifference; import com.google.common.collect.MapDifference.ValueDifference; +import com.google.common.collect.MapMaker; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -150,4 +154,24 @@ public class ModLoaderClientHelper implements IModLoaderSidedHelper { ((net.minecraft.src.BaseMod)mod).clientCustomPayload(client.field_71439_g.field_71174_a, packet); } + + private Map managerLookups = new MapMaker().weakKeys().weakValues().makeMap(); + @Override + public void clientConnectionOpened(NetHandler netClientHandler, NetworkManager manager, BaseModProxy mod) + { + managerLookups.put(manager, netClientHandler); + ((BaseMod)mod).clientConnect((NetClientHandler)netClientHandler); + } + + + @Override + public boolean clientConnectionClosed(NetworkManager manager, BaseModProxy mod) + { + if (managerLookups.containsKey(manager)) + { + ((BaseMod)mod).clientDisconnect((NetClientHandler) managerLookups.get(manager)); + return true; + } + return false; + } } diff --git a/fml/client/net/minecraft/src/BaseMod.java b/fml/client/net/minecraft/src/BaseMod.java index ca0bff72e..8f87f7a5a 100644 --- a/fml/client/net/minecraft/src/BaseMod.java +++ b/fml/client/net/minecraft/src/BaseMod.java @@ -144,7 +144,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr generateNether(w, random, chunkX << 4, chunkZ << 4); } } - + @Override public final boolean handleCommand(String command, Object... data) { @@ -308,6 +308,25 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr { } + /** + * Called when a client connects + * @param handler + */ + @SideOnly(CLIENT) + public void clientConnect(NetClientHandler handler) + { + + } + + /** + * Called when the client disconnects + * @param handler + */ + @SideOnly(CLIENT) + public void clientDisconnect(NetClientHandler handler) + { + + } /** * Called client side to receive a custom payload for this mod * diff --git a/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java b/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java index ce1bbe862..6792e477b 100644 --- a/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java +++ b/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java @@ -21,6 +21,7 @@ import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiScreen; import net.minecraft.src.IInventory; import net.minecraft.src.ItemStack; +import net.minecraft.src.NetClientHandler; import net.minecraft.src.NetHandler; import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetworkManager; diff --git a/fml/common/cpw/mods/fml/common/modloader/IModLoaderSidedHelper.java b/fml/common/cpw/mods/fml/common/modloader/IModLoaderSidedHelper.java index 793c484b5..9d908d271 100644 --- a/fml/common/cpw/mods/fml/common/modloader/IModLoaderSidedHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/IModLoaderSidedHelper.java @@ -4,6 +4,8 @@ import cpw.mods.fml.common.network.EntitySpawnPacket; import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; import net.minecraft.src.Entity; import net.minecraft.src.EntityPlayer; +import net.minecraft.src.NetHandler; +import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet250CustomPayload; public interface IModLoaderSidedHelper @@ -17,4 +19,8 @@ public interface IModLoaderSidedHelper void sendClientPacket(BaseModProxy mod, Packet250CustomPayload packet); + void clientConnectionOpened(NetHandler netClientHandler, NetworkManager manager, BaseModProxy mod); + + boolean clientConnectionClosed(NetworkManager manager, BaseModProxy mod); + } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java index 33d68aa85..91b3a5f2a 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderConnectionHandler.java @@ -33,14 +33,17 @@ public class ModLoaderConnectionHandler implements IConnectionHandler @Override public void connectionOpened(NetHandler netClientHandler, String server, int port, NetworkManager manager) { - // noop + ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod); } @Override public void connectionClosed(NetworkManager manager) { - mod.serverDisconnect(); - mod.onClientLogout(manager); + if (!ModLoaderHelper.sidedHelper.clientConnectionClosed(manager, mod)) + { + mod.serverDisconnect(); + mod.onClientLogout(manager); + } } @Override @@ -52,7 +55,7 @@ public class ModLoaderConnectionHandler implements IConnectionHandler @Override public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, NetworkManager manager) { - // noop + ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod); } }