Advertisement
Guest User

EventRenderHud

a guest
Jun 25th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.88 KB | None | 0 0
  1. package claygolem.events;
  2.  
  3. import java.text.DecimalFormat;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.client.event.RenderGameOverlayEvent;
  10. import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
  11.  
  12. import org.lwjgl.opengl.GL11;
  13.  
  14. import claygolem.client.gui.GuiScreenHud;
  15. import claygolem.entities.boss.EntityBossPart;
  16. import claygolem.util.ModConst;
  17. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  18. import cpw.mods.fml.relauncher.Side;
  19. import cpw.mods.fml.relauncher.SideOnly;
  20.  
  21. @SideOnly(Side.CLIENT)
  22. public class EventRenderHud extends GuiScreenHud {
  23.     protected int waitTicks;
  24.    
  25.     private EntityLivingBase prevEntity = null;
  26.    
  27.     private static final ResourceLocation hudPlayerInfo = new ResourceLocation(ModConst.MODID, "textures/gui/hud_playerinfo.png");
  28.     private static final ResourceLocation hudTargetInfo = new ResourceLocation(ModConst.MODID, "textures/gui/hud_targetinfo.png");
  29.    
  30.     public EventRenderHud(Minecraft mc) {
  31.         super(mc);
  32.     }
  33.    
  34.     @SubscribeEvent
  35.     public void doRenderOverlay(RenderGameOverlayEvent event) {
  36.         int centerX = (this.width - this.xSize) / 2;
  37.         int centerY = (this.height - this.ySize) / 2;
  38.         if(!mc.thePlayer.capabilities.isCreativeMode) {
  39.             this.renderPlayerInfo(this.mc.thePlayer.getHealth());
  40.            
  41.             if(event.type.equals(ElementType.HEALTH) && event.isCancelable())
  42.                 event.setCanceled(true);
  43.             if(event.type.equals(ElementType.EXPERIENCE) && event.isCancelable())
  44.                 event.setCanceled(true);
  45.             if(event.type.equals(ElementType.FOOD) && event.isCancelable())
  46.                 event.setCanceled(true);
  47.             if(waitTicks > 0) {
  48.                 Entity entity = this.getEntityMouseOver(mc, event.partialTicks);
  49.                 this.renderTargetHud(entity);
  50.             }
  51.             waitTicks--;
  52.         }
  53.     }
  54.    
  55.     public void renderPlayerInfo(float health) {
  56.         DecimalFormat df = new DecimalFormat("#0.##");
  57.         String currentHealth = df.format(health);
  58.         GL11.glPushMatrix();
  59.             GL11.glScalef(0.7f, 0.7f, 0.7f);
  60.             this.bind(hudPlayerInfo);
  61.             //main
  62.             this.drawTexturedModalRect(0, 0, 0, 0, 207, 46);
  63.             //health
  64.             this.drawTexturedModalRect(38, 8, 0, 58, 162, 9);
  65.             //energy
  66.             this.drawTexturedModalRect(38, 21, 0, 79, 162, 9);
  67.             //experience
  68.             this.drawTexturedModalRect(38, 34, 0, 102, 162, 5);
  69.             //player emblem
  70.             this.drawTexturedModalRect(7, 11, 0, 119, 24, 24);
  71.            
  72.             this.drawCenteredString(this.mc.fontRenderer, currentHealth, 38 + (162 / 2), 9, 0xffffffff);
  73.         GL11.glPopMatrix();
  74.        
  75.     }
  76.    
  77.     public void renderTargetHud(Entity entity) {
  78.         //TODO draw textured rectangle for pointed entity
  79.         this.renderPointedEntity(entity);
  80.     }
  81.    
  82.     public void renderPointedEntity(Entity entity) {
  83.         if(entity != null) {
  84.             waitTicks = 1500;
  85.             EntityLivingBase pointedEntity = null;
  86.             if(entity instanceof EntityLivingBase)
  87.                 pointedEntity = (EntityLivingBase)entity;
  88.             if(entity instanceof EntityBossPart)
  89.                 pointedEntity = ((EntityBossPart)entity).entityPartObj.getEntity();
  90.             if(pointedEntity != null) {
  91.                 prevEntity = pointedEntity;
  92.                 this.renderEntityMouseOver(50, 50, 30 / pointedEntity.height, (float)(50 + 51) - 120, (float)(50 + 75 - 50) - 55, pointedEntity);
  93.                 //System.out.println(EntityList.getEntityString(pointedEntity));
  94.             }
  95.         }
  96.         else {
  97.             if(prevEntity != null)
  98.                 this.renderEntityMouseOver(50, 50, 30 / prevEntity.height, (float)(50 + 51) - 120, (float)(50 + 75 - 50) - 55, prevEntity);
  99.         }
  100.     }
  101.    
  102.    
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement