2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-07-03 20:57:00 +02:00
|
|
|
* This file ("ClientEvents.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-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-07-03 20:57:00 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
2016-07-21 13:22:55 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.gui.EnergyDisplay;
|
2016-07-03 20:57:00 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockRedstoneTorch;
|
2015-09-13 20:50:32 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2016-03-18 15:42:06 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2016-07-22 00:58:39 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-08-01 00:30:56 +02:00
|
|
|
import net.minecraft.item.Item;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-01-22 19:40:00 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraft.profiler.Profiler;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2016-07-03 22:53:12 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
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;
|
2016-07-03 20:57:00 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-05-04 17:26:50 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
2016-01-22 19:40:00 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-07-03 20:57:00 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class ClientEvents{
|
2015-05-04 17:26:50 +02:00
|
|
|
|
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+" -";
|
2015-08-01 00:30:56 +02:00
|
|
|
|
2016-07-21 18:35:38 +02:00
|
|
|
private static EnergyDisplay energyDisplay;
|
2016-07-21 13:22:55 +02:00
|
|
|
|
2016-07-03 22:53:12 +02:00
|
|
|
public ClientEvents(){
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
//Advanced Item Info
|
2016-04-20 21:39:03 +02:00
|
|
|
if(event.getItemStack().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-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(TextFormatting.DARK_GRAY+""+TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".extraInfo.desc")+":");
|
2015-08-01 00:30:56 +02:00
|
|
|
|
|
|
|
//OreDict Names
|
2016-04-20 21:39:03 +02:00
|
|
|
int[] oreIDs = OreDictionary.getOreIDs(event.getItemStack());
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".oredictName.desc")+":");
|
2015-08-01 00:30:56 +02:00
|
|
|
if(oreIDs.length > 0){
|
|
|
|
for(int oreID : oreIDs){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+OreDictionary.getOreName(oreID));
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".noOredictNameAvail.desc"));
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Code Name
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".codeName.desc")+":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+Item.REGISTRY.getNameForObject(event.getItemStack().getItem()));
|
2015-08-01 00:30:56 +02:00
|
|
|
|
|
|
|
//Base Item's Unlocalized Name
|
2016-04-20 21:39:03 +02:00
|
|
|
String baseName = event.getItemStack().getItem().getUnlocalizedName();
|
2015-08-02 01:52:12 +02:00
|
|
|
if(baseName != null){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".baseUnlocName.desc")+":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+baseName);
|
2015-08-02 01:52:12 +02:00
|
|
|
}
|
2015-08-01 00:30:56 +02:00
|
|
|
|
2016-01-22 21:48:11 +01:00
|
|
|
//Metadata
|
2016-04-20 21:39:03 +02:00
|
|
|
int meta = event.getItemStack().getItemDamage();
|
2016-05-07 23:38:50 +02:00
|
|
|
int max = event.getItemStack().getMaxDamage();
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".meta.desc")+":");
|
2016-05-07 23:38:50 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+meta+(max > 0 ? "/"+max : ""));
|
2016-01-22 21:48:11 +01:00
|
|
|
|
2015-08-01 00:30:56 +02:00
|
|
|
//Unlocalized Name
|
2016-04-20 21:39:03 +02:00
|
|
|
String metaName = event.getItemStack().getItem().getUnlocalizedName(event.getItemStack());
|
2015-08-02 01:52:12 +02:00
|
|
|
if(metaName != null && baseName != null && !metaName.equals(baseName)){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".unlocName.desc")+":");
|
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+metaName);
|
2015-08-01 00:30:56 +02:00
|
|
|
}
|
2015-08-17 23:59:38 +02:00
|
|
|
|
2016-01-22 19:40:00 +01:00
|
|
|
//NBT
|
2016-04-20 21:39:03 +02:00
|
|
|
NBTTagCompound compound = event.getItemStack().getTagCompound();
|
2016-01-22 19:40:00 +01:00
|
|
|
if(compound != null && !compound.hasNoTags()){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".nbt.desc")+":");
|
2016-03-18 15:42:06 +01:00
|
|
|
if(GuiScreen.isShiftKeyDown()){
|
2016-01-22 19:40:00 +01:00
|
|
|
List<String> strgList = Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth(compound.toString(), 200);
|
|
|
|
for(String strg : strgList){
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+strg);
|
2016-01-22 19:40:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+TextFormatting.ITALIC+"["+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".pressShift.desc")+"]");
|
2016-01-22 19:40:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 23:59:38 +02:00
|
|
|
//Disabling Info
|
2016-04-20 21:39:03 +02:00
|
|
|
event.getToolTip().addAll(Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth(TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".disablingInfo.desc"), 200));
|
2016-01-22 19:40:00 +01: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()){
|
2016-05-02 17:12:31 +02:00
|
|
|
event.getToolTip().add(TextFormatting.DARK_GRAY+""+TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".ctrlForMoreInfo.desc"));
|
2015-08-02 09:58:36 +02:00
|
|
|
}
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-03 20:57:00 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onGameOverlay(RenderGameOverlayEvent.Post event){
|
|
|
|
if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){
|
|
|
|
Minecraft minecraft = Minecraft.getMinecraft();
|
|
|
|
Profiler profiler = minecraft.mcProfiler;
|
|
|
|
EntityPlayer player = minecraft.thePlayer;
|
|
|
|
RayTraceResult posHit = minecraft.objectMouseOver;
|
|
|
|
FontRenderer font = minecraft.fontRendererObj;
|
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
|
|
|
|
|
|
|
profiler.startSection(ModUtil.MOD_ID+"Hud");
|
|
|
|
|
|
|
|
if(stack != null){
|
|
|
|
if(stack.getItem() instanceof IHudDisplay){
|
|
|
|
profiler.startSection("ItemHudDisplay");
|
2016-07-08 19:08:54 +02:00
|
|
|
((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
|
2016-07-03 20:57:00 +02:00
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(posHit != null && posHit.getBlockPos() != null){
|
2016-07-04 20:15:41 +02:00
|
|
|
Block blockHit = minecraft.theWorld.getBlockState(posHit.getBlockPos()).getBlock();
|
2016-07-03 20:57:00 +02:00
|
|
|
TileEntity tileHit = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
|
|
|
|
|
|
|
|
if(blockHit instanceof IHudDisplay){
|
|
|
|
profiler.startSection("BlockHudDisplay");
|
2016-07-08 19:08:54 +02:00
|
|
|
((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
|
2016-07-03 20:57:00 +02:00
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tileHit instanceof TileEntityBase){
|
|
|
|
TileEntityBase base = (TileEntityBase)tileHit;
|
|
|
|
if(base.isRedstoneToggle()){
|
|
|
|
profiler.startSection("RedstoneToggleHudDisplay");
|
|
|
|
|
|
|
|
String strg = "Redstone Mode: "+TextFormatting.DARK_RED+(base.isPulseMode ? "Pulse" : "Deactivation")+TextFormatting.RESET;
|
|
|
|
font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
|
|
|
|
if(stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
|
|
|
|
String expl = TextFormatting.GREEN+"Right-Click to toggle!";
|
|
|
|
font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tileHit instanceof IEnergyDisplay){
|
|
|
|
IEnergyDisplay display = (IEnergyDisplay)tileHit;
|
|
|
|
if(!display.needsHoldShift() || player.isSneaking()){
|
|
|
|
profiler.startSection("EnergyDisplay");
|
2016-07-21 18:35:38 +02:00
|
|
|
|
|
|
|
if(energyDisplay == null){
|
|
|
|
energyDisplay = new EnergyDisplay(0, 0, null);
|
|
|
|
}
|
|
|
|
energyDisplay.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true);
|
2016-07-22 00:58:39 +02:00
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.color(1F, 1F, 1F, 1F);
|
2016-07-21 18:35:38 +02:00
|
|
|
energyDisplay.draw();
|
2016-07-22 00:58:39 +02:00
|
|
|
GlStateManager.popMatrix();
|
2016-07-21 18:35:38 +02:00
|
|
|
|
2016-07-03 20:57:00 +02:00
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|