Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package claygolem.events;
- import java.text.DecimalFormat;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.util.ResourceLocation;
- import net.minecraftforge.client.event.RenderGameOverlayEvent;
- import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
- import org.lwjgl.opengl.GL11;
- import claygolem.client.gui.GuiScreenHud;
- import claygolem.entities.boss.EntityBossPart;
- import claygolem.util.ModConst;
- import cpw.mods.fml.common.eventhandler.SubscribeEvent;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- @SideOnly(Side.CLIENT)
- public class EventRenderHud extends GuiScreenHud {
- protected int waitTicks;
- private EntityLivingBase prevEntity = null;
- private static final ResourceLocation hudPlayerInfo = new ResourceLocation(ModConst.MODID, "textures/gui/hud_playerinfo.png");
- private static final ResourceLocation hudTargetInfo = new ResourceLocation(ModConst.MODID, "textures/gui/hud_targetinfo.png");
- public EventRenderHud(Minecraft mc) {
- super(mc);
- }
- @SubscribeEvent
- public void doRenderOverlay(RenderGameOverlayEvent event) {
- int centerX = (this.width - this.xSize) / 2;
- int centerY = (this.height - this.ySize) / 2;
- if(!mc.thePlayer.capabilities.isCreativeMode) {
- this.renderPlayerInfo(this.mc.thePlayer.getHealth());
- if(event.type.equals(ElementType.HEALTH) && event.isCancelable())
- event.setCanceled(true);
- if(event.type.equals(ElementType.EXPERIENCE) && event.isCancelable())
- event.setCanceled(true);
- if(event.type.equals(ElementType.FOOD) && event.isCancelable())
- event.setCanceled(true);
- if(waitTicks > 0) {
- Entity entity = this.getEntityMouseOver(mc, event.partialTicks);
- this.renderTargetHud(entity);
- }
- waitTicks--;
- }
- }
- public void renderPlayerInfo(float health) {
- DecimalFormat df = new DecimalFormat("#0.##");
- String currentHealth = df.format(health);
- GL11.glPushMatrix();
- GL11.glScalef(0.7f, 0.7f, 0.7f);
- this.bind(hudPlayerInfo);
- //main
- this.drawTexturedModalRect(0, 0, 0, 0, 207, 46);
- //health
- this.drawTexturedModalRect(38, 8, 0, 58, 162, 9);
- //energy
- this.drawTexturedModalRect(38, 21, 0, 79, 162, 9);
- //experience
- this.drawTexturedModalRect(38, 34, 0, 102, 162, 5);
- //player emblem
- this.drawTexturedModalRect(7, 11, 0, 119, 24, 24);
- this.drawCenteredString(this.mc.fontRenderer, currentHealth, 38 + (162 / 2), 9, 0xffffffff);
- GL11.glPopMatrix();
- }
- public void renderTargetHud(Entity entity) {
- //TODO draw textured rectangle for pointed entity
- this.renderPointedEntity(entity);
- }
- public void renderPointedEntity(Entity entity) {
- if(entity != null) {
- waitTicks = 1500;
- EntityLivingBase pointedEntity = null;
- if(entity instanceof EntityLivingBase)
- pointedEntity = (EntityLivingBase)entity;
- if(entity instanceof EntityBossPart)
- pointedEntity = ((EntityBossPart)entity).entityPartObj.getEntity();
- if(pointedEntity != null) {
- prevEntity = pointedEntity;
- this.renderEntityMouseOver(50, 50, 30 / pointedEntity.height, (float)(50 + 51) - 120, (float)(50 + 75 - 50) - 55, pointedEntity);
- //System.out.println(EntityList.getEntityString(pointedEntity));
- }
- }
- else {
- if(prevEntity != null)
- this.renderEntityMouseOver(50, 50, 30 / prevEntity.height, (float)(50 + 51) - 120, (float)(50 + 75 - 50) - 55, prevEntity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement