Search in sources :

Example 1 with ShapeTypes

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

the class BlockDrawingHelper method setBlockState.

public void setBlockState(World w, BlockPos pos, XMLBlockState state) {
    if (!state.isValid())
        return;
    // Do some depressingly necessary specific stuff here for different block types:
    if (state.getBlock() instanceof BlockRailBase && state.variant != null) {
        // Caller has specified a variant - is it a shape variant?
        try {
            ShapeTypes shape = ShapeTypes.fromValue(state.variant.getValue());
            if (shape != null) {
                // Yes, user has requested a particular shape.
                // Minecraft won't honour this - and, worse, it may get altered by neighbouring pieces that are added later.
                // So we don't bother trying to get this right now - we add it as a state check, and set it correctly
                // after drawing has finished.
                StateCheck sc = new StateCheck();
                sc.pos = pos;
                sc.desiredState = state.state;
                sc.propertiesToCheck = new ArrayList<IProperty>();
                sc.propertiesToCheck.add(((BlockRailBase) state.getBlock()).getShapeProperty());
                this.checkList.add(sc);
            }
        } catch (IllegalArgumentException e) {
        // Wasn't a shape variation. Ignore.
        }
    }
    // Actually set the block state into the world:
    w.setBlockState(pos, state.state);
    // And now do the necessary post-placement processing:
    if (state.type == BlockType.MOB_SPAWNER) {
        TileEntity te = w.getTileEntity(pos);
        if (// Ought to be!
        te != null && te instanceof TileEntityMobSpawner) {
            // Attempt to use the variation to control what type of mob this spawns:
            try {
                EntityTypes entvar = EntityTypes.fromValue(state.variant.getValue());
                ((TileEntityMobSpawner) te).getSpawnerBaseLogic().setEntityName(entvar.value());
            } catch (Exception e) {
            // Do nothing - user has requested a non-entity variant.
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ShapeTypes(com.microsoft.Malmo.Schemas.ShapeTypes) IProperty(net.minecraft.block.properties.IProperty) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 2 with ShapeTypes

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

Aggregations

EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)2 ShapeTypes (com.microsoft.Malmo.Schemas.ShapeTypes)2 FlowerTypes (com.microsoft.Malmo.Schemas.FlowerTypes)1 HalfTypes (com.microsoft.Malmo.Schemas.HalfTypes)1 MonsterEggTypes (com.microsoft.Malmo.Schemas.MonsterEggTypes)1 StoneTypes (com.microsoft.Malmo.Schemas.StoneTypes)1 Variation (com.microsoft.Malmo.Schemas.Variation)1 WoodTypes (com.microsoft.Malmo.Schemas.WoodTypes)1 BlockRailBase (net.minecraft.block.BlockRailBase)1 IProperty (net.minecraft.block.properties.IProperty)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityMobSpawner (net.minecraft.tileentity.TileEntityMobSpawner)1