package net.minecraft.commands.arguments;

import net.minecraft.Util;
import com.google.common.collect.Maps;
import java.util.Arrays;
import net.minecraft.network.chat.TranslatableComponent;
import com.mojang.brigadier.Message;
import net.minecraft.world.entity.EquipmentSlot;
import java.util.HashMap;
import net.minecraft.commands.SharedSuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import java.util.concurrent.CompletableFuture;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.StringReader;
import net.minecraft.commands.CommandSourceStack;
import com.mojang.brigadier.context.CommandContext;
import java.util.Map;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import java.util.Collection;
import com.mojang.brigadier.arguments.ArgumentType;

public class SlotArgument implements ArgumentType<Integer> {
    private static final Collection<String> EXAMPLES;
    private static final DynamicCommandExceptionType ERROR_UNKNOWN_SLOT;
    private static final Map<String, Integer> SLOTS;
    
    public static SlotArgument slot() {
        return new SlotArgument();
    }
    
    public static int getSlot(final CommandContext<CommandSourceStack> commandContext, final String string) {
        return (int)commandContext.getArgument(string, (Class)Integer.class);
    }
    
    public Integer parse(final StringReader stringReader) throws CommandSyntaxException {
        final String string3 = stringReader.readUnquotedString();
        if (!SlotArgument.SLOTS.containsKey(string3)) {
            throw SlotArgument.ERROR_UNKNOWN_SLOT.create(string3);
        }
        return SlotArgument.SLOTS.get(string3);
    }
    
    public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> commandContext, final SuggestionsBuilder suggestionsBuilder) {
        return SharedSuggestionProvider.suggest(SlotArgument.SLOTS.keySet(), suggestionsBuilder);
    }
    
    public Collection<String> getExamples() {
        return SlotArgument.EXAMPLES;
    }
    
    static {
        EXAMPLES = Arrays.<String>asList("container.5", "12", "weapon");
        final TranslatableComponent translatableComponent;
        ERROR_UNKNOWN_SLOT = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("slot.unknown", new Object[] { object });
            return translatableComponent;
        });
        int integer2;
        int integer3;
        int integer4;
        int integer5;
        int integer6;
        int integer7;
        SLOTS = Util.<Map<String, Integer>>make(Maps.newHashMap(), hashMap -> {
            for (integer2 = 0; integer2 < 54; ++integer2) {
                hashMap.put("container." + integer2, integer2);
            }
            for (integer3 = 0; integer3 < 9; ++integer3) {
                hashMap.put("hotbar." + integer3, integer3);
            }
            for (integer4 = 0; integer4 < 27; ++integer4) {
                hashMap.put("inventory." + integer4, 9 + integer4);
            }
            for (integer5 = 0; integer5 < 27; ++integer5) {
                hashMap.put("enderchest." + integer5, 200 + integer5);
            }
            for (integer6 = 0; integer6 < 8; ++integer6) {
                hashMap.put("villager." + integer6, 300 + integer6);
            }
            for (integer7 = 0; integer7 < 15; ++integer7) {
                hashMap.put("horse." + integer7, 500 + integer7);
            }
            hashMap.put("weapon", 98);
            hashMap.put("weapon.mainhand", 98);
            hashMap.put("weapon.offhand", 99);
            hashMap.put("armor.head", 100 + EquipmentSlot.HEAD.getIndex());
            hashMap.put("armor.chest", 100 + EquipmentSlot.CHEST.getIndex());
            hashMap.put("armor.legs", 100 + EquipmentSlot.LEGS.getIndex());
            hashMap.put("armor.feet", 100 + EquipmentSlot.FEET.getIndex());
            hashMap.put("horse.saddle", 400);
            hashMap.put("horse.armor", 401);
            hashMap.put("horse.chest", 499);
        });
    }
}
