Advertisement
Guest User

issues with keystrokes

a guest
Nov 18th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. package com.HopelessPVP.Si1kn.Client.mods.imple;
  2.  
  3. import java.awt.Color;
  4.  
  5. import org.lwjgl.opengl.GL11;
  6.  
  7. import com.HopelessPVP.Si1kn.Client.gui.hud.ScreenPosition;
  8. import com.HopelessPVP.Si1kn.Client.mods.ModDraggable;
  9.  
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.client.gui.Gui;
  12. import net.minecraft.client.settings.KeyBinding;
  13.  
  14. public class ModKeystrokes extends ModDraggable
  15. {
  16. public static enum KeystrokesMode
  17. {
  18. WASD(Key.W, Key.A, Key.S, Key.D), WASD_MOUSE(Key.W, Key.A, Key.S, Key.D, Key.LMB, Key.RMB),
  19. WASD_SPRINT(Key.W, Key.A, Key.S, Key.D,
  20. new Key("Sprint", Minecraft.getMinecraft().gameSettings.keyBindSprint, 1, 41, 58, 18)),
  21. WASD_SPRINT_MOUSE(Key.W, Key.A, Key.S, Key.D, Key.LMB, Key.RMB,
  22. new Key("Sprint", Minecraft.getMinecraft().gameSettings.keyBindSprint, 1, 61, 58, 18));
  23. private final Key[] keys;
  24. private int width;
  25. private int height;
  26.  
  27. private KeystrokesMode(Key... keysIn)
  28. {
  29. this.keys = keysIn;
  30.  
  31. for (Key key : keys)
  32. {
  33. this.width = Math.max(this.width, key.getX() + key.getWidth());
  34. this.height = Math.max(this.height, key.getY() + key.getHeight());
  35. }
  36.  
  37. }
  38.  
  39. public int getHeight()
  40. {
  41. return height;
  42. }
  43.  
  44. public int getWidth()
  45. {
  46. return width;
  47. }
  48.  
  49. public Key[] getKeys()
  50. {
  51. return keys;
  52. }
  53. }
  54.  
  55. private static class Key
  56. {
  57.  
  58. private static final Key W = new Key("W", Minecraft.getMinecraft().gameSettings.keyBindForward, 21, 1, 18, 18);
  59. private static final Key A = new Key("A", Minecraft.getMinecraft().gameSettings.keyBindLeft, 1, 21, 18, 18);
  60. private static final Key S = new Key("S", Minecraft.getMinecraft().gameSettings.keyBindBack, 21, 21, 18, 18);
  61. private static final Key D = new Key("D", Minecraft.getMinecraft().gameSettings.keyBindRight, 41, 21, 18, 18);
  62.  
  63. private static final Key LMB = new Key("LMB", Minecraft.getMinecraft().gameSettings.keyBindAttack, 1, 41, 28,
  64. 18);
  65. private static final Key RMB = new Key("RMB", Minecraft.getMinecraft().gameSettings.keyBindUseItem, 31, 41, 28,
  66. 18);
  67.  
  68. private final String name;
  69. private final KeyBinding keybind;
  70. private final int x;
  71. private final int y;
  72. private final int width;
  73. private final int height;
  74.  
  75. public Key(String name, KeyBinding keybind, int x, int y, int width, int height)
  76. {
  77. this.name = name;
  78. this.keybind = keybind;
  79. this.x = x;
  80. this.y = y;
  81. this.width = width;
  82. this.height = height;
  83. }
  84.  
  85. public boolean isDown()
  86. {
  87. return keybind.isKeyDown();
  88. }
  89.  
  90. public int getHeight()
  91. {
  92. return height;
  93. }
  94.  
  95. public int getWidth()
  96. {
  97. return width;
  98. }
  99.  
  100. public int getX()
  101. {
  102. return x;
  103. }
  104.  
  105. public int getY()
  106. {
  107. return y;
  108. }
  109.  
  110. public String getName()
  111. {
  112. return name;
  113. }
  114. }
  115.  
  116. private ScreenPosition pos;
  117.  
  118. private KeystrokesMode mode = KeystrokesMode.WASD_SPRINT_MOUSE;
  119.  
  120. public void setMode(KeystrokesMode mode)
  121. {
  122. this.mode = mode;
  123. }
  124.  
  125. @Override
  126. public int getWidth()
  127. {
  128. return mode.getWidth();
  129. }
  130.  
  131. @Override
  132. public int getHeight()
  133. {
  134. return mode.getHeight();
  135. }
  136.  
  137. @Override
  138. public void render(ScreenPosition pos)
  139. {
  140. GL11.glPushMatrix();
  141.  
  142. boolean blend = GL11.glIsEnabled(GL11.GL_BLEND);
  143.  
  144.  
  145. GL11.glDisable(GL11.GL_BLEND);
  146.  
  147. for (Key key : mode.getKeys())
  148. {
  149. int textWidth = font.getStringWidth(key.getName());
  150.  
  151. Gui.drawRect(pos.getAbsoluteX() + key.getX(), pos.getAbsoluteY() + key.getY(),
  152. pos.getAbsoluteX() + key.getX() + key.getWidth(), pos.getAbsoluteY() + key.getY() + key.getHeight(),
  153. key.isDown() ? new Color(255, 255, 255, 102).getRGB() : new Color(0, 0, 0, 102).getRGB());
  154.  
  155. font.drawString(key.getName(), pos.getAbsoluteX() + key.getX() + key.getWidth() / 2 - textWidth / 2,
  156. pos.getAbsoluteY() + key.getY() + key.getHeight() / 2 - 4,
  157. key.isDown() ? Color.BLACK.getRGB() : Color.WHITE.getRGB());
  158. }
  159.  
  160.  
  161.  
  162. if (blend)
  163. {
  164. GL11.glEnable(GL11.GL_BLEND);
  165. }
  166.  
  167.  
  168. GL11.glPushMatrix();
  169. }
  170.  
  171. @Override
  172. public void save(ScreenPosition pos)
  173. {
  174. this.pos = pos;
  175. }
  176.  
  177. @Override
  178. public ScreenPosition load()
  179. {
  180. return pos;
  181. }
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement