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

104 lines
5.3 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("TooltipEvent.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 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+" -";
@SuppressWarnings("unchecked")
@SubscribeEvent
2015-05-04 17:26:50 +02:00
public void onTooltipEvent(ItemTooltipEvent event){
//Advanced Item Info
if(event.itemStack.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-03-18 23:47:22 +01:00
event.toolTip.add(TextFormatting.DARK_GRAY+""+TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".extraInfo.desc")+":");
//OreDict Names
int[] oreIDs = OreDictionary.getOreIDs(event.itemStack);
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".oredictName.desc")+":");
if(oreIDs.length > 0){
for(int oreID : oreIDs){
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+OreDictionary.getOreName(oreID));
}
}
else{
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".noOredictNameAvail.desc"));
}
//Code Name
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".codeName.desc")+":");
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+Item.itemRegistry.getNameForObject(event.itemStack.getItem()));
//Base Item's Unlocalized Name
String baseName = event.itemStack.getItem().getUnlocalizedName();
if(baseName != null){
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".baseUnlocName.desc")+":");
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+baseName);
}
//Metadata
int meta = event.itemStack.getItemDamage();
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".meta.desc")+":");
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+meta);
//Unlocalized Name
String metaName = event.itemStack.getItem().getUnlocalizedName(event.itemStack);
if(metaName != null && baseName != null && !metaName.equals(baseName)){
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".unlocName.desc")+":");
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+metaName);
}
//NBT
NBTTagCompound compound = event.itemStack.getTagCompound();
if(compound != null && !compound.hasNoTags()){
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".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){
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+strg);
}
}
else{
2016-03-18 23:47:22 +01:00
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+TextFormatting.ITALIC+"["+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".pressShift.desc")+"]");
}
}
//Disabling Info
2016-03-18 23:47:22 +01:00
event.toolTip.addAll(Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth(TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".disablingInfo.desc"), 200));
}
2015-08-02 09:58:36 +02:00
else{
if(ConfigBoolValues.CTRL_INFO_FOR_EXTRA_INFO.isEnabled()){
2016-03-18 23:47:22 +01:00
event.toolTip.add(TextFormatting.DARK_GRAY+""+TextFormatting .ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".ctrlForMoreInfo.desc"));
2015-08-02 09:58:36 +02:00
}
2015-05-04 17:26:50 +02:00
}
}
}
}
}