ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java

183 lines
9.2 KiB
Java
Raw Normal View History

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;
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;
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;
import net.minecraft.client.renderer.GlStateManager;
2016-07-03 20:57:00 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
2016-07-03 20:57:00 +02:00
import net.minecraft.item.ItemStack;
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;
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+" -";
private static EnergyDisplay energyDisplay;
2016-07-03 22:53:12 +02:00
public ClientEvents(){
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
2015-05-04 17:26:50 +02:00
public void onTooltipEvent(ItemTooltipEvent event){
//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")+":");
//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")+":");
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));
}
}
else{
2016-04-20 21:39:03 +02:00
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".noOredictNameAvail.desc"));
}
//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()));
//Base Item's Unlocalized Name
2016-04-20 21:39:03 +02:00
String baseName = event.getItemStack().getItem().getUnlocalizedName();
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);
}
//Metadata
2016-04-20 21:39:03 +02:00
int meta = event.getItemStack().getItemDamage();
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")+":");
event.getToolTip().add(ADVANCED_INFO_TEXT_PRE+meta+(max > 0 ? "/"+max : ""));
//Unlocalized Name
2016-04-20 21:39:03 +02:00
String metaName = event.getItemStack().getItem().getUnlocalizedName(event.getItemStack());
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);
}
//NBT
2016-04-20 21:39:03 +02:00
NBTTagCompound compound = event.getItemStack().getTagCompound();
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()){
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);
}
}
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")+"]");
}
}
//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));
}
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();
EntityPlayer player = minecraft.thePlayer;
RayTraceResult posHit = minecraft.objectMouseOver;
FontRenderer font = minecraft.fontRendererObj;
ItemStack stack = player.getHeldItemMainhand();
if(stack != null){
if(stack.getItem() instanceof IHudDisplay){
2016-07-25 22:37:14 +02:00
((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, event.getResolution());
2016-07-03 20:57:00 +02:00
}
}
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){
2016-07-25 22:37:14 +02:00
((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, event.getResolution());
2016-07-03 20:57:00 +02:00
}
if(tileHit instanceof TileEntityBase){
TileEntityBase base = (TileEntityBase)tileHit;
if(base.isRedstoneToggle()){
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);
}
}
}
if(tileHit instanceof IEnergyDisplay){
IEnergyDisplay display = (IEnergyDisplay)tileHit;
if(!display.needsHoldShift() || player.isSneaking()){
if(energyDisplay == null){
energyDisplay = new EnergyDisplay(0, 0, null);
}
energyDisplay.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true);
GlStateManager.pushMatrix();
GlStateManager.color(1F, 1F, 1F, 1F);
energyDisplay.draw();
GlStateManager.popMatrix();
2016-07-03 20:57:00 +02:00
}
}
}
}
}
2015-05-04 17:26:50 +02:00
}