/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.EventHandler
 *  net.minecraft.class_10255
 *  net.minecraft.class_1294
 *  net.minecraft.class_1657
 *  net.minecraft.class_1934
 *  net.minecraft.class_2246
 *  net.minecraft.class_238
 *  net.minecraft.class_259
 *  net.minecraft.class_2596
 *  net.minecraft.class_2680
 *  net.minecraft.class_2741
 *  net.minecraft.class_2769
 *  net.minecraft.class_2828
 *  net.minecraft.class_3545
 *  net.minecraft.class_3612
 *  net.minecraft.class_4985
 *  net.minecraft.class_5134
 *  net.minecraft.class_746
 *  org.joml.Vector2d
 */
package meteordevelopment.meteorclient.systems.modules.movement;

import meteordevelopment.meteorclient.events.entity.player.CanWalkOnFluidEvent;
import meteordevelopment.meteorclient.events.entity.player.PlayerMoveEvent;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.events.world.CollisionShapeEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixin.PlayerMoveC2SPacketAccessor;
import meteordevelopment.meteorclient.mixininterface.IVec3d;
import meteordevelopment.meteorclient.pathing.PathManagers;
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.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.movement.Flight;
import meteordevelopment.meteorclient.systems.modules.movement.speed.modes.Strafe;
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.class_10255;
import net.minecraft.class_1294;
import net.minecraft.class_1657;
import net.minecraft.class_1934;
import net.minecraft.class_2246;
import net.minecraft.class_238;
import net.minecraft.class_259;
import net.minecraft.class_2596;
import net.minecraft.class_2680;
import net.minecraft.class_2741;
import net.minecraft.class_2769;
import net.minecraft.class_2828;
import net.minecraft.class_3545;
import net.minecraft.class_3612;
import net.minecraft.class_4985;
import net.minecraft.class_5134;
import net.minecraft.class_746;
import org.joml.Vector2d;

