Hopefully fix enum defaults

This commit is contained in:
JFronny 2021-07-01 16:17:38 +02:00
parent 3fa12ce181
commit 1db554cb5a
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
3 changed files with 12 additions and 4 deletions

View File

@ -6,7 +6,7 @@ minecraft_version=1.17
yarn_mappings=build.1
loader_version=0.11.3
# Mod Properties
mod_version=2.1.0
mod_version=2.1.1
maven_group=io.gitlab.jfronny
archives_base_name=respackopts

View File

@ -1,5 +1,6 @@
package io.gitlab.jfronny.respackopts.data.entry;
import io.gitlab.jfronny.respackopts.Respackopts;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.text.Text;
@ -18,7 +19,7 @@ public abstract class ConfigEntry<T> {
public T getValue() {
if (value == null)
value = defaultValue;
value = getDefault();
return value;
}
@ -28,8 +29,10 @@ public abstract class ConfigEntry<T> {
}
public T getDefault() {
if (defaultValue == null)
defaultValue = value;
if (defaultValue == null) {
defaultValue = getValue();
Respackopts.LOGGER.warn("No default value set for entry, using current");
}
return defaultValue;
}

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.respackopts.gson;
import com.google.gson.*;
import io.gitlab.jfronny.respackopts.Respackopts;
import io.gitlab.jfronny.respackopts.data.entry.ConfigEnumEntry;
import java.lang.reflect.Type;
@ -36,6 +37,10 @@ public class EnumEntrySerializer implements JsonSerializer<ConfigEnumEntry>, Jso
else
throw new JsonSyntaxException("Expected string entry in enum");
}
if (result.values.isEmpty())
Respackopts.LOGGER.warn("Enum entry empty");
else
result.setDefault(result.values.get(0));
return result;
}
else