Advertisement
theonr

Untitled

Feb 11th, 2020
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.94 KB | None | 0 0
  1. package com.theonrd.rmod;
  2.  
  3. import net.minecraft.client.gui.GuiButton;
  4. import net.minecraft.client.gui.GuiScreen;
  5. import net.minecraft.client.renderer.Tessellator;
  6. import net.minecraft.util.ResourceLocation;
  7. import net.minecraftforge.client.event.GuiScreenEvent;
  8. import net.minecraftforge.common.MinecraftForge;
  9. import org.lwjgl.input.Keyboard;
  10. import org.lwjgl.input.Mouse;
  11. import org.lwjgl.opengl.GL11;
  12.  
  13. public class MapGui extends GuiScreen {
  14.  
  15.     private static int lastwidth;
  16.     private static int lastheight;
  17.     static float tileAdditiveX = 0;
  18.     static float tileAdditiveY = 0;
  19.     static float tileMultipler = 1;
  20.  
  21.  
  22.     private static ResourceLocation texture;
  23.     private static ResourceLocation backgr;
  24.     private String TextureName;
  25.  
  26.     public MapGui(String MapTexture){
  27.  
  28.         this.TextureName=MapTexture;
  29.     }
  30.  
  31.     @Override
  32.     public void initGui() {
  33.  
  34.         texture = new ResourceLocation("rmod", "textures/map_01.png");
  35.         backgr = new ResourceLocation("rmod", "textures/back_01.png");
  36.  
  37.         buttonList.clear();
  38.  
  39.         //buttonList.add(BTN_ADDBIND);
  40.     }
  41.  
  42.     public void updateScaling(){
  43.  
  44.         lastwidth = width;
  45.         lastheight = height;
  46.     }
  47.  
  48.     @Override
  49.     public void handleKeyboardInput() {
  50.  
  51.         if (Keyboard.getEventKeyState())
  52.         {
  53.             this.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey());
  54.         }
  55.  
  56.         this.mc.func_152348_aa();
  57.     }
  58.  
  59.     /*
  60.     * MouseButton:
  61.     *
  62.     * 0 > Left button
  63.     * 1 > Right Button
  64.     * 2 > Middle button
  65.     *
  66.     *  */
  67.     @Override
  68.     protected void mouseClicked(int coord_X, int coord_Y, int MouseButton) {
  69.  
  70.     }
  71.  
  72.     @Override
  73.     public void drawScreen(int i, int j, float f) {
  74.  
  75.         if(lastheight != height || lastwidth != width) initGui(); // If we change screen resolution, we need also update auto-scaling.
  76.  
  77.         if(Mouse.isButtonDown(2) || Mouse.isButtonDown(1)) {
  78.  
  79.             tileMultipler = .7F;
  80.             tileAdditiveX = (float) Mouse.getX() / width;
  81.             tileAdditiveY = (float) Mouse.getY() / height * -1;
  82.         }
  83.         else {
  84.  
  85.             tileMultipler = 1;
  86.             tileAdditiveX = 0;
  87.             tileAdditiveY = 0;
  88.         }
  89.  
  90.         drawDefaultBackground();
  91.  
  92.         mc.getTextureManager().bindTexture(texture);
  93.         drawQuad(floatToWidth(.6F / tileMultipler), floatToHeight(.8F / tileMultipler));
  94.  
  95.         super.drawScreen(i, j, f);
  96.     }
  97.  
  98.     public void drawQuad(int sizeX, int sizeY){
  99.  
  100.         if(sizeX <= sizeY) sizeY = sizeX;
  101.         else sizeX = sizeY;
  102.  
  103.         int x = (width - sizeX) / 2;
  104.         int y = (height - sizeY) / 2;
  105.  
  106.         Tessellator tessellator = Tessellator.instance;
  107.         tessellator.startDrawingQuads();
  108.  
  109.         tessellator.addVertexWithUV((double)(x + 0), (double)(y + sizeY), (double)this.zLevel,
  110.                 (double)((0F + tileAdditiveX) * tileMultipler), (double)((1F + tileAdditiveY) * tileMultipler));  // Left-Up
  111.        
  112.         tessellator.addVertexWithUV((double)(x + sizeX), (double)(y + sizeY), (double)this.zLevel,
  113.                 (double)((1F + tileAdditiveX) * tileMultipler), (double)((1F + tileAdditiveY) * tileMultipler));  // Right-Up
  114.  
  115.         tessellator.addVertexWithUV((double)(x + sizeX), (double)(y + 0), (double)this.zLevel,
  116.                 (double)((1F + tileAdditiveX) * tileMultipler), (double)((0F + tileAdditiveY) * tileMultipler));  // Right-Down
  117.  
  118.         tessellator.addVertexWithUV((double)(x + 0), (double)(y + 0), (double)this.zLevel,
  119.                 (double)((0F + tileAdditiveX) * tileMultipler), (double)((0F + tileAdditiveY) * tileMultipler));  // Left-Down
  120.         tessellator.draw();
  121.     }
  122.  
  123.     // WARN!
  124.     // Use float from range -1..1
  125.     public int floatToWidth (float f){
  126.  
  127.         return (int) (width * f);
  128.     }
  129.  
  130.     // WARN!
  131.     // Use float from range -1..1
  132.     public int floatToHeight (float f) {
  133.  
  134.         return (int) (height * f);
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement