Skip to content

Instantly share code, notes, and snippets.

@tterrag1098
Created May 2, 2017 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tterrag1098/c6725c6ebf6dd63b572c8f0eee84b843 to your computer and use it in GitHub Desktop.
Save tterrag1098/c6725c6ebf6dd63b572c8f0eee84b843 to your computer and use it in GitHub Desktop.
StringsToBlockstate
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