Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. package th.pack.mods;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.gui.Gui;
  5. import net.minecraft.client.settings.KeyBinding;
  6. import org.lwjgl.input.Keyboard;
  7. import org.lwjgl.opengl.GL11;
  8.  
  9. public class SpaceButton
  10. {
  11. private final Minecraft mc;
  12. private final KeyBinding key;
  13. private final int xOffset;
  14. private final int yOffset;
  15. private boolean wasPressed;
  16. private long lastPress;
  17. private int color;
  18. private double textBrightness;
  19.  
  20. public SpaceButton(KeyBinding key, int xOffset, int yOffset) {
  21. this.mc = Minecraft.getMinecraft();
  22. this.wasPressed = true;
  23. this.lastPress = 0L;
  24. this.color = 255;
  25. this.textBrightness = 1.0d;
  26. this.key = key;
  27. this.xOffset = xOffset;
  28. this.yOffset = yOffset;
  29. }
  30.  
  31. public void renderSpaceKey(int x, int y, int textColor) {
  32. final boolean pressed = this.key.isKeyDown();
  33. final String name = Keyboard.getKeyName(this.key.getKeyCode());
  34. final String SZMUL = "§l§m--------";
  35. if (pressed != this.wasPressed) {
  36. this.wasPressed = pressed;
  37. this.lastPress = System.currentTimeMillis();
  38. }
  39. if (pressed) {
  40. this.color = Math.min(255, (int)(2L * (System.currentTimeMillis() - this.lastPress)));
  41. this.textBrightness = Math.max(0.0, 1.0 - (System.currentTimeMillis() - this.lastPress) / 20.0);
  42. } else {
  43. this.color = Math.max(0, 255 - (int)(2L * (System.currentTimeMillis() - this.lastPress)));
  44. this.textBrightness = Math.min(1.0, (System.currentTimeMillis() - this.lastPress) / 20.0);
  45. }
  46. Gui.drawRect(x + this.xOffset, y + this.yOffset, x + this.xOffset + 70, y + this.yOffset + 16, 2013265920 + (this.color << 16) + (this.color << 8) + this.color);
  47. final int red = textColor >> 16 & 0xFF;
  48. final int green = textColor >> 8 & 0xFF;
  49. final int blue = textColor & 0xFF;
  50. mc.fontRendererObj.drawString(SZMUL, x + this.xOffset + 8, y + this.yOffset + 4, -16777216 + ((int)(red * this.textBrightness) << 16) + ((int)(green * this.textBrightness) << 8) + (int)(blue * this.textBrightness));
  51.  
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement