#Using a client sided ForgeEvent?

4 messages · Page 1 of 1 (latest)

supple mist
#

Under startup_scripts, I have the following in a file;

ForgeEvents.onEvent("net.minecraftforge.client.event.ViewportEvent$RenderFog", (event) => {
    if (Platform.isClientEnvironment()) global.RenderFog(event);
});
ForgeEvents.onEvent("net.minecraftforge.client.event.ViewportEvent$ComputeFogColor", (event) => {
    if (Platform.isClientEnvironment()) global.ComputeFogColor(event);
});

Of course, this errors on startup, because the client check happens after trying to hook onto the forge event, which throws a error on the server.
So, what do I do here?
I'm sure I could just package the script only to the client, but with the way I have my server stuff set up, this would be awfully inconvenient.

I assume there's some obvious answer, but I had no idea what to ctrl-f to find the answer. Any mixture of 'forge event client' didn't seem to help much.

tropic craneBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

supple mist
#

After bashing my head and trying some random things, I found a solution.
Try catch blocks work just fine even outside of functions. So I just sorrounded the ForgeEvents.onEvent call with a try catch block. On the server, it'll error and catch. On the client, it runs fine.