use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class RewardForCatchingMobImplementation method getCaughtEntities.
static List<Entity> getCaughtEntities() {
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
World world = player.worldObj;
// Get all the currently loaded entities:
List<?> entities = Minecraft.getMinecraft().theWorld.getLoadedEntityList();
// Now filter out all the player entities:
List<BlockPos> entityPositions = new ArrayList<BlockPos>();
for (Object obj : entities) {
if (obj instanceof EntityPlayer) {
EntityPlayer ep = (EntityPlayer) obj;
entityPositions.add(new BlockPos(ep.posX, ep.posY, ep.posZ));
}
}
// Now search for trapped entities
List<Entity> trappedEntities = new ArrayList<Entity>();
BlockPos playerPos = new BlockPos((int) player.posX, (int) player.posY, (int) player.posZ);
for (Object obj : entities) {
if (obj instanceof EntityPlayer)
// Don't score points for catching other players.
continue;
if (obj instanceof Entity) {
Entity e = (Entity) obj;
BlockPos entityPos = new BlockPos((int) e.posX, (int) e.posY, (int) e.posZ);
// For now, only consider entities on the same plane as us:
if (entityPos.getY() != playerPos.getY())
continue;
// Now see whether the mob can move anywhere:
boolean canEscape = false;
for (int x = -1; x <= 1 && !canEscape; x++) {
for (int z = -1; z <= 1 && !canEscape; z++) {
if (Math.abs(x) == Math.abs(z))
// Only consider the n/s/e/w blocks - ignore diagonals.
continue;
BlockPos square = new BlockPos(entityPos.getX() + x, entityPos.getY(), entityPos.getZ() + z);
if (world.isAirBlock(square) && !entityPositions.contains(square))
canEscape = true;
}
}
if (!canEscape) {
trappedEntities.add(e);
}
}
}
return trappedEntities;
}
use of net.minecraft.util.BlockPos 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 net.minecraft.util.BlockPos 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 net.minecraft.util.BlockPos in project malmo by Microsoft.
the class AgentQuitFromTouchingBlockTypeImplementation method doIWantToQuit.
@Override
public boolean doIWantToQuit(MissionInit missionInit) {
if (this.wantToQuit)
return true;
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
List<BlockPos> touchingBlocks = PositionHelper.getTouchingBlocks(player);
for (BlockPos pos : touchingBlocks) {
IBlockState bs = player.worldObj.getBlockState(pos);
// Does this block match our trigger specs?
String blockname = bs.getBlock().getUnlocalizedName().toLowerCase();
if (!this.blockTypeNames.contains(blockname))
continue;
// The type matches one of our block types, so now we need to perform additional checks.
for (BlockSpecWithDescription blockspec : this.params.getBlock()) {
if (findMatch(blockspec, bs)) {
this.quitCode = blockspec.getDescription();
// Yes, we want to quit!
return true;
}
}
}
// Nothing matched, we can quit happily.
return false;
}
use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class AnimationDecoratorImplementation method update.
@Override
public void update(World world) {
this.tickCounter++;
if (this.tickCounter < this.params.getTicksPerUpdate()) {
this.tickCounter++;
return;
}
this.frameCount++;
this.tickCounter = 0;
BlockPos oldpos = new BlockPos(this.origin);
if (this.params.getLinear() != null) {
Linear linear = this.params.getLinear();
double dx = this.velocity.xCoord;
double dy = this.velocity.yCoord;
double dz = this.velocity.zCoord;
if (this.drawContext.getMax().xCoord + dx > linear.getCanvasBounds().getMax().getX() + 1.0 || this.drawContext.getMin().xCoord + dx < linear.getCanvasBounds().getMin().getX())
dx = -dx;
if (this.drawContext.getMax().yCoord + dy > linear.getCanvasBounds().getMax().getY() + 1.0 || this.drawContext.getMin().yCoord + dy < linear.getCanvasBounds().getMin().getY())
dy = -dy;
if (this.drawContext.getMax().zCoord + dz > linear.getCanvasBounds().getMax().getZ() + 1.0 || this.drawContext.getMin().zCoord + dz < linear.getCanvasBounds().getMin().getZ())
dz = -dz;
this.velocity = new Vec3(dx, dy, dz);
this.origin = this.origin.add(this.velocity);
} else {
try {
double x = EvaluationHelper.eval(this.params.getParametric().getX(), this.frameCount, this.rng);
double y = EvaluationHelper.eval(this.params.getParametric().getY(), this.frameCount, this.rng);
double z = EvaluationHelper.eval(this.params.getParametric().getZ(), this.frameCount, this.rng);
this.origin = new Vec3(x, y, z);
} catch (Exception e) {
// Just fail and move on.
System.out.println("ERROR - check syntax of equations for animation.");
}
}
BlockPos newpos = new BlockPos(this.origin);
if (oldpos.equals(newpos))
return;
try {
this.drawContext.setOrigin(this.origin);
this.drawContext.Draw(this.params.getDrawingDecorator(), MinecraftServer.getServer().getEntityWorld());
this.drawContext.clearPrevious(MinecraftServer.getServer().getEntityWorld());
} catch (Exception e) {
System.out.println("ERROR - can not draw animation.");
}
}
Aggregations