render event is now render tick event

This commit is contained in:
MachineMuse 2014-09-09 15:52:32 -06:00
parent 0a26b6f6b8
commit c4c5c9d705
2 changed files with 53 additions and 51 deletions

View file

@ -2,12 +2,19 @@ package net.machinemuse.powersuits.event
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.gameevent.TickEvent
import cpw.mods.fml.common.gameevent.TickEvent.{ClientTickEvent, RenderTickEvent}
import net.machinemuse.general.gui.{EnergyMeter, HeatMeter}
import net.machinemuse.numina.network.{MusePacket, PacketSender}
import net.machinemuse.powersuits.block.BlockTinkerTable
import net.machinemuse.powersuits.common.Config
import net.machinemuse.powersuits.control.{KeybindManager, PlayerInputMap}
import net.machinemuse.powersuits.network.packets.MusePacketPlayerUpdate
import net.machinemuse.utils.MuseItemUtils
import net.machinemuse.utils.render.MuseRenderer
import net.machinemuse.utils.{ElectricItemUtils, MuseHeatUtils, MuseItemUtils, MuseStringUtils}
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityClientPlayerMP
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.entity.player.EntityPlayer
/**
* This handler is called before/after the game processes input events and
@ -17,7 +24,7 @@ import net.minecraft.client.entity.EntityClientPlayerMP
* @author MachineMuse
*/
class ClientTickHandler {
@SubscribeEvent def onPreClientTick(event: TickEvent.ClientTickEvent) {
@SubscribeEvent def onPreClientTick(event: ClientTickEvent) {
if (event.phase == TickEvent.Phase.START) {
import scala.collection.JavaConversions._
for (kb <- KeybindManager.getKeybindings) {
@ -43,4 +50,48 @@ class ClientTickHandler {
}
}
}
@SubscribeEvent def onRenderTickEvent(event: RenderTickEvent) {
if (event.phase == TickEvent.Phase.END) {
val player: EntityPlayer = Minecraft.getMinecraft.thePlayer
if (player != null && MuseItemUtils.modularItemsEquipped(player).size > 0 && Minecraft.getMinecraft.currentScreen == null) {
val mc: Minecraft = Minecraft.getMinecraft
val screen: ScaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight)
drawMeters(player, screen)
}
}
}
protected var heat: HeatMeter = null
protected var energy: HeatMeter = null
private var lightningCounter: Int = 0
private def drawMeters(player: EntityPlayer, screen: ScaledResolution) {
val currEnergy: Double = ElectricItemUtils.getPlayerEnergy(player)
val maxEnergy: Double = ElectricItemUtils.getMaxEnergy(player)
val currHeat: Double = MuseHeatUtils.getPlayerHeat(player)
val maxHeat: Double = MuseHeatUtils.getMaxHeat(player)
if (maxEnergy > 0 && BlockTinkerTable.energyIcon != null) {
val currStr: String = MuseStringUtils.formatNumberShort(currEnergy)
val maxStr: String = MuseStringUtils.formatNumberShort(maxEnergy)
val currHeatStr: String = MuseStringUtils.formatNumberShort(currHeat)
val maxHeatStr: String = MuseStringUtils.formatNumberShort(maxHeat)
if (Config.useGraphicalMeters) {
if (energy == null) {
energy = new EnergyMeter
heat = new HeatMeter
}
val left: Double = screen.getScaledWidth - 20
val top: Double = screen.getScaledHeight / 2.0 - 16
energy.draw(left, top, currEnergy / maxEnergy)
heat.draw(left + 8, top, currHeat / maxHeat)
MuseRenderer.drawRightAlignedString(currStr, left - 2, top + 10)
MuseRenderer.drawRightAlignedString(currHeatStr, left - 2, top + 20)
}
else {
MuseRenderer.drawString(currStr + '/' + maxStr + " \u1D60", 1, 1)
MuseRenderer.drawString(currHeatStr + '/' + maxHeatStr + " C", 1, 10)
}
}
}
}

View file

@ -69,53 +69,4 @@ public class RenderEventHandler {
}
}
@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent.Post event) {
switch(event.type) {
case EXPERIENCE:
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player != null && MuseItemUtils.modularItemsEquipped(player).size() > 0 && Minecraft.getMinecraft().currentScreen == null) {
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution screen = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
drawMeters(player, screen);
}
break;
default:
}
}
protected static HeatMeter heat;
protected static HeatMeter energy;
private int lightningCounter = 0;
private void drawMeters(EntityPlayer player, ScaledResolution screen) {
double currEnergy = ElectricItemUtils.getPlayerEnergy(player);
double maxEnergy = ElectricItemUtils.getMaxEnergy(player);
double currHeat = MuseHeatUtils.getPlayerHeat(player);
double maxHeat = MuseHeatUtils.getMaxHeat(player);
if (maxEnergy > 0 && BlockTinkerTable.energyIcon() != null) {
String currStr = MuseStringUtils.formatNumberShort(currEnergy);
String maxStr = MuseStringUtils.formatNumberShort(maxEnergy);
String currHeatStr = MuseStringUtils.formatNumberShort(currHeat);
String maxHeatStr = MuseStringUtils.formatNumberShort(maxHeat);
if (Config.useGraphicalMeters()) {
if (energy == null) {
energy = new EnergyMeter();
heat = new HeatMeter();
}
double left = screen.getScaledWidth() - 20;
double top = screen.getScaledHeight() / 2.0 - 16;
energy.draw(left, top, currEnergy / maxEnergy);
heat.draw(left + 8, top, currHeat / maxHeat);
MuseRenderer.drawRightAlignedString(currStr, left - 2, top + 10);
MuseRenderer.drawRightAlignedString(currHeatStr, left - 2, top + 20);
} else {
MuseRenderer.drawString(currStr + '/' + maxStr + " \u1D60", 1, 1);
MuseRenderer.drawString(currHeatStr + '/' + maxHeatStr + " C", 1, 10);
}
}
}
}