2014-06-14 21:40:45 +02:00
package com.pahimar.ee3.client.handler ;
2014-07-14 04:05:27 +02:00
import com.pahimar.ee3.api.EnergyValue ;
2014-07-07 21:31:10 +02:00
import com.pahimar.ee3.exchange.EnergyValueRegistry ;
import com.pahimar.ee3.exchange.WrappedStack ;
2015-02-18 02:05:18 +01:00
import com.pahimar.ee3.inventory.ContainerAlchemicalTome ;
2014-07-18 21:55:10 +02:00
import com.pahimar.ee3.util.IOwnable ;
2014-07-15 18:24:18 +02:00
import com.pahimar.ee3.util.ItemHelper ;
2014-06-14 21:40:45 +02:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent ;
import cpw.mods.fml.relauncher.Side ;
import cpw.mods.fml.relauncher.SideOnly ;
import net.minecraftforge.event.entity.player.ItemTooltipEvent ;
import org.lwjgl.input.Keyboard ;
import java.text.DecimalFormat ;
/ * *
* Equivalent - Exchange - 3
* < p / >
* ItemTooltipEventHandler
*
* @author pahimar
* /
@SideOnly ( Side . CLIENT )
public class ItemTooltipEventHandler
{
2014-06-20 21:57:27 +02:00
private static DecimalFormat energyValueDecimalFormat = new DecimalFormat ( " ###,###,###,###,###.### " ) ;
2014-06-14 21:40:45 +02:00
@SubscribeEvent
public void handleItemTooltipEvent ( ItemTooltipEvent event )
{
2015-02-18 02:05:18 +01:00
if ( Keyboard . isKeyDown ( Keyboard . KEY_LSHIFT ) | | Keyboard . isKeyDown ( Keyboard . KEY_RSHIFT ) | | event . entityPlayer . openContainer instanceof ContainerAlchemicalTome )
2014-06-14 21:40:45 +02:00
{
WrappedStack stack = new WrappedStack ( event . itemStack ) ;
2014-06-20 21:57:27 +02:00
if ( EnergyValueRegistry . getInstance ( ) . hasEnergyValue ( stack ) )
2014-06-14 21:40:45 +02:00
{
2014-06-20 21:57:27 +02:00
EnergyValue energyValue = EnergyValueRegistry . getInstance ( ) . getEnergyValue ( stack ) ;
2014-06-14 21:40:45 +02:00
if ( stack . getStackSize ( ) > 1 )
{
2015-02-18 02:05:18 +01:00
event . toolTip . add ( String . format ( " Exchange Energy (Item): %s " , energyValueDecimalFormat . format ( energyValue . getEnergyValue ( ) ) ) ) ;
2015-02-19 06:06:18 +01:00
event . toolTip . add ( String . format ( " Exchange Energy (Stack of %s): %s " , event . itemStack . stackSize , energyValueDecimalFormat . format ( stack . getStackSize ( ) * energyValue . getEnergyValue ( ) ) ) ) ;
2014-06-14 21:40:45 +02:00
}
else
{
2015-02-18 02:05:18 +01:00
event . toolTip . add ( String . format ( " Exchange Energy: %s " , energyValueDecimalFormat . format ( stack . getStackSize ( ) * energyValue . getEnergyValue ( ) ) ) ) ;
2014-06-14 21:40:45 +02:00
}
}
else
{
2014-06-20 21:57:27 +02:00
event . toolTip . add ( " No Exchange Energy value " ) ;
2014-06-14 21:40:45 +02:00
}
}
2014-07-15 18:24:18 +02:00
if ( event . itemStack . getItem ( ) instanceof IOwnable )
{
event . toolTip . add ( " Owner: " + ItemHelper . getOwnerName ( event . itemStack ) ) ;
}
2014-06-14 21:40:45 +02:00
}
}