From f9a26956626d977f9b820ecad3e5c4f6456baac5 Mon Sep 17 00:00:00 2001 From: mezz Date: Wed, 21 Mar 2018 20:11:17 -0700 Subject: [PATCH] Update docs for ItemTooltipEvent --- .../minecraftforge/event/ForgeEventFactory.java | 2 +- .../event/entity/player/ItemTooltipEvent.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index 2f9d1e3fa..8f63509f9 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -317,7 +317,7 @@ public class ForgeEventFactory return event.getDropChance(); } - public static ItemTooltipEvent onItemTooltip(ItemStack itemStack, EntityPlayer entityPlayer, List toolTip, ITooltipFlag flags) + public static ItemTooltipEvent onItemTooltip(ItemStack itemStack, @Nullable EntityPlayer entityPlayer, List toolTip, ITooltipFlag flags) { ItemTooltipEvent event = new ItemTooltipEvent(itemStack, entityPlayer, toolTip, flags); MinecraftForge.EVENT_BUS.post(event); diff --git a/src/main/java/net/minecraftforge/event/entity/player/ItemTooltipEvent.java b/src/main/java/net/minecraftforge/event/entity/player/ItemTooltipEvent.java index 0de42e774..5a736fd64 100644 --- a/src/main/java/net/minecraftforge/event/entity/player/ItemTooltipEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/player/ItemTooltipEvent.java @@ -21,11 +21,13 @@ package net.minecraftforge.event.entity.player; import java.util.List; +import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class ItemTooltipEvent extends PlayerEvent { @@ -35,9 +37,10 @@ public class ItemTooltipEvent extends PlayerEvent private final List toolTip; /** - * This event is fired in {@link ItemStack#getTooltip(EntityPlayer, boolean)}, which in turn is called from it's respective GUIContainer. + * This event is fired in {@link ItemStack#getTooltip(EntityPlayer, ITooltipFlag)}, which in turn is called from it's respective GUIContainer. + * Tooltips are also gathered with a null entityPlayer during startup by {@link Minecraft#populateSearchTreeManager()}. */ - public ItemTooltipEvent(@Nonnull ItemStack itemStack, EntityPlayer entityPlayer, List toolTip, ITooltipFlag flags) + public ItemTooltipEvent(@Nonnull ItemStack itemStack, @Nullable EntityPlayer entityPlayer, List toolTip, ITooltipFlag flags) { super(entityPlayer); this.itemStack = itemStack; @@ -69,4 +72,14 @@ public class ItemTooltipEvent extends PlayerEvent { return toolTip; } + + /** + * This event is fired with a null player during startup when populating search trees for tooltips. + */ + @Override + @Nullable + public EntityPlayer getEntityPlayer() + { + return super.getEntityPlayer(); + } }