diff --git a/src/main/java/de/guntram/mcmod/durabilityviewer/DurabilityViewer.java b/src/main/java/de/guntram/mcmod/durabilityviewer/DurabilityViewer.java index 2fe0592..18c354d 100644 --- a/src/main/java/de/guntram/mcmod/durabilityviewer/DurabilityViewer.java +++ b/src/main/java/de/guntram/mcmod/durabilityviewer/DurabilityViewer.java @@ -32,6 +32,7 @@ public class DurabilityViewer @Mod.Instance("durabilityviewer") public static DurabilityViewer instance; private static ConfigurationHandler confHandler; + private static String changedWindowTitle; @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { @@ -41,6 +42,7 @@ public void preInit(final FMLPreInitializationEvent event) { @Mod.EventHandler public void init(final FMLInitializationEvent event) { + changedWindowTitle=null; KeyHandler.init(); System.out.println("on Init, confHandler is "+confHandler); MinecraftForge.EVENT_BUS.register(this); @@ -59,7 +61,7 @@ public void onConnectedToServerEvent(FMLNetworkEvent.ClientConnectedToServerEven String serverName = (event.isLocal() ? "local game" : mc.getCurrentServerData().serverName); if (serverName==null) serverName="unknown server"; - Display.setTitle(mc.getSession().getUsername() + " on "+serverName); + changedWindowTitle=mc.getSession().getUsername() + " on "+serverName; } @SideOnly(Side.CLIENT) @@ -68,7 +70,18 @@ public void onDisconnectFromServerEvent(FMLNetworkEvent.ClientDisconnectionFromS if (!ConfigurationHandler.showPlayerServerName()) return; Minecraft mc=Minecraft.getMinecraft(); - Display.setTitle(mc.getSession().getUsername() + " not connected"); + changedWindowTitle=mc.getSession().getUsername() + " not connected"; } + // On windows, Display.setTitle crashes if we call it from + // (Dis)connectFromServerEvent. This is because these run on the netty + // thread, set a global lock, send a WM_SETTEXT, and need the main thread + // to process that WM_SETTEXT - but the main thread needs the global lock + // as well. As a workaround, we just set a global variable here, and retrieve + // it from within onRender from GuiItemDurability. + public static String getAndResetChangedWindowTitle() { + String result=changedWindowTitle; + changedWindowTitle=null; + return result; + } } diff --git a/src/main/java/de/guntram/mcmod/durabilityviewer/client/gui/GuiItemDurability.java b/src/main/java/de/guntram/mcmod/durabilityviewer/client/gui/GuiItemDurability.java index 114edf4..2788618 100644 --- a/src/main/java/de/guntram/mcmod/durabilityviewer/client/gui/GuiItemDurability.java +++ b/src/main/java/de/guntram/mcmod/durabilityviewer/client/gui/GuiItemDurability.java @@ -1,6 +1,7 @@ package de.guntram.mcmod.durabilityviewer.client.gui; import com.google.common.collect.Ordering; +import de.guntram.mcmod.durabilityviewer.DurabilityViewer; import de.guntram.mcmod.durabilityviewer.handler.ConfigurationHandler; import de.guntram.mcmod.durabilityviewer.itemindicator.InventorySlotsIndicator; import de.guntram.mcmod.durabilityviewer.itemindicator.ItemIndicator; @@ -26,6 +27,7 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import org.lwjgl.opengl.Display; public class GuiItemDurability extends Gui { @@ -100,6 +102,13 @@ private class RenderSize { @SubscribeEvent(priority = EventPriority.NORMAL) public void onRender(final RenderGameOverlayEvent.Post event) { + + // This needs to be done before everything else to make sure + // the title change that occurs when logging off gets through. + String newTitle=DurabilityViewer.getAndResetChangedWindowTitle(); + if (newTitle!=null) + Display.setTitle(newTitle); + if (!visible || event.isCanceled() diff --git a/src/main/java/de/guntram/mcmod/durabilityviewer/handler/ConfigurationHandler.java b/src/main/java/de/guntram/mcmod/durabilityviewer/handler/ConfigurationHandler.java index 7add38f..9c00ac4 100644 --- a/src/main/java/de/guntram/mcmod/durabilityviewer/handler/ConfigurationHandler.java +++ b/src/main/java/de/guntram/mcmod/durabilityviewer/handler/ConfigurationHandler.java @@ -43,7 +43,6 @@ public static String getConfigFileName() { @SubscribeEvent public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { - // System.out.println("OnConfigChanged for "+event.getModID()); if (event.getModID().equalsIgnoreCase("durabilityviewer")) { loadConfig(); } @@ -55,7 +54,7 @@ private void loadConfig() { effectDuration=config.getBoolean("Effect Duration", Configuration.CATEGORY_CLIENT, true, "Show effect durations"); minPercent = config.getInt("Minimum Percent", Configuration.CATEGORY_CLIENT, minPercent, 1, 100, "Play sound when durability below X percent"); minDurability = config.getInt("Minimum Durability", Configuration.CATEGORY_CLIENT, minDurability, 1, 1500, "Play sound when durability below X"); - showPlayerServerName = config.getBoolean("Set window title", Configuration.CATEGORY_CLIENT, false, "Set window title to player and server name (warning - this seems to lock up MC on some windows machines)"); + showPlayerServerName = config.getBoolean("Set window title", Configuration.CATEGORY_CLIENT, true, "Set window title to player and server name"); // useCustomSound = config.getBoolean("Use custom sound", Configuration.CATEGORY_CLIENT, false, "Use your own warning sound. You need to create your own custom.ogg in the mod folder"); tooltipColor=TextFormatting.fromColorIndex(color); @@ -75,7 +74,6 @@ public static Configuration getConfig() { return getInstance().config; } - public static boolean showEffectDuration() { return getInstance().effectDuration; }