package net.minecraft.server.commands;

import net.minecraft.network.chat.TranslatableComponent;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.resources.ResourceLocation;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import net.minecraft.commands.synchronization.SuggestionProviders;
import com.mojang.brigadier.arguments.ArgumentType;
import net.minecraft.commands.arguments.ResourceLocationArgument;
import net.minecraft.commands.Commands;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;

public class LocateBiomeCommand {
    public static final DynamicCommandExceptionType ERROR_INVALID_BIOME;
    private static final DynamicCommandExceptionType ERROR_BIOME_NOT_FOUND;
    
    public static void register(final CommandDispatcher<CommandSourceStack> commandDispatcher) {
        commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("locatebiome").requires(cz -> cz.hasPermission(2))).then(Commands.argument("biome", (com.mojang.brigadier.arguments.ArgumentType<Object>)ResourceLocationArgument.id()).suggests((SuggestionProvider)SuggestionProviders.AVAILABLE_BIOMES).executes(commandContext -> locateBiome((CommandSourceStack)commandContext.getSource(), (ResourceLocation)commandContext.getArgument("biome", (Class)ResourceLocation.class)))));
    }
    
    private static int locateBiome(final CommandSourceStack cz, final ResourceLocation uh) throws CommandSyntaxException {
        final Biome bre3 = Registry.BIOME.getOptional(uh).<Throwable>orElseThrow(() -> LocateBiomeCommand.ERROR_INVALID_BIOME.create(uh));
        final BlockPos fu4 = new BlockPos(cz.getPosition());
        final BlockPos fu5 = cz.getLevel().findNearestBiome(bre3, fu4, 6400, 8);
        final String string6 = uh.toString();
        if (fu5 == null) {
            throw LocateBiomeCommand.ERROR_BIOME_NOT_FOUND.create(string6);
        }
        return LocateCommand.showLocateResult(cz, string6, fu4, fu5, "commands.locatebiome.success");
    }
    
    static {
        final TranslatableComponent translatableComponent;
        ERROR_INVALID_BIOME = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("commands.locatebiome.invalid", new Object[] { object });
            return translatableComponent;
        });
        final TranslatableComponent translatableComponent2;
        ERROR_BIOME_NOT_FOUND = new DynamicCommandExceptionType(object -> {
            new TranslatableComponent("commands.locatebiome.notFound", new Object[] { object });
            return translatableComponent2;
        });
    }
}
