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

63 lines
3.1 KiB
Java
Raw Normal View History

2015-05-04 17:26:50 +02:00
package ellpeck.actuallyadditions.event;
import cpw.mods.fml.common.eventhandler.EventPriority;
2015-05-04 17:26:50 +02:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
2015-05-04 17:26:50 +02:00
import ellpeck.actuallyadditions.util.KeyUtil;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.item.Item;
2015-05-04 17:26:50 +02:00
import net.minecraft.util.StatCollector;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.oredict.OreDictionary;
public class TooltipEvent{
private static final String TEXT_PRE = StringUtil.GRAY+" ";
private static final String HEADER_PRE = StringUtil.LIGHT_GRAY+" -";
@SubscribeEvent(priority = EventPriority.LOWEST)
2015-05-04 17:26:50 +02:00
public void onTooltipEvent(ItemTooltipEvent event){
if(event.itemStack.getItem() != null){
if(KeyUtil.isControlPressed()){
if(ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()){
event.toolTip.add(StringUtil.GRAY+StringUtil.ITALIC+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".extraInfo.desc")+":");
//OreDict Names
int[] oreIDs = OreDictionary.getOreIDs(event.itemStack);
event.toolTip.add(HEADER_PRE+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".oredictName.desc")+":");
if(oreIDs.length > 0){
for(int oreID : oreIDs){
event.toolTip.add(TEXT_PRE+OreDictionary.getOreName(oreID));
}
}
else{
event.toolTip.add(TEXT_PRE+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".noOredictNameAvail.desc"));
}
//Code Name
event.toolTip.add(HEADER_PRE+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".codeName.desc")+":");
event.toolTip.add(TEXT_PRE+Item.itemRegistry.getNameForObject(event.itemStack.getItem()));
//Base Item's Unlocalized Name
String baseName = event.itemStack.getItem().getUnlocalizedName();
event.toolTip.add(HEADER_PRE+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".baseUnlocName.desc")+":");
event.toolTip.add(TEXT_PRE+baseName);
//Unlocalized Name
String metaName = event.itemStack.getItem().getUnlocalizedName(event.itemStack);
if(!metaName.equals(baseName)){
event.toolTip.add(HEADER_PRE+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".unlocName.desc")+":");
event.toolTip.add(TEXT_PRE+metaName);
}
}
}
else{
if(ConfigBoolValues.CTRL_INFO_FOR_EXTRA_INFO.isEnabled()){
event.toolTip.add(StringUtil.GRAY+StringUtil.ITALIC+StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".ctrlForMoreInfo.desc"));
2015-05-04 17:26:50 +02:00
}
}
}
}
}