diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-29 19:15:48 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-29 19:15:48 +0000 |
commit | c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1 (patch) | |
tree | 2b549b5dfe3f80421ae2d45e041f929ea46d59aa /src/main/java/gtPlusPlus/core/util | |
parent | b926dfb3bc67b74b53749a3e420a8a6ce0fba6a7 (diff) | |
parent | 0de849179b344dfddc68393aaa23b3b75b307670 (diff) | |
download | GT5-Unofficial-c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1.tar.gz GT5-Unofficial-c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1.tar.bz2 GT5-Unofficial-c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1.zip |
Merge branch 'master' of https://github.com/GTNewHorizons/GTplusplus into St00f
# Conflicts:
# .gitignore
# dependencies.gradle
# src/main/java/gtPlusPlus/core/config/ConfigHandler.java
# src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java
# src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java
# src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java
# src/main/resources/assets/miscutils/lang/en_US.lang
Diffstat (limited to 'src/main/java/gtPlusPlus/core/util')
4 files changed, 105 insertions, 73 deletions
diff --git a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java index ef5db6e4e0..4ff929c643 100644 --- a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java +++ b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java @@ -16,12 +16,12 @@ public class MathUtils { final static Random rand = CORE.RANDOM; - /** Formats a number with group separator and at most 2 fraction digits. */ - private static final NumberFormat sNumberFormat = NumberFormat.getInstance(); - - static { - sNumberFormat.setMaximumFractionDigits(2); - } + /** Formats a number with group separator and at most 2 fraction digits. */ + private static final NumberFormat sNumberFormat = NumberFormat.getInstance(); + + static { + sNumberFormat.setMaximumFractionDigits(2); + } /** * Returns a psuedo-random number between min and max, inclusive. @@ -567,7 +567,7 @@ public class MathUtils { return 0; } } - + public static <V> V safeCast(Object aNumberType) { long a1; double a2; @@ -586,7 +586,7 @@ public class MathUtils { String s = ""+a1; Short s1 = Short.valueOf(s); return (V) s1; - + } } else if ((aNumberType.getClass() == int.class) || (aNumberType instanceof Integer)){ @@ -594,7 +594,7 @@ public class MathUtils { String s = ""+a1; Integer s1 = Integer.valueOf(s); return (V) s1; - + } } else if ((aNumberType.getClass() == long.class) || (aNumberType instanceof Long)){ @@ -609,7 +609,7 @@ public class MathUtils { String s = ""+a1; Float s1 = Float.valueOf(s); return (V) s1; - + } } else if ((aNumberType.getClass() == double.class) || (aNumberType instanceof Double)){ @@ -617,40 +617,40 @@ public class MathUtils { String s = ""+a1; Double s1 = Double.valueOf(s); return (V) s1; - + } } - + Integer o = 0; return (V) o; - + } - + public static byte getSafeByte(Byte b) { Byte a = safeCast(b); return a.byteValue(); } - + public static short getSafeShort(Short b) { Short a = safeCast(b); return a.shortValue(); } - + public static int getSafeInt(Integer b) { Integer a = safeCast(b); return a.intValue(); } - + public static long getSafeLong(Long b) { Long a = safeCast(b); return a.longValue(); } - + public static float getSafeFloat(Float b) { Float a = safeCast(b); return a.floatValue(); } - + public static double getSafeDouble(Double b) { Double a = safeCast(b); return a.doubleValue(); @@ -712,7 +712,7 @@ public class MathUtils { public static int balance(int aInput, int aMin, int aMax) { return Math.max(Math.min(aInput, aMax), aMin); } - + /** * Balances a number within a range. * @param aInput - The number to balance @@ -723,7 +723,7 @@ public class MathUtils { public static Number balance(Number aInput, Number aMin, Number aMax) { return max(min(aInput, aMax), aMin); } - + /** * Balances a number within a range. * @param aInput - The number to balance @@ -734,7 +734,7 @@ public class MathUtils { public static int balanceInt(Number aInput, Number aMin, Number aMax) { return MathUtils.safeCast_LongToInt((long) balance(max(min(aInput, aMax), aMin), Integer.MIN_VALUE, Integer.MAX_VALUE)); } - + /** * Balances a number within a range. * @param aInput - The number to balance @@ -750,51 +750,62 @@ public class MathUtils { int aAmount = Math.max(Math.min(i, aMax), aMin); return aAmount; } - + public static Pair<Integer, Integer> splitLongIntoIntegers(long aLong){ int aIntMaxInLong = (int) Math.min(Integer.MAX_VALUE, Math.floor(aLong/Integer.MAX_VALUE)); int aRemainder = (int) (aLong - (aIntMaxInLong * Integer.MAX_VALUE)); return new Pair<Integer, Integer>(aIntMaxInLong, aRemainder); } - - - /** - * Returns the smaller of two {@code Number}s. That is, - * the result the argument closer to the value of - * {@link Long#MIN_VALUE}. If the arguments have the same - * value, the result is that same value. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b}. - */ - public static Number min(Number a, Number b) { - return (a.longValue() <= b.longValue()) ? a : b; - } - - /** - * Returns the greater of two {@code Number}s. That is, the - * result is the argument closer to the value of - * {@link Long#MAX_VALUE}. If the arguments have the same value, - * the result is that same value. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static Number max(Number a, Number b) { - return (a.longValue() >= b.longValue()) ? a : b; - } - - public static String formatNumbers(long aNumber) { - return sNumberFormat.format(aNumber); - } - - public static String formatNumbers(double aNumber) { - return sNumberFormat.format(aNumber); - } + + + /** + * Returns the smaller of two {@code Number}s. That is, + * the result the argument closer to the value of + * {@link Long#MIN_VALUE}. If the arguments have the same + * value, the result is that same value. + * + * @param a an argument. + * @param b another argument. + * @return the smaller of {@code a} and {@code b}. + */ + public static Number min(Number a, Number b) { + return (a.longValue() <= b.longValue()) ? a : b; + } + + /** + * Returns the greater of two {@code Number}s. That is, the + * result is the argument closer to the value of + * {@link Long#MAX_VALUE}. If the arguments have the same value, + * the result is that same value. + * + * @param a an argument. + * @param b another argument. + * @return the larger of {@code a} and {@code b}. + */ + public static Number max(Number a, Number b) { + return (a.longValue() >= b.longValue()) ? a : b; + } + + public static long combineTwoIntegersToLong(int a, int b) { + long val = (((long) a) << 32) | (b & 0xffffffffL); + return val; + } + public static int[] splitLongIntoTwoIntegers(long aNum) { + int a = (int) (aNum >> 32); + int b = (int) aNum; + return new int[] {a, b}; + } + + public static String formatNumbers(long aNumber) { + return sNumberFormat.format(aNumber); + } + + public static String formatNumbers(double aNumber) { + return sNumberFormat.format(aNumber); + } + } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/MaterialUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/MaterialUtils.java index 0323bf0161..0ccd752775 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/MaterialUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/MaterialUtils.java @@ -18,6 +18,7 @@ import gtPlusPlus.core.client.CustomTextureSet.TextureSets; import gtPlusPlus.core.item.base.BaseItemComponent; import gtPlusPlus.core.item.base.BaseItemComponent.ComponentTypes; import gtPlusPlus.core.item.base.plates.BaseItemPlateHeavy; +import gtPlusPlus.core.item.base.wire.BaseItemFineWire; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.MaterialStack; @@ -457,6 +458,9 @@ public class MaterialUtils { if (aType == ComponentTypes.PLATEHEAVY) { aGC = new BaseItemPlateHeavy(aMaterial); } + else if (aType == ComponentTypes.FINEWIRE) { + aGC = new BaseItemFineWire(aMaterial); + } else { aGC = new BaseItemComponent(aMaterial, aType); } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/RecipeUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/RecipeUtils.java index da5bc071bc..595635d411 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/RecipeUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/RecipeUtils.java @@ -703,14 +703,14 @@ public static int mInvalidID = 1; CORE.crash("Bad Shaped Recipe."); } } - Logger.INFO("Using String: "+aFullString); + Logger.RECIPE("Using String: "+aFullString); String aRow1 = aFullString.substring(0, 3); String aRow2 = aFullString.substring(3, 6); String aRow3 = aFullString.substring(6, 9); - Logger.INFO(""+aRow1); - Logger.INFO(""+aRow2); - Logger.INFO(""+aRow3); + Logger.RECIPE(""+aRow1); + Logger.RECIPE(""+aRow2); + Logger.RECIPE(""+aRow3); String[] aStringData = new String[] {aRow1, aRow2, aRow3}; Object[] aDataObject = new Object[19]; @@ -730,10 +730,10 @@ public static int mInvalidID = 1; aIndex++; } - Logger.INFO("Data Size: "+aDataObject.length); + Logger.RECIPE("Data Size: "+aDataObject.length); aDataObject = ArrayUtils.removeNulls(aDataObject); - Logger.INFO("Clean Size: "+aDataObject.length); - Logger.INFO("ArrayData: "+Arrays.toString(aDataObject)); + Logger.RECIPE("Clean Size: "+aDataObject.length); + Logger.RECIPE("ArrayData: "+Arrays.toString(aDataObject)); ShapedOreRecipe aRecipe = new ShapedOreRecipe(aOutputStack, aDataObject); diff --git a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 48cdb18d7c..a5e0bea0cb 100644 --- a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -22,7 +22,6 @@ import com.google.common.reflect.ClassPath; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.util.data.StringUtils; -import gtPlusPlus.xmod.gregtech.common.StaticFields59; public class ReflectionUtils { @@ -271,6 +270,21 @@ public class ReflectionUtils { } } + public static Field[] getAllFields(final Class<?> aClass) { + if (aClass == null) { + return null; + } + Field[] aFields = aClass.getDeclaredFields(); + for (Field f : aFields) { + CachedField y = mCachedFields.get(aClass.getName()+"."+f.getName()); + if (y == null) { + makeFieldAccessible(f); + cacheField(aClass, f); + } + } + return aFields; + } + /** * Returns a cached {@link Field} object. * @param aInstance - {@link Object} to get the field instance from. @@ -335,6 +349,9 @@ public class ReflectionUtils { public static String getMethodName(final int depth) { final StackTraceElement[] ste = new Throwable().getStackTrace(); //System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName()); + if (ste.length < depth) { + return "No valid stack."; + } return ste[depth+1].getMethodName(); } @@ -441,7 +458,7 @@ public class ReflectionUtils { t.printStackTrace(); } } - + /** * Allows to change the state of an immutable instance. Huh?!? */ @@ -529,7 +546,7 @@ public class ReflectionUtils { Logger.REFLECTION("Invoke failed or did something wrong."); return false; } - + public static boolean invokeVoid(Object objectInstance, Method method, Object[] values){ if (method == null || values == null || (!ReflectionUtils.isStaticMethod(method) && objectInstance == null)){ //Logger.REFLECTION("Null value when trying to Dynamically invoke "+methodName+" on an object of type: "+objectInstance.getClass().getName()); @@ -543,8 +560,8 @@ public class ReflectionUtils { if (mInvokingMethod != null){ Logger.REFLECTION(methodName+" was not null."); mInvokingMethod.invoke(objectInstance, values); - Logger.REFLECTION("Successfully invoked "+methodName+"."); - return true; + Logger.REFLECTION("Successfully invoked "+methodName+"."); + return true; } } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { @@ -589,7 +606,7 @@ public class ReflectionUtils { String classname = objectInstance != null ? objectInstance.getClass().getCanonicalName() : method.getDeclaringClass().getCanonicalName(); Logger.REFLECTION("Trying to invoke "+methodName+" on an instance of "+classname+"."); try { - return method.invoke(objectInstance, values); + return method.invoke(objectInstance, values); } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { Logger.REFLECTION("Failed to Dynamically invoke "+methodName+" on an object of type: "+classname); |