Skip to content

Notifications system

MFFbrokenSwing edited this page Apr 27, 2018 · 2 revisions

Send a notification

The notification system allows mods to send notifications to the clients with an unified system, the benefit of using this library is all notifications will be displayed in the same GUI.

In order to send notifications you have to query a DedicatedNotificationManager during the initilization phase :

DedicatedNotificationManager manager = null;

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
    manager = NotificationManager.instance().queryDedicatedManager();
}

Once the DedicatedNotificationManager queried, you can use it to send notifications to a specific user using DedicatedNotificationManager#sendNotificationTo(UUID clientTarget, Notification notification) or answer to a notification using DedicatedNotificationManager#replyToServer(int notificationId).

Create a notification

The notifications are objects which are sent through network to the specified users, you have to create a notification class before sending it. So, create a new class extending Notification and implement abstract methods. The notifications are created on server and notifications' parameters' values are initialized on server too, then the notification si sent to the client. The client makes modifications to the notification and send it back to the server where the new parameters's values are handled.

Parameters

We don't want the client being able to modify all the notification values, so multiple builtin parameters are available :

  • SharedNotifParameter is sent on client but the client can't modify it
  • RemoteNotifParameter is not sent on client and the client can't modify it
  • ModifiableNotifParameter is sent to the client and the client can modify it

There is 2 pre-added parameters to the notifications :

  • A parameter containing the timestamp the notification was created (shared)
  • A parameter containing the id of the mod which sent the notification (shared)

Displaying the notification

You have to provide a display for your notification. The display extends NotificationDisplay and draws the notification's informations to the client. The width of the display is specified in the function but you returns the height of the display, so you shouldn't miss space.

Clone this wiki locally