Hopefully fix enum defaults
This commit is contained in:
parent
3fa12ce181
commit
1db554cb5a
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user