use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class BuildBattleDecoratorImplementation method updateAndScorePlayerVolume.
private void updateAndScorePlayerVolume(World w, boolean updateReward) {
int wrongBlocks = 0;
int rightBlocks = 0;
int totalMatchingBlocks = 0;
BlockDrawingHelper drawContext = new BlockDrawingHelper();
drawContext.beginDrawing(w);
for (int x = this.sourceBounds.getMin().getX(); x <= this.sourceBounds.getMax().getX(); x++) {
for (int y = this.sourceBounds.getMin().getY(); y <= this.sourceBounds.getMax().getY(); y++) {
for (int z = this.sourceBounds.getMin().getZ(); z <= this.sourceBounds.getMax().getZ(); z++) {
BlockPos goalStructurePos = new BlockPos(x, y, z);
BlockPos playerStructurePos = goalStructurePos.add(this.delta);
// We don't compare the world's block states, since we re-colour them to give
// feedback on right / wrong blocks.
// Instead, query our internal representations:
IBlockState srcState = getSourceBlockState(w, goalStructurePos);
IBlockState dstState = getDestBlockState(w, playerStructurePos);
if (srcState == null || dstState == null)
// Shouldn't happen unless we've had an out-of-bounds error somehow.
continue;
boolean destAir = w.isAirBlock(playerStructurePos);
if (srcState.equals(dstState)) {
// They match. We count this if the dest block is not air.
if (!destAir)
rightBlocks++;
if (blockTypeOnCorrectPlacement != null && !w.isAirBlock(goalStructurePos)) {
// Mark both source and destination blocks for correct placement:
drawContext.setBlockState(w, playerStructurePos, blockTypeOnCorrectPlacement);
drawContext.setBlockState(w, goalStructurePos, blockTypeOnCorrectPlacement);
}
totalMatchingBlocks++;
} else {
// Non-match. We call this wrong if the dest block is not air.
if (!destAir) {
wrongBlocks++;
if (blockTypeOnIncorrectPlacement != null) {
// Recolour the destination block only:
drawContext.setBlockState(w, playerStructurePos, blockTypeOnIncorrectPlacement);
}
}
// Check the source block - if it was previously correct, and has become incorrect,
// then we will need to reset the world's blockstate:
IBlockState actualState = w.getBlockState(goalStructurePos);
if (!actualState.equals(srcState))
drawContext.setBlockState(w, goalStructurePos, new XMLBlockState(srcState));
}
}
}
}
drawContext.endDrawing(w);
int score = rightBlocks - wrongBlocks;
boolean sendData = false;
boolean sendCompletionBonus = false;
int reward = 0;
if (updateReward && score != this.currentScore) {
reward = score - this.currentScore;
sendData = true;
}
this.currentScore = score;
if (totalMatchingBlocks == this.structureVolume) {
if (!this.structureHasBeenCompleted) {
// final block.)
if (updateReward)
sendCompletionBonus = true;
}
this.structureHasBeenCompleted = true;
}
this.valid = true;
if (sendData) {
HashMap<String, String> data = new HashMap<String, String>();
data.put("reward", Integer.toString(reward));
data.put("completed", Boolean.toString(sendCompletionBonus));
MalmoMod.safeSendToAll(MalmoMessageType.SERVER_BUILDBATTLEREWARD, data);
}
}
use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class AnimationDrawingHelper method setBlockState.
@Override
public void setBlockState(World w, BlockPos pos, XMLBlockState state) {
BlockPos offsetPos = pos.add(this.origin.xCoord, this.origin.yCoord, this.origin.zCoord);
this.drawing.add(offsetPos);
this.previousFrame.remove(offsetPos);
if (this.minPos == null)
this.minPos = new Vec3(offsetPos.getX() - 0.5, offsetPos.getY(), offsetPos.getZ() - 0.5);
else {
double x = Math.min(this.minPos.xCoord, offsetPos.getX() - 0.5);
double y = Math.min(this.minPos.yCoord, offsetPos.getY() - 0.5);
double z = Math.min(this.minPos.zCoord, offsetPos.getZ() - 0.5);
if (x != this.minPos.xCoord || y != this.minPos.yCoord || z != this.minPos.zCoord)
this.minPos = new Vec3(x, y, z);
}
if (this.maxPos == null)
this.maxPos = new Vec3(offsetPos.getX() + 0.5, offsetPos.getY() + 1, offsetPos.getZ() + 0.5);
else {
double x = Math.max(this.maxPos.xCoord, offsetPos.getX() + 0.5);
double y = Math.max(this.maxPos.yCoord, offsetPos.getY() + 0.5);
double z = Math.max(this.maxPos.zCoord, offsetPos.getZ() + 0.5);
if (x != this.maxPos.xCoord || y != this.maxPos.yCoord || z != this.maxPos.zCoord)
this.maxPos = new Vec3(x, y, z);
}
super.setBlockState(w, offsetPos, state);
}
use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class BlockDrawingHelper method DrawPrimitive.
/**
* Draw a solid sphere made up of Minecraft blocks.
* @param s Contains information about the sphere to be drawn.
* @param w The world in which to draw.
* @throws Exception Throws an exception if the block type is not recognised.
*/
private void DrawPrimitive(DrawSphere s, World w) throws Exception {
XMLBlockState blockType = new XMLBlockState(s.getType(), s.getColour(), null, s.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecognised block type: " + s.getType().value());
int radius = s.getRadius();
for (int x = s.getX() - radius; x <= s.getX() + radius; x++) {
for (int y = s.getY() - radius; y <= s.getY() + radius; y++) {
for (int z = s.getZ() - radius; z <= s.getZ() + radius; z++) {
if ((z - s.getZ()) * (z - s.getZ()) + (y - s.getY()) * (y - s.getY()) + (x - s.getX()) * (x - s.getX()) <= (radius * radius)) {
BlockPos pos = new BlockPos(x, y, z);
setBlockState(w, pos, blockType);
AxisAlignedBB aabb = new AxisAlignedBB(pos, pos).expand(0.5, 0.5, 0.5);
clearEntities(w, aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
}
}
}
}
}
use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class BlockDrawingHelper method DrawPrimitive.
/**
* Draw a filled cuboid of Minecraft blocks of a single type.
* @param c Contains information about the cuboid to be drawn.
* @param w The world in which to draw.
* @throws Exception Throws an exception if the block type is not recognised.
*/
private void DrawPrimitive(DrawCuboid c, World w) throws Exception {
XMLBlockState blockType = new XMLBlockState(c.getType(), c.getColour(), c.getFace(), c.getVariant());
if (!blockType.isValid())
throw new Exception("Unrecogised item type: " + c.getType().value());
clearEntities(w, c.getX1(), c.getY1(), c.getZ1(), c.getX2(), c.getY2(), c.getZ2());
int x1 = Math.min(c.getX1(), c.getX2());
int x2 = Math.max(c.getX1(), c.getX2());
int y1 = Math.min(c.getY1(), c.getY2());
int y2 = Math.max(c.getY1(), c.getY2());
int z1 = Math.min(c.getZ1(), c.getZ2());
int z2 = Math.max(c.getZ1(), c.getZ2());
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
for (int z = z1; z <= z2; z++) {
BlockPos pos = new BlockPos(x, y, z);
setBlockState(w, pos, blockType);
}
}
}
}
use of net.minecraft.util.BlockPos in project malmo by Microsoft.
the class SnakeDecoratorImplementation method update.
@Override
public void update(World world) {
this.timeSinceLastBuild++;
if (this.timeSinceLastBuild > this.speedInTicks && !this.pendingBlock)
updatePath();
if (this.path.size() > 0 && this.pendingBlock) {
BlockPos bp = this.path.get(this.path.size() - 1);
// Create the block, or a gap if we are leaving a gap:
world.setBlockState(bp, this.consecutiveGaps == 0 ? this.freshBlock : Blocks.air.getDefaultState());
world.markBlockForUpdate(bp);
this.pendingBlock = false;
// Create space above and below this block (even if we are leaving a gap):
BlockPos bpUp = bp;
BlockPos bpDown = bp;
for (int i = 0; i < 3; i++) {
bpUp = bpUp.add(0, 1, 0);
bpDown = bpDown.add(0, -1, 0);
world.setBlockToAir(bpUp);
world.setBlockToAir(bpDown);
}
// Now remove block at the other end of the path, if need be:
if (this.path.size() > this.maxPathLength) {
bp = this.path.remove(0);
world.setBlockState(bp, this.staleBlock);
}
}
}
Aggregations