Search in sources :

Example 16 with BlockPos

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;
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) World(net.minecraft.world.World)

Example 17 with BlockPos

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);
                }
            }
        }
    }
}
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 18 with BlockPos

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;
}
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 19 with BlockPos

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockSpecWithDescription(com.microsoft.Malmo.Schemas.BlockSpecWithDescription) BlockPos(net.minecraft.util.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 20 with BlockPos

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.");
    }
}
Also used : Vec3(net.minecraft.util.Vec3) BlockPos(net.minecraft.util.BlockPos) Linear(com.microsoft.Malmo.Schemas.AnimationDecorator.Linear)

Aggregations

BlockPos (net.minecraft.util.BlockPos)30 IBlockState (net.minecraft.block.state.IBlockState)11 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)6 Entity (net.minecraft.entity.Entity)5 BlockDrawingHelper (com.microsoft.Malmo.Utils.BlockDrawingHelper)4 XMLBlockState (com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState)4 ArrayList (java.util.ArrayList)4 ItemStack (net.minecraft.item.ItemStack)4 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)3 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)2 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 Vec3 (net.minecraft.util.Vec3)2 World (net.minecraft.world.World)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1