Skip to content

Commit 303fc9a

Browse files
authored
Merge pull request #603 from Nxer/misc
add utils
2 parents 0ad4090 + a2ea878 commit 303fc9a

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

src/main/java/com/Nxer/TwistSpaceTechnology/common/machine/GT_TileEntity_MegaEggGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
import com.Nxer.TwistSpaceTechnology.common.block.BasicBlocks;
2727
import com.Nxer.TwistSpaceTechnology.common.machine.multiMachineClasses.TT_MultiMachineBase_EM;
28+
import com.Nxer.TwistSpaceTechnology.util.MathUtils;
2829
import com.Nxer.TwistSpaceTechnology.util.TextLocalization;
29-
import com.cleanroommc.modularui.utils.MathUtils;
3030
import com.github.technus.tectech.thing.casing.TT_Container_Casings;
3131
import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti;
3232
import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoTunnel;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.Nxer.TwistSpaceTechnology.util;
2+
3+
/**
4+
* Copy from com.cleanroommc.modularui.utils.MathUtils
5+
*/
6+
public class MathUtils {
7+
8+
public static int clamp(int v, int min, int max) {
9+
return Math.max(min, Math.min(v, max));
10+
}
11+
12+
public static float clamp(float v, float min, float max) {
13+
return Math.max(min, Math.min(v, max));
14+
}
15+
16+
public static double clamp(double v, double min, double max) {
17+
return Math.max(min, Math.min(v, max));
18+
}
19+
20+
public static long clamp(long v, long min, long max) {
21+
return Math.max(min, Math.min(v, max));
22+
}
23+
24+
public static int cycler(int x, int min, int max) {
25+
return x < min ? max : (x > max ? min : x);
26+
}
27+
28+
public static float cycler(float x, float min, float max) {
29+
return x < min ? max : (x > max ? min : x);
30+
}
31+
32+
public static double cycler(double x, double min, double max) {
33+
return x < min ? max : (x > max ? min : x);
34+
}
35+
36+
public static int gridIndex(int x, int y, int size, int width) {
37+
x = x / size;
38+
y = y / size;
39+
40+
return x + y * width / size;
41+
}
42+
43+
public static int gridRows(int count, int size, int width) {
44+
double x = count * size / (double) width;
45+
46+
return count <= 0 ? 1 : (int) Math.ceil(x);
47+
}
48+
49+
public static int min(int... values) {
50+
if (values == null || values.length == 0) throw new IllegalArgumentException();
51+
if (values.length == 1) return values[0];
52+
if (values.length == 2) return Math.min(values[0], values[1]);
53+
int min = Integer.MAX_VALUE;
54+
for (int i : values) {
55+
if (i < min) {
56+
min = i;
57+
}
58+
}
59+
return min;
60+
}
61+
62+
public static int max(int... values) {
63+
if (values == null || values.length == 0) throw new IllegalArgumentException();
64+
if (values.length == 1) return values[0];
65+
if (values.length == 2) return Math.max(values[0], values[1]);
66+
int max = Integer.MIN_VALUE;
67+
for (int i : values) {
68+
if (i > max) {
69+
max = i;
70+
}
71+
}
72+
return max;
73+
}
74+
75+
}

0 commit comments

Comments
 (0)