Hey guys,
it's me again.
I'm trying to get the configuration for my mod sent from the server to the client, so that the client can set its variables to that of the server.
I'm using an IMessage to send two variables from the server to the client, the message gets sent using the PlayerLoggedInEvent:
@SubscribeEvent
public void JoinServer(PlayerLoggedInEvent event) {
SolidStone.network.sendTo(new SSMessage(SSConfig.solidity, SSConfig.smeltingEnabled), (EntityPlayerMP)event.player);
}
This works fine. The client accepts the new values.
When trying to reset the values for the client, I use a different message "SSMessageReset" without any arguments and try to send it when the PlayerLoggedOutEvent triggers:
@SubscribeEvent
public void LeaveServer(PlayerLoggedOutEvent event) {
SolidStone.network.sendTo(new SSMessageReset(), (EntityPlayerMP)event.player);
}
This however, doesn't seem to produce any results. The LeaveServer method gets called, but the IMessageHandler for the SSMessageReset IMessage doesn't get called. I'm wondering if this is because the client has already disconnected?
FYI, the messages are registered like this, in the preInit method of my main mod class:
network = NetworkRegistry.INSTANCE.newSimpleChannel("SSChannel");
network.registerMessage(SSMessage.Handler.class, SSMessage.class, 0, Side.CLIENT);
network.registerMessage(SSMessageReset.Handler.class, SSMessageReset.class, 1, Side.CLIENT);
The only work-around I see for this, is that instead of using the same variables for both singleplayer and multiplayer games, the client stores two seperate sets of variables, effectively removing the need for a reset of the sent variables.
That option doesn't seem as elegant to me though, and it really (really) bugs me, that my first approach doesn't work.
I'm wondering if there's anything I might be doing wrong here, or if it really is true that the client has already disconnected when the PlayerLoggedOutEvent gets called.
Any answers to this?
Thanks in advance,
- Apace