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

import dev.crucifixbeta.api.events.eventbus.EventListener;
import dev.crucifixbeta.api.events.impl.PacketEvent;
import dev.crucifixbeta.mod.modules.Module;
import dev.crucifixbeta.mod.modules.settings.impl.BooleanSetting;
import dev.crucifixbeta.mod.modules.settings.impl.SliderSetting;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket;

@Environment(EnvType.CLIENT)
public class WindChargeHighJump extends Module {
   public static WindChargeHighJump INSTANCE;
   private final SliderSetting height = this.add(new SliderSetting("Height", 1.5, 0.5, 10.0, 0.1));
   private final BooleanSetting onlyGround = this.add(new BooleanSetting("OnlyGround", true));
   private final BooleanSetting addVelocity = this.add(new BooleanSetting("AddVelocity", true));

   public WindChargeHighJump() {
      super("WindChargeHighJump", Module.Category.Exploit);
      this.setChinese("\u98ce\u5f39\u9ad8\u8df3");
      INSTANCE = this;
   }

   @Override
   public String getInfo() {
      return String.valueOf(this.height.getValue());
   }

   @EventListener(
      priority = 100
   )
   public void onPacketSend(PacketEvent.Send event) {
      if (!nullCheck()) {
         if (event.getPacket() instanceof PlayerInteractItemC2SPacket var3) {
            if (!this.isHoldingWindCharge()) {
               return;
            }

            if (this.onlyGround.getValue() && !mc.player.isOnGround()) {
               return;
            }

            if (this.addVelocity.getValue()) {
               mc.player.addVelocity(0.0, this.height.getValue(), 0.0);
            } else {
               mc.player.setVelocity(mc.player.getVelocity().x, this.height.getValue(), mc.player.getVelocity().z);
            }
         }
      }
   }

   private boolean isHoldingWindCharge() {
      return mc.player.getMainHandStack().getItem() == Items.WIND_CHARGE || mc.player.getOffHandStack().getItem() == Items.WIND_CHARGE;
   }
}
