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
* http : //github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
* <EFBFBD> 2015 Ellpeck
* /
2015-05-04 17:26:50 +02:00
package ellpeck.actuallyadditions.event ;
import cpw.mods.fml.common.eventhandler.SubscribeEvent ;
2015-09-13 20:50:32 +02:00
import cpw.mods.fml.relauncher.ReflectionHelper ;
import ellpeck.actuallyadditions.booklet.GuiBooklet ;
import ellpeck.actuallyadditions.booklet.InitBooklet ;
import ellpeck.actuallyadditions.booklet.page.BookletPage ;
2015-08-01 00:30:56 +02:00
import ellpeck.actuallyadditions.config.values.ConfigBoolValues ;
2015-09-13 20:50:32 +02:00
import ellpeck.actuallyadditions.util.KeyBinds ;
2015-05-04 17:26:50 +02:00
import ellpeck.actuallyadditions.util.KeyUtil ;
import ellpeck.actuallyadditions.util.ModUtil ;
import ellpeck.actuallyadditions.util.StringUtil ;
2015-09-13 20:50:32 +02:00
import net.minecraft.client.Minecraft ;
import net.minecraft.client.audio.PositionedSoundRecord ;
import net.minecraft.client.gui.GuiScreen ;
import net.minecraft.client.gui.inventory.GuiContainer ;
import net.minecraft.inventory.Slot ;
2015-08-01 00:30:56 +02:00
import net.minecraft.item.Item ;
2015-09-13 20:50:32 +02:00
import net.minecraft.item.ItemStack ;
2015-08-30 01:19:03 +02:00
import net.minecraft.util.EnumChatFormatting ;
2015-09-13 20:50:32 +02:00
import net.minecraft.util.ResourceLocation ;
2015-05-04 17:26:50 +02:00
import net.minecraftforge.event.entity.player.ItemTooltipEvent ;
import net.minecraftforge.oredict.OreDictionary ;
2015-09-13 20:50:32 +02:00
import org.lwjgl.input.Keyboard ;
import org.lwjgl.input.Mouse ;
2015-05-04 17:26:50 +02:00
2015-08-17 23:59:38 +02:00
import java.util.regex.Pattern ;
2015-05-04 17:26:50 +02:00
public class TooltipEvent {
2015-09-13 20:50:32 +02:00
private static final String ADVANCED_INFO_TEXT_PRE = EnumChatFormatting . DARK_GRAY + " " ;
private static final String ADVANCED_INFO_HEADER_PRE = EnumChatFormatting . 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
//Booklet Access
GuiScreen screen = Minecraft . getMinecraft ( ) . currentScreen ;
if ( screen ! = null & & ! ( screen instanceof GuiBooklet ) & & screen instanceof GuiContainer ) {
GuiContainer gui = ( GuiContainer ) screen ;
for ( Object o : gui . inventorySlots . inventorySlots ) {
if ( o instanceof Slot ) {
Slot slot = ( Slot ) o ;
int guiLeft = ReflectionHelper . getPrivateValue ( GuiContainer . class , gui , 4 ) ;
int guiTop = ReflectionHelper . getPrivateValue ( GuiContainer . class , gui , 5 ) ;
int mouseX = Mouse . getEventX ( ) * gui . width / Minecraft . getMinecraft ( ) . displayWidth - guiLeft ;
int mouseY = gui . height - Mouse . getEventY ( ) * gui . height / Minecraft . getMinecraft ( ) . displayHeight - 1 - guiTop ;
if ( mouseX > = slot . xDisplayPosition - 1 & & mouseY > = slot . yDisplayPosition - 1 & & mouseX < = slot . xDisplayPosition + 16 & & mouseY < = slot . yDisplayPosition + 16 ) {
ItemStack stack = slot . getStack ( ) ;
if ( stack ! = null ) {
for ( BookletPage page : InitBooklet . pagesWithItemStackData ) {
if ( page . getItemStackForPage ( ) ! = null & & page . getItemStackForPage ( ) . isItemEqual ( stack ) ) {
int keyCode = KeyBinds . keybindOpenBooklet . getKeyCode ( ) ;
event . toolTip . add ( EnumChatFormatting . GOLD + StringUtil . localizeFormatted ( " booklet. " + ModUtil . MOD_ID_LOWER + " .keyToSeeRecipe " , keyCode > 0 & & keyCode < Keyboard . KEYBOARD_SIZE ? " ' " + Keyboard . getKeyName ( keyCode ) + " ' " : " [KEY NOT DEFINED!] " ) ) ;
//Do something better for checking if the key is pressed
if ( Keyboard . isKeyDown ( KeyBinds . keybindOpenBooklet . getKeyCode ( ) ) ) {
GuiBooklet book = new GuiBooklet ( ) ;
Minecraft . getMinecraft ( ) . getSoundHandler ( ) . playSound ( PositionedSoundRecord . func_147674_a ( new ResourceLocation ( " gui.button.press " ) , 1 . 0F ) ) ;
Minecraft . getMinecraft ( ) . displayGuiScreen ( book ) ;
book . openIndexEntry ( page . getChapter ( ) . entry , InitBooklet . entries . indexOf ( page . getChapter ( ) . entry ) / GuiBooklet . BUTTONS_PER_PAGE + 1 , true ) ;
book . openChapter ( page . getChapter ( ) , page ) ;
}
break ;
}
}
}
}
}
}
}
//Advanced Item Info
2015-08-01 00:30:56 +02:00
if ( event . itemStack . getItem ( ) ! = null ) {
2015-08-02 09:58:36 +02:00
if ( ConfigBoolValues . CTRL_EXTRA_INFO . isEnabled ( ) ) {
if ( KeyUtil . isControlPressed ( ) ) {
2015-08-30 01:19:03 +02:00
event . toolTip . add ( EnumChatFormatting . DARK_GRAY + " " + EnumChatFormatting . ITALIC + StringUtil . localize ( " tooltip. " + ModUtil . MOD_ID_LOWER + " .extraInfo.desc " ) + " : " ) ;
2015-08-01 00:30:56 +02:00
//OreDict Names
int [ ] oreIDs = OreDictionary . getOreIDs ( event . itemStack ) ;
2015-09-13 20:50:32 +02:00
event . toolTip . add ( ADVANCED_INFO_HEADER_PRE + StringUtil . localize ( " tooltip. " + ModUtil . MOD_ID_LOWER + " .oredictName.desc " ) + " : " ) ;
2015-08-01 00:30:56 +02:00
if ( oreIDs . length > 0 ) {
for ( int oreID : oreIDs ) {
2015-09-13 20:50:32 +02:00
event . toolTip . add ( ADVANCED_INFO_TEXT_PRE + OreDictionary . getOreName ( oreID ) ) ;
2015-08-01 00:30:56 +02:00
}
}
else {
2015-09-13 20:50:32 +02:00
event . toolTip . add ( ADVANCED_INFO_TEXT_PRE + StringUtil . localize ( " tooltip. " + ModUtil . MOD_ID_LOWER + " .noOredictNameAvail.desc " ) ) ;
2015-08-01 00:30:56 +02:00
}
//Code Name
2015-09-13 20:50:32 +02:00
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 ( ) ) ) ;
2015-08-01 00:30:56 +02:00
//Base Item's Unlocalized Name
String baseName = event . itemStack . getItem ( ) . getUnlocalizedName ( ) ;
2015-08-02 01:52:12 +02:00
if ( baseName ! = null ) {
2015-09-13 20:50:32 +02:00
event . toolTip . add ( ADVANCED_INFO_HEADER_PRE + StringUtil . localize ( " tooltip. " + ModUtil . MOD_ID_LOWER + " .baseUnlocName.desc " ) + " : " ) ;
event . toolTip . add ( ADVANCED_INFO_TEXT_PRE + baseName ) ;
2015-08-02 01:52:12 +02:00
}
2015-08-01 00:30:56 +02:00
//Unlocalized Name
String metaName = event . itemStack . getItem ( ) . getUnlocalizedName ( event . itemStack ) ;
2015-08-02 01:52:12 +02:00
if ( metaName ! = null & & baseName ! = null & & ! metaName . equals ( baseName ) ) {
2015-09-13 20:50:32 +02:00
event . toolTip . add ( ADVANCED_INFO_HEADER_PRE + StringUtil . localize ( " tooltip. " + ModUtil . MOD_ID_LOWER + " .unlocName.desc " ) + " : " ) ;
event . toolTip . add ( ADVANCED_INFO_TEXT_PRE + metaName ) ;
2015-08-01 00:30:56 +02:00
}
2015-08-17 23:59:38 +02:00
//Disabling Info
for ( String str : StringUtil . localize ( " tooltip. " + ModUtil . MOD_ID_LOWER + " .disablingInfo.desc " ) . split ( Pattern . quote ( " | " ) ) ) {
2015-08-30 01:19:03 +02:00
event . toolTip . add ( EnumChatFormatting . ITALIC + str ) ;
2015-08-17 23:59:38 +02: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 ( ) ) {
2015-08-30 01:19:03 +02:00
event . toolTip . add ( EnumChatFormatting . DARK_GRAY + " " + EnumChatFormatting . 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
}
}
}
}
}