package dev.crucifixbeta.mod.modules.impl.exploit;

import dev.crucifixbeta.api.events.eventbus.EventListener;
import dev.crucifixbeta.api.events.impl.PacketEvent;
import dev.crucifixbeta.api.events.impl.UpdateEvent;
import dev.crucifixbeta.mod.gui.clickgui.ClickGuiScreen;
import dev.crucifixbeta.mod.modules.Module;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket;

@Environment(EnvType.CLIENT)
public class XCarry extends Module {
   Screen lastScreen = null;

   public XCarry() {
      super("XCarry", Module.Category.Exploit);
      this.setChinese("\u5408\u6210\u680f\u643a\u5e26");
   }

   @EventListener
   public void onUpdate(UpdateEvent event) {
      if (mc.currentScreen != null
         && !(mc.currentScreen instanceof GameMenuScreen)
         && !(mc.currentScreen instanceof ChatScreen)
         && !(mc.currentScreen instanceof ClickGuiScreen)) {
         this.lastScreen = mc.currentScreen;
      }
   }

   @EventListener
   public void onPacketSend(PacketEvent.Send event) {
      if (this.lastScreen instanceof InventoryScreen && event.getPacket() instanceof CloseHandledScreenC2SPacket) {
         event.cancel();
      }
   }
}
