ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/event/TooltipEvent.java

104 lines
5.4 KiB
Java
Raw Normal View History

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;
import net.minecraft.client.Minecraft;
2016-03-18 15:42:06 +01:00
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.Item;
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;
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+" -";
@SubscribeEvent
2015-05-04 17:26:50 +02:00
public void onTooltipEvent(ItemTooltipEvent event){
//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")+":");
//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")+":");
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));
}
}
else{
2016-04-20 21:39:03 +02:00
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".noOredictNameAvail.desc"));
}
//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()));
//Base Item's Unlocalized Name
2016-04-20 21:39:03 +02:00
String baseName = event.getItemStack().getItem().getUnlocalizedName();
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);
}
//Metadata
2016-04-20 21:39:03 +02:00
int meta = event.getItemStack().getItemDamage();
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")+":");
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+meta+(max > 0 ? "/"+max : ""));
//Unlocalized Name
2016-04-20 21:39:03 +02:00
String metaName = event.getItemStack().getItem().getUnlocalizedName(event.getItemStack());
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);
}
//NBT
2016-04-20 21:39:03 +02:00
NBTTagCompound compound = event.getItemStack().getTagCompound();
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()){
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);
}
}
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")+"]");
}
}
//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));
}
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
}
}
}
}
}