Skip to content

Commit 957d878

Browse files
authored
Add a method to the material builder to set the color using separate r, g, and b values instead of them being moshed together. (GregTechCEu#2757)
1 parent 3315f3e commit 957d878

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/java/gregtech/api/unification/material/Material.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import crafttweaker.annotations.ZenRegister;
4949
import org.jetbrains.annotations.NotNull;
5050
import org.jetbrains.annotations.Nullable;
51+
import org.jetbrains.annotations.Range;
5152
import stanhebben.zenscript.annotations.OperatorType;
5253
import stanhebben.zenscript.annotations.ZenClass;
5354
import stanhebben.zenscript.annotations.ZenGetter;
@@ -892,6 +893,20 @@ public Builder color(int color) {
892893
return this;
893894
}
894895

896+
/**
897+
* Set the color of this Material.
898+
* Defaults to 0xFFFFFF unless {@link Builder#colorAverage()} was called, where it will be a weighted average of
899+
* the components of the Material.
900+
*
901+
* @param r the red component of the color
902+
* @param g the green component of the color
903+
* @param b the blue component of the color
904+
*/
905+
public Builder color(@Range(from = 0, to = 255) int r, @Range(from = 0, to = 255) int g,
906+
@Range(from = 0, to = 255) int b) {
907+
return color(GTUtility.combineRGB(r, g, b));
908+
}
909+
895910
public Builder colorAverage() {
896911
this.averageRGB = true;
897912
return this;

src/main/java/gregtech/api/util/GTUtility.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.jetbrains.annotations.Contract;
6262
import org.jetbrains.annotations.NotNull;
6363
import org.jetbrains.annotations.Nullable;
64+
import org.jetbrains.annotations.Range;
6465

6566
import java.util.AbstractList;
6667
import java.util.ArrayList;
@@ -959,4 +960,9 @@ public static long scaleVoltage(long voltage, int workingTier) {
959960
// Sanity check to make sure we don't accidentally create full-amp recipes.
960961
return Math.min(voltage, GTValues.VA[workingTier]);
961962
}
963+
964+
public static int combineRGB(@Range(from = 0, to = 255) int r, @Range(from = 0, to = 255) int g,
965+
@Range(from = 0, to = 255) int b) {
966+
return (r << 16) | (g << 8) | b;
967+
}
962968
}

0 commit comments

Comments
 (0)