4141import net .minecraft .util .EnumChatFormatting ;
4242import net .minecraftforge .common .MinecraftForge ;
4343import net .minecraftforge .event .entity .EntityJoinWorldEvent ;
44+ import cpw .mods .fml .common .FMLCommonHandler ;
4445import cpw .mods .fml .common .eventhandler .SubscribeEvent ;
46+ import cpw .mods .fml .common .gameevent .TickEvent ;
4547
4648import java .nio .charset .StandardCharsets ;
4749import java .security .MessageDigest ;
5052public class Calibration {
5153 private static final Calibration INSTANCE = new Calibration ();
5254
55+ private static boolean calibrateRequest = false ;
56+
5357 public static void registerBus () {
5458 MinecraftForge .EVENT_BUS .register (INSTANCE );
59+ FMLCommonHandler .instance ().bus ().register (INSTANCE );
5560 }
5661
5762 @ SneakyThrows
@@ -102,7 +107,7 @@ public void onSinglePlayer(EntityJoinWorldEvent e) {
102107 val alert = FormattedText .parse (EnumChatFormatting .RED +
103108 I18n .format ("chat.triangulator.calibration.message" ));
104109 val text = alert .toChatText ();
105- val ce = new ClickEvent (ClickEvent .Action .RUN_COMMAND , "triangulator_calibrate" );
110+ val ce = new ClickEvent (ClickEvent .Action .RUN_COMMAND , "/ triangulator_calibrate" );
106111 for (val t : text ) {
107112 t .getChatStyle ()
108113 .setChatClickEvent (ce );
@@ -111,6 +116,15 @@ public void onSinglePlayer(EntityJoinWorldEvent e) {
111116 }
112117 }
113118
119+ @ SubscribeEvent
120+ public void onTick (TickEvent .ClientTickEvent e ) {
121+ if (calibrateRequest ) {
122+ calibrateRequest = false ;
123+ Minecraft .getMinecraft ()
124+ .displayGuiScreen (new CalibrationGUI ());
125+ }
126+ }
127+
114128 public static class CalibrationCommand extends CommandBase {
115129 @ Override
116130 public String getCommandName () {
@@ -129,8 +143,7 @@ public String getCommandUsage(ICommandSender sender) {
129143
130144 @ Override
131145 public void processCommand (ICommandSender sender , String [] args ) {
132- Minecraft .getMinecraft ()
133- .displayGuiScreen (new CalibrationGUI ());
146+ calibrateRequest = true ;
134147 }
135148 }
136149}
0 commit comments