2727import lombok .NoArgsConstructor ;
2828import lombok .SneakyThrows ;
2929
30+ import net .minecraft .client .entity .EntityClientPlayerMP ;
31+ import net .minecraftforge .common .MinecraftForge ;
32+ import net .minecraftforge .event .entity .EntityJoinWorldEvent ;
3033import cpw .mods .fml .common .FMLCommonHandler ;
3134import cpw .mods .fml .common .eventhandler .SubscribeEvent ;
35+ import cpw .mods .fml .common .network .FMLNetworkEvent ;
3236import cpw .mods .fml .relauncher .Side ;
3337import cpw .mods .fml .relauncher .SideOnly ;
3438
39+ import java .util .concurrent .atomic .AtomicBoolean ;
40+
3541@ NoArgsConstructor (access = AccessLevel .PRIVATE )
3642@ SideOnly (Side .CLIENT )
3743public final class ClientEventHandlerPost {
3844 private static final ClientEventHandlerPost INSTANCE = new ClientEventHandlerPost ();
3945
4046 public static void registerBus () {
47+ MinecraftForge .EVENT_BUS .register (INSTANCE );
4148 FMLCommonHandler .instance ().bus ().register (INSTANCE );
4249 }
4350
@@ -47,4 +54,22 @@ public static void registerBus() {
4754 public void onSyncRequestClient (ConfigSyncRequestEvent .Client e ) {
4855 ConfigurationManagerImpl .sendSyncRequest ();
4956 }
57+
58+ private AtomicBoolean shouldDoConfigSync = new AtomicBoolean (false );
59+
60+ @ SneakyThrows
61+ @ SubscribeEvent
62+ public void onJoinWorld (FMLNetworkEvent .ClientConnectedToServerEvent e ) {
63+ if (e .isLocal )
64+ return ;
65+ shouldDoConfigSync .set (true );
66+ }
67+
68+ @ SneakyThrows
69+ @ SubscribeEvent
70+ public void onJoinWorld (EntityJoinWorldEvent e ) {
71+ if (e .world .isRemote && e .entity instanceof EntityClientPlayerMP && shouldDoConfigSync .compareAndSet (true , false )) {
72+ ConfigurationManagerImpl .sendSyncRequest ();
73+ }
74+ }
5075}
0 commit comments