/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.mojang.brigadier.Message
 *  com.mojang.brigadier.arguments.IntegerArgumentType
 *  com.mojang.brigadier.builder.LiteralArgumentBuilder
 *  com.mojang.brigadier.context.CommandContext
 *  com.mojang.brigadier.exceptions.SimpleCommandExceptionType
 *  net.minecraft.class_2172
 *  net.minecraft.class_243
 *  net.minecraft.class_2561
 *  net.minecraft.class_2596
 *  net.minecraft.class_2828$class_2829
 */
package meteordevelopment.meteorclient.commands.commands;

import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.movement.NoFall;
import meteordevelopment.meteorclient.systems.modules.player.AntiHunger;
import net.minecraft.class_2172;
import net.minecraft.class_243;
import net.minecraft.class_2561;
import net.minecraft.class_2596;
import net.minecraft.class_2828;

public class DamageCommand
extends Command {
    private static final SimpleCommandExceptionType INVULNERABLE = new SimpleCommandExceptionType((Message)class_2561.method_43470((String)"You are invulnerable."));

    public DamageCommand() {
        super("damage", "Damages self", "dmg");
    }

    @Override
    public void build(LiteralArgumentBuilder<class_2172> builder) {
        builder.then(DamageCommand.argument("damage", IntegerArgumentType.integer((int)1, (int)7)).executes(context -> {
            int amount = IntegerArgumentType.getInteger((CommandContext)context, (String)"damage");
            if (DamageCommand.mc.field_1724.method_31549().field_7480) {
                throw INVULNERABLE.create();
            }
            this.damagePlayer(amount);
            return 1;
        }));
    }

    private void damagePlayer(int amount) {
        boolean antiHunger;
        boolean noFall = Modules.get().isActive(NoFall.class);
        if (noFall) {
            Modules.get().get(NoFall.class).toggle();
        }
        if (antiHunger = Modules.get().isActive(AntiHunger.class)) {
            Modules.get().get(AntiHunger.class).toggle();
        }
        class_243 pos = DamageCommand.mc.field_1724.method_73189();
        for (int i = 0; i < 80; ++i) {
            this.sendPositionPacket(pos.field_1352, pos.field_1351 + (double)amount + 2.1, pos.field_1350, false);
            this.sendPositionPacket(pos.field_1352, pos.field_1351 + 0.05, pos.field_1350, false);
        }
        this.sendPositionPacket(pos.field_1352, pos.field_1351, pos.field_1350, true);
        if (noFall) {
            Modules.get().get(NoFall.class).toggle();
        }
        if (antiHunger) {
            Modules.get().get(AntiHunger.class).toggle();
        }
    }

    private void sendPositionPacket(double x, double y, double z, boolean onGround) {
        DamageCommand.mc.field_1724.field_3944.method_52787((class_2596)new class_2828.class_2829(x, y, z, onGround, DamageCommand.mc.field_1724.field_5976));
    }
}

