Search in sources :

Example 1 with Facing

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;
}
Also used : Facing(com.microsoft.Malmo.Schemas.Facing) EnumFacing(net.minecraft.util.EnumFacing) BlockType(com.microsoft.Malmo.Schemas.BlockType) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Aggregations

BlockType (com.microsoft.Malmo.Schemas.BlockType)1 Colour (com.microsoft.Malmo.Schemas.Colour)1 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)1 Facing (com.microsoft.Malmo.Schemas.Facing)1 Variation (com.microsoft.Malmo.Schemas.Variation)1 IProperty (net.minecraft.block.properties.IProperty)1 EnumFacing (net.minecraft.util.EnumFacing)1 ResourceLocation (net.minecraft.util.ResourceLocation)1