use of com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState in project malmo by Microsoft.
the class MazeDecoratorImplementation method getBlock.
private XMLBlockState getBlock(MazeBlock mblock, Random rand) {
BlockType blockName = chooseBlock(mblock.getType(), rand);
Colour blockCol = chooseColour(mblock.getColour(), rand);
Variation blockVar = chooseVariant(mblock.getVariant(), rand);
return new XMLBlockState(blockName, blockCol, null, blockVar);
}
use of com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState in project malmo by Microsoft.
the class MazeDecoratorImplementation method placeBlocks.
private void placeBlocks(World world, Cell[] grid, Cell start, Cell end) {
BlockDrawingHelper drawContext = new BlockDrawingHelper();
drawContext.beginDrawing(world);
int scale = this.mazeParams.getSizeAndPosition().getScale();
// First remove any entities lying around in our area:
drawContext.clearEntities(world, this.xOrg, this.yOrg, this.zOrg, this.xOrg + this.width * scale, this.yOrg + this.mazeParams.getSizeAndPosition().getHeight(), this.zOrg + this.length * scale);
// Clear a volume of air, lay a carpet, and put the random pavement over it:
for (int x = 0; x < this.width * scale; x++) {
for (int z = 0; z < this.length * scale; z++) {
for (int y = 0; y < this.mazeParams.getSizeAndPosition().getHeight(); y++) {
world.setBlockToAir(new BlockPos(x + this.xOrg, y + this.yOrg, z + this.zOrg));
}
BlockPos bp = new BlockPos(x + this.xOrg, this.yOrg, z + this.zOrg);
drawContext.setBlockState(world, bp, this.floorBlock);
Cell c = grid[(x / scale) + ((z / scale) * this.width)];
XMLBlockState bs = (c == null) ? this.gapBlock : (c.isOnOptimalPath ? this.optimalPathBlock : this.pathBlock);
int h = (c == null) ? this.gapHeight : (c.isOnOptimalPath ? this.optimalPathHeight : this.pathHeight);
if (c != null && c.isSubgoal) {
bs = this.subgoalPathBlock;
h = this.subgoalHeight;
}
if (c != null && c.isWaypoint && x % scale == scale / 2 && z % scale == scale / 2) {
if (this.mazeParams.getWaypoints().getWaypointBlock() != null) {
bs = this.waypointBlock;
h = this.pathHeight;
} else if (this.waypointItem != null) {
// Place a waypoint item here:
// (scale % 2 == 0) ? 1 : 0;
int offset = 0;
drawContext.placeItem(this.waypointItem.copy(), new BlockPos(x + this.xOrg + offset, this.yOrg + h + 1, z + this.zOrg + offset), world, (scale % 2 == 1));
}
}
if (c != null && c == start) {
h = this.startHeight;
bs = this.startBlock;
}
if (c != null && c == end) {
h = this.endHeight;
bs = this.endBlock;
}
for (int y = 1; y <= h; y++) {
BlockPos pos = new BlockPos(x + this.xOrg, y + this.yOrg, z + this.zOrg);
drawContext.setBlockState(world, pos, bs);
}
}
}
}
use of com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState in project malmo by Microsoft.
the class MovingTargetDecoratorImplementation method parseParameters.
@Override
public boolean parseParameters(Object params) {
if (params == null || !(params instanceof MovingTargetDecorator))
return false;
this.targetParams = (MovingTargetDecorator) params;
this.arenaBounds = this.targetParams.getArenaBounds();
DrawBlockBasedObjectType targetBlock = this.targetParams.getBlockType();
this.blockType = (targetBlock != null) ? new XMLBlockState(targetBlock.getType(), targetBlock.getColour(), targetBlock.getFace(), targetBlock.getVariant()) : null;
Pos pos = this.targetParams.getStartPos();
int xPos = pos.getX().intValue();
int yPos = pos.getY().intValue();
int zPos = pos.getZ().intValue();
// Check start pos lies within arena:
xPos = Math.min(this.arenaBounds.getMax().getX(), Math.max(this.arenaBounds.getMin().getX(), xPos));
yPos = Math.min(this.arenaBounds.getMax().getY(), Math.max(this.arenaBounds.getMin().getY(), yPos));
zPos = Math.min(this.arenaBounds.getMax().getZ(), Math.max(this.arenaBounds.getMin().getZ(), zPos));
this.startPos = new BlockPos(xPos, yPos, zPos);
if (this.targetParams.getUpdateSpeed() == null || this.targetParams.getUpdateSpeed().equals("turnbased")) {
this.mustWaitTurn = true;
} else {
this.speedInTicks = Integer.parseInt(this.targetParams.getUpdateSpeed());
}
createRNG();
return true;
}
use of com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState in project malmo by Microsoft.
the class MovingTargetDecoratorImplementation method update.
@Override
public void update(World world) {
if (// Using the turn scheduler?
this.mustWaitTurn && !this.isOurTurn)
return;
if (!this.mustWaitTurn) {
// Not using turn scheduler - using update speed
this.timeSinceLastUpdate++;
if (this.timeSinceLastUpdate < this.speedInTicks)
return;
}
this.timeSinceLastUpdate = 0;
// We're taking it right now.
this.isOurTurn = false;
if (!pinchedByPlayer(world)) {
BlockPos posHead = this.path.peekFirst();
BlockPos posTail = this.path.peekLast();
// For now, only move in 2D - can make this more flexible later.
ArrayList<BlockPos> possibleMovesForward = new ArrayList<BlockPos>();
ArrayList<BlockPos> possibleMovesBackward = new ArrayList<BlockPos>();
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
if (z != 0 && x != 0)
// No diagonal moves.
continue;
if (z == 0 && x == 0)
// Don't allow no-op.
continue;
// Check this is a valid move...
BlockPos candidateHeadPos = new BlockPos(posHead.getX() + x, posHead.getY(), posHead.getZ() + z);
BlockPos candidateTailPos = new BlockPos(posTail.getX() + x, posTail.getY(), posTail.getZ() + z);
if (isValid(world, candidateHeadPos))
possibleMovesForward.add(candidateHeadPos);
if (isValid(world, candidateTailPos))
possibleMovesBackward.add(candidateTailPos);
}
}
// Choose whether to move the "head" or the "tail"
ArrayList<BlockPos> candidates = null;
boolean forwards = true;
if (possibleMovesBackward.isEmpty()) {
candidates = possibleMovesForward;
forwards = true;
} else if (possibleMovesForward.isEmpty()) {
candidates = possibleMovesBackward;
forwards = false;
} else {
forwards = this.rng.nextDouble() < 0.5;
candidates = forwards ? possibleMovesForward : possibleMovesBackward;
}
if (!candidates.isEmpty()) {
BlockDrawingHelper drawContext = new BlockDrawingHelper();
drawContext.beginDrawing(world);
BlockPos newPos = candidates.get(this.rng.nextInt(candidates.size()));
if (forwards) {
// Add the new head:
this.originalPath.addFirst(world.getBlockState(newPos));
drawContext.setBlockState(world, newPos, this.blockType);
this.path.addFirst(newPos);
// Move the tail?
if (this.path.size() > this.pathSize) {
drawContext.setBlockState(world, posTail, new XMLBlockState(this.originalPath.removeLast()));
this.path.removeLast();
}
} else {
// Backwards - add the new tail:
this.originalPath.addLast(world.getBlockState(newPos));
drawContext.setBlockState(world, newPos, this.blockType);
this.path.addLast(newPos);
// Move the head?
if (this.path.size() > this.pathSize) {
drawContext.setBlockState(world, posHead, new XMLBlockState(this.originalPath.removeFirst()));
this.path.removeFirst();
}
}
drawContext.endDrawing(world);
}
}
if (this.mustWaitTurn) {
// Let server know we have finished.
Map<String, String> data = new HashMap<String, String>();
data.put("agentname", this.guid);
MalmoMod.network.sendToServer(new MalmoMod.MalmoMessage(MalmoMessageType.CLIENT_TURN_TAKEN, 0, data));
}
}
use of com.microsoft.Malmo.Utils.BlockDrawingHelper.XMLBlockState in project malmo by Microsoft.
the class BuildBattleDecoratorImplementation method parseParameters.
/**
* Attempt to parse the given object as a set of parameters for this handler.
*
* @param params the parameter block to parse
* @return true if the object made sense for this handler; false otherwise.
*/
@Override
public boolean parseParameters(Object params) {
if (params == null || !(params instanceof BuildBattleDecorator))
return false;
this.params = (BuildBattleDecorator) params;
this.sourceBounds = this.params.getGoalStructureBounds();
this.destBounds = this.params.getPlayerStructureBounds();
this.delta = new Vec3i(destBounds.getMin().getX() - sourceBounds.getMin().getX(), destBounds.getMin().getY() - sourceBounds.getMin().getY(), destBounds.getMin().getZ() - sourceBounds.getMin().getZ());
this.structureVolume = volumeOfBounds(this.sourceBounds);
assert (this.structureVolume == volumeOfBounds(this.destBounds));
this.dest = new ArrayList<IBlockState>(Collections.nCopies(this.structureVolume, (IBlockState) null));
this.source = new ArrayList<IBlockState>(Collections.nCopies(this.structureVolume, (IBlockState) null));
DrawBlockBasedObjectType tickBlock = this.params.getBlockTypeOnCorrectPlacement();
DrawBlockBasedObjectType crossBlock = this.params.getBlockTypeOnIncorrectPlacement();
this.blockTypeOnCorrectPlacement = (tickBlock != null) ? new XMLBlockState(tickBlock.getType(), tickBlock.getColour(), tickBlock.getFace(), tickBlock.getVariant()) : null;
this.blockTypeOnIncorrectPlacement = (crossBlock != null) ? new XMLBlockState(crossBlock.getType(), crossBlock.getColour(), crossBlock.getFace(), crossBlock.getVariant()) : null;
return true;
}
Aggregations