Search in sources :

Example 6 with EntityTypes

use of com.microsoft.Malmo.Schemas.EntityTypes 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().setEntityId(new ResourceLocation(entvar.value()));
            } catch (Exception e) {
            // Do nothing - user has requested a non-entity variant.
            }
        }
    }
    if (state.type == BlockType.NOTEBLOCK) {
        TileEntity te = w.getTileEntity(pos);
        if (te != null && te instanceof TileEntityNote && state.variant != null) {
            try {
                NoteTypes note = NoteTypes.fromValue(state.variant.getValue());
                if (note != null) {
                    // User has requested a particular note.
                    ((TileEntityNote) te).note = (byte) note.ordinal();
                }
            } catch (IllegalArgumentException e) {
            // Wasn't a note variation. Ignore.
            }
        }
    }
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ShapeTypes(com.microsoft.Malmo.Schemas.ShapeTypes) NoteTypes(com.microsoft.Malmo.Schemas.NoteTypes) BlockRailBase(net.minecraft.block.BlockRailBase) TileEntity(net.minecraft.tileentity.TileEntity) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityNote(net.minecraft.tileentity.TileEntityNote) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Example 7 with EntityTypes

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

the class AgentQuitFromCatchingMobImplementation method doIWantToQuit.

@Override
public boolean doIWantToQuit(MissionInit missionInit) {
    this.quitCode = "";
    List<Entity> caughtEntities = RewardForCatchingMobImplementation.getCaughtEntities();
    for (Entity ent : caughtEntities) {
        // Do we care about this entity?
        for (MobWithDescription mob : this.qcmparams.getMob()) {
            for (EntityTypes et : mob.getType()) {
                if (et.value().equals(ent.getName())) {
                    if (!mob.isGlobal()) {
                        // If global flag is false, our player needs to be adjacent to the mob in order to claim the reward.
                        BlockPos entityPos = new BlockPos(ent.posX, ent.posY, ent.posZ);
                        EntityPlayerSP player = Minecraft.getMinecraft().player;
                        BlockPos playerPos = new BlockPos(player.posX, player.posY, player.posZ);
                        if (Math.abs(entityPos.getX() - playerPos.getX()) + Math.abs(entityPos.getZ() - playerPos.getZ()) > 1)
                            continue;
                    }
                    this.quitCode = mob.getDescription();
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) Entity(net.minecraft.entity.Entity) MobWithDescription(com.microsoft.Malmo.Schemas.MobWithDescription) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Aggregations

EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)7 ServerInitialConditions (com.microsoft.Malmo.Schemas.ServerInitialConditions)2 ServerSection (com.microsoft.Malmo.Schemas.ServerSection)2 ShapeTypes (com.microsoft.Malmo.Schemas.ShapeTypes)2 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 Entity (net.minecraft.entity.Entity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ColourMapProducer (com.microsoft.Malmo.Schemas.ColourMapProducer)1 FlowerTypes (com.microsoft.Malmo.Schemas.FlowerTypes)1 HalfTypes (com.microsoft.Malmo.Schemas.HalfTypes)1 MobWithColour (com.microsoft.Malmo.Schemas.MobWithColour)1 MobWithDescription (com.microsoft.Malmo.Schemas.MobWithDescription)1 MobWithDescriptionAndReward (com.microsoft.Malmo.Schemas.MobWithDescriptionAndReward)1 MonsterEggTypes (com.microsoft.Malmo.Schemas.MonsterEggTypes)1 NoteTypes (com.microsoft.Malmo.Schemas.NoteTypes)1 StoneTypes (com.microsoft.Malmo.Schemas.StoneTypes)1 Variation (com.microsoft.Malmo.Schemas.Variation)1 WoodTypes (com.microsoft.Malmo.Schemas.WoodTypes)1