/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.EventHandler
 *  net.minecraft.class_1297
 *  net.minecraft.class_1304
 *  net.minecraft.class_1560
 *  net.minecraft.class_2246
 *  net.minecraft.class_243
 */
package meteordevelopment.meteorclient.systems.modules.world;

import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.EnumSetting;
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.Target;
import meteordevelopment.meteorclient.utils.player.Rotations;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.class_1297;
import net.minecraft.class_1304;
import net.minecraft.class_1560;
import net.minecraft.class_2246;
import net.minecraft.class_243;

public class EndermanLook
extends Module {
    private final SettingGroup sgGeneral;
    private final Setting<Mode> lookMode;
    private final Setting<Boolean> stun;

    public EndermanLook() {
        super(Categories.World, "enderman-look", "Either looks at all Endermen or prevents you from looking at Endermen.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.lookMode = this.sgGeneral.add(((EnumSetting.Builder)((EnumSetting.Builder)((EnumSetting.Builder)new EnumSetting.Builder().name("look-mode")).description("How this module behaves.")).defaultValue(Mode.Away)).build());
        this.stun = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("stun-hostiles")).description("Automatically stares at hostile endermen to stun them in place.")).defaultValue(true)).visible(() -> this.lookMode.get() == Mode.Away)).build());
    }

    @EventHandler
    private void onTick(TickEvent.Pre event) {
        if (this.mc.field_1724.method_6118(class_1304.field_6169).method_31574(class_2246.field_10147.method_8389()) || this.mc.field_1724.method_31549().field_7477) {
            return;
        }
        for (class_1297 entity : this.mc.field_1687.method_18112()) {
            class_1560 enderman;
            if (!(entity instanceof class_1560) || !(enderman = (class_1560)entity).method_5805() || !this.mc.field_1724.method_6057((class_1297)enderman)) continue;
            switch (this.lookMode.get().ordinal()) {
                case 1: {
                    if (enderman.method_7028() && this.stun.get().booleanValue()) {
                        Rotations.rotate(Rotations.getYaw((class_1297)enderman), Rotations.getPitch((class_1297)enderman, Target.Head), -75, null);
                        break;
                    }
                    if (!this.angleCheck(enderman)) break;
                    Rotations.rotate(this.mc.field_1724.method_36454(), 90.0, -75, null);
                    break;
                }
                case 0: {
                    if (enderman.method_7028()) break;
                    Rotations.rotate(Rotations.getYaw((class_1297)enderman), Rotations.getPitch((class_1297)enderman, Target.Head), -75, null);
                }
            }
        }
    }

    private boolean angleCheck(class_1560 entity) {
        class_243 vec3d = this.mc.field_1724.method_5828(1.0f).method_1029();
        class_243 vec3d2 = new class_243(entity.method_23317() - this.mc.field_1724.method_23317(), entity.method_23320() - this.mc.field_1724.method_23320(), entity.method_23321() - this.mc.field_1724.method_23321());
        double d = vec3d2.method_1033();
        double e = vec3d.method_1026(vec3d2 = vec3d2.method_1029());
        return e > 1.0 - 0.025 / d;
    }

    public static enum Mode {
        At,
        Away;

    }
}

