Guest User

SpurtScroll

a guest
Jun 28th, 2016
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. package svk.industrialTech.gui;
  2.  
  3. import org.lwjgl.input.Mouse;
  4.  
  5. import svk.industrialTech.utils.RenderHelper;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.util.ResourceLocation;
  8.  
  9. public class SpurtScroll
  10. {
  11.     public final ResourceLocation texture = new ResourceLocation("minecraft:textures/gui/container/creative_inventory/tabs.png");
  12.     int posX, posY, sizeY, amountSteps, step;
  13.  
  14.     public SpurtScroll(int posX, int posY, int sizeY, int amountSteps)
  15.     {
  16.         this.posX = posX;
  17.         this.posY = posY;
  18.         this.sizeY = sizeY;
  19.         this.amountSteps = amountSteps;
  20.     }
  21.  
  22.     public void draw()
  23.     {
  24.         Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  25.  
  26.         if(amountSteps == 0)
  27.         {
  28.             RenderHelper.drawTextureCustomSize(posX, posY, 232+12, 0, 12, 15, 256, 256);
  29.         }
  30.         else
  31.         {
  32.             float percent = ((float) step/amountSteps);
  33.             if(step == 0) RenderHelper.drawTextureCustomSize(posX, posY, 232, 0, 12, 15, 256, 256);
  34.             else if(step < amountSteps) RenderHelper.drawTextureCustomSize(posX, posY + sizeY * percent - 15*percent, 232, 0, 12, 15, 256, 256);
  35.             else if(step == amountSteps) RenderHelper.drawTextureCustomSize(posX, posY + sizeY * percent - 15, 232, 0, 12, 15, 256, 256);
  36.         }
  37.     }
  38.  
  39.     public void mouseClickMove(int x, int y, int key, long time)
  40.     {
  41.         if(x >= posX && y >= posY && x <= posX+12 && y <= posY+sizeY)
  42.         {
  43.             float percent = (float) (y - posY)/sizeY;
  44.             float stepSize = 1.0F/(amountSteps+1);
  45.             this.step = (int) (percent/stepSize);
  46.         }
  47.     }
  48.  
  49.     public void handleMouseInput(int x, int y)
  50.     {
  51.         if(x >= posX && y >= posY && x <= posX+12 && y <= posY+sizeY)
  52.         {
  53.             int scrollType = Mouse.getEventDWheel();
  54.             if(scrollType < 0) //Back
  55.             {      
  56.                 this.scrollDown();
  57.             }
  58.             else if(scrollType > 0)//Back to the future
  59.             {
  60.                 this.scrollUp();
  61.             }      
  62.         }
  63.     }
  64.  
  65.     public void scrollUp()
  66.     {
  67.         this.step = this.step > 0 ? this.step -= 1 : this.step;
  68.     }
  69.  
  70.     public void scrollDown()
  71.     {
  72.         this.step = this.step < amountSteps ? this.step += 1 : this.step;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment