aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/util
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-08-04 19:55:10 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-08-04 19:55:10 +1000
commita94c9acbb4455be86d5841598d4ac07f3cddbaf0 (patch)
tree6c17ca80736ac3faedddebd0b83a5b51fd1e4b6b /src/Java/miscutil/core/util
parenta0d482a7f23bd959ca26466de024d779ec6bf352 (diff)
downloadGT5-Unofficial-a94c9acbb4455be86d5841598d4ac07f3cddbaf0.tar.gz
GT5-Unofficial-a94c9acbb4455be86d5841598d4ac07f3cddbaf0.tar.bz2
GT5-Unofficial-a94c9acbb4455be86d5841598d4ac07f3cddbaf0.zip
% Changed handling of generated block names back to how it was.
% Changed power handling for Universal Battery. % Disabled Sinter furnacing and related debugging completely for release. % Changed generated dust tooltip handling.
Diffstat (limited to 'src/Java/miscutil/core/util')
-rw-r--r--src/Java/miscutil/core/util/debug/UtilsRendering.java7
-rw-r--r--src/Java/miscutil/core/util/math/MathUtils.java213
2 files changed, 215 insertions, 5 deletions
diff --git a/src/Java/miscutil/core/util/debug/UtilsRendering.java b/src/Java/miscutil/core/util/debug/UtilsRendering.java
index d57d92b6ff..89967e1a6a 100644
--- a/src/Java/miscutil/core/util/debug/UtilsRendering.java
+++ b/src/Java/miscutil/core/util/debug/UtilsRendering.java
@@ -2,9 +2,6 @@ package miscutil.core.util.debug;
import javax.vecmath.Point3d;
-import libshapedraw.LibShapeDraw;
-import libshapedraw.primitive.ReadonlyColor;
-import libshapedraw.shape.WireframeCuboid;
import miscutil.core.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@@ -29,7 +26,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class UtilsRendering {
static Tessellator drawBlock = Tessellator.instance;
- public static void drawBlockInWorld(final int x, final int y, final int z, final ReadonlyColor colours){
+ /*public static void drawBlockInWorld(final int x, final int y, final int z, final ReadonlyColor colours){
Thread t = new Thread() {
@Override
public void run() {
@@ -51,7 +48,7 @@ public class UtilsRendering {
}
};
t.start();
- }
+ }*/
public static void renderStuff (int x, int y, int z){
Utils.LOG_INFO("Doing Some Debug Rendering.");
diff --git a/src/Java/miscutil/core/util/math/MathUtils.java b/src/Java/miscutil/core/util/math/MathUtils.java
new file mode 100644
index 0000000000..bc3cb2843c
--- /dev/null
+++ b/src/Java/miscutil/core/util/math/MathUtils.java
@@ -0,0 +1,213 @@
+package miscutil.core.util.math;
+
+import java.util.Map;
+import java.util.Random;
+
+import miscutil.core.util.Utils;
+
+public class MathUtils {
+
+ /**
+ * Returns a psuedo-random number between min and max, inclusive.
+ * The difference between min and max can be at most
+ * Integer.MAX_VALUE - 1.
+ *
+ * @param min Minimim value
+ * @param max Maximim value. Must be greater than min.
+ * @return Integer between min and max, inclusive.
+ * @see java.util.Random#nextInt(int)
+ */
+ public static int randInt(int min, int max) {
+
+ // Usually this can be a field rather than a method variable
+ Random rand = new Random();
+
+ // nextInt is normally exclusive of the top value,
+ // so add 1 to make it inclusive
+ int randomNum = rand.nextInt((max - min) + 1) + min;
+
+ return randomNum;
+ }
+
+
+ /**
+ * Returns a psuedo-random number between min and max, inclusive.
+ * The difference between min and max can be at most
+ * Long.MAX_VALUE - 1.
+ *
+ * @param min Minimim value
+ * @param max Maximim value. Must be greater than min.
+ * @return Long between min and max, inclusive.
+ * @see java.util.Random#nextLong(long)
+ */
+ public static long randLong(long min, long max) {
+ // Usually this can be a field rather than a method variable
+ Random rand = new Random();
+
+ // nextInt is normally exclusive of the top value,
+ // so add 1 to make it inclusive
+ long randomNum = MathUtils.nextLong(rand,(max - min) + 1) + min;
+
+ return randomNum;
+ }
+ private static long nextLong(Random rng, long n) {
+ // error checking and 2^x checking removed for simplicity.
+ long bits, val;
+ do {
+ bits = (rng.nextLong() << 1) >>> 1;
+ val = bits % n;
+ } while (bits-val+(n-1) < 0L);
+ return val;
+ }
+
+
+ /**
+ * Returns a percentage.
+ * The returned number is the % of X in Y.
+ * Supports Doubles.
+ *
+ * @param current Current value.
+ * @param max Maximim value. Must be greater than min.
+ * @return double between min and max, inclusive.
+ */
+ public static double findPercentage(double current, double max){
+ double c = ((double) current / max) * 100;
+ double roundOff = Math.round(c * 100.00) / 100.00;
+ return roundOff;
+ }
+
+
+ //Smooth Rounding Function
+ /**
+ * Returns a double.
+ * The returned number is d rounded to the nearest d.01.
+ * Supports Doubles.
+ *
+ * @param current Current value.
+ * @return double Rounded value.
+ */
+ public static double decimalRounding(double d) {
+ return Math.round(d * 2) / 2.0;
+ }
+
+
+ //Smooth Rounding Function (Nearest 5)
+ /**
+ * Returns a double.
+ * The returned number is d rounded to the nearest d.5.
+ * Supports Doubles.
+ *
+ * @param current Current value.
+ * @return double Rounded value.
+ */
+ public static double decimalRoundingToWholes(double d) {
+ return 5*(Math.round(d/5));
+ }
+
+
+ /**
+ * Returns a boolean.
+ * The returned boolean is wether or not X evenly fits in to Y.
+ * Supports ints.
+ *
+ * @param x Value A.
+ * @param y Value B. Must be greater than min.
+ * @return boolean Whether or not it divides evenly.
+ */
+ public static boolean divideXintoY(int x, int y){
+ if ((x % y) == 0)
+ {
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Returns a boolean.
+ * The returned boolean is based on the odd/eveness of the input.
+ * Supports ints.
+ *
+ * @param x Value A.
+ * @return boolean Whether or not it divides evenly.
+ */
+ public static boolean isNumberEven(int x){
+ if ((x % 2) == 0)
+ {
+ return true;
+ }
+ return false;
+ }
+
+
+
+ /**
+ * Returns an int.
+ * The returned number is the value on i + 273.15F.
+ * Supports ints.
+ *
+ * @param i Temp in Celcius.
+ * @return int The celcius temp returned as Kelvin, rounded to the readest whole.
+ */
+ public static float celsiusToKelvin(int i){
+ double f = i + 273.15F;
+ return (int)decimalRoundingToWholes(f);
+ }
+
+
+ /**
+ * Returns a hexInteger.
+ * The returned number is the hex value of the input.
+ * Supports ints.
+ *
+ * @param input Current value.
+ * @return hexInteger.
+ */
+ public static int getHexNumberFromInt(int input){
+ String result = Integer.toHexString(input);
+ int resultINT = Integer.getInteger(result);
+ return resultINT;
+ }
+
+
+ /**
+ * Returns a hexInteger.
+ * The returned value is between min and max.
+ * Supports ints.
+ *
+ * @param min Minimum value.
+ * @param max Maximium value. Must be greater than min.
+ * @return hexInteger between min and max, inclusive.
+ */
+ public static int generateRandomHexValue(int min, int max){
+ int result = getHexNumberFromInt(randInt(min, max));
+ return result;
+ }
+
+
+ /**
+ * Returns a random hex value.
+ * The returned value is between 000000-ffffff.
+ *
+ * @return hexInteger between min and max, inclusive.
+ */
+ public static int generateSingularRandomHexValue(){
+ String temp;
+ int randomInt = randInt(1, 5);
+ final Map<Integer, String> colours = Utils.hexColourGeneratorRandom(5);
+
+ if (colours.get(randomInt) != null && colours.size() > 0){
+ temp = colours.get(randomInt);
+ }
+ else {
+ temp = "0F0F0F";
+ }
+
+ Utils.LOG_WARNING("Operating with "+temp);
+ temp = Utils.appenedHexNotationToString(String.valueOf(temp));
+ Utils.LOG_WARNING("Made "+temp+" - Hopefully it's not a mess.");
+ Utils.LOG_WARNING("It will decode into "+Integer.decode(temp)+".");
+ return Integer.decode(temp);
+ }
+
+}