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