diff options
Diffstat (limited to 'src/main/java/me/Danker/utils')
-rw-r--r-- | src/main/java/me/Danker/utils/Utils.java | 93 |
1 files changed, 1 insertions, 92 deletions
diff --git a/src/main/java/me/Danker/utils/Utils.java b/src/main/java/me/Danker/utils/Utils.java index 6c1fadb..e4f7873 100644 --- a/src/main/java/me/Danker/utils/Utils.java +++ b/src/main/java/me/Danker/utils/Utils.java @@ -25,7 +25,6 @@ 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; @@ -387,96 +386,6 @@ 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; @@ -532,5 +441,5 @@ public class Utils { return null; } } - + } |