27
27
import lombok .NoArgsConstructor ;
28
28
import lombok .SneakyThrows ;
29
29
30
+ import net .minecraft .client .entity .EntityClientPlayerMP ;
31
+ import net .minecraftforge .common .MinecraftForge ;
32
+ import net .minecraftforge .event .entity .EntityJoinWorldEvent ;
30
33
import cpw .mods .fml .common .FMLCommonHandler ;
31
34
import cpw .mods .fml .common .eventhandler .SubscribeEvent ;
35
+ import cpw .mods .fml .common .network .FMLNetworkEvent ;
32
36
import cpw .mods .fml .relauncher .Side ;
33
37
import cpw .mods .fml .relauncher .SideOnly ;
34
38
39
+ import java .util .concurrent .atomic .AtomicBoolean ;
40
+
35
41
@ NoArgsConstructor (access = AccessLevel .PRIVATE )
36
42
@ SideOnly (Side .CLIENT )
37
43
public final class ClientEventHandlerPost {
38
44
private static final ClientEventHandlerPost INSTANCE = new ClientEventHandlerPost ();
39
45
40
46
public static void registerBus () {
47
+ MinecraftForge .EVENT_BUS .register (INSTANCE );
41
48
FMLCommonHandler .instance ().bus ().register (INSTANCE );
42
49
}
43
50
@@ -47,4 +54,22 @@ public static void registerBus() {
47
54
public void onSyncRequestClient (ConfigSyncRequestEvent .Client e ) {
48
55
ConfigurationManagerImpl .sendSyncRequest ();
49
56
}
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
+ }
50
75
}
0 commit comments