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

import dev.crucifixbeta.api.events.eventbus.EventListener;
import dev.crucifixbeta.api.events.impl.UpdateEvent;
import dev.crucifixbeta.api.utils.player.MovementUtil;
import dev.crucifixbeta.api.utils.world.BlockPosX;
import dev.crucifixbeta.mod.modules.Module;
import dev.crucifixbeta.mod.modules.settings.impl.SliderSetting;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Blocks;

@Environment(EnvType.CLIENT)
public class AntiVoid extends Module {
   private final SliderSetting voidHeight = this.add(new SliderSetting("VoidHeight", -64.0, -64.0, 319.0, 1.0));
   private final SliderSetting height = this.add(new SliderSetting("Height", 100.0, -40.0, 256.0, 1.0));

   public AntiVoid() {
      super("AntiVoid", "Allows you to fly over void blocks", Module.Category.Movement);
      this.setChinese("\u53cd\u865a\u7a7a");
   }

   @EventListener
   public void onUpdate(UpdateEvent event) {
      boolean var2 = true;

      for (int var3 = (int)mc.player.getY(); var3 > this.voidHeight.getValueInt() - 1; var3--) {
         if (!mc.world.getBlockState(new BlockPosX(mc.player.getX(), (double)var3, mc.player.getZ())).isAir()
            && mc.world.getBlockState(new BlockPosX(mc.player.getX(), (double)var3, mc.player.getZ())).getBlock() != Blocks.VOID_AIR) {
            var2 = false;
            break;
         }
      }

      if (mc.player.getY() < this.height.getValue() + this.voidHeight.getValue() && var2) {
         MovementUtil.setMotionY(0.0);
      }
   }
}
