ha
This commit is contained in:
parent
510ea47b44
commit
e2be271998
@ -6,7 +6,7 @@ minecraft_version=1.21.4
|
|||||||
yarn_mappings=1.21.4+build.8
|
yarn_mappings=1.21.4+build.8
|
||||||
loader_version=0.16.10
|
loader_version=0.16.10
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.14.514.008
|
mod_version=1.14.514.009
|
||||||
maven_group=org.branulf
|
maven_group=org.branulf
|
||||||
archives_base_name=branulf_toolbox
|
archives_base_name=branulf_toolbox
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -178,15 +178,57 @@ public class SimpleHudHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getColorForPercentage(float percentage) {
|
private int getColorForPercentage(float percentage) {
|
||||||
if (percentage > 0.80f) {
|
percentage = MathHelper.clamp(percentage, 0.0f, 1.0f);
|
||||||
return 0x7700EEFF; // 青
|
|
||||||
} else if (percentage > 0.30f) {
|
final int COLOR_CYAN = 0x7700EEFF; // 青
|
||||||
return 0x7700FF00; // 绿
|
final int COLOR_GREEN = 0x7700FF00; // 绿
|
||||||
|
final int COLOR_YELLOW = 0x77FFFF00; // 黄
|
||||||
|
final int COLOR_RED = 0x77FF0000; // 红
|
||||||
|
|
||||||
|
final float THRESHOLD_CYAN_GREEN = 0.75f;
|
||||||
|
final float THRESHOLD_GREEN_YELLOW = 0.50f;
|
||||||
|
final float THRESHOLD_YELLOW_RED = 0.25f;
|
||||||
|
|
||||||
|
if (percentage >= THRESHOLD_CYAN_GREEN) {
|
||||||
|
// 青 绿
|
||||||
|
float offset = (percentage - THRESHOLD_CYAN_GREEN) / (1.0f - THRESHOLD_CYAN_GREEN);
|
||||||
|
return interpolateColor(COLOR_GREEN, COLOR_CYAN, offset);
|
||||||
|
} else if (percentage >= THRESHOLD_GREEN_YELLOW) {
|
||||||
|
// 绿 黄
|
||||||
|
float offset = (percentage - THRESHOLD_GREEN_YELLOW) / (THRESHOLD_CYAN_GREEN - THRESHOLD_GREEN_YELLOW);
|
||||||
|
return interpolateColor(COLOR_YELLOW, COLOR_GREEN, offset);
|
||||||
|
} else if (percentage >= THRESHOLD_YELLOW_RED) {
|
||||||
|
// 黄 红
|
||||||
|
float offset = (percentage - THRESHOLD_YELLOW_RED) / (THRESHOLD_GREEN_YELLOW - THRESHOLD_YELLOW_RED);
|
||||||
|
return interpolateColor(COLOR_RED, COLOR_YELLOW, offset);
|
||||||
} else {
|
} else {
|
||||||
return 0x77FF0000; // 红
|
// 红
|
||||||
|
return COLOR_RED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从betterping那边偷来的(不是)
|
||||||
|
private int interpolateColor(int colorStart, int colorEnd, float offset) {
|
||||||
|
offset = MathHelper.clamp(offset, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
int alphaStart = (colorStart >> 24) & 0xFF;
|
||||||
|
int redStart = (colorStart >> 16) & 0xFF;
|
||||||
|
int greenStart = (colorStart >> 8) & 0xFF;
|
||||||
|
int blueStart = colorStart & 0xFF;
|
||||||
|
|
||||||
|
int alphaEnd = (colorEnd >> 24) & 0xFF;
|
||||||
|
int redEnd = (colorEnd >> 16) & 0xFF;
|
||||||
|
int greenEnd = (colorEnd >> 8) & 0xFF;
|
||||||
|
int blueEnd = colorEnd & 0xFF;
|
||||||
|
|
||||||
|
int newAlpha = Math.round(alphaStart + (alphaEnd - alphaStart) * offset);
|
||||||
|
int newRed = Math.round(redStart + (redEnd - redStart) * offset);
|
||||||
|
int newGreen = Math.round(greenStart + (greenEnd - greenStart) * offset);
|
||||||
|
int newBlue = Math.round(blueStart + (blueEnd - blueStart) * offset);
|
||||||
|
|
||||||
|
return (newAlpha << 24) | (newRed << 16) | (newGreen << 8) | newBlue;
|
||||||
|
}
|
||||||
|
|
||||||
private void drawArc(DrawContext context, int centerX, int centerY, int radius, int thickness, int startAngleDegrees, int totalArcDegrees, float fillPercentage, int color, boolean clockwise) {
|
private void drawArc(DrawContext context, int centerX, int centerY, int radius, int thickness, int startAngleDegrees, int totalArcDegrees, float fillPercentage, int color, boolean clockwise) {
|
||||||
RenderSystem.backupProjectionMatrix();
|
RenderSystem.backupProjectionMatrix();
|
||||||
Matrix4f originalProjection = RenderSystem.getProjectionMatrix();
|
Matrix4f originalProjection = RenderSystem.getProjectionMatrix();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user