diff --git a/src/main/java/techreborn/client/hud/ChargeHud.java b/src/main/java/techreborn/client/hud/ChargeHud.java new file mode 100644 index 000000000..e4cc6304e --- /dev/null +++ b/src/main/java/techreborn/client/hud/ChargeHud.java @@ -0,0 +1,49 @@ +package techreborn.client.hud; + +import ic2.api.item.IElectricItem; +import ic2.api.item.IElectricItemManager; +import ic2.core.item.ElectricItemManager; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; + +public class ChargeHud +{ + public static final ChargeHud instance = new ChargeHud(); + private static Minecraft mc = Minecraft.getMinecraft(); + + @SideOnly(Side.CLIENT) + @SubscribeEvent(priority = EventPriority.LOW) + public void onRenderExperienceBar(RenderGameOverlayEvent event) + { + if (event.isCancelable() || event.type != ElementType.ALL) + return; + + if (mc.inGameHasFocus || (mc.currentScreen != null && mc.gameSettings.showDebugInfo)) + drawChargeHud(event.resolution); + } + + public void drawChargeHud(ScaledResolution res) + { + EntityPlayer player = mc.thePlayer; + ItemStack stack = player.getCurrentArmor(2);; + if(stack != null) + { + if((stack.getItem() instanceof IElectricItem)) + { + double MaxCharge = ((IElectricItem) stack.getItem()).getMaxCharge(stack); + //TODO find a way to get current charge + double CurrentCharge = ((IElectricItem) stack.getItem()).getMaxCharge(stack); + mc.fontRenderer.drawString(Double.toString(CurrentCharge) + "/" + Double.toString(MaxCharge), 0, 0, 0); + } + } + } +} diff --git a/src/main/java/techreborn/proxies/ClientProxy.java b/src/main/java/techreborn/proxies/ClientProxy.java index af08336cf..2bccdc88f 100644 --- a/src/main/java/techreborn/proxies/ClientProxy.java +++ b/src/main/java/techreborn/proxies/ClientProxy.java @@ -2,6 +2,7 @@ package techreborn.proxies; import net.minecraftforge.common.MinecraftForge; import techreborn.client.IconSupplier; +import techreborn.client.hud.ChargeHud; public class ClientProxy extends CommonProxy { @@ -10,5 +11,6 @@ public class ClientProxy extends CommonProxy { { super.init(); MinecraftForge.EVENT_BUS.register(new IconSupplier()); + MinecraftForge.EVENT_BUS.register(new ChargeHud()); } }