Search in sources :

Example 1 with BlockType

use of com.microsoft.Malmo.Schemas.BlockType 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 2 with BlockType

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

the class AgentQuitFromTouchingBlockTypeImplementation method parseParameters.

@Override
public boolean parseParameters(Object params) {
    if (params == null || !(params instanceof AgentQuitFromTouchingBlockType))
        return false;
    this.params = (AgentQuitFromTouchingBlockType) params;
    // Flatten all the possible block type names for ease of matching later:
    this.blockTypeNames = new ArrayList<String>();
    for (BlockSpec bs : this.params.getBlock()) {
        for (BlockType bt : bs.getType()) {
            Block b = Block.getBlockFromName(bt.value());
            this.blockTypeNames.add(b.getUnlocalizedName().toLowerCase());
        }
    }
    return true;
}
Also used : BlockType(com.microsoft.Malmo.Schemas.BlockType) AgentQuitFromTouchingBlockType(com.microsoft.Malmo.Schemas.AgentQuitFromTouchingBlockType) Block(net.minecraft.block.Block) BlockSpec(com.microsoft.Malmo.Schemas.BlockSpec) AgentQuitFromTouchingBlockType(com.microsoft.Malmo.Schemas.AgentQuitFromTouchingBlockType)

Example 3 with BlockType

use of com.microsoft.Malmo.Schemas.BlockType 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.REGISTRY.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 : 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 4 with BlockType

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

the class BlockDrawingHelper method DrawPrimitive.

protected void DrawPrimitive(DrawContainer c, World w) throws Exception {
    // First, draw the container block:
    String cType = c.getType().value();
    // Safe - ContainerType is a subset of BlockType
    BlockType bType = BlockType.fromValue(cType);
    XMLBlockState blockType = new XMLBlockState(bType, c.getColour(), c.getFace(), c.getVariant());
    if (!blockType.isValid())
        throw new Exception("Unrecogised item type: " + c.getType().value());
    BlockPos pos = new BlockPos(c.getX(), c.getY(), c.getZ());
    setBlockState(w, pos, blockType);
    // Now fill the container:
    TileEntity tileentity = w.getTileEntity(pos);
    if (tileentity instanceof TileEntityLockableLoot) {
        // First clear out any leftovers:
        ((TileEntityLockableLoot) tileentity).clear();
        int index = 0;
        for (ContainedObjectType cot : c.getObject()) {
            DrawItem di = new DrawItem();
            di.setColour(cot.getColour());
            di.setType(cot.getType());
            di.setVariant(cot.getVariant());
            ItemStack stack = MinecraftTypeHelper.getItemStackFromDrawItem(di);
            stack.setCount(cot.getQuantity());
            ((TileEntityLockableLoot) tileentity).setInventorySlotContents(index, stack);
            index++;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLockableLoot(net.minecraft.tileentity.TileEntityLockableLoot) BlockType(com.microsoft.Malmo.Schemas.BlockType) ContainedObjectType(com.microsoft.Malmo.Schemas.ContainedObjectType) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) ItemStack(net.minecraft.item.ItemStack)

Example 5 with BlockType

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

the class BlockDrawingHelper method DrawPrimitive.

protected void DrawPrimitive(DrawSign s, World w) throws Exception {
    String sType = s.getType().value();
    // Safe - SignType is a subset of BlockType
    BlockType bType = BlockType.fromValue(sType);
    XMLBlockState blockType = new XMLBlockState(bType, s.getColour(), s.getFace(), s.getVariant());
    BlockPos pos = new BlockPos(s.getX(), s.getY(), s.getZ());
    setBlockState(w, pos, blockType);
    if (blockType.type == BlockType.STANDING_SIGN && s.getRotation() != null) {
        IBlockState placedBlockState = w.getBlockState(pos);
        if (placedBlockState != null) {
            Block placedBlock = placedBlockState.getBlock();
            if (placedBlock != null) {
                IBlockState rotatedBlock = placedBlock.getStateFromMeta(s.getRotation());
                w.setBlockState(pos, rotatedBlock);
            }
        }
    }
    TileEntity tileentity = w.getTileEntity(pos);
    if (tileentity instanceof TileEntitySign) {
        TileEntitySign sign = (TileEntitySign) tileentity;
        if (s.getLine1() != null)
            sign.signText[0] = new TextComponentString(s.getLine1());
        if (s.getLine2() != null)
            sign.signText[1] = new TextComponentString(s.getLine2());
        if (s.getLine3() != null)
            sign.signText[2] = new TextComponentString(s.getLine3());
        if (s.getLine4() != null)
            sign.signText[3] = new TextComponentString(s.getLine4());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySign(net.minecraft.tileentity.TileEntitySign) IBlockState(net.minecraft.block.state.IBlockState) BlockType(com.microsoft.Malmo.Schemas.BlockType) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

BlockType (com.microsoft.Malmo.Schemas.BlockType)6 Colour (com.microsoft.Malmo.Schemas.Colour)3 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)3 Variation (com.microsoft.Malmo.Schemas.Variation)3 Block (net.minecraft.block.Block)2 IProperty (net.minecraft.block.properties.IProperty)2 IBlockState (net.minecraft.block.state.IBlockState)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 AgentQuitFromTouchingBlockType (com.microsoft.Malmo.Schemas.AgentQuitFromTouchingBlockType)1 BlockSpec (com.microsoft.Malmo.Schemas.BlockSpec)1 ContainedObjectType (com.microsoft.Malmo.Schemas.ContainedObjectType)1 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)1 Facing (com.microsoft.Malmo.Schemas.Facing)1 XMLBlockState (com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntityLockableLoot (net.minecraft.tileentity.TileEntityLockableLoot)1 TileEntitySign (net.minecraft.tileentity.TileEntitySign)1