Search in sources :

Example 6 with Variation

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

the class MinecraftTypeHelper method getItemStackFromDrawItem.

public static ItemStack getItemStackFromDrawItem(DrawItem i) {
    ItemStack itemStack = null;
    // First see if this is an item:
    Item item = MinecraftTypeHelper.ParseItemType(i.getType(), false);
    if (item == null) {
        // No, so is it a block type?
        IBlockState block = MinecraftTypeHelper.ParseBlockType(i.getType());
        if (block != null) {
            // It is - apply the modifications:
            block = BlockDrawingHelper.applyModifications(block, i.getColour(), i.getFace(), i.getVariant());
            // And try to return as an item:
            if (block != null && block.getBlock() != null && Item.getItemFromBlock(block.getBlock()) != null) {
                itemStack = new ItemStack(block.getBlock(), 1, block.getBlock().getMetaFromState(block));
            }
        }
    } else {
        if (item.getHasSubtypes() && (i.getColour() != null || i.getVariant() != null)) {
            // Attempt to find the subtype for this colour/variant - made tricky
            // because Items don't provide any nice property stuff like Blocks do...
            NonNullList<ItemStack> subItems = NonNullList.create();
            item.getSubItems(item, null, subItems);
            for (ItemStack is : subItems) {
                String fullName = is.getUnlocalizedName();
                if (is.getItem() instanceof ItemMonsterPlacer) {
                    // Special handling for eggs
                    fullName += "." + ItemMonsterPlacer.getNamedIdFrom(is).toString();
                }
                String[] parts = fullName.split("\\.");
                for (int p = 0; p < parts.length; p++) {
                    Variation v = attemptToGetAsVariant(parts[p], is);
                    Colour c = attemptToGetAsColour(parts[p]);
                    if ((v != null && i.getVariant() != null && v.getValue().equals(i.getVariant().getValue())) || (c != null && i.getColour() != null && c == i.getColour())) {
                        // This is it??
                        return is;
                    }
                }
            }
        }
        itemStack = new ItemStack(item);
    }
    return itemStack;
}
Also used : DrawItem(com.microsoft.Malmo.Schemas.DrawItem) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) Variation(com.microsoft.Malmo.Schemas.Variation) ItemMonsterPlacer(net.minecraft.item.ItemMonsterPlacer) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 7 with Variation

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

the class MinecraftTypeHelper method getItemStackFromParameterString.

/**
 * Take a string of parameters, delimited by spaces, and create an ItemStack from it.
 * @param parameters the item name, variation, colour etc of the required item, separated by spaces.
 * @return an Itemstack for these parameters, or null if unrecognised.
 */
public static ItemStack getItemStackFromParameterString(String parameters) {
    // Split into parameters:
    List<String> params = new ArrayList<String>(Arrays.asList(parameters.split(" ")));
    Colour col = null;
    Variation var = null;
    // See if any parameters appear to be a colour:
    Iterator<String> it = params.iterator();
    while (it.hasNext() && col == null) {
        col = MinecraftTypeHelper.attemptToGetAsColour(it.next());
        if (col != null)
            // This parameter was a colour - we've parsed it, so remove it.
            it.remove();
    }
    // See if any parameters appear to be a variant:
    it = params.iterator();
    while (it.hasNext() && var == null) {
        var = MinecraftTypeHelper.attemptToGetAsVariant(it.next());
        if (var != null)
            // This parameter was a variant - we've parsed it, so remove it.
            it.remove();
    }
    // Hopefully we have at most one parameter left, which will be the type.
    if (params.size() == 0)
        // Dunno what to do, really.
        return null;
    String itemName = params.get(0);
    DrawItem di = new DrawItem();
    di.setColour(col);
    di.setVariant(var);
    di.setType(itemName);
    return getItemStackFromDrawItem(di);
}
Also used : ArrayList(java.util.ArrayList) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 8 with Variation

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

the class MinecraftTypeHelper method attemptToGetAsVariant.

/**
 * Attempt to parse string as a Variation
 * @param part string token to parse
 * @return the BlockVariant enum value for the requested variant, or null if it wasn't valid.
 */
public static Variation attemptToGetAsVariant(String part) {
    // and have an object in the schemas that returns a list, so we can just iterate...
    try {
        StoneTypes var = StoneTypes.valueOf(part.toUpperCase());
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    try {
        WoodTypes var = WoodTypes.valueOf(part.toUpperCase());
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    try {
        FlowerTypes var = FlowerTypes.fromValue(part);
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    try {
        EntityTypes var = EntityTypes.fromValue(part);
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    try {
        MonsterEggTypes var = MonsterEggTypes.fromValue(part);
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    try {
        ShapeTypes var = ShapeTypes.fromValue(part);
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    try {
        HalfTypes var = HalfTypes.fromValue(part);
        if (var != null) {
            Variation bv = new Variation();
            bv.setValue(var.value());
            return bv;
        }
    } catch (Exception e) {
    // Does nothing.
    }
    return null;
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ShapeTypes(com.microsoft.Malmo.Schemas.ShapeTypes) StoneTypes(com.microsoft.Malmo.Schemas.StoneTypes) WoodTypes(com.microsoft.Malmo.Schemas.WoodTypes) MonsterEggTypes(com.microsoft.Malmo.Schemas.MonsterEggTypes) Variation(com.microsoft.Malmo.Schemas.Variation) FlowerTypes(com.microsoft.Malmo.Schemas.FlowerTypes) HalfTypes(com.microsoft.Malmo.Schemas.HalfTypes)

Example 9 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 BlockType (com.microsoft.Malmo.Schemas.BlockType)3 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)3 ArrayList (java.util.ArrayList)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