Search in sources :

Example 6 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromDiscreteCellImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    // Return a string that is unique for every cell on the x/z plane (ignores y)
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    // getPosition() rounds to int.
    int x = player.getPosition().getX();
    int z = player.getPosition().getZ();
    json.addProperty("cell", "(" + x + "," + z + ")");
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 7 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromDistanceImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    for (NamedPoint marker : odparams.getMarker()) {
        EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
        json.addProperty("distanceFrom" + makeSafe(marker.getName()), PositionHelper.calcDistanceFromPlayerToPosition(player, marker));
    }
}
Also used : NamedPoint(com.microsoft.Malmo.Schemas.NamedPoint) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 8 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromNearbyEntitiesImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    this.tickCount++;
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    // Get all the currently loaded entities:
    List<?> entities = Minecraft.getMinecraft().theWorld.getLoadedEntityList();
    // Get the list of RangeDefinitions that need firing:
    List<RangeDefinition> rangesToFire = new ArrayList<RangeDefinition>();
    int index = 0;
    for (RangeDefinition rd : this.oneparams.getRange()) {
        if (this.tickCount - this.lastFiringTimes[index] >= rd.getUpdateFrequency()) {
            rangesToFire.add(rd);
            this.lastFiringTimes[index] = this.tickCount;
        }
        index++;
    }
    // Create a list of empty lists to populate:
    List<List<Entity>> entitiesInRange = new ArrayList<List<Entity>>();
    for (int i = 0; i < rangesToFire.size(); i++) entitiesInRange.add(new ArrayList<Entity>());
    // Populate all our lists according to which entities are in range:
    for (Object obj : entities) {
        if (obj instanceof Entity) {
            Entity e = (Entity) obj;
            index = 0;
            for (RangeDefinition rd : rangesToFire) {
                if (Math.abs(e.posX - player.posX) < rd.getXrange().doubleValue() && Math.abs(e.posY - player.posY) < rd.getYrange().doubleValue() && Math.abs(e.posZ - player.posZ) < rd.getZrange().doubleValue()) {
                    // Belongs in this list:
                    entitiesInRange.get(index).add(e);
                }
                index++;
            }
        }
    }
    // Now build up a JSON array for each populated list:
    index = 0;
    for (List<Entity> entsInRangeList : entitiesInRange) {
        if (!entitiesInRange.isEmpty()) {
            JsonArray arr = new JsonArray();
            for (Entity e : entsInRangeList) {
                JsonObject jsent = new JsonObject();
                jsent.addProperty("x", e.posX);
                jsent.addProperty("y", e.posY);
                jsent.addProperty("z", e.posZ);
                jsent.addProperty("yaw", e.rotationYaw);
                jsent.addProperty("pitch", e.rotationPitch);
                String name = e.getName();
                if (e instanceof EntityItem) {
                    ItemStack is = ((EntityItem) e).getEntityItem();
                    DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
                    if (di != null) {
                        name = di.getType();
                        if (di.getColour() != null)
                            jsent.addProperty("colour", di.getColour().value());
                        if (di.getVariant() != null)
                            jsent.addProperty("variation", di.getVariant().getValue());
                    }
                    jsent.addProperty("quantity", is.stackSize);
                }
                jsent.addProperty("name", name);
                arr.add(jsent);
            }
            json.add(this.oneparams.getRange().get(index).getName(), arr);
            index++;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) RangeDefinition(com.microsoft.Malmo.Schemas.RangeDefinition) EntityItem(net.minecraft.entity.item.EntityItem)

Example 9 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class RewardForTouchingBlockTypeImplementation method calculateReward.

private void calculateReward(MultidimensionalReward reward) {
    // Determine what blocks we are touching.
    // This code is largely cribbed from Entity, where it is used to fire the Block.onEntityCollidedWithBlock methods.
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    List<BlockPos> touchingBlocks = PositionHelper.getTouchingBlocks(player);
    for (BlockPos pos : touchingBlocks) {
        IBlockState iblockstate = player.worldObj.getBlockState(pos);
        for (BlockMatcher bm : this.matchers) {
            if (bm.applies(pos) && bm.matches(pos, iblockstate)) {
                float reward_value = bm.reward();
                float adjusted_reward = adjustAndDistributeReward(reward_value, this.params.getDimension(), bm.spec.getDistribution());
                reward.add(this.params.getDimension(), adjusted_reward);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 10 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ChatCommandsImplementation method onExecute.

@Override
protected boolean onExecute(String verb, String parameter, MissionInit missionInit) {
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    if (player == null) {
        return false;
    }
    if (!verb.equalsIgnoreCase(ChatCommand.CHAT.value())) {
        return false;
    }
    player.sendChatMessage(parameter);
    return true;
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Aggregations

EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)37 ItemStack (net.minecraft.item.ItemStack)9 Entity (net.minecraft.entity.Entity)7 BlockPos (net.minecraft.util.BlockPos)6 SideOnly (cpw.mods.fml.relauncher.SideOnly)3 ArrayList (java.util.ArrayList)3 RailcraftContainer (mods.railcraft.common.gui.containers.RailcraftContainer)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 JsonObject (com.google.gson.JsonObject)2 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)2 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)2 List (java.util.List)2 IBlockState (net.minecraft.block.state.IBlockState)2 WorldClient (net.minecraft.client.multiplayer.WorldClient)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MovementInput (net.minecraft.util.MovementInput)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 Vector (ValkyrienWarfareBase.API.Vector)1 CoordTransformObject (ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject)1 JsonArray (com.google.gson.JsonArray)1