Skip to content

Commit

Permalink
Use mojang's colour utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Sep 26, 2023
1 parent 6eaa32d commit a244cf1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/com/minelittlepony/common/util/Color.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
package com.minelittlepony.common.util;

import net.minecraft.util.math.ColorHelper;

/**
* Colouration Utilities
*/
public interface Color {

/**
* Returns the ALPHA channel for the given colour hex code.
*/
static float a(int hex) {
return (hex >> 24 & 255) / 255F;
return ColorHelper.Argb.getAlpha(hex);
}

/**
* Returns the RED channel for the given colour hex code.
*/
static float r(int hex) {
return (hex >> 16 & 255) / 255F;
return ColorHelper.Argb.getRed(hex);
}

/**
* Returns the GREEN channel for the given colour hex code.
*/
static float g(int hex) {
return (hex >> 8 & 255) / 255F;
return ColorHelper.Argb.getGreen(hex);
}

/**
* Returns the BLUE channel for the given colour hex code.
*/
static float b(int hex) {
return (hex & 255) / 255F;
return ColorHelper.Argb.getBlue(hex);
}

/**
* Converts the given rgb floats on a range of 0-1 into a colour hex code.
*/
static int argbToHex(float a, float r, float g, float b) {
return argbToHex((int)(a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255));
return ColorHelper.Argb.getArgb((int)(a * 255), (int) (r * 255), (int) (g * 255), (int) (b * 255));
}

/**
* Converts the given rbg int on a range of 0-255 into a colour hex code.
*/
static int argbToHex(int a, int r, int g, int b) {
return (a << 24) | (r << 16) | (g << 8) | (b);
return ColorHelper.Argb.getArgb(a, r, g, b);
}

/**
Expand Down

0 comments on commit a244cf1

Please sign in to comment.