2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TooltipEvent.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.event;
|
2015-05-04 17:26:50 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-09-13 20:50:32 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2016-03-18 15:42:06 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2015-08-01 00:30:56 +02:00
|
|
|
import net.minecraft.item.Item;
|
2016-01-22 19:40:00 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2015-05-04 17:26:50 +02:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2015-05-04 17:26:50 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
2016-01-22 19:40:00 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
public class TooltipEvent{
|
|
|
|
|
2016-03-18 23:47:22 +01:00
|
|
|
private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY+" ";
|
|
|
|
private static final String ADVANCED_INFO_HEADER_PRE = TextFormatting.GRAY+" -";
|
2015-08-01 00:30:56 +02:00
|
|
|
|
2015-08-01 01:30:50 +02:00
|
|
|
@SubscribeEvent
|
2015-05-04 17:26:50 +02:00
|
|
|
public void onTooltipEvent(ItemTooltipEvent event){
|
2015-09-13 20:50:32 +02:00
|
|
|
//Advanced Item Info
|
2016-04-20 21:39:03 +02:00
|
|
|
if(event.getItemStack().getItem() != null){
|
2015-08-02 09:58:36 +02:00
|
|
|
if(ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()){
|
2016-03-18 15:42:06 +01:00
|
|
|
if(GuiScreen.isCtrlKeyDown()){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(TextFormatting.DARK_GRAY+""+TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".extraInfo.desc")+":");
|
2015-08-01 00:30:56 +02:00
|
|
|
|
|
|
|
//OreDict Names
|
2016-04-20 21:39:03 +02:00
|
|
|
int[] oreIDs = OreDictionary.getOreIDs(event.getItemStack());
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".oredictName.desc")+":");
|
2015-08-01 00:30:56 +02:00
|
|
|
if(oreIDs.length > 0){
|
|
|
|
for(int oreID : oreIDs){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+OreDictionary.getOreName(oreID));
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".noOredictNameAvail.desc"));
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Code Name
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".codeName.desc")+":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+Item.REGISTRY.getNameForObject(event.getItemStack().getItem()));
|
2015-08-01 00:30:56 +02:00
|
|
|
|
|
|
|
//Base Item's Unlocalized Name
|
2016-04-20 21:39:03 +02:00
|
|
|
String baseName = event.getItemStack().getItem().getUnlocalizedName();
|
2015-08-02 01:52:12 +02:00
|
|
|
if(baseName != null){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".baseUnlocName.desc")+":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+baseName);
|
2015-08-02 01:52:12 +02:00
|
|
|
}
|
2015-08-01 00:30:56 +02:00
|
|
|
|
2016-01-22 21:48:11 +01:00
|
|
|
//Metadata
|
2016-04-20 21:39:03 +02:00
|
|
|
int meta = event.getItemStack().getItemDamage();
|
2016-05-07 23:38:50 +02:00
|
|
|
int max = event.getItemStack().getMaxDamage();
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".meta.desc")+":");
|
2016-05-07 23:38:50 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+meta+(max > 0 ? "/"+max : ""));
|
2016-01-22 21:48:11 +01:00
|
|
|
|
2015-08-01 00:30:56 +02:00
|
|
|
//Unlocalized Name
|
2016-04-20 21:39:03 +02:00
|
|
|
String metaName = event.getItemStack().getItem().getUnlocalizedName(event.getItemStack());
|
2015-08-02 01:52:12 +02:00
|
|
|
if(metaName != null && baseName != null && !metaName.equals(baseName)){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".unlocName.desc")+":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+metaName);
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
2015-08-17 23:59:38 +02:00
|
|
|
|
2016-01-22 19:40:00 +01:00
|
|
|
//NBT
|
2016-04-20 21:39:03 +02:00
|
|
|
NBTTagCompound compound = event.getItemStack().getTagCompound();
|
2016-01-22 19:40:00 +01:00
|
|
|
if(compound != null && !compound.hasNoTags()){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".nbt.desc")+":");
|
2016-03-18 15:42:06 +01:00
|
|
|
if(GuiScreen.isShiftKeyDown()){
|
2016-01-22 19:40:00 +01:00
|
|
|
List<String> strgList = Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth(compound.toString(), 200);
|
|
|
|
for(String strg : strgList){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+strg);
|
2016-01-22 19:40:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+TextFormatting.ITALIC+"["+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".pressShift.desc")+"]");
|
2016-01-22 19:40:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 23:59:38 +02:00
|
|
|
//Disabling Info
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().addAll(Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth(TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".disablingInfo.desc"), 200));
|
2016-01-22 19:40:00 +01:00
|
|
|
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
2015-08-02 09:58:36 +02:00
|
|
|
else{
|
|
|
|
if(ConfigBoolValues.CTRL_INFO_FOR_EXTRA_INFO.isEnabled()){
|
2016-05-02 17:12:31 +02:00
|
|
|
event.getToolTip().add(TextFormatting.DARK_GRAY+""+TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".ctrlForMoreInfo.desc"));
|
2015-08-02 09:58:36 +02:00
|
|
|
}
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|