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