/*
 * 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.builder.RequiredArgumentBuilder
 *  com.mojang.brigadier.context.CommandContext
 *  com.mojang.brigadier.exceptions.CommandSyntaxException
 *  com.mojang.brigadier.exceptions.SimpleCommandExceptionType
 *  net.minecraft.class_1799
 *  net.minecraft.class_2172
 *  net.minecraft.class_2287
 *  net.minecraft.class_2561
 *  net.minecraft.class_2596
 *  net.minecraft.class_2873
 *  net.minecraft.class_7157
 */
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.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import net.minecraft.class_1799;
import net.minecraft.class_2172;
import net.minecraft.class_2287;
import net.minecraft.class_2561;
import net.minecraft.class_2596;
import net.minecraft.class_2873;
import net.minecraft.class_7157;

public class GiveCommand
extends Command {
    private static final SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType((Message)class_2561.method_43470((String)"You must be in creative mode to use this."));
    private static final SimpleCommandExceptionType NO_SPACE = new SimpleCommandExceptionType((Message)class_2561.method_43470((String)"No space in hotbar."));

    public GiveCommand() {
        super("give", "Gives you any item.", new String[0]);
    }

    @Override
    public void build(LiteralArgumentBuilder<class_2172> builder) {
        builder.then(((RequiredArgumentBuilder)GiveCommand.argument("item", class_2287.method_9776((class_7157)REGISTRY_ACCESS)).executes(context -> {
            if (!GiveCommand.mc.field_1724.method_31549().field_7477) {
                throw NOT_IN_CREATIVE.create();
            }
            class_1799 item = class_2287.method_9777((CommandContext)context, (String)"item").method_9781(1, false);
            this.giveItem(item);
            return 1;
        })).then(GiveCommand.argument("number", IntegerArgumentType.integer((int)1, (int)99)).executes(context -> {
            if (!GiveCommand.mc.field_1724.method_31549().field_7477) {
                throw NOT_IN_CREATIVE.create();
            }
            class_1799 item = class_2287.method_9777((CommandContext)context, (String)"item").method_9781(IntegerArgumentType.getInteger((CommandContext)context, (String)"number"), true);
            this.giveItem(item);
            return 1;
        })));
    }

    private void giveItem(class_1799 item) throws CommandSyntaxException {
        FindItemResult fir = InvUtils.find(class_1799::method_7960, 0, 8);
        if (!fir.found()) {
            throw NO_SPACE.create();
        }
        mc.method_1562().method_52787((class_2596)new class_2873(36 + fir.slot(), item));
        GiveCommand.mc.field_1724.field_7498.method_7611(36 + fir.slot()).method_53512(item);
    }
}

