Created
May 2, 2017 04:43
-
-
Save tterrag1098/c6725c6ebf6dd63b572c8f0eee84b843 to your computer and use it in GitHub Desktop.
StringsToBlockstate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void parseStates(Block block, List<Map<String, String>> states, Collection<IBlockState> data) { | |
if (states.isEmpty()) { | |
data.addAll(block.getBlockState().getValidStates()); | |
} else { | |
for (Map<String, String> state : states) { | |
data.add(parseState(block, state)); | |
} | |
} | |
} | |
@SuppressWarnings({ "unchecked", "rawtypes", "null" }) | |
private static IBlockState parseState(Block block, Map<String, String> state) { | |
IBlockState realstate = block.getDefaultState(); | |
BlockStateContainer container = block.getBlockState(); | |
for (Entry<String, String> e : state.entrySet()) { | |
IProperty<?> prop = container.getProperty(e.getKey()); | |
if (prop != null) { | |
Comparable<?> value = null; | |
for (Comparable<?> obj : prop.getAllowedValues()) { | |
if (obj.toString().equals(e.getValue())) { | |
value = obj; | |
break; | |
} | |
} | |
if (value != null) { | |
realstate = realstate.withProperty((IProperty) prop, (Comparable) value); | |
} | |
} | |
} | |
if (realstate instanceof IExtendedBlockState) { | |
realstate = ((IExtendedBlockState) realstate).getClean(); // ??? | |
} | |
return realstate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment