From a38a4521f1b9dcb7a80b8a0625ab09c07116885d Mon Sep 17 00:00:00 2001 From: MrCrayfish Date: Tue, 23 Feb 2021 15:16:38 +1030 Subject: [PATCH] Fixed disconnect notification not showing --- .../mrcrayfish/controllable/Controllable.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mrcrayfish/controllable/Controllable.java b/src/main/java/com/mrcrayfish/controllable/Controllable.java index e5432d48..e9e11243 100644 --- a/src/main/java/com/mrcrayfish/controllable/Controllable.java +++ b/src/main/java/com/mrcrayfish/controllable/Controllable.java @@ -12,7 +12,10 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.FMLFileResourcePack; import net.minecraftforge.fml.client.FMLFolderResourcePack; -import net.minecraftforge.fml.common.*; +import net.minecraftforge.fml.common.DummyModContainer; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.LoadController; +import net.minecraftforge.fml.common.ModMetadata; import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.LogManager; @@ -21,6 +24,8 @@ import javax.annotation.Nullable; import java.io.File; import java.util.Collections; +import java.util.Comparator; +import java.util.Optional; import static org.libsdl.SDL.*; @@ -170,7 +175,30 @@ public void connected(int jid) @Override public void disconnected(int jid) { + Minecraft.getMinecraft().addScheduledTask(() -> + { + if(Controllable.controller != null) + { + if(Controllable.controller.getJid() == jid) + { + Controller oldController = Controllable.controller; + setController(null); + + if(Controllable.getOptions().isAutoSelect() && manager.getControllerCount() > 0) + { + Optional optional = manager.getControllers().keySet().stream().min(Comparator.comparing(i -> i)); + optional.ifPresent(minJid -> setController(new Controller(minJid))); + } + + Minecraft mc = Minecraft.getMinecraft(); + if(mc.player != null) + { + Minecraft.getMinecraft().getToastGui().add(new ControllerToast(false, oldController.getName())); + } + } + } + }); } public static void setController(@Nullable Controller controller)