Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/main/java/appeng/util/item/AEItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.event.HoverEvent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
Expand Down Expand Up @@ -558,7 +561,19 @@ public String getUnlocalizedName() {

@Override
public IChatComponent getChatComponent() {
return this.getItemStack().func_151000_E();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns just stack.getDisplayName() with no brackets or hover event. There's also no mixin in GTNHLib that adds that rendering in GuiChat. Replacing with it would drop the [...] brackets and the item tooltip hover, which are part of vanilla func_151000_E() behavior that this fix preserves.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, couldn’t these two lines be replaced?

final String translationKey = itemStack.getItem().getUnlocalizedName(itemStack) + ".name";
final IChatComponent nameComponent = new ChatComponentTranslation(translationKey);

Also, for the hover event, it might be worth adding an option to ChatComponentItemName.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. We ended up moving the fix to Hodgepodge (GTNewHorizons/Hodgepodge#924) so it applies globally to all mods, not just AE2U.

On ChatComponentTranslation: it works for simple items but breaks for anything with a custom display name (renamed items, enchanted items, items with NBT-driven names) since getUnlocalizedName() won't reflect those. ChatComponentItemName with full ItemStack serialization handles all cases correctly.

On the hover event in ChatComponentItemName: agreed it would be cleaner to have it there rather than in a separate GuiChat mixin. Filed GTNewHorizons/GTNHLib#396 for the brackets change already. The hover tooltip is currently handled by a dedicated mixin in Hodgepodge to avoid the NBT toString crash from GTNH#21933/#21940 - if GTNHLib adds a safe binary-serialized hover event we can drop that mixin.

final ItemStack itemStack = this.getItemStack();
// Use ChatComponentTranslation so the client translates the name in their own locale.
// Wrap in brackets and attach hover event (shows item tooltip) like vanilla func_151000_E().
final String translationKey = itemStack.getItem().getUnlocalizedName(itemStack) + ".name";
final IChatComponent nameComponent = new ChatComponentTranslation(translationKey);
final ChatComponentText result = new ChatComponentText("[");
result.appendSibling(nameComponent);
result.appendText("]");
result.getChatStyle().setChatHoverEvent(
new HoverEvent(
HoverEvent.Action.SHOW_ITEM,
new ChatComponentText(itemStack.writeToNBT(new NBTTagCompound()).toString())));
return result;
}

// addon...
Expand Down