package info.u_team.u_team_core.intern.command.uteamcore;

import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.exceptions.*;

import info.u_team.u_team_core.util.MathUtil;
import net.minecraft.command.*;
import net.minecraft.command.arguments.ResourceLocationArgument;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.*;
import net.minecraft.util.text.*;
import net.minecraft.util.text.event.*;
import net.minecraftforge.registries.GameData;

public class LocateStructureSubCommand {
	
	private static final SimpleCommandExceptionType FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslationTextComponent("commands.uteamcore.locatestructure.failed"));
	
	public static ArgumentBuilder<CommandSource, ?> register() {
		return Commands.literal("locatestructure") //
				.requires(source -> source.hasPermissionLevel(2)) //
				.then(Commands.argument("structure", ResourceLocationArgument.resourceLocation()) //
						.suggests((context, builder) -> ISuggestionProvider.suggest(GameData.getStructureFeatures().keySet().stream().map(ResourceLocation::toString), builder)) //
						.executes(context -> locateStructure(context.getSource(), context.getArgument("structure", ResourceLocation.class))));
	}
	
	private static int locateStructure(CommandSource source, ResourceLocation structureName) throws CommandSyntaxException {
		final BlockPos pos = new BlockPos(source.getPos());
		
		final BlockPos foundPos = source.getWorld().findNearestStructure(structureName.getPath(), pos, 100, false);
		
		if (foundPos == null) {
			throw FAILED_EXCEPTION.create();
		}
		
		final int distance = MathHelper.floor(MathUtil.getPlaneDistance(pos.getX(), pos.getZ(), foundPos.getX(), foundPos.getZ()));
		
		final ITextComponent text = TextComponentUtils.wrapInSquareBrackets(new TranslationTextComponent("chat.coordinates", foundPos.getX(), "~", foundPos.getZ())).applyTextStyle((style) -> {
			style.setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tp @s " + foundPos.getX() + " ~ " + foundPos.getZ())).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.coordinates.tooltip")));
		});
		source.sendFeedback(new TranslationTextComponent("commands.uteamcore.locatestructure.success", structureName, text, distance), false);
		
		return distance;
	}
}

@@ -148,57 +148,32 @@
 ons.
-*;%0A%0Aimport info.u_team.u_team_core.util.MathUtil;
+CommandSyntaxException;%0A
 %0Aimp
@@ -291,29 +291,34 @@
 aft.
-util.ResourceLocation
+command.impl.LocateCommand
 ;%0Aim
@@ -345,14 +345,24 @@
 til.
-math.*
+ResourceLocation
 ;%0Aim
@@ -384,59 +384,45 @@
 aft.
-util.text.*;%0Aimport net.minecraft.util.text.event.*
+world.gen.feature.structure.Structure
 ;%0Aim
@@ -456,24 +456,31 @@
 istries.
-GameData
+ForgeRegistries
 ;%0A%0Apubli
@@ -521,185 +521,8 @@
 %7B%0A%09%0A
-%09private static final SimpleCommandExceptionType FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslationTextComponent(%22commands.uteamcore.locatestructure.failed%22));%0A%09%0A
 %09pub
@@ -843,46 +843,50 @@
 est(
-GameData.getStructureFeatures().keySet
+ForgeRegistries.STRUCTURE_FEATURES.getKeys
 ().s
@@ -1003,16 +1003,60 @@
 urce(), 
+ForgeRegistries.STRUCTURE_FEATURES.getValue(
 context.
@@ -1106,16 +1106,17 @@
 lass))))
+)
 ;%0A%09%7D%0A%09%0A%09
@@ -1172,32 +1172,28 @@
 source, 
-ResourceLocation
+Structure%3C?%3E
  structu
@@ -1194,20 +1194,16 @@
 tructure
-Name
 ) throws
@@ -1234,1002 +1234,62 @@
 %7B%0A%09%09
-final BlockPos pos = new BlockPos(source.getPos());%0A%09%09%0A%09%09final BlockPos foundPos = source.getWorld().findNearestStructure(structureName.getPath(), pos, 100, false);%0A%09%09%0A%09%09if (foundPos == null) %7B%0A%09%09%09throw FAILED_EXCEPTION.create();%0A%09%09%7D%0A%09%09%0A%09%09final int distance = MathHelper.floor(MathUtil.getPlaneDistance(pos.getX(), pos.getZ(), foundPos.getX(), foundPos.getZ()));%0A%09%09%0A%09%09final ITextComponent text = TextComponentUtils.wrapInSquareBrackets(new TranslationTextComponent(%22chat.coordinates%22, foundPos.getX(), %22~%22, foundPos.getZ())).applyTextStyle((style) -%3E %7B%0A%09%09%09style.setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, %22/tp @s %22 + foundPos.getX() + %22 ~ %22 + foundPos.getZ())).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent(%22chat.coordinates.tooltip%22)));%0A%09%09%7D);%0A%09%09source.sendFeedback(new TranslationTextComponent(%22commands.uteamcore.locatestructure.success%22, structureName, text, distance), false);%0A%09%09%0A%09%09return distance
+return LocateCommand.func_241053_a_(source, structure)
 ;%0A%09%7D

Update locate structure command