This commit is contained in:
Leijurv 2019-04-20 15:35:11 -07:00
parent 1047d4ade9
commit 5da14fcb3f
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 11 additions and 12 deletions

View File

@ -28,7 +28,6 @@ import net.minecraft.util.text.ITextComponent;
import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.Parameter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
@ -850,9 +849,9 @@ public final class Settings {
Settings() {
Field[] temp = getClass().getFields();
Map<String, Setting<?>> tmpByName = new HashMap<>();
List<Setting<?>> tmpAll = new ArrayList<>();
Map<Setting<?>, Type> tmpSettingTypes = new HashMap<>();
Map<String, Setting<?>> tmpByName = new HashMap<>();
List<Setting<?>> tmpAll = new ArrayList<>();
Map<Setting<?>, Type> tmpSettingTypes = new HashMap<>();
try {
for (Field field : temp) {
@ -872,8 +871,8 @@ public final class Settings {
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
byLowerName = Collections.unmodifiableMap(tmpByName);
allSettings = Collections.unmodifiableList(tmpAll);
byLowerName = Collections.unmodifiableMap(tmpByName);
allSettings = Collections.unmodifiableList(tmpAll);
settingTypes = Collections.unmodifiableMap(tmpSettingTypes);
}

View File

@ -30,7 +30,8 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
@ -131,7 +132,7 @@ public class SettingsUtil {
throw new IllegalStateException("No setting by that name");
}
Class intendedType = setting.getValueClass();
Parser ioMethod = Parser.getParser(setting.getType());
ISettingParser ioMethod = Parser.getParser(setting.getType());
Object parsed = ioMethod.parse(new ParserContext(setting), settingValue);
if (!intendedType.isInstance(parsed)) {
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
@ -166,7 +167,7 @@ public class SettingsUtil {
DOUBLE(Double.class, Double::parseDouble),
BOOLEAN(Boolean.class, Boolean::parseBoolean),
INTEGER(Integer.class, Integer::parseInt),
FLOAT(Float.class,Float::parseFloat),
FLOAT(Float.class, Float::parseFloat),
LONG(Long.class, Long::parseLong),
ENUMFACING(EnumFacing.class, EnumFacing::byName),
COLOR(
@ -176,16 +177,15 @@ public class SettingsUtil {
),
BLOCK(
Block.class,
BlockUtils::stringToBlockRequired,
str -> BlockUtils.stringToBlockRequired(str.trim()),
BlockUtils::blockToString
),
ITEM(
Item.class,
Item::getByNameOrId,
str -> Item.getByNameOrId(str.trim()),
item -> Item.REGISTRY.getNameForObject(item).toString()
),
LIST() {
@Override
public Object parse(ParserContext context, String raw) {
Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0];