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

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

import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.IForgeRegistryEntry;

public class ItemStackInfoSubCommand {
	
	private static final String SUCCESS_TRANSLATION_STRING = "commands.uteamcore.stackinfo.success.";
	
	public static ArgumentBuilder<CommandSourceStack, ?> register() {
		return Commands.literal("stackinfo").executes(context -> execute(context.getSource()));
	}
	
	private static int execute(CommandSourceStack source) throws CommandSyntaxException {
		final ItemStack stack = source.getPlayerOrException().getMainHandItem();
		final Item item = stack.getItem();
		
		source.sendSuccess(new TranslatableComponent(SUCCESS_TRANSLATION_STRING + "item", createRegistryInfo(item)), false);
		
		if (item instanceof BlockItem) {
			source.sendSuccess(new TranslatableComponent(SUCCESS_TRANSLATION_STRING + "block", createRegistryInfo(((BlockItem) item).getBlock())), false);
		}
		
		if (stack.hasTag()) {
			source.sendSuccess(new TranslatableComponent(SUCCESS_TRANSLATION_STRING + "nbt", NbtUtils.toPrettyComponent(stack.getTag())), false);
		}
		return 0;
	}
	
	private static Component createRegistryInfo(IForgeRegistryEntry<?> entry) {
		final MutableComponent component = new TextComponent(entry.getRegistryName().toString());
		Style style = component.getStyle();
		final String className = getClassString(entry);
		style = style.withColor(ChatFormatting.AQUA);
		style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(className).withStyle(ChatFormatting.YELLOW)));
		style = style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, className));
		component.setStyle(style);
		return component;
	}
	
	private static String getClassString(Object object) {
		return object.getClass().getName() + "@" + Integer.toHexString(object.hashCode());
	}
}

@@ -565,114 +565,8 @@
 le;%0A
-import net.minecraft.network.chat.TextComponent;%0Aimport net.minecraft.network.chat.TranslatableComponent;%0A
 impo
@@ -722,17 +722,16 @@
 istries.
-I
 ForgeReg
@@ -734,19 +734,69 @@
 eRegistr
-yEn
+ies;%0Aimport net.minecraftforge.registries.IForgeRegis
 try;%0A%0Apu
@@ -1312,37 +1312,43 @@
 rce.sendSuccess(
-new T
+Component.t
 ranslatableCompo
@@ -1338,33 +1338,24 @@
 translatable
-Component
 (SUCCESS_TRA
@@ -1403,16 +1403,39 @@
 nfo(item
+, ForgeRegistries.ITEMS
 )), fals
@@ -1490,37 +1490,43 @@
 rce.sendSuccess(
-new T
+Component.t
 ranslatableCompo
@@ -1516,33 +1516,24 @@
 translatable
-Component
 (SUCCESS_TRA
@@ -1607,16 +1607,40 @@
 tBlock()
+, ForgeRegistries.BLOCKS
 )), fals
@@ -1696,21 +1696,27 @@
 Success(
-new T
+Component.t
 ranslata
@@ -1718,25 +1718,16 @@
 slatable
-Component
 (SUCCESS
@@ -1844,16 +1844,20 @@
 e static
+ %3CT%3E
  Compone
@@ -1878,16 +1878,25 @@
 tryInfo(
+T entry, 
 IForgeRe
@@ -1905,19 +1905,17 @@
 stry
-Entry%3C?%3E en
+%3CT%3E regis
 try)
@@ -1954,24 +1954,16 @@
 onent = 
-new Text
 Componen
@@ -1967,81 +1967,50 @@
 nent
-(entry.getRegistryName().toString());%0A%09%09Style style = component.getStyle(
+.literal(registry.getKey(entry).toString()
 );%0A%09
@@ -2056,37 +2056,72 @@
 g(entry);%0A%09%09
-style = style
+final Style style = component.getStyle() //%0A%09%09%09%09
 .withColor(C
@@ -2139,33 +2139,24 @@
 ng.AQUA)
-;%0A%09%09style = style
+ //%0A%09%09%09%09
 .withHov
@@ -2211,16 +2211,8 @@
 XT, 
-new Text
 Comp
@@ -2216,16 +2216,24 @@
 omponent
+.literal
 (classNa
@@ -2274,25 +2274,16 @@
 W)))
-;%0A%09%09style = style
+ //%0A%09%09%09%09
 .wit

Fix item stack info command