/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.EventHandler
 *  net.minecraft.class_243
 *  net.minecraft.class_2596
 *  net.minecraft.class_2743
 */
package meteordevelopment.meteorclient.systems.modules.movement;

import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixin.EntityVelocityUpdateS2CPacketAccessor;
import meteordevelopment.meteorclient.mixininterface.IVec3d;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.DoubleSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.class_243;
import net.minecraft.class_2596;
import net.minecraft.class_2743;

public class Velocity
extends Module {
    private final SettingGroup sgGeneral;
    public final Setting<Boolean> knockback;
    public final Setting<Double> knockbackHorizontal;
    public final Setting<Double> knockbackVertical;
    public final Setting<Boolean> explosions;
    public final Setting<Double> explosionsHorizontal;
    public final Setting<Double> explosionsVertical;
    public final Setting<Boolean> liquids;
    public final Setting<Double> liquidsHorizontal;
    public final Setting<Double> liquidsVertical;
    public final Setting<Boolean> entityPush;
    public final Setting<Double> entityPushAmount;
    public final Setting<Boolean> blocks;
    public final Setting<Boolean> sinking;
    public final Setting<Boolean> fishing;

    public Velocity() {
        super(Categories.Movement, "velocity", "Prevents you from being moved by external forces.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.knockback = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("knockback")).description("Modifies the amount of knockback you take from attacks.")).defaultValue(true)).build());
        this.knockbackHorizontal = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("knockback-horizontal")).description("How much horizontal knockback you will take.")).defaultValue(0.0).sliderMax(1.0).visible(this.knockback::get)).build());
        this.knockbackVertical = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("knockback-vertical")).description("How much vertical knockback you will take.")).defaultValue(0.0).sliderMax(1.0).visible(this.knockback::get)).build());
        this.explosions = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("explosions")).description("Modifies your knockback from explosions.")).defaultValue(true)).build());
        this.explosionsHorizontal = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("explosions-horizontal")).description("How much velocity you will take from explosions horizontally.")).defaultValue(0.0).sliderMax(1.0).visible(this.explosions::get)).build());
        this.explosionsVertical = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("explosions-vertical")).description("How much velocity you will take from explosions vertically.")).defaultValue(0.0).sliderMax(1.0).visible(this.explosions::get)).build());
        this.liquids = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("liquids")).description("Modifies the amount you are pushed by flowing liquids.")).defaultValue(true)).build());
        this.liquidsHorizontal = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("liquids-horizontal")).description("How much velocity you will take from liquids horizontally.")).defaultValue(0.0).sliderMax(1.0).visible(this.liquids::get)).build());
        this.liquidsVertical = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("liquids-vertical")).description("How much velocity you will take from liquids vertically.")).defaultValue(0.0).sliderMax(1.0).visible(this.liquids::get)).build());
        this.entityPush = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("entity-push")).description("Modifies the amount you are pushed by entities.")).defaultValue(true)).build());
        this.entityPushAmount = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("entity-push-amount")).description("How much you will be pushed.")).defaultValue(0.0).sliderMax(1.0).visible(this.entityPush::get)).build());
        this.blocks = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("blocks")).description("Prevents you from being pushed out of blocks.")).defaultValue(true)).build());
        this.sinking = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("sinking")).description("Prevents you from sinking in liquids.")).defaultValue(false)).build());
        this.fishing = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("fishing")).description("Prevents you from being pulled by fishing rods.")).defaultValue(false)).build());
    }

    @EventHandler
    private void onTick(TickEvent.Post event) {
        if (!this.sinking.get().booleanValue()) {
            return;
        }
        if (this.mc.field_1690.field_1903.method_1434() || this.mc.field_1690.field_1832.method_1434()) {
            return;
        }
        if ((this.mc.field_1724.method_5799() || this.mc.field_1724.method_5771()) && this.mc.field_1724.method_18798().field_1351 < 0.0) {
            ((IVec3d)this.mc.field_1724.method_18798()).meteor$setY(0.0);
        }
    }

    @EventHandler
    private void onPacketReceive(PacketEvent.Receive event) {
        class_2743 packet;
        class_2596<?> class_25962;
        if (this.knockback.get().booleanValue() && (class_25962 = event.packet) instanceof class_2743 && (packet = (class_2743)class_25962).method_11818() == this.mc.field_1724.method_5628()) {
            double velX = (packet.method_73085().method_10216() - this.mc.field_1724.method_18798().field_1352) * this.knockbackHorizontal.get();
            double velY = (packet.method_73085().method_10214() - this.mc.field_1724.method_18798().field_1351) * this.knockbackVertical.get();
            double velZ = (packet.method_73085().method_10215() - this.mc.field_1724.method_18798().field_1350) * this.knockbackHorizontal.get();
            ((EntityVelocityUpdateS2CPacketAccessor)packet).meteor$setVelocity(new class_243(velX + this.mc.field_1724.method_18798().field_1352, velY + this.mc.field_1724.method_18798().field_1351, velZ + this.mc.field_1724.method_18798().field_1350));
        }
    }

    public double getHorizontal(Setting<Double> setting) {
        return this.isActive() ? setting.get() : 1.0;
    }

    public double getVertical(Setting<Double> setting) {
        return this.isActive() ? setting.get() : 1.0;
    }
}

