Example #1
0
  @Override
  public boolean commitCuboid(CuboidBlockMaterialBuffer buffer, Cause<?> cause) {
    Vector3 base = buffer.getBase();
    int x = base.getFloorX();
    int y = base.getFloorY();
    int z = base.getFloorZ();
    SpoutChunk[][][] chunks = getChunks(x, y, z, buffer);

    return commitCuboid(chunks, buffer, cause);
  }
 private void place() {
   for (int x = start.getFloorX(); x < end.getFloorX(); x++) {
     final double xOffset = (chunk.getX() + x + 0.5f - target.getX()) / horizontalSize;
     for (int z = start.getFloorZ(); z < end.getFloorZ(); z++) {
       final double zOffset = (chunk.getZ() + z + 0.5f - target.getZ()) / horizontalSize;
       if (xOffset * xOffset + zOffset * zOffset >= 1) {
         continue;
       }
       for (int y = end.getFloorY() - 1; y >= start.getFloorY(); y--) {
         final double yOffset = (y + 0.5f - target.getY()) / verticalSize;
         if (yOffset > -0.7 && xOffset * xOffset + yOffset * yOffset + zOffset * zOffset < 1) {
           final int xx = chunk.getFloorX() + x;
           final int zz = chunk.getFloorZ() + z;
           final BlockMaterial material = blockData.get(xx, y, zz);
           if (material.equals(VanillaMaterials.NETHERRACK)) {
             blockData.set(xx, y, zz, VanillaMaterials.AIR);
           }
         }
       }
     }
   }
 }
 private boolean canPlace() {
   for (int x = start.getFloorX(); x < end.getFloorX(); x++) {
     for (int z = start.getFloorZ(); z < end.getFloorZ(); z++) {
       for (int y = end.getFloorY() + 1; y >= start.getFloorY() - 1; y--) {
         if (blockData.get(chunk.getFloorX() + x, y, chunk.getFloorZ() + z) instanceof Lava) {
           return false;
         }
         if (y != start.getFloorY() - 1
             && x != start.getFloorX()
             && x != end.getFloorX() - 1
             && z != start.getFloorZ()
             && z != end.getFloorZ() - 1) {
           y = start.getFloorY();
         }
       }
     }
   }
   return true;
 }
Example #4
0
  private SpoutChunk[][][] getChunks(int x, int y, int z, CuboidBlockMaterialBuffer buffer) {
    Vector3 size = buffer.getSize();

    int startX = x;
    int startY = y;
    int startZ = z;

    int endX = x + size.getFloorX();
    int endY = y + size.getFloorY();
    int endZ = z + size.getFloorZ();

    Chunk start = getChunkFromBlock(startX, startY, startZ);
    Chunk end = getChunkFromBlock(endX - 1, endY - 1, endZ - 1);

    int chunkStartX = start.getX();
    int chunkStartY = start.getY();
    int chunkStartZ = start.getZ();

    int chunkEndX = end.getX();
    int chunkEndY = end.getY();
    int chunkEndZ = end.getZ();

    int chunkSizeX = chunkEndX - chunkStartX + 1;
    int chunkSizeY = chunkEndY - chunkStartY + 1;
    int chunkSizeZ = chunkEndZ - chunkStartZ + 1;

    SpoutChunk[][][] chunks = new SpoutChunk[chunkSizeX][chunkSizeY][chunkSizeZ];
    for (int dx = chunkStartX; dx <= chunkEndX; dx++) {
      for (int dy = chunkStartY; dy <= chunkEndY; dy++) {
        for (int dz = chunkStartZ; dz <= chunkEndZ; dz++) {
          SpoutChunk chunk = getChunk(dx, dy, dz, LoadOption.LOAD_GEN);
          if (chunk == null) {
            throw new IllegalStateException("Null chunk loaded with LoadOption.LOAD_GEN");
          }
          chunks[dx - chunkStartX][dy - chunkStartY][dz - chunkStartZ] = chunk;
        }
      }
    }
    return chunks;
  }
Example #5
0
  protected boolean commitCuboid(
      SpoutChunk[][][] chunks, CuboidBlockMaterialBuffer buffer, Cause<?> cause) {

    Vector3 base = buffer.getBase();
    int x = base.getFloorX();
    int y = base.getFloorY();
    int z = base.getFloorZ();

    lockChunks(chunks);

    try {
      for (int dx = 0; dx < chunks.length; dx++) {
        SpoutChunk[][] subArray1 = chunks[dx];
        for (int dy = 0; dy < subArray1.length; dy++) {
          SpoutChunk[] subArray2 = subArray1[dy];
          for (int dz = 0; dz < subArray2.length; dz++) {
            if (!subArray2[dz].testCuboid(x, y, z, buffer)) {
              return false;
            }
          }
        }
      }

      // set
      for (int dx = 0; dx < chunks.length; dx++) {
        SpoutChunk[][] subArray1 = chunks[dx];
        for (int dy = 0; dy < subArray1.length; dy++) {
          SpoutChunk[] subArray2 = subArray1[dy];
          for (int dz = 0; dz < subArray2.length; dz++) {
            subArray2[dz].setCuboid(x, y, z, buffer, cause);
          }
        }
      }

      return true;
    } finally {
      unlockChunks(chunks);
    }
  }
 @Override
 public void generate(
     CuboidBlockMaterialBuffer blockData, int chunkX, int chunkY, int chunkZ, World world) {
   blockData.flood(BlockMaterial.AIR);
 }
Example #7
0
 @Override
 public void getCuboid(CuboidBlockMaterialBuffer buffer) {
   Vector3 base = buffer.getBase();
   getCuboid(base.getFloorX(), base.getFloorY(), base.getFloorZ(), buffer);
 }
Example #8
0
 @Override
 public void setCuboid(CuboidBlockMaterialBuffer buffer, Cause<?> cause) {
   Vector3 base = buffer.getBase();
   setCuboid(base.getFloorX(), base.getFloorY(), base.getFloorZ(), buffer, cause);
 }
Example #9
0
 /**
  * Simulates the result of a blocks falling inside a buffer. If the blocks reach the bottom of the
  * buffer without hitting any obstacles they may either be removed or stopped at the bottom. If
  * the block at (x, y, z) is not a SolidMoving, nothing will happen, else it and the blocks above
  * will be subject to the simulation. If the blocks fall on a placement obstacle (such as a torch)
  * they will be removed.
  *
  * @param buffer The buffer in which to simulate the fall.
  * @param x The x coordinate of the block.
  * @param y The y coordinate of the block.
  * @param z The Z coordinate of the block.
  * @param remove If the blocks should be removed after reaching the bottom of the buffer, or
  *     stopped.
  */
 public static void simulateFall(
     CuboidBlockMaterialBuffer buffer, int x, int y, int z, boolean remove) {
   if (!buffer.isInside(x, y, z)) {
     return;
   }
   BlockMaterial falling = buffer.get(x, y, z);
   if (!(falling instanceof SolidMoving)) {
     return;
   }
   int baseY = buffer.getBase().getFloorY();
   for (int obstacleY = y; --obstacleY >= baseY; ) {
     if (FallingBlock.isFallingObstacle(buffer.get(x, obstacleY, z))) {
       // obstacle found
       if (obstacleY == y - 1) {
         // right underneath, nowhere to fall
         return;
       }
       if (buffer.get(x, ++obstacleY, z).isPlacementObstacle()) {
         // blocks can't stay here. Delete them
         remove = true;
         break;
       }
       do {
         // move the blocks above the obstacle
         buffer.set(x, obstacleY++, z, falling);
         buffer.set(x, y++, z, VanillaMaterials.AIR);
       } while ((falling = buffer.get(x, y, z)) instanceof SolidMoving);
       return;
     }
   }
   // no obstacle found
   if (remove) {
     // delete the blocks
     final int topY = buffer.getTop().getFloorY() - 1;
     do {
       buffer.set(x, y++, z, VanillaMaterials.AIR);
     } while (y <= topY && buffer.get(x, y, z) instanceof SolidMoving);
   } else {
     // move the blocks to the bottom of the buffer
     do {
       buffer.set(x, baseY++, z, falling);
       buffer.set(x, y++, z, VanillaMaterials.AIR);
     } while ((falling = buffer.get(x, y, z)) instanceof SolidMoving);
   }
 }