Fixed parsing fuzzy blocks failing.

This commit is contained in:
Matthew Miller 2019-02-11 20:30:42 +10:00
parent c53a40b577
commit 3e988e7ffe

View File

@ -148,7 +148,9 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
} }
} }
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 if (stateProperties.length > 0) { // Block data not yet detected
// Parse the block data (optional) // Parse the block data (optional)
for (String parseableData : stateProperties) { for (String parseableData : stateProperties) {
@ -159,9 +161,12 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
} }
@SuppressWarnings("unchecked") @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) { 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; Object value;
try { try {
@ -170,7 +175,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]); throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]);
} }
state = state.with(propertyKey, value); blockStates.put(propertyKey, value);
} catch (NoMatchException e) { } catch (NoMatchException e) {
throw e; // Pass-through throw e; // Pass-through
} catch (Exception e) { } catch (Exception e) {
@ -180,7 +185,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
} }
} }
return state; return blockStates;
} }
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException { private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
@ -265,9 +270,16 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
} }
} }
blockStates.putAll(parseProperties(blockType, stateProperties));
if (!context.isPreferringWildcard()) { if (!context.isPreferringWildcard()) {
// No wildcards allowed => eliminate them. (Start with default state) // No wildcards allowed => eliminate them. (Start with default state)
state = blockType.getDefaultState(); 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 { } else {
FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder(); FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder();
fuzzyBuilder.type(blockType); fuzzyBuilder.type(blockType);
@ -278,8 +290,6 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
} }
state = fuzzyBuilder.build(); state = fuzzyBuilder.build();
} }
state = applyProperties(state, stateProperties);
} }
// Check if the item is allowed // Check if the item is allowed