Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.2]What's the event which is fired when the client disconnects from a server

Featured Replies

Posted

I think it's cpw.mods.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent.

But when I handle this event like this:

@SideOnly(Side.CLIENT)
public class VCCListener {

private boolean active = false;

@SubscribeEvent
public void onClientDisconnectionFromServer(ClientDisconnectionFromServerEvent event) {
	System.out.println("onClientDisconnectionFromServer");
	active = false;
}
}

And register the handler like this:

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	listener = new VCCListener();
	MinecraftForge.EVENT_BUS.register(listener);
}

It doesn't work. I mean there's no output when I disconnect from a server.

So how to handle the client disconnection from server?

  • Author

It is a FML event, so you have to use the FML EventBus (FMLCommonHandler.instance().bus()). You can see if an Event is FML or Forge by looking at it's package.

So I should use FMLCommonHandler when handling a FML event and use MinecraftForge.EVENT_BUS when handling a Forge event?

Thanks very much!

  • Author

Yes.

And another newbie's question: When is better to register event handler, on preinit or on init? And how about registering a new channel?

  • Author

That does not really matter. Both do the same in this case.

Channel = Network Channel? Then it does not matter either. But I usually go with preInit for both.

Thanks for your help!

Guest
This topic is now closed to further replies.

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.