use of com.microsoft.Malmo.Schemas.Facing in project malmo by Microsoft.
the class MinecraftTypeHelper method getDrawBlockFromBlockState.
/** Extract the type, variation and facing attributes of a blockstate and return them in a new DrawBlock object.<br>
* @param state the IBlockState to be examined
* @return A DrawBlock object
*/
public static DrawBlock getDrawBlockFromBlockState(IBlockState state, List<IProperty> extraProperties) {
if (state == null)
return null;
DrawBlock block = new DrawBlock();
Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
if (blockName instanceof ResourceLocation) {
String name = ((ResourceLocation) blockName).getResourcePath();
BlockType type = BlockType.fromValue(name);
block.setType(type);
}
Colour col = null;
Variation var = null;
Facing face = null;
// Add properties:
for (IProperty prop : (java.util.Set<IProperty>) state.getProperties().keySet()) {
String propVal = state.getValue(prop).toString();
boolean matched = false;
// Try colour first:
if (col == null) {
col = attemptToGetAsColour(propVal);
if (col != null)
matched = true;
}
// Then variant:
if (!matched && var == null) {
var = attemptToGetAsVariant(propVal);
if (var != null)
matched = true;
}
// Then facing:
if (!matched && face == null) {
face = attemptToGetAsFacing(propVal);
if (face != null)
matched = true;
}
if (!matched) {
if (extraProperties != null)
extraProperties.add(prop);
}
}
if (col != null)
block.setColour(col);
if (var != null)
block.setVariant(var);
if (face != null)
block.setFace(face);
return block;
}
Aggregations