2323public class TimeLoop implements ModInitializer {
2424 public static final Logger LOOP_LOGGER = LoggerFactory .getLogger ("TimeLoop" );
2525 private Commands commands ;
26- private LoopBossBar loopBossBar ;
2726 private static MinecraftServer server ;
2827 private ServerWorld serverWorld ;
2928
29+ public LoopBossBar loopBossBar ;
30+
3031 // These fields will be initialized from the configuration file.
3132 public int loopIteration ;
3233 public int loopTicks ;
@@ -69,9 +70,8 @@ public void onInitialize() {
6970 loopBossBar = new LoopBossBar ();
7071
7172 EntitySleepEvents .STOP_SLEEPING .register ((entity , sleepingPos ) -> {
72- LOOP_LOGGER .info ("Loop type: " + loopType );
7373 if (entity .isPlayer () && (loopType == LoopTypes .SLEEP ) ) {
74- LOOP_LOGGER .info ("PLAYER SLEPT, LOOPING " );
74+ LOOP_LOGGER .info ("Player slept, looping. " );
7575 runLoopIteration ();
7676 }
7777 });
@@ -98,9 +98,9 @@ public void onInitialize() {
9898 TimeLoop .server = server ;
9999 this .serverWorld = server .getOverworld ();
100100
101- // loop bossbar info
101+ // Loop boss bar info
102102 String loopInfo = (loopType == LoopTypes .TICKS ? "Ticks Left: " + loopTicks : loopType == LoopTypes .TIME_OF_DAY ? "Time left: " + (timeOfDay - timeSetting ) : "" );
103- loopBossBar .visible (showLoopInfo );
103+ loopBossBar .visible (false );
104104 loopBossBar .setBossBarName (loopInfo );
105105
106106 // set mocap settings
@@ -163,19 +163,43 @@ public void onInitialize() {
163163
164164 ServerTickEvents .END_SERVER_TICK .register (server -> {
165165 if (loopType == LoopTypes .SLEEP || loopType == LoopTypes .DEATH ) { return ; }
166- if ( loopType == LoopTypes . TIME_OF_DAY ) { timeOfDay = serverWorld . getTimeOfDay (); };
166+
167167 if (isLooping ) {
168- tickCounter ++;
169- ticksLeft = loopTicks - tickCounter ;
170- loopBossBar .visible (showLoopInfo );
171- if (showLoopInfo && (loopType == LoopTypes .TICKS || loopType == LoopTypes .TIME_OF_DAY )) {
172- loopBossBar .setBossBarName (loopType == LoopTypes .TICKS ? "Ticks Left: " + ticksLeft : loopType == LoopTypes .TIME_OF_DAY ? "Time left: " + (timeOfDay - timeSetting ) : "" );
173- loopBossBar .setBossBarPercentage (loopTicks , tickCounter );
168+ if (loopType == LoopTypes .TIME_OF_DAY ) {
169+ LOOP_LOGGER .info ("TimeOfDay: {}" , serverWorld .getTimeOfDay ());
170+ timeOfDay = serverWorld .getTimeOfDay ();
171+
172+ long timeLeft = (timeOfDay > timeSetting ) ? Math .abs (serverWorld .getTimeOfDay () - (2 * timeSetting )) : Math .abs (timeOfDay - timeSetting );
173+
174+ LOOP_LOGGER .info ("Time Left: {}" , timeLeft );
175+
176+ LOOP_LOGGER .info ("Time setting: {}" , timeSetting );
177+
178+ LOOP_LOGGER .info ("Time setting - timeleft: {}" , timeSetting - timeLeft );
179+
180+ if (showLoopInfo ) {
181+ loopBossBar .setBossBarName ("Time Left: " + timeLeft );
182+ loopBossBar .setBossBarPercentage ((int )timeSetting , (int )(timeSetting - timeLeft ));
183+ }
184+
185+ if (timeSetting - timeLeft == timeSetting ) {
186+ runLoopIteration ();
187+ }
174188 }
175- if (tickCounter >= loopTicks || ( timeOfDay == timeSetting && (loopType == LoopTypes .TIME_OF_DAY )) ) {
176- tickCounter = 0 ; // Reset counter
177- ticksLeft = loopTicks ; // Reset
178- runLoopIteration ();
189+
190+ else if (loopType == LoopTypes .TICKS ) {
191+ tickCounter ++;
192+ ticksLeft = loopTicks - tickCounter ;
193+ if (showLoopInfo ) {
194+ loopBossBar .setBossBarName ("Ticks Left: " + ticksLeft );
195+ loopBossBar .setBossBarPercentage (loopTicks , tickCounter );
196+ }
197+
198+ if (tickCounter >= loopTicks ) {
199+ tickCounter = 0 ; // Reset counter
200+ ticksLeft = loopTicks ; // Reset
201+ runLoopIteration ();
202+ }
179203 }
180204 }
181205 });
0 commit comments