Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I'm trying to understand how I can get the description of an Item. I'm talking about the tab that apears when you hower over an item:

 

image.png.6d6b78839d7a0aafe7e35e522292e0c9.png

currently I'm using 

itemStack.getTextComponent()

I get this output:

TextComponent{text='[', siblings=[TextComponent{text='', siblings=[TranslatableComponent{key='item.minecraft.wooden_sword', args=[], siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=HoverEvent{action=SHOW_ITEM, 
value='TextComponent{text='{id:"minecraft:wooden_sword",Count:1b}',siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}'}, insertion=null}}], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=HoverEvent{action=SHOW_ITEM,
value='TextComponent{text='{id:"minecraft:wooden_sword",Count:1b}', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}'}, insertion=null}}, TextComponent{text=']', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=HoverEvent{action=SHOW_ITEM, 
value='TextComponent{text='{id:"minecraft:wooden_sword",Count:1b}', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}'}, insertion=null}}], style=Style{hasParent=false, color=, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=HoverEvent{action=SHOW_ITEM, 
value='TextComponent{text='{id:"minecraft:wooden_sword",Count:1b}', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}'}, insertion=null}}                

But I dont think that this is right. It shows the name of the item but it does not show the Attackvalue and Attack speed for example.

Is there a proper way to get the whole information from this "hover tab"?

 

Also What format is this? First I thought its json but its not.

Edited by HenryFoster
Posted (edited)

Thank you now I get all what I want!

Do you have an idea what kind of format this is? I mean sure I could parse the data easy by hand but maybe there is a better way. I only worked with XML  and Json before.

[TextComponent{text='', 
	siblings=[TranslatableComponent{key='item.minecraft.wooden_sword', args=[], siblings=[], 
		style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], 
		style=Style{hasParent=false, color=, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}
}, 
TextComponent{text='', 
	siblings=[], 
		style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}
}, 
TranslatableComponent{key='item.modifiers.mainhand', args=[], 
			siblings=[], style=Style{hasParent=false, color=, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}
}, 
TextComponent{text=' ', 
	siblings=[TranslatableComponent{key='attribute.modifier.equals.0', 
	args=[1.6, TranslatableComponent{key='attribute.name.generic.attackSpeed', args=[], siblings=[], 
		style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], 
		siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], 
		style=Style{hasParent=false, color=, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}
}, 
TextComponent{text=' ', 
	siblings=[TranslatableComponent{key='attribute.modifier.equals.0', 
	args=[4, TranslatableComponent{key='attribute.name.generic.attackDamage', args=[], 
	siblings=[], 
		style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], siblings=[], 
		style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], 
		style=Style{hasParent=false, color=, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}
}]

 

 

 

Edited by HenryFoster
Posted

I want to have something like

 

name: woodenswpord

enchantments: null

modifires: mainhand

Attackspeed: 1,6

Attackdamage: 4

 

as list or string or anything that I can use to put it into a "database" or file maybe using Java Objectserialisation.

 

The idea of my mod is export all the data of my chests so I can do querrys on that data like getting  the amount of swords with an attack of 4 or more. Just as an example.

 

 

Posted (edited)

Yea I also considered this but I have to see if this also workes with custom items with custom ToolTips. I will try it out thanks.

 

It seems I got it:

 

List<ITextComponent> liste = itemStack.getTooltip(player, TooltipFlags.NORMAL);
			for(ITextComponent itex: liste) {
				System.out.println("----------------------------------------------");
				for(ITextComponent itex2: itex.getSiblings()) {
					System.out.println(itex2.getString());
				}
			}

 

[15:10:28.607] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:67]: ----------------------------------------------
[15:10:28.607] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:69]: Wooden Sword
[15:10:28.608] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:67]: ----------------------------------------------
[15:10:28.608] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:67]: ----------------------------------------------
[15:10:28.608] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:67]: ----------------------------------------------
[15:10:28.608] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:69]: 1.6 Attack Speed
[15:10:28.608] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:67]: ----------------------------------------------
[15:10:28.609] [Client thread/INFO] [STDOUT/]: [KeyInputHandler:pickup:69]: 4 Attack Damage

 

Ok now I get how the ITextComponent works. Now I can gett exactly the data I want thank you!

Edited by HenryFoster
Posted

Here is the Full code and two examples:

 

@SubscribeEvent
	public static void getTooltip(GuiOpenEvent event) throws FileNotFoundException, UnsupportedEncodingException 
	{

		GuiScreen chestScreen =  Minecraft.getInstance().currentScreen;
		EntityPlayer player = Minecraft.getInstance().player;
		
		if (chestScreen instanceof GuiContainer && pressed) 
		{
			GuiContainer c = (GuiContainer) chestScreen; 
			Container container = c.inventorySlots;
			NonNullList<ItemStack> itemStackList = container.getInventory();
			PrintWriter writer;
			writer = new PrintWriter("C:\\Users\\N3XUS\\Desktop\\test\\test.txt", "UTF-8");
			
			ItemStack itemStack = itemStackList.get(13);
			
			List<ITextComponent> liste = itemStack.getTooltip(player, TooltipFlags.NORMAL);
			for(ITextComponent itex: liste) {
				writer.println(itex.getUnformattedComponentText());
				for(ITextComponent itex2: itex.getSiblings()) {
					writer.print(itex2.getString());
				}
				writer.println();
			}
			writer.println("=======================================================================================");
			writer.close();	
		}
	}

 

 

Diamond Sword
Flame



When in main hand:

 
1.6 Attack Speed
 
7 Attack Damage
===================
Potion of the Turtle Master
Slowness
 IV (0:40)
Resistance
 III (0:40)


When Applied:

-60% Speed

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.