public class Jesus
extends Module {
    private final SettingGroup sgGeneral;
    private final SettingGroup sgWater;
    private final SettingGroup sgLava;
    private final Setting<Boolean> powderSnow;
    private final Setting<Boolean> ncpBypass;
    private final Setting<Boolean> slowDown;
    private final Setting<Mode> waterMode;
    private final Setting<Boolean> dipIfBurning;
    private final Setting<Boolean> dipOnSneakWater;
    private final Setting<Boolean> dipOnFallWater;
    private final Setting<Integer> dipFallHeightWater;
    private final Setting<Mode> lavaMode;
    private final Setting<Boolean> dipIfFireResistant;
    private final Setting<Boolean> dipOnSneakLava;
    private final Setting<Boolean> dipOnFallLava;
    private final Setting<Integer> dipFallHeightLava;
    private int ascending;
    private int swimmingTicks;
    private boolean prePathManagerWalkOnWater;
    private boolean prePathManagerWalkOnLava;
    public boolean isInBubbleColumn;

    public Jesus() {
        super(Categories.Movement, "jesus", "Walk on liquids and powder snow like Jesus.");
        this.sgGeneral = this.settings.createGroup("General");
        this.sgWater = this.settings.createGroup("Water");
        this.sgLava = this.settings.createGroup("Lava");
        this.powderSnow = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("powder-snow")).description("Walk on powder snow.")).defaultValue(true)).build());
        this.ncpBypass = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("ncp-bypass")).description("Whether to apply a bypass for NCP.")).defaultValue(false)).build());
        this.slowDown = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("slow-down")).description("Further movement option to try bypassing NCP")).defaultValue(false)).visible(this.ncpBypass::get)).build());
        this.waterMode = this.sgWater.add(((EnumSetting.Builder)((EnumSetting.Builder)((EnumSetting.Builder)new EnumSetting.Builder().name("mode")).description("How to treat the water.")).defaultValue(Mode.Solid)).build());
        this.dipIfBurning = this.sgWater.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("dip-if-burning")).description("Lets you go into the water when you are burning.")).defaultValue(true)).visible(() -> this.waterMode.get() == Mode.Solid)).build());
        this.dipOnSneakWater = this.sgWater.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("dip-on-sneak")).description("Lets you go into the water when your sneak key is held.")).defaultValue(true)).visible(() -> this.waterMode.get() == Mode.Solid)).build());
        this.dipOnFallWater = this.sgWater.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("dip-on-fall")).description("Lets you go into the water when you fall over a certain height.")).defaultValue(true)).visible(() -> this.waterMode.get() == Mode.Solid)).build());
        this.dipFallHeightWater = this.sgWater.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("dip-fall-height")).description("The fall height at which you will go into the water.")).defaultValue(4)).range(1, 255).sliderRange(3, 20).visible(() -> this.waterMode.get() == Mode.Solid && this.dipOnFallWater.get() != false)).build());
        this.lavaMode = this.sgLava.add(((EnumSetting.Builder)((EnumSetting.Builder)((EnumSetting.Builder)new EnumSetting.Builder().name("mode")).description("How to treat the lava.")).defaultValue(Mode.Solid)).build());
        this.dipIfFireResistant = this.sgLava.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("dip-if-resistant")).description("Lets you go into the lava if you have Fire Resistance effect.")).defaultValue(true)).visible(() -> this.lavaMode.get() == Mode.Solid)).build());
        this.dipOnSneakLava = this.sgLava.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("dip-on-sneak")).description("Lets you go into the lava when your sneak key is held.")).defaultValue(true)).visible(() -> this.lavaMode.get() == Mode.Solid)).build());
        this.dipOnFallLava = this.sgLava.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("dip-on-fall")).description("Lets you go into the lava when you fall over a certain height.")).defaultValue(true)).visible(() -> this.lavaMode.get() == Mode.Solid)).build());
        this.dipFallHeightLava = this.sgLava.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("dip-fall-height")).description("The fall height at which you will go into the lava.")).defaultValue(4)).range(1, 255).sliderRange(3, 20).visible(() -> this.lavaMode.get() == Mode.Solid && this.dipOnFallLava.get() != false)).build());
        this.ascending = 10;
        this.swimmingTicks = 0;
        this.isInBubbleColumn = false;
    }

    @Override
    public void onActivate() {
        this.prePathManagerWalkOnWater = PathManagers.get().getSettings().getWalkOnWater().get();
        this.prePathManagerWalkOnLava = PathManagers.get().getSettings().getWalkOnLava().get();
        PathManagers.get().getSettings().getWalkOnWater().set(this.waterMode.get() == Mode.Solid);
        PathManagers.get().getSettings().getWalkOnLava().set(this.lavaMode.get() == Mode.Solid);
    }

    @Override
    public void onDeactivate() {
        PathManagers.get().getSettings().getWalkOnWater().set(this.prePathManagerWalkOnWater);
        PathManagers.get().getSettings().getWalkOnLava().set(this.prePathManagerWalkOnLava);
    }

    @EventHandler
    private void onTick(TickEvent.Post event) {
        class_746 movingEntity;
        boolean bubbleColumn = this.isInBubbleColumn;
        this.isInBubbleColumn = false;
        if (this.mc.field_1724.method_20232()) {
            return;
        }
        if (this.mc.field_1724.method_5799() && !this.waterShouldBeSolid()) {
            return;
        }
        if (this.mc.field_1724.method_5771() && !this.lavaShouldBeSolid()) {
            return;
        }
        Object object = movingEntity = this.mc.field_1724.method_5765() ? this.mc.field_1724.method_5854() : this.mc.field_1724;
        if (bubbleColumn) {
            if (this.mc.field_1690.field_1903.method_1434() && movingEntity.method_18798().method_10214() < 0.11) {
                ((IVec3d)movingEntity.method_18798()).meteor$setY(0.11);
            }
            return;
        }
        if (movingEntity.method_5799() || movingEntity.method_5771()) {
            ((IVec3d)movingEntity.method_18798()).meteor$setY(0.11);
            this.ascending = 0;
            return;
        }
        class_2680 blockBelowState = this.mc.field_1687.method_8320(movingEntity.method_24515().method_10074());
        boolean waterLogged = (Boolean)blockBelowState.method_61767((class_2769)class_2741.field_12508, (Comparable)Boolean.valueOf(false));
        if (this.ascending == 0) {
            ((IVec3d)movingEntity.method_18798()).meteor$setY(0.11);
        } else if (this.ascending == 1 && (blockBelowState.method_26204() == class_2246.field_10382 || blockBelowState.method_26204() == class_2246.field_10164 || waterLogged)) {
            ((IVec3d)movingEntity.method_18798()).meteor$setY(0.0);
        }
        ++this.ascending;
    }

    @EventHandler
    private void onCanWalkOnFluid(CanWalkOnFluidEvent event) {
        if (this.mc.field_1724 != null && this.mc.field_1724.method_5681()) {
            return;
        }
        if ((event.fluidState.method_15772() == class_3612.field_15910 || event.fluidState.method_15772() == class_3612.field_15909) && this.waterShouldBeSolid()) {
            event.walkOnFluid = true;
        } else if ((event.fluidState.method_15772() == class_3612.field_15908 || event.fluidState.method_15772() == class_3612.field_15907) && this.lavaShouldBeSolid()) {
            event.walkOnFluid = true;
        }
    }

    @EventHandler
    private void onFluidCollisionShape(CollisionShapeEvent event) {
        if (event.state.method_26227().method_15769()) {
            return;
        }
        if ((event.state.method_26204() == class_2246.field_10382 || event.state.method_26227().method_15772() == class_3612.field_15910) && !this.mc.field_1724.method_5799() && this.waterShouldBeSolid() && (double)event.pos.method_10264() <= this.mc.field_1724.method_23318() - 1.0) {
            event.shape = class_259.method_1077();
        } else if (event.state.method_26204() == class_2246.field_10164 && !this.mc.field_1724.method_5771() && this.lavaShouldBeSolid() && (this.isLavaDangerous() || (double)event.pos.method_10264() <= this.mc.field_1724.method_23318() - 1.0)) {
            event.shape = class_259.method_1077();
        }
    }

    @EventHandler
    private void onSendPacket(PacketEvent.Send event) {
        boolean shouldWork;
        class_2596<?> class_25962 = event.packet;
        if (!(class_25962 instanceof class_2828)) {
            return;
        }
        class_2828 packet = (class_2828)class_25962;
        if (this.mc.field_1724.method_5799() && !this.waterShouldBeSolid()) {
            return;
        }
        if (this.mc.field_1724.method_5771() && !this.lavaShouldBeSolid()) {
            return;
        }
        if (!this.ncpBypass.get().booleanValue()) {
            return;
        }
        class_3545<Boolean, Boolean> overLiquid = this.isOverLiquid();
        boolean bl = shouldWork = (Boolean)overLiquid.method_15442() != false && this.waterShouldBeSolid() || (Boolean)overLiquid.method_15441() != false && this.lavaShouldBeSolid();
        if (this.mc.field_1724.method_5799() || this.mc.field_1724.method_5771() || this.mc.field_1724.field_6017 > 3.0 || !shouldWork) {
            return;
        }
        ((PlayerMoveC2SPacketAccessor)packet).meteor$setOnGround(false);
        if (!this.mc.field_1724.method_24828() || !packet.method_36171()) {
            return;
        }
        ((PlayerMoveC2SPacketAccessor)packet).meteor$setY(packet.method_12268(0.0) - (0.02 + 1.0E-4 * (double)this.swimmingTicks));
    }

    @EventHandler
    private void onMoveEvent(PlayerMoveEvent event) {
        boolean lava;
        if (!this.ncpBypass.get().booleanValue()) {
            return;
        }
        class_3545<Boolean, Boolean> overLiquid = this.isOverLiquid();
        boolean water = (Boolean)overLiquid.method_15442() != false && this.waterShouldBeSolid();
        boolean bl = lava = (Boolean)overLiquid.method_15441() != false && this.lavaShouldBeSolid();
        if (!water && !lava) {
            this.swimmingTicks = 0;
            return;
        }
        if (++this.swimmingTicks < 15) {
            if (this.mc.field_1724.method_24828()) {
                Vector2d vel = Strafe.transformStrafe(PlayerUtils.isMoving() ? 0.2873 : 0.0);
                ((IVec3d)event.movement).meteor$setXZ(vel.x, vel.y);
            }
            return;
        }
        this.swimmingTicks = 0;
        if (this.slowDown.get().booleanValue()) {
            ((IVec3d)event.movement).meteor$setXZ(0.0, 0.0);
        }
        ((IVec3d)this.mc.field_1724.method_18798()).meteor$setY(0.08);
    }

    private boolean waterShouldBeSolid() {
        if (EntityUtils.getGameMode((class_1657)this.mc.field_1724) == class_1934.field_9219 || this.mc.field_1724.method_31549().field_7479) {
            return false;
        }
        if (this.mc.field_1724.method_5854() != null && this.mc.field_1724.method_5854() instanceof class_10255) {
            return false;
        }
        if (Modules.get().get(Flight.class).isActive()) {
            return false;
        }
        if (this.dipIfBurning.get().booleanValue() && this.mc.field_1724.method_5809()) {
            return false;
        }
        if (this.dipOnSneakWater.get().booleanValue() && this.mc.field_1690.field_1832.method_1434()) {
            return false;
        }
        if (this.dipOnFallWater.get().booleanValue() && this.mc.field_1724.field_6017 > (double)this.dipFallHeightWater.get().intValue()) {
            return false;
        }
        return this.waterMode.get() == Mode.Solid;
    }

    private boolean lavaShouldBeSolid() {
        if (EntityUtils.getGameMode((class_1657)this.mc.field_1724) == class_1934.field_9219 || this.mc.field_1724.method_31549().field_7479) {
            return false;
        }
        if (this.mc.field_1724.method_5854() != null && this.mc.field_1724.method_5854() instanceof class_4985) {
            return false;
        }
        if (this.isLavaDangerous() && this.lavaMode.get() == Mode.Solid) {
            return true;
        }
        if (this.dipOnSneakLava.get().booleanValue() && this.mc.field_1690.field_1832.method_1434()) {
            return false;
        }
        if (this.dipOnFallLava.get().booleanValue() && this.mc.field_1724.field_6017 > (double)this.dipFallHeightLava.get().intValue()) {
            return false;
        }
        return this.lavaMode.get() == Mode.Solid;
    }

    private boolean isLavaDangerous() {
        if (!this.dipIfFireResistant.get().booleanValue()) {
            return true;
        }
        return !this.mc.field_1724.method_6059(class_1294.field_5918) || !((double)this.mc.field_1724.method_6112(class_1294.field_5918).method_5584() > 300.0 * this.mc.field_1724.method_45325(class_5134.field_51579));
    }

    private class_3545<Boolean, Boolean> isOverLiquid() {
        class_238 box = this.mc.field_1724.method_5765() ? this.mc.field_1724.method_5829().method_991(this.mc.field_1724.method_5854().method_5829()) : this.mc.field_1724.method_5829();
        class_2680[] states = (class_2680[])this.mc.field_1687.method_29546(box.method_989(0.0, -0.01, 0.0)).toArray(class_2680[]::new);
        boolean water = false;
        boolean lava = false;
        boolean foundSolid = false;
        for (class_2680 state : states) {
            if (state.method_26204() == class_2246.field_10382 || state.method_26227().method_15772() == class_3612.field_15910) {
                water = true;
                continue;
            }
            if (state.method_26204() == class_2246.field_10164) {
                lava = true;
                continue;
            }
            if (state.method_26215()) continue;
            foundSolid = true;
            break;
        }
        return new class_3545((Object)(water && !foundSolid ? 1 : 0), (Object)(lava && !foundSolid ? 1 : 0));
    }

    public boolean canWalkOnPowderSnow() {
        return this.isActive() && this.powderSnow.get() != false;
    }

    public static enum Mode {
        Solid,
        Ignore;

    }
}

