aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java142
1 files changed, 101 insertions, 41 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
index 847b9430..93d7687b 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
@@ -35,6 +35,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
@@ -155,8 +156,9 @@ public class Utils {
public static Splitter PATH_SPLITTER = Splitter.on(".").omitEmptyStrings().limit(2);
private static ScaledResolution lastScale = new ScaledResolution(Minecraft.getMinecraft());
private static long startTime = 0;
- private static DecimalFormat simpleDoubleFormat = new DecimalFormat("0.0");
+ private static final DecimalFormat simpleDoubleFormat = new DecimalFormat("0.0");
+ @SafeVarargs
public static <T> ArrayList<T> createList(T... values) {
ArrayList<T> list = new ArrayList<>();
Collections.addAll(list, values);
@@ -172,7 +174,7 @@ public class Utils {
}
public static ScaledResolution pushGuiScale(int scale) {
- if (guiScales.size() == 0) {
+ if (guiScales.isEmpty()) {
if (Loader.isModLoaded("labymod")) {
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrixOld);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewMatrixOld);
@@ -180,7 +182,7 @@ public class Utils {
}
if (scale < 0) {
- if (guiScales.size() > 0) {
+ if (!guiScales.isEmpty()) {
guiScales.pop();
}
} else {
@@ -191,7 +193,7 @@ public class Utils {
}
}
- int newScale = guiScales.size() > 0
+ int newScale = !guiScales.isEmpty()
? Math.max(0, guiScales.peek())
: Minecraft.getMinecraft().gameSettings.guiScale;
if (newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale;
@@ -201,7 +203,7 @@ public class Utils {
ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
Minecraft.getMinecraft().gameSettings.guiScale = oldScale;
- if (guiScales.size() > 0) {
+ if (!guiScales.isEmpty()) {
GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
GlStateManager.matrixMode(GL11.GL_PROJECTION);
GlStateManager.loadIdentity();
@@ -347,14 +349,12 @@ public class Utils {
return simpleDoubleFormat.format(n);
}
- if (n < 1000 && iteration == 0) return "" + (int) n;
+ if (n < 1000 && iteration == 0) return String.valueOf((int) n);
double d = ((long) n / 100) / 10.0;
boolean isRound = (d * 10) % 10 == 0;
- return (d < 1000 ?
- ((d > 99.9 || isRound || (!isRound && d > 9.99) ?
- (int) d * 10 / 10 : d + ""
- ) + "" + c[iteration])
- : shortNumberFormat(d, iteration + 1));
+ return d < 1000 ?
+ (isRound || d > 9.99 ? (int) d * 10 / 10 : String.valueOf(d)) + String.valueOf(c[iteration])
+ : shortNumberFormat(d, iteration + 1);
}
public static String trimIgnoreColour(String str) {
@@ -473,6 +473,7 @@ public class Utils {
return list;
}
+ @SuppressWarnings("MalformedFormatString")
public static String floatToString(float f, int decimals) {
if (decimals <= 0) {
return String.valueOf(Math.round(f));
@@ -495,9 +496,9 @@ public class Utils {
Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(true, true);
GlStateManager.enableRescaleNormal();
GlStateManager.enableAlpha();
- GlStateManager.alphaFunc(516, 0.1F);
+ GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
GlStateManager.enableBlend();
- GlStateManager.blendFunc(770, 771);
+ GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
setupGuiTransform(x, y, ibakedmodel.isGui3d());
ibakedmodel = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(
@@ -589,7 +590,7 @@ public class Utils {
GlStateManager.enableBlend();
GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enableAlpha();
- GlStateManager.alphaFunc(516, 0.1F);
+ GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
int x = guiLeft - 28;
int y = guiTop + yIndex * 28;
@@ -630,7 +631,7 @@ public class Utils {
GlStateManager.enableBlend();
GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enableAlpha();
- GlStateManager.alphaFunc(516, 0.1F);
+ GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
Minecraft.getMinecraft().getTextureManager().bindTexture(GuiProfileViewer.pv_elements);
@@ -869,7 +870,7 @@ public class Utils {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
worldrenderer
.pos(x, y + height, 0.0D)
.tex(uMin, vMax).endVertex();
@@ -908,7 +909,7 @@ public class Utils {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
worldrenderer
.pos(x, y + height, 0.0D)
.tex(uMin, vMax).endVertex();
@@ -1470,17 +1471,17 @@ public class Utils {
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
- GlStateManager.shadeModel(7425);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
+ GlStateManager.shadeModel(GL11.GL_SMOOTH);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
worldrenderer.pos(right, top, 0).color(f1, f2, f3, f).endVertex();
worldrenderer.pos(left, top, 0).color(f1, f2, f3, f).endVertex();
worldrenderer.pos(left, bottom, 0).color(f5, f6, f7, f4).endVertex();
worldrenderer.pos(right, bottom, 0).color(f5, f6, f7, f4).endVertex();
tessellator.draw();
- GlStateManager.shadeModel(7424);
+ GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
@@ -1498,17 +1499,17 @@ public class Utils {
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
- GlStateManager.shadeModel(7425);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
+ GlStateManager.shadeModel(GL11.GL_SMOOTH);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
worldrenderer.pos(right, top, 0).color(f5, f6, f7, f4).endVertex();
worldrenderer.pos(left, top, 0).color(f1, f2, f3, f).endVertex();
worldrenderer.pos(left, bottom, 0).color(f1, f2, f3, f).endVertex();
worldrenderer.pos(right, bottom, 0).color(f5, f6, f7, f4).endVertex();
tessellator.draw();
- GlStateManager.shadeModel(7424);
+ GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
@@ -1547,8 +1548,7 @@ public class Utils {
StandardCharsets.UTF_8
))
) {
- T obj = gson.fromJson(reader, clazz);
- return obj;
+ return gson.fromJson(reader, clazz);
} catch (Exception e) {
return null;
}
@@ -1648,12 +1648,7 @@ public class Utils {
if (c == '\u00A7') {
lastColourCode = i;
} else if (lastColourCode == i - 1) {
- int colIndex = "0123456789abcdef".indexOf(c);
- if (colIndex >= 0) {
- currentColour = colIndex;
- } else {
- currentColour = 0;
- }
+ currentColour = Math.max(0, "0123456789abcdef".indexOf(c));
} else if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(c) >= 0) {
if (currentColour > 0) {
mostCommon[currentColour]++;
@@ -1694,7 +1689,7 @@ public class Utils {
if (!textLines.isEmpty()) {
int borderColorStart = 0x505000FF;
if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderColours) {
- if (textLines.size() > 0) {
+ if (!textLines.isEmpty()) {
String first = textLines.get(0);
borderColorStart = getPrimaryColour(first).getRGB() & 0x00FFFFFF |
((NotEnoughUpdates.INSTANCE.config.tooltipTweaks.tooltipBorderOpacity) << 24);
@@ -1935,19 +1930,19 @@ public class Utils {
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
- GlStateManager.shadeModel(7425);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
+ GlStateManager.shadeModel(GL11.GL_SMOOTH);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
worldrenderer.pos(right, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
worldrenderer.pos(left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex();
worldrenderer.pos(left, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
worldrenderer.pos(right, bottom, zLevel).color(endRed, endGreen, endBlue, endAlpha).endVertex();
tessellator.draw();
- GlStateManager.shadeModel(7424);
+ GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
@@ -1974,7 +1969,7 @@ public class Utils {
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
GlStateManager.disableTexture2D();
GlStateManager.color(f, f1, f2, f3);
- worldrenderer.begin(7, DefaultVertexFormats.POSITION);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
worldrenderer.pos(left, bottom, 0.0D).endVertex();
worldrenderer.pos(right, bottom, 0.0D).endVertex();
worldrenderer.pos(right, top, 0.0D).endVertex();
@@ -1983,6 +1978,71 @@ public class Utils {
GlStateManager.enableTexture2D();
}
+ /**
+ * Draws a solid color rectangle with the specified coordinates and color (ARGB format). Args: x1, y1, x2, y2, color
+ * @see Gui#drawRect
+ */
+ public static void drawRect(float left, float top, float right, float bottom, int color) {
+ float i;
+ if (left < right) {
+ i = left;
+ left = right;
+ right = i;
+ }
+ if (top < bottom) {
+ i = top;
+ top = bottom;
+ bottom = i;
+ }
+ float f = (float)(color >> 24 & 0xFF) / 255.0f;
+ float g = (float)(color >> 16 & 0xFF) / 255.0f;
+ float h = (float)(color >> 8 & 0xFF) / 255.0f;
+ float j = (float)(color & 0xFF) / 255.0f;
+ Tessellator tessellator = Tessellator.getInstance();
+ WorldRenderer worldRenderer = tessellator.getWorldRenderer();
+ GlStateManager.enableBlend();
+ GlStateManager.disableTexture2D();
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
+ GlStateManager.color(g, h, j, f);
+ worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
+ worldRenderer.pos(left, bottom, 0.0).endVertex();
+ worldRenderer.pos(right, bottom, 0.0).endVertex();
+ worldRenderer.pos(right, top, 0.0).endVertex();
+ worldRenderer.pos(left, top, 0.0).endVertex();
+ tessellator.draw();
+ GlStateManager.enableTexture2D();
+ GlStateManager.disableBlend();
+ }
+
+
+ /**
+ * Draws a default-size 16 by 16 item-overlay at <i>x</i> and <i>y</i>.
+ *
+ * @param x position of the overlay
+ * @param y position of the overlay
+ */
+ public static void drawHoverOverlay(int x, int y) {
+ drawHoverOverlay(x, y, 16, 16);
+ }
+
+ /**
+ * Draws an item-overlay of given <i>width</i> and <i>height</i> at <i>x</i> and <i>y</i>.
+ *
+ * @param x position of the overlay
+ * @param y position of the overlay
+ * @param width width of the overlay
+ * @param height height of the overlay
+ */
+ public static void drawHoverOverlay(int x, int y, int width, int height) {
+ GlStateManager.disableLighting();
+ GlStateManager.disableDepth();
+ GlStateManager.colorMask(true, true, true, false);
+ Utils.drawGradientRect(x, y, x + 16, y + 16, 0x80ffffff, 0x80ffffff);
+ GlStateManager.colorMask(true, true, true, true);
+ GlStateManager.enableLighting();
+ GlStateManager.enableDepth();
+ }
+
public static String prettyTime(Duration time) {
return prettyTime(time.toMillis());
}
@@ -2022,7 +2082,7 @@ public class Utils {
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
GlStateManager.color(f1, f2, f3, f);
GL11.glLineWidth(width);
GL11.glBegin(GL11.GL_LINES);
@@ -2063,7 +2123,7 @@ public class Utils {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
- worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
+ worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
worldrenderer
.pos(x1, y1, 0.0D)
.tex(uMin, vMax).endVertex();