Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.66 KB | None | 0 0
  1. package net.minecraft.client.gui;
  2.  
  3. import net.minecraft.client.renderer.GlStateManager;
  4. import net.minecraft.client.renderer.Tessellator;
  5. import net.minecraft.client.renderer.VertexBuffer;
  6. import net.minecraft.client.renderer.texture.TextureAtlasSprite;
  7. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.fml.relauncher.Side;
  10. import net.minecraftforge.fml.relauncher.SideOnly;
  11.  
  12. @SideOnly(Side.CLIENT)
  13. public class Gui
  14. {
  15.     public static final ResourceLocation OPTIONS_BACKGROUND = new ResourceLocation("textures/gui/options_background.png");
  16.     public static final ResourceLocation STAT_ICONS = new ResourceLocation("textures/gui/container/stats_icons.png");
  17.     public static final ResourceLocation ICONS = new ResourceLocation("textures/gui/icons.png");
  18.     protected float zLevel;
  19.  
  20.     /**
  21.      * Draws a thin horizontal line between two points.
  22.      */
  23.     protected void drawHorizontalLine(int startX, int endX, int y, int color)
  24.     {
  25.         if (endX < startX)
  26.         {
  27.             int i = startX;
  28.             startX = endX;
  29.             endX = i;
  30.         }
  31.  
  32.         drawRect(startX, y, endX + 1, y + 1, color);
  33.     }
  34.  
  35.     /**
  36.      * Draw a 1 pixel wide vertical line. Args : x, y1, y2, color
  37.      */
  38.     protected void drawVerticalLine(int x, int startY, int endY, int color)
  39.     {
  40.         if (endY < startY)
  41.         {
  42.             int i = startY;
  43.             startY = endY;
  44.             endY = i;
  45.         }
  46.  
  47.         drawRect(x, startY + 1, x + 1, endY, color);
  48.     }
  49.  
  50.     /**
  51.      * Draws a solid color rectangle with the specified coordinates and color.
  52.      */
  53.     public static void drawRect(int left, int top, int right, int bottom, int color)
  54.     {
  55.         if (left < right)
  56.         {
  57.             int i = left;
  58.             left = right;
  59.             right = i;
  60.         }
  61.  
  62.         if (top < bottom)
  63.         {
  64.             int j = top;
  65.             top = bottom;
  66.             bottom = j;
  67.         }
  68.  
  69.         float f3 = (float)(color >> 24 & 255) / 255.0F;
  70.         float f = (float)(color >> 16 & 255) / 255.0F;
  71.         float f1 = (float)(color >> 8 & 255) / 255.0F;
  72.         float f2 = (float)(color & 255) / 255.0F;
  73.         Tessellator tessellator = Tessellator.getInstance();
  74.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  75.         GlStateManager.enableBlend();
  76.         GlStateManager.disableTexture2D();
  77.         GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
  78.         GlStateManager.color(f, f1, f2, f3);
  79.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION);
  80.         vertexbuffer.pos((double)left, (double)bottom, 0.0D).endVertex();
  81.         vertexbuffer.pos((double)right, (double)bottom, 0.0D).endVertex();
  82.         vertexbuffer.pos((double)right, (double)top, 0.0D).endVertex();
  83.         vertexbuffer.pos((double)left, (double)top, 0.0D).endVertex();
  84.         tessellator.draw();
  85.         GlStateManager.enableTexture2D();
  86.         GlStateManager.disableBlend();
  87.     }
  88.  
  89.     /**
  90.      * Draws a rectangle with a vertical gradient between the specified colors (ARGB format). Args : x1, y1, x2, y2,
  91.      * topColor, bottomColor
  92.      */
  93.     protected void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
  94.     {
  95.         float f = (float)(startColor >> 24 & 255) / 255.0F;
  96.         float f1 = (float)(startColor >> 16 & 255) / 255.0F;
  97.         float f2 = (float)(startColor >> 8 & 255) / 255.0F;
  98.         float f3 = (float)(startColor & 255) / 255.0F;
  99.         float f4 = (float)(endColor >> 24 & 255) / 255.0F;
  100.         float f5 = (float)(endColor >> 16 & 255) / 255.0F;
  101.         float f6 = (float)(endColor >> 8 & 255) / 255.0F;
  102.         float f7 = (float)(endColor & 255) / 255.0F;
  103.         GlStateManager.disableTexture2D();
  104.         GlStateManager.enableBlend();
  105.         GlStateManager.disableAlpha();
  106.         GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
  107.         GlStateManager.shadeModel(7425);
  108.         Tessellator tessellator = Tessellator.getInstance();
  109.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  110.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
  111.         vertexbuffer.pos((double)right, (double)top, (double)this.zLevel).color(f1, f2, f3, f).endVertex();
  112.         vertexbuffer.pos((double)left, (double)top, (double)this.zLevel).color(f1, f2, f3, f).endVertex();
  113.         vertexbuffer.pos((double)left, (double)bottom, (double)this.zLevel).color(f5, f6, f7, f4).endVertex();
  114.         vertexbuffer.pos((double)right, (double)bottom, (double)this.zLevel).color(f5, f6, f7, f4).endVertex();
  115.         tessellator.draw();
  116.         GlStateManager.shadeModel(7424);
  117.         GlStateManager.disableBlend();
  118.         GlStateManager.enableAlpha();
  119.         GlStateManager.enableTexture2D();
  120.     }
  121.  
  122.     /**
  123.      * Renders the specified text to the screen, center-aligned. Args : renderer, string, x, y, color
  124.      */
  125.     public void drawCenteredString(FontRenderer fontRendererIn, String text, int x, int y, int color)
  126.     {
  127.         fontRendererIn.drawStringWithShadow(text, (float)(x - fontRendererIn.getStringWidth(text) / 2), (float)y, color);
  128.     }
  129.  
  130.     /**
  131.      * Renders the specified text to the screen. Args : renderer, string, x, y, color
  132.      */
  133.     public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color)
  134.     {
  135.         fontRendererIn.drawStringWithShadow(text, (float)x, (float)y, color);
  136.     }
  137.  
  138.     /**
  139.      * Draws a textured rectangle at the current z-value.
  140.      */
  141.     public void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
  142.     {
  143.         float f = 0.00390625F;
  144.         float f1 = 0.00390625F;
  145.         Tessellator tessellator = Tessellator.getInstance();
  146.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  147.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  148.         vertexbuffer.pos((double)(x + 0), (double)(y + height), (double)this.zLevel).tex((double)((float)(textureX + 0) * 0.00390625F), (double)((float)(textureY + height) * 0.00390625F)).endVertex();
  149.         vertexbuffer.pos((double)(x + width), (double)(y + height), (double)this.zLevel).tex((double)((float)(textureX + width) * 0.00390625F), (double)((float)(textureY + height) * 0.00390625F)).endVertex();
  150.         vertexbuffer.pos((double)(x + width), (double)(y + 0), (double)this.zLevel).tex((double)((float)(textureX + width) * 0.00390625F), (double)((float)(textureY + 0) * 0.00390625F)).endVertex();
  151.         vertexbuffer.pos((double)(x + 0), (double)(y + 0), (double)this.zLevel).tex((double)((float)(textureX + 0) * 0.00390625F), (double)((float)(textureY + 0) * 0.00390625F)).endVertex();
  152.         tessellator.draw();
  153.     }
  154.  
  155.     /**
  156.      * Draws a textured rectangle using the texture currently bound to the TextureManager
  157.      */
  158.     public void drawTexturedModalRect(float xCoord, float yCoord, int minU, int minV, int maxU, int maxV)
  159.     {
  160.         float f = 0.00390625F;
  161.         float f1 = 0.00390625F;
  162.         Tessellator tessellator = Tessellator.getInstance();
  163.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  164.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  165.         vertexbuffer.pos((double)(xCoord + 0.0F), (double)(yCoord + (float)maxV), (double)this.zLevel).tex((double)((float)(minU + 0) * 0.00390625F), (double)((float)(minV + maxV) * 0.00390625F)).endVertex();
  166.         vertexbuffer.pos((double)(xCoord + (float)maxU), (double)(yCoord + (float)maxV), (double)this.zLevel).tex((double)((float)(minU + maxU) * 0.00390625F), (double)((float)(minV + maxV) * 0.00390625F)).endVertex();
  167.         vertexbuffer.pos((double)(xCoord + (float)maxU), (double)(yCoord + 0.0F), (double)this.zLevel).tex((double)((float)(minU + maxU) * 0.00390625F), (double)((float)(minV + 0) * 0.00390625F)).endVertex();
  168.         vertexbuffer.pos((double)(xCoord + 0.0F), (double)(yCoord + 0.0F), (double)this.zLevel).tex((double)((float)(minU + 0) * 0.00390625F), (double)((float)(minV + 0) * 0.00390625F)).endVertex();
  169.         tessellator.draw();
  170.     }
  171.  
  172.     /**
  173.      * Draws a texture rectangle using the texture currently bound to the TextureManager
  174.      */
  175.     public void drawTexturedModalRect(int xCoord, int yCoord, TextureAtlasSprite textureSprite, int widthIn, int heightIn)
  176.     {
  177.         Tessellator tessellator = Tessellator.getInstance();
  178.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  179.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  180.         vertexbuffer.pos((double)(xCoord + 0), (double)(yCoord + heightIn), (double)this.zLevel).tex((double)textureSprite.getMinU(), (double)textureSprite.getMaxV()).endVertex();
  181.         vertexbuffer.pos((double)(xCoord + widthIn), (double)(yCoord + heightIn), (double)this.zLevel).tex((double)textureSprite.getMaxU(), (double)textureSprite.getMaxV()).endVertex();
  182.         vertexbuffer.pos((double)(xCoord + widthIn), (double)(yCoord + 0), (double)this.zLevel).tex((double)textureSprite.getMaxU(), (double)textureSprite.getMinV()).endVertex();
  183.         vertexbuffer.pos((double)(xCoord + 0), (double)(yCoord + 0), (double)this.zLevel).tex((double)textureSprite.getMinU(), (double)textureSprite.getMinV()).endVertex();
  184.         tessellator.draw();
  185.     }
  186.  
  187.     /**
  188.      * Draws a textured rectangle at z = 0. Args: x, y, u, v, width, height, textureWidth, textureHeight
  189.      */
  190.     public static void drawModalRectWithCustomSizedTexture(int x, int y, float u, float v, int width, int height, float textureWidth, float textureHeight)
  191.     {
  192.         float f = 1.0F / textureWidth;
  193.         float f1 = 1.0F / textureHeight;
  194.         Tessellator tessellator = Tessellator.getInstance();
  195.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  196.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  197.         vertexbuffer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)height) * f1)).endVertex();
  198.         vertexbuffer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)width) * f), (double)((v + (float)height) * f1)).endVertex();
  199.         vertexbuffer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)width) * f), (double)(v * f1)).endVertex();
  200.         vertexbuffer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
  201.         tessellator.draw();
  202.     }
  203.  
  204.     /**
  205.      * Draws a scaled, textured, tiled modal rect at z = 0. This method isn't used anywhere in vanilla code.
  206.      */
  207.     public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight)
  208.     {
  209.         float f = 1.0F / tileWidth;
  210.         float f1 = 1.0F / tileHeight;
  211.         Tessellator tessellator = Tessellator.getInstance();
  212.         VertexBuffer vertexbuffer = tessellator.getBuffer();
  213.         vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
  214.         vertexbuffer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)vHeight) * f1)).endVertex();
  215.         vertexbuffer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)uWidth) * f), (double)((v + (float)vHeight) * f1)).endVertex();
  216.         vertexbuffer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)uWidth) * f), (double)(v * f1)).endVertex();
  217.         vertexbuffer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
  218.         tessellator.draw();
  219.     }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement