/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.EventHandler
 *  net.minecraft.class_1297
 *  net.minecraft.class_1309
 *  net.minecraft.class_1743
 *  net.minecraft.class_1799
 *  net.minecraft.class_3489
 */
package meteordevelopment.meteorclient.systems.modules.combat;

import meteordevelopment.meteorclient.events.entity.player.AttackEntityEvent;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.EnumSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.entity.DamageUtils;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.class_1297;
import net.minecraft.class_1309;
import net.minecraft.class_1743;
import net.minecraft.class_1799;
import net.minecraft.class_3489;

public class AutoWeapon
extends Module {
    private final SettingGroup sgGeneral;
    private final Setting<Weapon> weapon;
    private final Setting<Integer> threshold;
    private final Setting<Boolean> antiBreak;

    public AutoWeapon() {
        super(Categories.PvP, "auto-weapon", "Finds the best weapon to use in your hotbar.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.weapon = this.sgGeneral.add(((EnumSetting.Builder)((EnumSetting.Builder)((EnumSetting.Builder)new EnumSetting.Builder().name("weapon")).description("What type of weapon to use.")).defaultValue(Weapon.Sword)).build());
        this.threshold = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("threshold")).description("If the non-preferred weapon produces this much damage this will favor it over your preferred weapon.")).defaultValue(4)).build());
        this.antiBreak = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("anti-break")).description("Prevents you from breaking your weapon.")).defaultValue(false)).build());
    }

    @EventHandler
    private void onAttack(AttackEntityEvent event) {
        class_1297 class_12972 = event.entity;
        if (class_12972 instanceof class_1309) {
            class_1309 livingEntity = (class_1309)class_12972;
            InvUtils.swap(this.getBestWeapon(livingEntity), false);
        }
    }

    private int getBestWeapon(class_1309 target) {
        int slotS = this.mc.field_1724.method_31548().method_67532();
        int slotA = this.mc.field_1724.method_31548().method_67532();
        double damageS = 0.0;
        double damageA = 0.0;
        for (int i = 0; i < 9; ++i) {
            double currentDamageA;
            class_1799 stack = this.mc.field_1724.method_31548().method_5438(i);
            if (stack.method_31573(class_3489.field_42611) && (!this.antiBreak.get().booleanValue() || stack.method_7936() - stack.method_7919() > 10)) {
                double currentDamageS = DamageUtils.getAttackDamage((class_1309)this.mc.field_1724, (class_1297)target, stack);
                if (!(currentDamageS > damageS)) continue;
                damageS = currentDamageS;
                slotS = i;
                continue;
            }
            if (!(stack.method_7909() instanceof class_1743) || this.antiBreak.get().booleanValue() && stack.method_7936() - stack.method_7919() <= 10 || !((currentDamageA = (double)DamageUtils.getAttackDamage((class_1309)this.mc.field_1724, (class_1297)target, stack)) > damageA)) continue;
            damageA = currentDamageA;
            slotA = i;
        }
        if (this.weapon.get() == Weapon.Sword && (double)this.threshold.get().intValue() > damageA - damageS) {
            return slotS;
        }
        if (this.weapon.get() == Weapon.Axe && (double)this.threshold.get().intValue() > damageS - damageA) {
            return slotA;
        }
        if (this.weapon.get() == Weapon.Sword && (double)this.threshold.get().intValue() < damageA - damageS) {
            return slotA;
        }
        if (this.weapon.get() == Weapon.Axe && (double)this.threshold.get().intValue() < damageS - damageA) {
            return slotS;
        }
        return this.mc.field_1724.method_31548().method_67532();
    }

    public static enum Weapon {
        Sword,
        Axe;

    }
}

