Guest User

Key Input Handler

a guest
Mar 2nd, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. package halocraft;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.gui.Gui;
  7. import net.minecraft.client.gui.ScaledResolution;
  8. import net.minecraft.client.renderer.Tessellator;
  9. import net.minecraft.client.renderer.WorldRenderer;
  10. import net.minecraft.util.ChatComponentText;
  11. import net.minecraft.util.ResourceLocation;
  12. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  13. import net.minecraftforge.fml.common.gameevent.InputEvent;
  14.  
  15. public class KeyInputHandler extends Gui {
  16. private Minecraft mc = Minecraft.getMinecraft();
  17. ResourceLocation brscope = new ResourceLocation("halocraft:textures/gui/BattleRifleScope.png");
  18. public static boolean keyPressed = false;
  19. @SubscribeEvent
  20. public void onKeyInput(InputEvent.KeyInputEvent event) {
  21. while(KeyBindings.scope.isPressed()){
  22. if(mc.thePlayer.getHeldItem() != null){
  23. if(mc.thePlayer.getHeldItem().getItem() == halocraft.Main.itemBattleRifle){
  24. //Chat Message telling Player Scope is Initialized{Debugging Purpose}
  25. mc.thePlayer.addChatMessage(new ChatComponentText("[HaloCraft 2.0] Scope Initialized."));
  26. //Rendering Scope
  27. // Add this block of code before you draw the section of your texture containing transparency
  28. //Rendering Halo HUD
  29. ScaledResolution scaled = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
  30. System.out.println("Scaled Width: " + scaled.getScaledWidth());
  31. System.out.println("Scaled Height: " + scaled.getScaledHeight());
  32. int xPos = (scaled.getScaledWidth() - 256) / 2;
  33. int yPos = (scaled.getScaledHeight() - 256) / 2;
  34. System.out.println("X-Pos " + xPos + " Y-Pos " + yPos);
  35. this.mc.getTextureManager().bindTexture(brscope);
  36. // Add this block of code before you draw the section of your texture containing transparency
  37. GL11.glEnable(GL11.GL_BLEND);
  38. GL11.glDisable(GL11.GL_DEPTH_TEST);
  39. GL11.glDepthMask(false);
  40. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  41. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  42. GL11.glDisable(GL11.GL_ALPHA_TEST);
  43. drawTexturedModalRect(xPos, yPos, 256, 256, 256, 256);
  44. GL11.glDisable(GL11.GL_BLEND);
  45. GL11.glEnable(GL11.GL_DEPTH_TEST);
  46. GL11.glDepthMask(true);
  47.  
  48. }
  49. else{
  50. mc.thePlayer.addChatMessage(new ChatComponentText("[HaloCraft 2.0] This is not a weapon or does not have a scope."));
  51. }
  52. }
  53. else{
  54. mc.thePlayer.addChatMessage(new ChatComponentText("[HaloCraft 2.0] You're not holding anything!"));
  55. }
  56. }
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment