Search in sources :

Example 1 with ServerInitialConditions

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

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

the class EnvironmentHelper method setMissionWeather.

public static void setMissionWeather(MissionInit minit) {
    ServerSection ss = minit.getMission().getServerSection();
    ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
    if (sic != null && sic.getWeather() != null && !sic.getWeather().equalsIgnoreCase("normal")) {
        // Max allowed by Minecraft's own Weather Command.
        int maxtime = 1000000 * 20;
        int cleartime = (sic.getWeather().equalsIgnoreCase("clear")) ? maxtime : 0;
        int raintime = (sic.getWeather().equalsIgnoreCase("rain")) ? maxtime : 0;
        int thundertime = (sic.getWeather().equalsIgnoreCase("thunder")) ? maxtime : 0;
        WorldServer worldserver = MinecraftServer.getServer().worldServers[0];
        WorldInfo worldinfo = worldserver.getWorldInfo();
        worldinfo.setCleanWeatherTime(cleartime);
        worldinfo.setRainTime(raintime);
        worldinfo.setThunderTime(thundertime);
        worldinfo.setRaining(raintime + thundertime > 0);
        worldinfo.setThundering(thundertime > 0);
    }
}
Also used : ServerSection(com.microsoft.Malmo.Schemas.ServerSection) WorldInfo(net.minecraft.world.storage.WorldInfo) WorldServer(net.minecraft.world.WorldServer) ServerInitialConditions(com.microsoft.Malmo.Schemas.ServerInitialConditions)

Example 3 with ServerInitialConditions

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

Aggregations

ServerInitialConditions (com.microsoft.Malmo.Schemas.ServerInitialConditions)3 ServerSection (com.microsoft.Malmo.Schemas.ServerSection)3 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 WorldServer (net.minecraft.world.WorldServer)1 SpawnListEntry (net.minecraft.world.biome.BiomeGenBase.SpawnListEntry)1 WorldInfo (net.minecraft.world.storage.WorldInfo)1