Skip to content

Commit

Permalink
Update Cloth Config
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Apr 24, 2020
1 parent 335339a commit 63bc76c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 49 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'

version = "4.4"
version = "4.5"
group = "me.shedaniel" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "LightOverlay"

Expand Down Expand Up @@ -58,7 +58,7 @@ repositories {

dependencies {
minecraft 'net.minecraftforge:forge:1.15.2-31.1.39'
implementation fg.deobf("curse.maven:cloth-config-forge:2844737")
implementation fg.deobf("curse.maven:cloth-config-forge:2938583")
}

jar {
Expand Down
48 changes: 2 additions & 46 deletions src/main/java/me/shedaniel/lightoverlay/LightOverlayCloth.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
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) -> {
Expand All @@ -22,18 +18,8 @@ public static void register() {
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 {
Expand All @@ -45,34 +31,4 @@ public static void register() {
}).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);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To provide users with NEI-like light overlay.
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[2.0,)" #mandatory
versionRange="[3.0,)" #mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="CLIENT"

0 comments on commit 63bc76c

Please sign in to comment.