303

mod_hurtflash

303
Mar 21st, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.27 KB | None | 0 0
  1. import org.lwjgl.opengl.GL11;
  2. import org.lwjgl.input.Keyboard;
  3. import net.minecraft.client.Minecraft;
  4.  
  5. public class mod_hurtflash extends BaseMod {
  6.     public  int hurtColor = 0xff0000;
  7.     public  int healColor = 0x0000ff;
  8.     public static mod_hurtflash inst;
  9.     public  float maxAlpha = 0.4f;
  10.     public  Minecraft mc = ModLoader.getMinecraftInstance();
  11.  
  12.     public int fadeColor;
  13.     public float fadeColorStep, fadeColorStop, fadeColorAlpha;
  14.     public boolean fadeColorRunning = false;
  15.  
  16.     public String fadeImagePath;
  17.     public float fadeImageStep, fadeImageStop, fadeImageAlpha;
  18.     public boolean fadeImageRunning = false;
  19.  
  20.     public long clock;
  21.  
  22.     public long timedImageTicks;
  23.     public boolean timedImageRunning;
  24.     public float timedImageAlpha;
  25.     public String timedImage;
  26.  
  27.     public long timedColorTicks;
  28.     public boolean timedColorRunning;
  29.     public float timedColorAlpha;
  30.     public int timedColor;
  31.  
  32.     public mod_hurtflash() {
  33.         inst = this;
  34.         ModLoader.SetInGameHook(this, true, false);
  35.     }
  36.  
  37.  
  38.     public void OnTickInGame(Minecraft game) {
  39.         if (game.q != null)
  40.             return;
  41.  
  42.         if (Keyboard.isKeyDown(Keyboard.KEY_Y)) {
  43.             GL11.glDisable(GL11.GL_DEPTH_TEST);
  44.         } else {
  45.             GL11.glEnable(GL11.GL_DEPTH_TEST);
  46.         }
  47.  
  48.         // these are just examples on how to use the methods
  49.         // you can just as well call these from outside of mod_hurtflash.class
  50.         // like in the poison arrow you could do fadeColor purple etc
  51.  
  52.         if (game.g != null && game.g.X > 0) {
  53.             float a = Math.min(Math.max((float)game.g.X / game.g.Y, 0f), maxAlpha);
  54.             flashColor(a, hurtColor);
  55.         }
  56.  
  57.         if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
  58.             fadeColor(healColor, 0f, 0.05f, 0.5f);
  59.         }
  60.  
  61.         if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
  62.             displayImage("%blur%/misc/vignette.png", 0.4f, 100);
  63.         }
  64.  
  65.         if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
  66.             fadeImage("%blur%/misc/pumpkinblur.png", 1f, -0.05f, 0f);
  67.         }
  68.  
  69.         if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
  70.             displayColor(healColor, 0.7f, 100);
  71.         }
  72.  
  73.         if (fadeColorRunning) {
  74.             flashColor(fadeColorAlpha, fadeColor);
  75.  
  76.             fadeColorAlpha += fadeColorStep;
  77.  
  78.             if ((fadeColorStep > 0 && fadeColorAlpha > fadeColorStop) || (fadeColorStep < 0 && fadeColorAlpha < fadeColorStop))
  79.                 fadeColorRunning = false;
  80.         }
  81.  
  82.         if (fadeImageRunning) {
  83.             flashImage(fadeImagePath, fadeImageAlpha);
  84.  
  85.             fadeImageAlpha += fadeImageStep;
  86.  
  87.             if ((fadeImageStep > 0 && fadeImageAlpha > fadeImageStop) || (fadeImageStep < 0 && fadeImageAlpha < fadeImageStop))
  88.                 fadeImageRunning = false;
  89.         }
  90.  
  91.  
  92.  
  93.         if (mc.e != null && (timedImageRunning || timedColorRunning)) {
  94.             long l = mc.e.r();
  95.  
  96.             if (timedImageRunning) {
  97.                 flashImage(timedImage, timedImageAlpha);
  98.  
  99.                 if (l != clock) {
  100.                     timedImageTicks--;
  101.  
  102.                     if (timedImageTicks <= 0) {
  103.                         timedImageRunning = false;
  104.                     }
  105.                 }
  106.             }
  107.  
  108.             if (timedColorRunning) {
  109.                 flashColor(timedColorAlpha, timedColor);
  110.  
  111.                 if (l != clock) {
  112.                     timedColorTicks--;
  113.  
  114.                     if (timedColorTicks <= 0) {
  115.                         timedColorRunning = false;
  116.                     }
  117.                 }
  118.             }
  119.  
  120.             clock = l;
  121.         }
  122.     }
  123.  
  124.  
  125.     public void displayColor(int color, float alpha, long ticks) {
  126.         timedColor = color;
  127.         timedColorAlpha = alpha;
  128.         timedColorTicks = ticks;
  129.         timedColorRunning = true;
  130.     }
  131.  
  132.     public void displayImage(String path, float alpha, long ticks) {
  133.         timedImageRunning = true;
  134.         timedImage = path;
  135.         timedImageAlpha = alpha;
  136.         timedImageTicks = ticks;
  137.     }
  138.  
  139.     public void fadeColor(int color_, float alpha_, float step_, float stop_) {
  140.         fadeColor = color_;
  141.         fadeColorAlpha = alpha_;
  142.         fadeColorStep = step_;
  143.         fadeColorStop = stop_;
  144.         fadeColorRunning = true;
  145.     }
  146.  
  147.     public void fadeImage(String path, float alpha, float step, float stop) {
  148.         fadeImagePath = path;
  149.         fadeImageAlpha = alpha;
  150.         fadeImageStep = step;
  151.         fadeImageStop = stop;
  152.         fadeImageRunning = true;
  153.     }
  154.  
  155.     public void flashColor(float a, int color) {
  156.         float r = (float)(color >> 16 & 0xff) / 255F;
  157.         float g = (float)(color >> 8 & 0xff) / 255F;
  158.         float b = (float)(color & 0xff) / 255F;
  159.         flashColor(a, r, g, b);
  160.     }
  161.  
  162.     public void flashColor(float a, float r, float g, float b) {
  163.         int i = 0, k = 0;
  164.         mt kh1 = new mt(mc.c, mc.d);
  165.         int l = kh1.a();
  166.         int i1 = kh1.b();
  167.  
  168.         kv kv1 = kv.a;
  169.         GL11.glEnable(3042);
  170.         GL11.glDisable(3553);
  171.         GL11.glBlendFunc(770, 771);
  172.         GL11.glColor4f(r, g, b, a);
  173.  
  174.         kv1.b();
  175.         kv1.a(i, i1, 0.0D);
  176.         kv1.a(l, i1, 0.0D);
  177.         kv1.a(l, k, 0.0D);
  178.         kv1.a(i, k, 0.0D);
  179.         kv1.a();
  180.  
  181.         GL11.glEnable(3553);
  182.         GL11.glDisable(3042);
  183.     }
  184.  
  185.     public void flashImage(String path, float alpha) {
  186.         mt kh1 = new mt(mc.c, mc.d);
  187.         int width = kh1.a();
  188.         int height = kh1.b();
  189.  
  190.         GL11.glEnable(3042);
  191.         GL11.glDisable(2929);
  192.         GL11.glDepthMask(false);
  193.         GL11.glBlendFunc(770, 771);
  194.         GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
  195.         GL11.glDisable(3008);
  196.         GL11.glBindTexture(3553, mc.o.a(path));
  197.  
  198.         kv tessellator = kv.a;
  199.         tessellator.b();
  200.         tessellator.a(0.0D, height, -90.0D, 0.0D, 1.0D);
  201.         tessellator.a(width, height, -90.0D, 1.0D, 1.0D);
  202.         tessellator.a(width, 0.0D, -90.0D, 1.0D, 0.0D);
  203.         tessellator.a(0.0D, 0.0D, -90.0D, 0.0D, 0.0D);
  204.         tessellator.a();
  205.  
  206.         GL11.glDepthMask(true);
  207.         GL11.glEnable(2929);
  208.         GL11.glEnable(3008);
  209.         GL11.glColor4f(1.0F, 1.0F, 1.0F, alpha);
  210.     }
  211.  
  212.     public String Version() {
  213.         return "wahtever";
  214.     }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment