Permalink
Browse files

Fixed parsing fuzzy blocks failing.

  • Loading branch information...
me4502 committed Feb 11, 2019
1 parent c53a40b commit 3e988e7ffe08a3edc44c35d5c4e02f9ae696a476
@@ -148,7 +148,9 @@ private String woolMapper(String string) {
}
}

private static BlockState applyProperties(BlockState state, String[] stateProperties) throws NoMatchException {
private static Map<Property<?>, Object> parseProperties(BlockType type, String[] stateProperties) throws NoMatchException {
Map<Property<?>, Object> blockStates = new HashMap<>();

if (stateProperties.length > 0) { // Block data not yet detected
// Parse the block data (optional)
for (String parseableData : stateProperties) {
@@ -159,9 +161,12 @@ private static BlockState applyProperties(BlockState state, String[] stateProper
}

@SuppressWarnings("unchecked")
Property<Object> propertyKey = (Property<Object>) state.getBlockType().getPropertyMap().get(parts[0]);
Property<Object> propertyKey = (Property<Object>) type.getPropertyMap().get(parts[0]);
if (propertyKey == null) {
throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getName());
}
if (blockStates.containsKey(propertyKey)) {
throw new NoMatchException("Duplicate property " + parts[0]);
}
Object value;
try {
@@ -170,7 +175,7 @@ private static BlockState applyProperties(BlockState state, String[] stateProper
throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]);
}

state = state.with(propertyKey, value);
blockStates.put(propertyKey, value);
} catch (NoMatchException e) {
throw e; // Pass-through
} catch (Exception e) {
@@ -180,7 +185,7 @@ private static BlockState applyProperties(BlockState state, String[] stateProper
}
}

return state;
return blockStates;
}

private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
@@ -265,9 +270,16 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa
}
}

blockStates.putAll(parseProperties(blockType, stateProperties));

if (!context.isPreferringWildcard()) {
// No wildcards allowed => eliminate them. (Start with default state)
state = blockType.getDefaultState();
for (Map.Entry<Property<?>, Object> blockState : blockStates.entrySet()) {
@SuppressWarnings("unchecked")
Property<Object> objProp = (Property<Object>) blockState.getKey();
state = state.with(objProp, blockState.getValue());
}
} else {
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
fuzzyBuilder.type(blockType);
@@ -278,8 +290,6 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa
}
state = fuzzyBuilder.build();
}

state = applyProperties(state, stateProperties);
}

// Check if the item is allowed

0 comments on commit 3e988e7

Please sign in to comment.