mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 01:15:08 +01:00
@@ -146,11 +146,11 @@ public abstract class MidnightConfig {
|
|||||||
if (requiredModLoaded) entries.add(info);
|
if (requiredModLoaded) entries.add(info);
|
||||||
}
|
}
|
||||||
public static Class<?> getUnderlyingType(Field field) {
|
public static Class<?> getUnderlyingType(Field field) {
|
||||||
if (field.getType() == List.class) {
|
Class<?> rawType = field.getType();
|
||||||
Class<?> listType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
if (field.getType() == List.class)
|
||||||
try { return (Class<?>) listType.getField("TYPE").get(null);
|
rawType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||||
} catch (NoSuchFieldException | IllegalAccessException ignored) { return listType; }
|
try { return (Class<?>) rawType.getField("TYPE").get(null); // Tries to get primitive types from non-primitives (e.g. Boolean -> boolean)
|
||||||
} else return field.getType();
|
} catch (NoSuchFieldException | IllegalAccessException ignored) { return rawType; }
|
||||||
}
|
}
|
||||||
public static Tooltip getTooltip(EntryInfo info, boolean isButton) {
|
public static Tooltip getTooltip(EntryInfo info, boolean isButton) {
|
||||||
String key = info.modid + ".midnightconfig."+info.field.getName()+(!isButton ? ".label" : "" )+".tooltip";
|
String key = info.modid + ".midnightconfig."+info.field.getName()+(!isButton ? ".label" : "" )+".tooltip";
|
||||||
@@ -476,8 +476,8 @@ public abstract class MidnightConfig {
|
|||||||
@Override
|
@Override
|
||||||
public void applyValue() {
|
public void applyValue() {
|
||||||
if (info.dataType == int.class) info.setValue(((Number) (e.min() + value * (e.max() - e.min()))).intValue());
|
if (info.dataType == int.class) info.setValue(((Number) (e.min() + value * (e.max() - e.min()))).intValue());
|
||||||
else if (info.field.getType() == double.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (double) e.precision()) / (double) e.precision());
|
else if (info.dataType == double.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (double) e.precision()) / (double) e.precision());
|
||||||
else if (info.field.getType() == float.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (float) e.precision()) / (float) e.precision());
|
else if (info.dataType == float.class) info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (float) e.precision()) / (float) e.precision());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
@Comment(category = TEXT, centered = true) public static Comment text2; // Centered comments are the same as normal ones - just centered!
|
@Comment(category = TEXT, centered = true) public static Comment text2; // Centered comments are the same as normal ones - just centered!
|
||||||
@Comment(category = TEXT) public static Comment spacer1; // Comments containing the word "spacer" will just appear as a blank line
|
@Comment(category = TEXT) public static Comment spacer1; // Comments containing the word "spacer" will just appear as a blank line
|
||||||
@Entry(category = TEXT) public static boolean showInfo = true; // Example for a boolean option
|
@Entry(category = TEXT) public static boolean showInfo = true; // Example for a boolean option
|
||||||
|
@Entry(category = TEXT, name="I am a (non-primitive) Boolean") public static Boolean nonPrimitive = true; // Example for a non-primative boolean option
|
||||||
@Entry(category = TEXT) public static String name = "Hello World!"; // Example for a string option, which is in a category!
|
@Entry(category = TEXT) public static String name = "Hello World!"; // Example for a string option, which is in a category!
|
||||||
@Entry(category = TEXT, width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a color chooser for a hexadecimal color
|
@Entry(category = TEXT, width = 7, min = 7, isColor = true, name = "I am a color!") public static String titleColor = "#ffffff"; // The isColor property adds a color chooser for a hexadecimal color
|
||||||
@Entry(category = TEXT, idMode = 0) public static Identifier id = Identifier.ofVanilla("diamond"); // Example for an identifier with matching items displayed next to it!
|
@Entry(category = TEXT, idMode = 0) public static Identifier id = Identifier.ofVanilla("diamond"); // Example for an identifier with matching items displayed next to it!
|
||||||
@@ -34,6 +35,7 @@ public class MidnightConfigExample extends MidnightConfig {
|
|||||||
@Entry(category = NUMBERS, min=69,max=420) public static int hello = 420; // - The entered number has to be larger than 69 and smaller than 420
|
@Entry(category = NUMBERS, min=69,max=420) public static int hello = 420; // - The entered number has to be larger than 69 and smaller than 420
|
||||||
@Entry(category = SLIDERS, name = "I am an int slider.",isSlider = true, min = 0, max = 100) public static int intSlider = 35; // Int fields can also be displayed as a Slider
|
@Entry(category = SLIDERS, name = "I am an int slider.",isSlider = true, min = 0, max = 100) public static int intSlider = 35; // Int fields can also be displayed as a Slider
|
||||||
@Entry(category = SLIDERS, name = "I am a float slider!", isSlider = true, min = 0f, max = 1f, precision = 1000) public static float floatSlider = 0.24f; // And so can floats! Precision defines the amount of decimal places
|
@Entry(category = SLIDERS, name = "I am a float slider!", isSlider = true, min = 0f, max = 1f, precision = 1000) public static float floatSlider = 0.24f; // And so can floats! Precision defines the amount of decimal places
|
||||||
|
@Entry(category = SLIDERS, name = "I am a non-primitive double slider!", isSlider = true, min = 0d, max = 4d, precision = 10000) public static Double nonPrimitiveDoubleSlider = 3.76d; // Even works for non-primitive fields
|
||||||
// The name field can be used to specify a custom translation string or plain text
|
// The name field can be used to specify a custom translation string or plain text
|
||||||
@Entry(category = LISTS, name = "I am a string list!") public static List<String> stringList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
|
@Entry(category = LISTS, name = "I am a string list!") public static List<String> stringList = Lists.newArrayList("String1", "String2"); // Array String Lists are also supported
|
||||||
@Entry(category = LISTS, isColor = true, name = "I am a color list!") public static List<String> colorList = Lists.newArrayList("#ac5f99", "#11aa44"); // Lists also support colors
|
@Entry(category = LISTS, isColor = true, name = "I am a color list!") public static List<String> colorList = Lists.newArrayList("#ac5f99", "#11aa44"); // Lists also support colors
|
||||||
|
|||||||
Reference in New Issue
Block a user