I have a packet that's sent to the client to open a GUI, which I'm using DistExecutor to do.
The packet's handler method does the following:
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> ClientOnlyNetworkMethods.openClientScreen(message))
ClientOnlyNetworkMethods.openClientScreen currently looks like this:
public static DistExecutor.SafeRunnable openClientScreen(final OpenClientScreenMessage message) {
return new DistExecutor.SafeRunnable() {
@Override
public void run() {
ClientScreenManager.openScreen(message.getId(), message.getAdditionalData(), Minecraft.getInstance());
}
};
}
ClientScreenManager is a client-only class that handles opening the GUI.
As you can see from the code, I need to pass arguments from the packet to the client-only method; which rules out using a method reference as the SafeRunnable implementation.
When I replace the anonymous class implementation of SafeRunnable in ClientOnlyNetworkMethods.openClientScreen with a lambda, DistExecutor.validateSafeReferent throws an "Unsafe Referent usage found in safe referent method" exception. From what I can see, using any non-lambda implementation of SafeReferent simply bypasses the safety checks in validateSafeReferent but doesn't necessarily mean that the code is safe.
The current code with the anonymous class does seem to work on the dedicated server, but is this the correct way to use DistExecutor; or is there a better way to do it?