package net.minecraft.commands.arguments;

import java.util.Arrays;
import net.minecraft.network.chat.TranslatableComponent;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.StringReader;
import net.minecraft.world.level.storage.loot.PredicateManager;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.Recipe;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.advancements.Advancement;
import net.minecraft.commands.CommandSourceStack;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import java.util.Collection;
import net.minecraft.resources.ResourceLocation;
import com.mojang.brigadier.arguments.ArgumentType;

public class ResourceLocationArgument implements ArgumentType<ResourceLocation> {
    private static final Collection<String> EXAMPLES;
    private static final DynamicCommandExceptionType ERROR_UNKNOWN_ADVANCEMENT;
    private static final DynamicCommandExceptionType ERROR_UNKNOWN_RECIPE;
    private static final DynamicCommandExceptionType ERROR_UNKNOWN_PREDICATE;
    
    public static ResourceLocationArgument id() {
        return new ResourceLocationArgument();
    }
    
    public static Advancement getAdvancement(final CommandContext<CommandSourceStack> commandContext, final String string) throws CommandSyntaxException {
        final ResourceLocation sm3 = (ResourceLocation)commandContext.getArgument(string, (Class)ResourceLocation.class);
        final Advancement u4 = ((CommandSourceStack)commandContext.getSource()).getServer().getAdvancements().getAdvancement(sm3);
        if (u4 == null) {
            throw ResourceLocationArgument.ERROR_UNKNOWN_ADVANCEMENT.create(sm3);
        }
        return u4;
    }
    
    public static Recipe<?> getRecipe(final CommandContext<CommandSourceStack> commandContext, final String string) throws CommandSyntaxException {
        final RecipeManager bgx3 = ((CommandSourceStack)commandContext.getSource()).getServer().getRecipeManager();
        final ResourceLocation sm4 = (ResourceLocation)commandContext.getArgument(string, (Class)ResourceLocation.class);
        return bgx3.byKey(sm4).<Throwable>orElseThrow(() -> ResourceLocationArgument.ERROR_UNKNOWN_RECIPE.create(sm4));
    }
    
    public static LootItemCondition getPredicate(final CommandContext<CommandSourceStack> commandContext, final String string) throws CommandSyntaxException {
        final ResourceLocation sm3 = (ResourceLocation)commandContext.getArgument(string, (Class)ResourceLocation.class);
        final PredicateManager csc4 = ((CommandSourceStack)commandContext.getSource()).getServer().getPredicateManager();
        final LootItemCondition cum5 = csc4.get(sm3);
        if (cum5 == null) {
            throw ResourceLocationArgument.ERROR_UNKNOWN_PREDICATE.create(sm3);
        }
        return cum5;
    }
    
    public static ResourceLocation getId(final CommandContext<CommandSourceStack> commandContext, final String string) {
        return (ResourceLocation)commandContext.getArgument(string, (Class)ResourceLocation.class);
    }
    
    public ResourceLocation parse(final StringReader stringReader) throws CommandSyntaxException {
        return ResourceLocation.read(stringReader);
    }
    
    public Collection<String> getExamples() {
        return ResourceLocationArgument.EXAMPLES;
    }
    
    static {
        EXAMPLES = Arrays.<String>asList("foo", "foo:bar", "012");
        final TranslatableComponent translatableComponent;
        ERROR_UNKNOWN_ADVANCEMENT = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("advancement.advancementNotFound", new Object[] { object });
            return translatableComponent;
        });
        final TranslatableComponent translatableComponent2;
        ERROR_UNKNOWN_RECIPE = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("recipe.notFound", new Object[] { object });
            return translatableComponent2;
        });
        final TranslatableComponent translatableComponent3;
        ERROR_UNKNOWN_PREDICATE = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("predicate.unknown", new Object[] { object });
            return translatableComponent3;
        });
    }
}
