hassansyyid

Untitled

Jul 9th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.52 KB | None | 0 0
  1. package halocraft.handlers;
  2.  
  3. import halocraft.Main;
  4.  
  5. import java.util.ArrayList;
  6. import java.util.Collection;
  7. import java.util.Iterator;
  8. import java.util.List;
  9.  
  10. import org.lwjgl.opengl.GL11;
  11.  
  12. import net.minecraft.client.Minecraft;
  13. import net.minecraft.client.gui.Gui;
  14. import net.minecraft.client.gui.ScaledResolution;
  15. import net.minecraft.client.renderer.Tessellator;
  16. import net.minecraft.client.renderer.WorldRenderer;
  17. import net.minecraft.entity.Entity;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.potion.Potion;
  21. import net.minecraft.potion.PotionEffect;
  22. import net.minecraft.util.EnumFacing;
  23. import net.minecraft.util.MathHelper;
  24. import net.minecraft.util.ResourceLocation;
  25. import net.minecraftforge.client.event.RenderGameOverlayEvent;
  26. import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
  27. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  28. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  29. import net.minecraftforge.fml.common.gameevent.TickEvent;
  30. import net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent;
  31.  
  32. public class HaloEventHandler extends Gui{
  33.     private Minecraft mc;
  34.     ResourceLocation overlayTop = new ResourceLocation("halocraft:textures/gui/HaloOverlayTop.png");
  35.     ResourceLocation overlayBottom = new ResourceLocation("halocraft:textures/gui/HaloOverlayBottom.png");
  36.     ResourceLocation texture = new ResourceLocation("halocraft:textures/gui/HealthBar.png");
  37.     ResourceLocation brscope = new ResourceLocation("halocraft:textures/gui/BattleRifleScope.png");
  38.     ResourceLocation redSquare = new ResourceLocation("halocraft:textures/gui/RedSquare.png");
  39.     ResourceLocation minimap = new ResourceLocation("halocraft:textures/gui/HaloOverlayMinimap.png");
  40.     public HaloEventHandler(Minecraft mc){
  41.         super();
  42.         // We need this to invoke the render engine.
  43.         this.mc = mc;
  44.     }
  45.    
  46.     private int getCompassAngle(EntityPlayer player)
  47.     {
  48.         int yaw = (int) player.rotationYawHead;
  49.         yaw = (yaw - 90) % 360;
  50.         yaw *= (256d / 360d);
  51.         return yaw;
  52.     }
  53.    
  54.     /**
  55.      * Draws textured rectangles of sizes other than 256x256
  56.      * @param x The x value of the top-left corner point on the screen where drawing to starts
  57.      * @param y The y value of the top-left corner point on the screen where drawing to starts
  58.      * @param u The u (x) value of top-left corner point of the texture to start drawing from
  59.      * @param v The v (y) value of top-left corner point of the texture to start drawing from
  60.      * @param width The width of the rectangle to draw on screen
  61.      * @param height The height of the rectangle to draw on screen
  62.      * @param textureWidth The width of the whole texture
  63.      * @param textureHeight The height of the whole texture
  64.      */
  65.     protected void drawNonStandardTexturedRect(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight)
  66.     {
  67.         double f = 1F / (double)textureWidth;
  68.         double f1 = 1F / (double)textureHeight;
  69.         WorldRenderer tessellator = Tessellator.getInstance().getWorldRenderer();
  70.         tessellator.startDrawingQuads();
  71.         tessellator.addVertexWithUV(x, y + height, 0, u * f, (v + height) * f1);
  72.         tessellator.addVertexWithUV(x + width, y + height, 0, (u + width) * f, (v + height) * f1);
  73.         tessellator.addVertexWithUV(x + width, y, 0, (u + width) * f, v * f1);
  74.         tessellator.addVertexWithUV(x, y, 0, u * f, v * f1);
  75.         Tessellator.getInstance().draw();
  76.     }
  77.  
  78.     @SubscribeEvent(priority = EventPriority.NORMAL)
  79.     public void onRenderGameOverlay(RenderGameOverlayEvent event)
  80.     {
  81.         ItemStack helmet = mc.thePlayer.inventory.armorItemInSlot(3);
  82.         if(helmet != null){
  83.             if(helmet.getItem() == halocraft.Main.SpartanHelmet || helmet.getItem() == halocraft.Main.GreenSpartanHelmet || helmet.getItem() == halocraft.Main.BlueSpartanHelmet || helmet.getItem() == halocraft.Main.RedSpartanHelmet){
  84.                 if(event.isCancelable() && event.type == ElementType.HEALTH){
  85.                     event.setCanceled(true);
  86.                 }
  87.             }
  88.         }
  89.         if(event.isCancelable() || event.type != ElementType.EXPERIENCE){
  90.             return;
  91.         }
  92.         //Render Scope (If Z is pressed)
  93.         if(halocraft.handlers.KeyInputHandler.keyPressed == true){
  94.             ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
  95.             int xPos = (scaled.getScaledWidth() - 420) / 2;
  96.             int yPos = (scaled.getScaledHeight() - 250) / 2;
  97.             GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  98.             GL11.glDisable(GL11.GL_LIGHTING);
  99.             this.mc.renderEngine.bindTexture(brscope);
  100.             this.drawNonStandardTexturedRect(xPos, yPos, 0, 0, 420, 250, 420, 250);
  101.         }
  102.         //Checking for Spartan Helmet
  103.         helmet = mc.thePlayer.inventory.armorItemInSlot(3);
  104.         if(helmet != null){
  105.             if(helmet.getItem() == halocraft.Main.SpartanHelmet || helmet.getItem() == halocraft.Main.GreenSpartanHelmet || helmet.getItem() == halocraft.Main.BlueSpartanHelmet || helmet.getItem() == halocraft.Main.RedSpartanHelmet)
  106.             {
  107.                 //Rendering Top of Halo HUD
  108.                 ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
  109.                 int xPos = (scaled.getScaledWidth() - 420) / 2;
  110.                 int yPos = 0;
  111.                 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  112.                 GL11.glDisable(GL11.GL_LIGHTING);
  113.                 this.mc.renderEngine.bindTexture(overlayTop);
  114.                 this.drawNonStandardTexturedRect(xPos, yPos, 0, 0, 420, 57, 420, 57);
  115.                 //Drawing Halo-Style Health Bar
  116.                 int xPosHealth = xPos + 169;
  117.                 int yPosHealth = yPos + 14;
  118.                 this.mc.getTextureManager().bindTexture(texture);              
  119.                 // Add this block of code before you draw the section of your texture containing transparency
  120.                 GL11.glEnable(GL11.GL_BLEND);
  121.                 GL11.glDisable(GL11.GL_DEPTH_TEST);
  122.                 GL11.glDepthMask(false);
  123.                 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  124.                 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  125.                 GL11.glDisable(GL11.GL_ALPHA_TEST);
  126.                 // Here we draw the background bar which contains a transparent section; note the new size
  127.                 drawTexturedModalRect(xPosHealth, yPosHealth, 0, 0, 86, 13);
  128.                 //Drawing Actual Health
  129.                 int manabarwidth = (int)(((float) mc.thePlayer.getHealth() / mc.thePlayer.getMaxHealth()) * 90);
  130.                 drawTexturedModalRect(xPosHealth + 1, yPosHealth + 1, 0, 13, manabarwidth, 11);
  131.                 yPos = scaled.getScaledHeight() - 85;
  132.                 //Draw Bottom of Halo HUD
  133.                 this.mc.renderEngine.bindTexture(overlayBottom);
  134.                 this.drawNonStandardTexturedRect(xPos, yPos, 0, 0, 420, 85, 420, 85);
  135.                
  136.                 this.mc.renderEngine.bindTexture(minimap);
  137.                 GL11.glPushMatrix();
  138.                 GL11.glRotatef(this.getCompassAngle(mc.thePlayer), 0, 0, 0);
  139.                 this.drawNonStandardTexturedRect(xPos + 65, yPos + 41, 0, 0, 50, 50, 50, 50);
  140.                 GL11.glPopMatrix();
  141.                
  142.                 boolean noEntitiesFound = false;
  143.  
  144.                 List<Entity> entities = new ArrayList<Entity>();
  145.                 try
  146.                 {
  147.                     entities = mc.thePlayer.worldObj.getEntitiesWithinAABBExcludingEntity(mc.thePlayer, mc.thePlayer.getEntityBoundingBox().expand(10, 100, 10));
  148.                 }
  149.                 catch(NullPointerException e)
  150.                 {
  151.                     noEntitiesFound = true;
  152.                 }
  153.                
  154.                 if(!noEntitiesFound)
  155.                 {
  156.                     //Draw Map
  157.                     this.mc.renderEngine.bindTexture(redSquare);
  158.                     for(Entity entityIn : entities)
  159.                     {
  160.                         double x = mc.thePlayer.posX - entityIn.posX;
  161.                         x += 50;
  162.                         double y = mc.thePlayer.posZ - entityIn.posZ;  
  163.                         y += 50;
  164.  
  165.                         this.drawNonStandardTexturedRect((int) ((scaled.getScaledWidth() - 420) / 2 + x), (int) (scaled.getScaledHeight() - y), 0, 0, 5, 5, 5, 5);
  166.                     }
  167.                 }
  168.                
  169.                 GL11.glDisable(GL11.GL_BLEND);
  170.                 GL11.glEnable(GL11.GL_DEPTH_TEST);
  171.                 GL11.glDepthMask(true);
  172.             }
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment