Package org.cyclops.cyclopscore.helper
Class Helpers
java.lang.Object
org.cyclops.cyclopscore.helper.Helpers
A collection of helper methods and fields.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
addAlphaToColor
(int color, float alpha) Add the given alpha value to the given RGB color.static int
addAlphaToColor
(int color, int alpha) Add the given alpha value to the given RGB color.static int
addSafe
(int a, int b) Take the sum of these two values capped atInteger.MAX_VALUE
.static int
castSafe
(long value) Cast a long value safely to an int.static int
getNewId
(ModBase mod, Helpers.IDType type) Get a new ID for the given type.intToRGB
(int color) Convert a color in integer representation to seperated r, g and b colors.static int
multiplySafe
(int a, int b) Take the multiplication of these two values capped atInteger.MAX_VALUE
.static void
Open the given URL in the player's browser.static int
RGBAToInt
(int r, int g, int b, int a) Convert r, g, b and a colors to an integer representation.static int
rgbToBgr
(int color) Convert the given color from RGB encoding to BGR encoding.static int
rgbToBgra
(int color, int alpha) Convert the given color from RGB encoding to BGR encoding.static int
RGBToInt
(int r, int g, int b) Convert r, g and b colors to an integer representation.static Object
Safe parsing of a string to it's real object type.
-
Constructor Details
-
Helpers
public Helpers()
-
-
Method Details
-
tryParse
Safe parsing of a string to it's real object type. The real object type is determined by checking the class of the oldValue.- Parameters:
newValue
- The value to parseoldValue
- The old value that has a certain type.- Returns:
- The parsed newValue.
-
getNewId
Get a new ID for the given type.- Parameters:
type
- Type for something.mod
- The mod to register the id for.- Returns:
- The incremented ID.
-
RGBToInt
public static int RGBToInt(int r, int g, int b) Convert r, g and b colors to an integer representation.- Parameters:
r
- redg
- greenb
- blue- Returns:
- integer representation of the color.
-
RGBAToInt
public static int RGBAToInt(int r, int g, int b, int a) Convert r, g, b and a colors to an integer representation.- Parameters:
r
- redg
- greenb
- bluea
- alpha- Returns:
- integer representation of the color.
-
addAlphaToColor
public static int addAlphaToColor(int color, int alpha) Add the given alpha value to the given RGB color.- Parameters:
color
- The color.alpha
- The alpha from 0-255- Returns:
- The color with alpha.
-
addAlphaToColor
public static int addAlphaToColor(int color, float alpha) Add the given alpha value to the given RGB color.- Parameters:
color
- The color.alpha
- The alpha from 0-1- Returns:
- The color with alpha.
-
intToRGB
Convert a color in integer representation to seperated r, g and b colors.- Parameters:
color
- The color in integer representation.- Returns:
- The separated r, g and b colors.
-
rgbToBgra
public static int rgbToBgra(int color, int alpha) Convert the given color from RGB encoding to BGR encoding.- Parameters:
color
- The color in RGBalpha
- The alpha to apply- Returns:
- The color in BGR
-
rgbToBgr
public static int rgbToBgr(int color) Convert the given color from RGB encoding to BGR encoding.- Parameters:
color
- The color in RGB- Returns:
- The color in BGR
-
addSafe
public static int addSafe(int a, int b) Take the sum of these two values capped atInteger.MAX_VALUE
.- Parameters:
a
- Integerb
- Integer- Returns:
- The safe sum.
-
multiplySafe
public static int multiplySafe(int a, int b) Take the multiplication of these two values capped atInteger.MAX_VALUE
.- Parameters:
a
- Positive Integerb
- Positive Integer- Returns:
- The safe multiplication.
-
castSafe
public static int castSafe(long value) Cast a long value safely to an int. If the casting would result in an overflow, return theInteger.MAX_VALUE
.- Parameters:
value
- A value to cast.- Returns:
- The casted value.
-
openUrl
Open the given URL in the player's browser.- Parameters:
url
- An URL.
-