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

View File

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