Search in sources :

Example 1 with Variation

use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.

the class SnakeDecoratorImplementation method getBlock.

private IBlockState getBlock(SnakeBlock sblock, Random rand) {
    String blockName = chooseBlock(sblock.getType(), rand);
    Colour blockCol = chooseColour(sblock.getColour(), rand);
    Variation blockVar = chooseVariant(sblock.getVariant(), rand);
    return BlockDrawingHelper.applyModifications(MinecraftTypeHelper.ParseBlockType(blockName), blockCol, null, blockVar);
}
Also used : Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 2 with Variation

use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.

the class MazeDecoratorImplementation method getBlock.

private XMLBlockState getBlock(MazeBlock mblock, Random rand) {
    BlockType blockName = chooseBlock(mblock.getType(), rand);
    Colour blockCol = chooseColour(mblock.getColour(), rand);
    Variation blockVar = chooseVariant(mblock.getVariant(), rand);
    return new XMLBlockState(blockName, blockCol, null, blockVar);
}
Also used : BlockType(com.microsoft.Malmo.Schemas.BlockType) Variation(com.microsoft.Malmo.Schemas.Variation) XMLBlockState(com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 3 with Variation

use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.

the class MinecraftTypeHelper method getDrawItemFromItemStack.

/** Attempt to break the item on this itemstack into a type/variant/colour which we can use for communication with the Malmo platform.
     * @param is the ItemStack containing the item we are attempting to deconstruct.
     * @return an XML DrawItem object containing the item's type, variant, colour etc.
     */
public static DrawItem getDrawItemFromItemStack(ItemStack is) {
    if (is == null)
        return null;
    DrawItem di = new DrawItem();
    // Get unlocalised name from the stack, not the stack's item - this ensures we keep the metadata.
    String name = is.getUnlocalizedName();
    if (is.getHasSubtypes()) {
        // If the item has subtypes, then there are varieties - eg different colours, types, etc.
        // Attempt to map from these subtypes back to variant/colour.
        // Do this by decomposing the unlocalised name:
        List<String> itemParts = new ArrayList<String>(Arrays.asList(name.split("\\.")));
        if (is.getItem() instanceof ItemMonsterPlacer) {
            // Special case for eggs:
            itemParts.add(ItemMonsterPlacer.getEntityName(is));
        }
        // First part will be "tile" or "item".
        // Second part will be the item itself (eg "dyePowder" or "stainedGlass" etc).
        // Third part will be the variant, colour etc.
        Colour col = null;
        Variation var = null;
        for (int part = 2; part < itemParts.size(); part++) {
            String section = itemParts.get(part);
            // First see if this matches a colour:
            if (col == null) {
                col = attemptToGetAsColour(section);
                if (// If it wasn't a colour, check to see if it was a variant:
                col == null && var == null)
                    var = attemptToGetAsVariant(section, is);
            } else if (var == null)
                var = attemptToGetAsVariant(section, is);
        }
        di.setColour(col);
        di.setVariant(var);
    }
    // Use the item registry name for the item - this is what we use in Types.XSD
    Object obj = Item.itemRegistry.getNameForObject(is.getItem());
    String publicName;
    if (obj instanceof ResourceLocation)
        publicName = ((ResourceLocation) obj).getResourcePath();
    else
        publicName = obj.toString();
    di.setType(publicName);
    return di;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) Variation(com.microsoft.Malmo.Schemas.Variation) ItemMonsterPlacer(net.minecraft.item.ItemMonsterPlacer) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 4 with Variation

use of com.microsoft.Malmo.Schemas.Variation 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)

Example 5 with Variation

use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.

the class MovingTargetDecoratorImplementation method isValid.

private boolean isValid(World world, BlockPos pos) {
    // In bounds?
    if (!blockInBounds(pos, this.arenaBounds))
        return false;
    // Already in path?
    if (this.path.contains(pos))
        return false;
    // Does there need to be air above the target?
    if (this.targetParams.isRequiresAirAbove() && !world.isAirBlock(pos.up()))
        return false;
    // Check the current block is "permeable"...
    IBlockState block = world.getBlockState(pos);
    List<IProperty> extraProperties = new ArrayList<IProperty>();
    DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(block, extraProperties);
    boolean typesMatch = this.targetParams.getPermeableBlocks().getType().isEmpty();
    for (BlockType bt : this.targetParams.getPermeableBlocks().getType()) {
        if (db.getType() == bt) {
            typesMatch = true;
            break;
        }
    }
    if (!typesMatch)
        return false;
    if (db.getColour() != null) {
        boolean coloursMatch = this.targetParams.getPermeableBlocks().getColour().isEmpty();
        for (Colour col : this.targetParams.getPermeableBlocks().getColour()) {
            if (db.getColour() == col) {
                coloursMatch = true;
                break;
            }
        }
        if (!coloursMatch)
            return false;
    }
    if (db.getVariant() != null) {
        boolean variantsMatch = this.targetParams.getPermeableBlocks().getVariant().isEmpty();
        for (Variation var : this.targetParams.getPermeableBlocks().getVariant()) {
            if (db.getVariant() == var) {
                variantsMatch = true;
                break;
            }
        }
        if (!variantsMatch)
            return false;
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) BlockType(com.microsoft.Malmo.Schemas.BlockType) ArrayList(java.util.ArrayList) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Aggregations

Variation (com.microsoft.Malmo.Schemas.Variation)9 Colour (com.microsoft.Malmo.Schemas.Colour)7 ArrayList (java.util.ArrayList)4 BlockType (com.microsoft.Malmo.Schemas.BlockType)3 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)3 IProperty (net.minecraft.block.properties.IProperty)3 IBlockState (net.minecraft.block.state.IBlockState)3 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)2 ItemMonsterPlacer (net.minecraft.item.ItemMonsterPlacer)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)1 Facing (com.microsoft.Malmo.Schemas.Facing)1 FlowerTypes (com.microsoft.Malmo.Schemas.FlowerTypes)1 HalfTypes (com.microsoft.Malmo.Schemas.HalfTypes)1 MonsterEggTypes (com.microsoft.Malmo.Schemas.MonsterEggTypes)1 ShapeTypes (com.microsoft.Malmo.Schemas.ShapeTypes)1 StoneTypes (com.microsoft.Malmo.Schemas.StoneTypes)1 WoodTypes (com.microsoft.Malmo.Schemas.WoodTypes)1 XMLBlockState (com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState)1 Item (net.minecraft.item.Item)1