Add a config comment that lists the available constants of enums (#6079)

This commit is contained in:
ichttt 2019-08-29 06:28:21 +02:00 committed by LexManos
parent d5e20b13b9
commit 06c3e255b3

View file

@ -38,6 +38,7 @@ import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
@ -388,6 +389,8 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<Config>
}
public <V extends Enum<V>> EnumValue<V> defineEnum(List<String> path, Supplier<V> defaultSupplier, EnumGetMethod converter, Predicate<Object> validator, Class<V> clazz) {
context.setClazz(clazz);
V[] allowedValues = clazz.getEnumConstants();
context.setComment(ObjectArrays.concat(context.getComment(), "Allowed Values: " + Arrays.stream(allowedValues).map(Enum::name).collect(Collectors.joining(", "))));
return new EnumValue<V>(this, define(path, new ValueSpec(defaultSupplier, validator, context), defaultSupplier).getPath(), defaultSupplier, converter, clazz);
}