Search in sources :

Example 1 with EntityTypes

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

the class ServerStateMachine method onCheckSpawn.

/** Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.*/
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs) {
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null) {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty()) {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.classToStringMapping.get(cs.entity.getClass()).toString();
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs()) {
                if (mob.value().equals(mobName)) {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ServerSection(com.microsoft.Malmo.Schemas.ServerSection) ServerInitialConditions(com.microsoft.Malmo.Schemas.ServerInitialConditions) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityTypes

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

the class RewardForCatchingMobImplementation method getReward.

@Override
public void getReward(MissionInit missionInit, MultidimensionalReward reward) {
    super.getReward(missionInit, reward);
    List<Entity> trappedEntities = getCaughtEntities();
    for (MobWithDescriptionAndReward mob : this.rcmparams.getMob()) {
        // Have we caught one of these mobs?
        for (EntityTypes et : mob.getType()) {
            String mobName = et.value();
            for (Entity e : trappedEntities) {
                if (e.getName().equals(mobName)) {
                    // Potential match... check other options.
                    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(e.posX, e.posY, e.posZ);
                        EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
                        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;
                    }
                    // If oneshot flag is true, only allow the reward from this mob to be counted once.
                    if (mob.isOneshot() && this.caughtEntities.contains(e))
                        continue;
                    // Can claim the reward.
                    float adjusted_reward = adjustAndDistributeReward(mob.getReward().floatValue(), this.rcmparams.getDimension(), mob.getDistribution());
                    reward.add(this.rcmparams.getDimension(), adjusted_reward);
                }
            }
        }
    }
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) Entity(net.minecraft.entity.Entity) MobWithDescriptionAndReward(com.microsoft.Malmo.Schemas.MobWithDescriptionAndReward) BlockPos(net.minecraft.util.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 3 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().thePlayer;
                        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.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 4 with EntityTypes

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

the class ServerStateMachine method onGetPotentialSpawns.

/** Called by Forge - call setCanceled(true) to prevent spawning in our world.*/
@SubscribeEvent
public void onGetPotentialSpawns(PotentialSpawns ps) {
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null) {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty()) {
            // Spawning is allowed, but restricted to our list:
            Iterator<SpawnListEntry> it = ps.list.iterator();
            while (it.hasNext()) {
                // Is this on our list?
                SpawnListEntry sle = it.next();
                String mobName = EntityList.classToStringMapping.get(sle.entityClass).toString();
                boolean allowed = false;
                for (EntityTypes mob : sic.getAllowedMobs()) {
                    if (mob.value().equals(mobName))
                        allowed = true;
                }
                if (!allowed)
                    it.remove();
            }
        }
    }
    // Cancel spawn event:
    if (!allowSpawning)
        ps.setCanceled(true);
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ServerSection(com.microsoft.Malmo.Schemas.ServerSection) SpawnListEntry(net.minecraft.world.biome.BiomeGenBase.SpawnListEntry) ServerInitialConditions(com.microsoft.Malmo.Schemas.ServerInitialConditions) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 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().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)

Aggregations

EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)6 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.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 FlowerTypes (com.microsoft.Malmo.Schemas.FlowerTypes)1 HalfTypes (com.microsoft.Malmo.Schemas.HalfTypes)1 MobWithDescription (com.microsoft.Malmo.Schemas.MobWithDescription)1 MobWithDescriptionAndReward (com.microsoft.Malmo.Schemas.MobWithDescriptionAndReward)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