2015-12-21 22:18:33 +01:00
|
|
|
/*
|
|
|
|
* This file ("HudEvent.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
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-12-21 22:18:33 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-12-21 22:18:33 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.event;
|
2015-12-21 22:18:33 +01:00
|
|
|
|
2016-01-17 12:17:24 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.IRedstoneToggle;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
2016-01-08 13:31:58 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockRedstoneTorch;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-12-22 00:30:08 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.profiler.Profiler;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2015-12-21 22:18:33 +01:00
|
|
|
|
|
|
|
public class HudEvent{
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onGameOverlay(RenderGameOverlayEvent.Post event){
|
2016-04-20 21:39:03 +02:00
|
|
|
if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){
|
2015-12-21 22:18:33 +01:00
|
|
|
Minecraft minecraft = Minecraft.getMinecraft();
|
|
|
|
Profiler profiler = minecraft.mcProfiler;
|
|
|
|
EntityPlayer player = minecraft.thePlayer;
|
2016-03-18 23:47:22 +01:00
|
|
|
RayTraceResult posHit = minecraft.objectMouseOver;
|
2016-01-08 08:10:55 +01:00
|
|
|
FontRenderer font = minecraft.fontRendererObj;
|
2016-05-01 22:26:26 +02:00
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
2015-12-21 22:18:33 +01:00
|
|
|
|
|
|
|
profiler.startSection(ModUtil.MOD_ID+"Hud");
|
|
|
|
|
2015-12-22 16:08:53 +01:00
|
|
|
if(stack != null){
|
|
|
|
if(stack.getItem() instanceof IHudDisplay){
|
|
|
|
profiler.startSection("ItemHudDisplay");
|
2016-04-20 21:39:03 +02:00
|
|
|
((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
|
2015-12-22 16:08:53 +01:00
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 15:21:05 +01:00
|
|
|
if(posHit != null && posHit.getBlockPos() != null){
|
2016-01-08 13:31:58 +01:00
|
|
|
Block blockHit = PosUtil.getBlock(posHit.getBlockPos(), minecraft.theWorld);
|
2016-01-08 08:10:55 +01:00
|
|
|
TileEntity tileHit = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
|
2015-12-21 22:18:33 +01:00
|
|
|
|
|
|
|
if(blockHit instanceof IHudDisplay){
|
|
|
|
profiler.startSection("BlockHudDisplay");
|
2016-04-20 21:39:03 +02:00
|
|
|
((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
|
2015-12-21 22:18:33 +01:00
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tileHit instanceof IRedstoneToggle){
|
2015-12-22 00:30:08 +01:00
|
|
|
profiler.startSection("RedstoneToggleHudDisplay");
|
2015-12-21 22:18:33 +01:00
|
|
|
|
2016-03-18 23:47:22 +01:00
|
|
|
String strg = "Redstone Mode: "+TextFormatting.DARK_RED+(((IRedstoneToggle)tileHit).isPulseMode() ? "Pulse" : "Deactivation")+TextFormatting.RESET;
|
2016-04-20 21:39:03 +02:00
|
|
|
font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:18:33 +01:00
|
|
|
|
2015-12-22 00:30:08 +01:00
|
|
|
if(stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
|
2016-03-18 23:47:22 +01:00
|
|
|
String expl = TextFormatting.GREEN+"Right-Click to toggle!";
|
2016-04-20 21:39:03 +02:00
|
|
|
font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
2015-12-22 00:30:08 +01:00
|
|
|
|
|
|
|
profiler.endSection();
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(tileHit instanceof IEnergyDisplay){
|
|
|
|
profiler.startSection("EnergyDisplay");
|
|
|
|
String strg = ((IEnergyDisplay)tileHit).getEnergy()+"/"+((IEnergyDisplay)tileHit).getMaxEnergy()+" RF";
|
2016-04-20 21:39:03 +02:00
|
|
|
font.drawStringWithShadow(TextFormatting.GOLD+strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2-10, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:18:33 +01:00
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
profiler.endSection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|