content: package io.github.anonymous123_code.quilt_bisect;
  
  import io.github.anonymous123_code.quilt_bisect.gui.BisectSummaryScreen;
  import io.github.anonymous123_code.quilt_bisect.gui.CreateIssueScreen;
  import io.github.anonymous123_code.quilt_bisect.gui.SelectIssueScreen;
  import io.github.anonymous123_code.quilt_bisect.gui.StartBisectScreen;
  import io.github.anonymous123_code.quilt_bisect.mixin.ScreenInvoker;
  import io.github.anonymous123_code.quilt_bisect.shared_mod.ActiveBisectConfig;
  import net.minecraft.client.MinecraftClient;
  import net.minecraft.client.gui.widget.button.ButtonWidget;
  import net.minecraft.server.integrated.IntegratedServer;
  import net.minecraft.text.Text;
  import org.quiltmc.loader.api.ModContainer;
  import org.quiltmc.loader.api.entrypoint.PreLaunchEntrypoint;
  import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
  import org.quiltmc.qsl.lifecycle.api.client.event.ClientTickEvents;
  import org.quiltmc.qsl.screen.api.client.ScreenEvents;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  public class QuiltBisect implements ModInitializer, PreLaunchEntrypoint, ClientTickEvents.Start {
  	// This logger is used to write text to the console and the log file.
  	// It is considered best practice to use your mod name as the logger's name.
  	// That way, it's clear which mod wrote info, warnings, and errors.
  	public static final Logger LOGGER = LoggerFactory.getLogger("Quilt Bisect");
  	// Gets set to false on world join if autoJoinType != None, else on title screen load
  	public static boolean firstTimeInAutoJoinScope = true;
  	public static long joinedTimestamp = -1;
  	public static String MOD_ID;
  
  	public static void markAsWorkingAndShutdown() {
  		GracefulTerminator.gracefullyTerminate(56);
  	}
  
  	@Override
  	public void onInitialize(ModContainer mod) {
  		MOD_ID = mod.metadata().id();
  
  		var bisectConfig = ActiveBisectConfig.INSTANCE;
  		if (bisectConfig.isActive()) {
  			ScreenEvents.AFTER_INIT.register((screen, client, firstInit) -> {
  				if (!(screen instanceof BisectSummaryScreen || screen instanceof CreateIssueScreen || screen instanceof SelectIssueScreen || screen instanceof StartBisectScreen)) {
  					((ScreenInvoker) screen).invokeAddDrawableSelectableElement(ButtonWidget.builder(
  						Text.translatable("gui.bisect.no_issue"),
  						buttonWidget -> markAsWorkingAndShutdown()
  					).position(screen.width / 2 - ButtonWidget.DEFAULT_WIDTH - 5, 0).build());
  					((ScreenInvoker) screen).invokeAddDrawableSelectableElement(ButtonWidget.builder(
  						Text.translatable("gui.bisect.manual_issue"),
  						buttonWidget -> screen.getClient().setScreen(new SelectIssueScreen(screen))
  					).position(screen.width / 2 + 5, 0).build());
  				} else {
  					((ScreenInvoker) screen).invokeAddDrawableSelectableElement(ButtonWidget.builder(
  						Text.translatable("gui.bisect.no_issue"),
  						buttonWidget -> markAsWorkingAndShutdown()
  					).position(20, 10).build());
  				}
  			});
  			ClientTickEvents.START.register(this);
  		} else {
  			ScreenEvents.AFTER_INIT.register((screen, client, firstInit) -> {
  				if (!(screen instanceof BisectSummaryScreen || screen instanceof CreateIssueScreen || screen instanceof SelectIssueScreen || screen instanceof StartBisectScreen)) {
  					((ScreenInvoker) screen).invokeAddDrawableSelectableElement(ButtonWidget.builder(
  						Text.translatable("gui.bisect.start"),
  						(w) -> screen.getClient().setScreen(new StartBisectScreen(screen))
  					).position(screen.width / 2 - ButtonWidget.DEFAULT_WIDTH / 2, 0).build());
  				}
  			});
  		}
  	}
  
  	@Override
  	public void onPreLaunch(ModContainer mod) {
  		if (!"true".equals(System.getProperty("quiltBisect.active"))) {
  			throw new RuntimeException("Failed to load loader plugin: Something went very long");
  		}
  		LOGGER.info(
  			"Successfully battled quilt loader demons, bisect is alive! Cursed stuff may happen, make sure to test the errors you found without bisect before reporting them. (Bisect can't include itself in search)");
  	}
  
  	@Override
  	public void startClientTick(MinecraftClient client) {
  		if (joinedTimestamp > 0) {
  			long currentTime = System.currentTimeMillis();
  			long deltaTime = currentTime - joinedTimestamp;
  			long deltaTimeTicks = deltaTime / 50; // 50ms per tick
  			if (deltaTimeTicks > ActiveBisectConfig.INSTANCE.bisectSettings.autoAcceptTime()) {
  				IntegratedServer server = client.getServer();
  				if (server == null || server.getTicks() > ActiveBisectConfig.INSTANCE.bisectSettings.autoAcceptTime()) { // If a server exists, both the server must have ticked for the autoAcceptTime, and the client must have been in the world for long enough
  					markAsWorkingAndShutdown();
  				}
  			}
  		}
  	}
  }
  