|
@@ -3,14 +3,10 @@ package me.shedaniel.lightoverlay;
|
|
|
import me.shedaniel.forge.clothconfig2.api.ConfigBuilder;
|
|
|
import me.shedaniel.forge.clothconfig2.api.ConfigCategory;
|
|
|
import me.shedaniel.forge.clothconfig2.api.ConfigEntryBuilder;
|
|
|
-import net.minecraft.client.resources.I18n;
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
import net.minecraftforge.fml.ExtensionPoint;
|
|
|
import net.minecraftforge.fml.ModLoadingContext;
|
|
|
|
|
|
-import java.util.Locale;
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
public class LightOverlayCloth {
|
|
|
public static void register() {
|
|
|
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> (client, parent) -> {
|
|
@@ -22,18 +18,8 @@ public class LightOverlayCloth {
|
|
|
general.addEntry(eb.startIntSlider("config.lightoverlay-forge.crossLevel", LightOverlayClient.crossLevel, 0, 15).setDefaultValue(7).setTextGetter(integer -> "Cross Level: " + integer).setSaveConsumer(integer -> LightOverlayClient.crossLevel = integer).build());
|
|
|
general.addEntry(eb.startBooleanToggle("config.lightoverlay-forge.showNumber", LightOverlayClient.showNumber).setDefaultValue(false).setSaveConsumer(bool -> LightOverlayClient.showNumber = bool).build());
|
|
|
general.addEntry(eb.startIntSlider("config.lightoverlay-forge.lineWidth", MathHelper.floor(LightOverlayClient.lineWidth * 100), 100, 700).setDefaultValue(100).setTextGetter(integer -> "Light Width: " + LightOverlayClient.FORMAT.format(integer / 100d)).setSaveConsumer(integer -> LightOverlayClient.lineWidth = integer / 100f).build());
|
|
|
- general.addEntry(eb.startStrField("config.lightoverlay-forge.yellowColor", "#" + toStringColor(LightOverlayClient.yellowColor)).setDefaultValue("#FFFF00").setSaveConsumer(str -> LightOverlayClient.yellowColor = toIntColor(str)).setErrorSupplier(s -> {
|
|
|
- if (!s.startsWith("#") || s.length() != 7 || !isInt(s.substring(1)))
|
|
|
- return Optional.of(I18n.format("config.lightoverlay-forge.invalidColor"));
|
|
|
- else
|
|
|
- return Optional.empty();
|
|
|
- }).build());
|
|
|
- general.addEntry(eb.startStrField("config.lightoverlay-forge.redColor", "#" + toStringColor(LightOverlayClient.redColor)).setDefaultValue("#FF0000").setSaveConsumer(str -> LightOverlayClient.redColor = toIntColor(str)).setErrorSupplier(s -> {
|
|
|
- if (!s.startsWith("#") || s.length() != 7 || !isInt(s.substring(1)))
|
|
|
- return Optional.of(I18n.format("config.lightoverlay-forge.invalidColor"));
|
|
|
- else
|
|
|
- return Optional.empty();
|
|
|
- }).build());
|
|
|
+ general.addEntry(eb.startColorField("config.lightoverlay-forge.yellowColor", LightOverlayClient.yellowColor).setDefaultValue(0xFFFF00).setSaveConsumer(color -> LightOverlayClient.yellowColor = color).build());
|
|
|
+ general.addEntry(eb.startColorField("config.lightoverlay-forge.redColor", LightOverlayClient.redColor).setDefaultValue(0xFF0000).setSaveConsumer(color -> LightOverlayClient.redColor = color).build());
|
|
|
|
|
|
return builder.setSavingRunnable(() -> {
|
|
|
try {
|
|
@@ -45,34 +31,4 @@ public class LightOverlayCloth {
|
|
|
}).build();
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- private static boolean isInt(String s) {
|
|
|
- try {
|
|
|
- Integer.parseInt(s, 16);
|
|
|
- return true;
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static int toIntColor(String str) {
|
|
|
- String substring = str.substring(1);
|
|
|
- int r = Integer.parseInt(substring.substring(0, 2), 16);
|
|
|
- int g = Integer.parseInt(substring.substring(2, 4), 16);
|
|
|
- int b = Integer.parseInt(substring.substring(4, 6), 16);
|
|
|
- return (r << 16) + (g << 8) + b;
|
|
|
- }
|
|
|
-
|
|
|
- private static String toStringColor(int toolColor) {
|
|
|
- String r = Integer.toHexString((toolColor >> 16) & 0xFF);
|
|
|
- String g = Integer.toHexString((toolColor >> 8) & 0xFF);
|
|
|
- String b = Integer.toHexString(toolColor & 0xFF);
|
|
|
- if (r.length() == 1)
|
|
|
- r = "0" + r;
|
|
|
- if (g.length() == 1)
|
|
|
- g = "0" + g;
|
|
|
- if (b.length() == 1)
|
|
|
- b = "0" + b;
|
|
|
- return (r + g + b).toUpperCase(Locale.ROOT);
|
|
|
- }
|
|
|
}
|