aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/utils
diff options
context:
space:
mode:
authorMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2020-12-14 12:17:50 -0500
committerMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2020-12-14 12:17:50 -0500
commit12ff5bebbe431924e5c13f8a0f88843ce9709eae (patch)
treea0c3f23b4511da1ed6c76605eeca224a3692c045 /src/main/java/me/Danker/utils
parentc3c6730abd0cfc1619c81f68f0f9eda60cc8b903 (diff)
downloadSkyblockMod-12ff5bebbe431924e5c13f8a0f88843ce9709eae.tar.gz
SkyblockMod-12ff5bebbe431924e5c13f8a0f88843ce9709eae.tar.bz2
SkyblockMod-12ff5bebbe431924e5c13f8a0f88843ce9709eae.zip
Add feature trace inactive terminals
Diffstat (limited to 'src/main/java/me/Danker/utils')
-rw-r--r--src/main/java/me/Danker/utils/Utils.java93
1 files changed, 92 insertions, 1 deletions
diff --git a/src/main/java/me/Danker/utils/Utils.java b/src/main/java/me/Danker/utils/Utils.java
index e4f7873..6c1fadb 100644
--- a/src/main/java/me/Danker/utils/Utils.java
+++ b/src/main/java/me/Danker/utils/Utils.java
@@ -25,6 +25,7 @@ import net.minecraft.util.*;
import org.lwjgl.opengl.GL11;
import java.awt.*;
+import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -386,6 +387,96 @@ public class Utils {
RenderHelper.disableStandardItemLighting();
GlStateManager.disableRescaleNormal();
}
+
+ public static double interpolate(double current, double old, double scale) {
+ return old + (current - old) * scale;
+ }
+
+ // Yoink! https://stackoverflow.com/a/51780112
+ public static Color blendColors(float[] fractions, Color[] colors, float progress) {
+ Color color;
+ if (fractions != null) {
+ if (colors != null) {
+ if (fractions.length == colors.length) {
+ int[] indices = getFractionIndices(fractions, progress);
+ if (indices[0] >= 0 && indices[0] < fractions.length && indices[1] >= 0 && indices[1] < fractions.length) {
+ float[] range = new float[]{fractions[indices[0]], fractions[indices[1]]};
+ Color[] colorRange = new Color[]{colors[indices[0]], colors[indices[1]]};
+ float max = range[1] - range[0];
+ float value = progress - range[0];
+ float weight = value / max;
+ color = blend(colorRange[0], colorRange[1], 1.0F - weight);
+ return color;
+ } else {
+ return colors[0];
+ }
+ } else {
+ throw new IllegalArgumentException("Fractions and colours must have equal number of elements");
+ }
+ } else {
+ throw new IllegalArgumentException("Colors can't be null");
+ }
+ } else {
+ throw new IllegalArgumentException("Fractions can't be null");
+ }
+ }
+
+ public static int[] getFractionIndices(float[] fractions, float progress) {
+ int[] range = new int[2];
+
+ int startPoint;
+ for (startPoint = 0; startPoint < fractions.length && fractions[startPoint] <= progress; ++startPoint) {
+ }
+
+ if (startPoint >= fractions.length) {
+ startPoint = fractions.length - 1;
+ }
+
+ range[0] = startPoint - 1;
+ range[1] = startPoint;
+ return range;
+ }
+
+ public static Color blend(Color color1, Color color2, double ratio) {
+ float r = (float) ratio;
+ float ir = 1.0F - r;
+ float[] rgb1 = new float[3];
+ float[] rgb2 = new float[3];
+ color1.getColorComponents(rgb1);
+ color2.getColorComponents(rgb2);
+ float red = rgb1[0] * r + rgb2[0] * ir;
+ float green = rgb1[1] * r + rgb2[1] * ir;
+ float blue = rgb1[2] * r + rgb2[2] * ir;
+ if (red < 0.0F) {
+ red = 0.0F;
+ } else if (red > 255.0F) {
+ red = 255.0F;
+ }
+
+ if (green < 0.0F) {
+ green = 0.0F;
+ } else if (green > 255.0F) {
+ green = 255.0F;
+ }
+
+ if (blue < 0.0F) {
+ blue = 0.0F;
+ } else if (blue > 255.0F) {
+ blue = 255.0F;
+ }
+
+ Color color = null;
+
+ try {
+ color = new Color(red, green, blue);
+ } catch (IllegalArgumentException var14) {
+ NumberFormat nf = NumberFormat.getNumberInstance();
+ System.out.println(nf.format(red) + "; " + nf.format(green) + "; " + nf.format(blue));
+ var14.printStackTrace();
+ }
+
+ return color;
+ }
public static BlockPos getFirstBlockPosAfterVectors(Minecraft mc, Vec3 pos1, Vec3 pos2, int strength, int distance) {
double x = pos2.xCoord - pos1.xCoord;
@@ -441,5 +532,5 @@ public class Utils {
return null;
}
}
-
+
}