package asm.mixins;

import dev.crucifixbeta.mod.gui.EpsilonMainMenuScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin({TitleScreen.class})
public class MixinTitleScreenBackground {
   @Unique
   private static boolean crucifix$openingEpsilonMenu;

   @Inject(
      method = {"init"},
      at = {@At("HEAD")}
   )
   private void crucifix$openEpsilonMainMenu(CallbackInfo ci) {
      if (!crucifix$openingEpsilonMenu) {
         MinecraftClient var2 = MinecraftClient.getInstance();
         if (var2 != null && !(var2.currentScreen instanceof EpsilonMainMenuScreen)) {
            crucifix$openingEpsilonMenu = true;
            var2.setScreen(EpsilonMainMenuScreen.INSTANCE);
            crucifix$openingEpsilonMenu = false;
         }
      }
   }
}
