Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/gregtech/api/unification/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import crafttweaker.annotations.ZenRegister;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import stanhebben.zenscript.annotations.OperatorType;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
Expand Down Expand Up @@ -868,6 +869,20 @@ public Builder color(int color) {
return this;
}

/**
* Set the color of this Material.
* Defaults to 0xFFFFFF unless {@link Builder#colorAverage()} was called, where it will be a weighted average of
* the components of the Material.
*
* @param r the red component of the color
* @param g the green component of the color
* @param b the blue component of the color
*/
public Builder color(@Range(from = 0, to = 255) int r, @Range(from = 0, to = 255) int g,
@Range(from = 0, to = 255) int b) {
return color(GTUtility.combineRGB(r, g, b));
}

public Builder colorAverage() {
this.averageRGB = true;
return this;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;

import java.util.AbstractList;
import java.util.ArrayList;
Expand Down Expand Up @@ -959,4 +960,9 @@ public static long scaleVoltage(long voltage, int workingTier) {
// Sanity check to make sure we don't accidentally create full-amp recipes.
return Math.min(voltage, GTValues.VA[workingTier]);
}

public static int combineRGB(@Range(from = 0, to = 255) int r, @Range(from = 0, to = 255) int g,
@Range(from = 0, to = 255) int b) {
return (r << 16) | (g << 8) | b;
}
}
Loading