2014-06-14 21:40:45 +02:00
|
|
|
package com.pahimar.ee3.client.handler;
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2016-05-25 19:30:17 +02:00
|
|
|
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
2015-05-07 19:45:06 +02:00
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValue;
|
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
2016-05-22 04:55:14 +02:00
|
|
|
import com.pahimar.ee3.api.knowledge.PlayerKnowledgeRegistryProxy;
|
2014-07-07 21:31:10 +02:00
|
|
|
import com.pahimar.ee3.exchange.WrappedStack;
|
2015-11-28 05:07:45 +01:00
|
|
|
import com.pahimar.ee3.inventory.ContainerAlchenomicon;
|
2015-05-07 22:18:12 +02:00
|
|
|
import com.pahimar.ee3.inventory.ContainerResearchStation;
|
2015-05-03 02:36:26 +02:00
|
|
|
import com.pahimar.ee3.inventory.ContainerTransmutationTablet;
|
2015-02-20 04:09:10 +01:00
|
|
|
import com.pahimar.ee3.reference.Messages;
|
2014-07-18 21:55:10 +02:00
|
|
|
import com.pahimar.ee3.util.IOwnable;
|
2016-05-27 22:03:14 +02:00
|
|
|
import com.pahimar.ee3.util.ItemStackUtils;
|
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;
|
2015-02-20 04:09:10 +01:00
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import net.minecraftforge.common.UsernameCache;
|
2014-06-14 21:40:45 +02:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2015-04-19 21:01:35 +02:00
|
|
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2014-06-14 21:40:45 +02:00
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-05-27 17:10:38 +02:00
|
|
|
public class ItemTooltipEventHandler {
|
2014-06-14 21:40:45 +02:00
|
|
|
@SubscribeEvent
|
2016-05-25 19:30:17 +02:00
|
|
|
public void handleItemTooltipEvent(ItemTooltipEvent event) {
|
2023-01-03 17:47:36 +01:00
|
|
|
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)
|
|
|
|
|| Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)
|
|
|
|
|| (event.entityPlayer != null
|
|
|
|
&& (event.entityPlayer.openContainer instanceof ContainerAlchenomicon
|
|
|
|
|| event.entityPlayer.openContainer
|
|
|
|
instanceof ContainerTransmutationTablet))) {
|
2015-04-19 21:01:35 +02:00
|
|
|
WrappedStack wrappedItemStack = WrappedStack.wrap(event.itemStack);
|
2023-01-03 17:47:36 +01:00
|
|
|
EnergyValue energyValue
|
|
|
|
= EnergyValueRegistryProxy.getEnergyValue(wrappedItemStack);
|
|
|
|
EnergyValue stackEnergyValue
|
|
|
|
= EnergyValueRegistryProxy.getEnergyValueForStack(wrappedItemStack);
|
2014-06-14 21:40:45 +02:00
|
|
|
|
2016-06-04 01:44:33 +02:00
|
|
|
if (energyValue != null) {
|
2016-05-25 19:30:17 +02:00
|
|
|
if (wrappedItemStack.getStackSize() > 1) {
|
2023-01-03 17:47:36 +01:00
|
|
|
event.toolTip.add(
|
|
|
|
String.format("Exchange Energy (Item): %s", energyValue)
|
|
|
|
); // TODO Localize
|
|
|
|
event.toolTip.add(String.format(
|
|
|
|
"Exchange Energy (Stack of %s): %s",
|
|
|
|
event.itemStack.stackSize,
|
|
|
|
stackEnergyValue
|
|
|
|
)); // TODO Localize
|
|
|
|
} else {
|
|
|
|
event.toolTip.add(
|
|
|
|
String.format("Exchange Energy: %s", stackEnergyValue)
|
|
|
|
); // TODO Localize
|
|
|
|
|
|
|
|
if (FluidContainerRegistry.getFluidForFilledItem(event.itemStack)
|
|
|
|
!= null) {
|
|
|
|
FluidStack fluidStack
|
|
|
|
= FluidContainerRegistry.getFluidForFilledItem(event.itemStack
|
|
|
|
);
|
|
|
|
EnergyValue fluidStackEnergyValue
|
|
|
|
= EnergyValueRegistryProxy.getEnergyValueForStack(fluidStack);
|
2015-04-19 21:01:35 +02:00
|
|
|
|
2016-05-28 20:57:10 +02:00
|
|
|
if (fluidStackEnergyValue != null) {
|
2023-01-03 17:47:36 +01:00
|
|
|
event.toolTip.add(String.format(
|
|
|
|
" - Exchange Energy (%smB of %s): %s",
|
|
|
|
fluidStack.amount,
|
|
|
|
fluidStack.getLocalizedName(),
|
|
|
|
fluidStackEnergyValue
|
|
|
|
)); // TODO Localize
|
|
|
|
event.toolTip.add(String.format(
|
|
|
|
" - Exchange Energy (Container): %s",
|
|
|
|
new EnergyValue(
|
|
|
|
energyValue.getValue()
|
|
|
|
- fluidStackEnergyValue.getValue()
|
|
|
|
)
|
|
|
|
)); // TODO Localize
|
2015-04-19 21:01:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else {
|
2015-03-05 05:31:43 +01:00
|
|
|
event.toolTip.add("No Exchange Energy value"); // TODO Localize
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
2016-06-04 01:44:33 +02:00
|
|
|
|
|
|
|
if (!BlacklistRegistryProxy.isLearnable(wrappedItemStack)) {
|
|
|
|
event.toolTip.add("Not learnable"); // TODO Localize
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BlacklistRegistryProxy.isExchangeable(wrappedItemStack)) {
|
|
|
|
event.toolTip.add("Not exchangeable"); // TODO Localize
|
|
|
|
}
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
2014-07-15 18:24:18 +02:00
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (((Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)
|
|
|
|
|| Keyboard.isKeyDown(Keyboard.KEY_RSHIFT))
|
|
|
|
&& (event.entityPlayer != null
|
|
|
|
&& event.entityPlayer.openContainer instanceof ContainerResearchStation)
|
|
|
|
)) {
|
|
|
|
if (PlayerKnowledgeRegistryProxy.doesPlayerKnow(
|
|
|
|
event.entityPlayer, event.itemStack
|
|
|
|
)) {
|
|
|
|
event.toolTip.add("You know how to transmute this"
|
|
|
|
); // TODO Localize with better phrasing
|
2015-05-07 22:18:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 17:10:38 +02:00
|
|
|
if (event.itemStack.getItem() instanceof IOwnable) {
|
2016-05-27 22:03:14 +02:00
|
|
|
UUID playerUUID = ItemStackUtils.getOwnerUUID(event.itemStack);
|
2016-05-27 17:10:38 +02:00
|
|
|
|
|
|
|
if (playerUUID != null && UsernameCache.containsUUID(playerUUID)) {
|
2023-01-03 17:47:36 +01:00
|
|
|
event.toolTip.add(StatCollector.translateToLocalFormatted(
|
|
|
|
Messages.Tooltips.ITEM_BELONGS_TO,
|
|
|
|
UsernameCache.getLastKnownUsername(playerUUID)
|
|
|
|
));
|
|
|
|
} else if (ItemStackUtils.getOwnerName(event.itemStack) != null) {
|
|
|
|
event.toolTip.add(StatCollector.translateToLocalFormatted(
|
|
|
|
Messages.Tooltips.ITEM_BELONGS_TO,
|
|
|
|
ItemStackUtils.getOwnerName(event.itemStack)
|
|
|
|
));
|
2015-02-20 04:09:10 +01:00
|
|
|
}
|
2014-07-15 18:24:18 +02:00
|
|
|
}
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|