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);
}
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);
}
}
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);
}
Aggregations