Esempio n. 1
0
  /**
   * Tests the simple input at a block.
   *
   * @param pt
   * @return
   */
  public static Boolean testSimpleInput(int worldType, Vector pt) {
    Boolean result = null;
    Boolean temp;

    temp = isHigh(worldType, pt.add(1, 0, 0), true);
    if (temp != null)
      if (temp) return true;
      else result = false;
    temp = isHigh(worldType, pt.add(-1, 0, 0), true);
    if (temp != null)
      if (temp) return true;
      else result = false;
    temp = isHigh(worldType, pt.add(0, 0, 1), true);
    if (temp != null)
      if (temp) return true;
      else result = false;
    temp = isHigh(worldType, pt.add(0, 0, -1), true);
    if (temp != null)
      if (temp) return true;
      else result = false;
    temp = isHigh(worldType, pt.add(0, -1, 0), true);
    if (temp != null)
      if (temp) return true;
      else result = false;
    return result;
  }
Esempio n. 2
0
 /**
  * Get the distance between a point and this cuboid.
  *
  * @param pos
  * @return
  */
 public double distance(Vector pos) {
   Vector max = origin.add(new Vector(width, height, length));
   int closestX = Math.max(origin.getBlockX(), Math.min(max.getBlockX(), pos.getBlockX()));
   int closestY = Math.max(origin.getBlockY(), Math.min(max.getBlockY(), pos.getBlockY()));
   int closestZ = Math.max(origin.getBlockZ(), Math.min(max.getBlockZ(), pos.getBlockZ()));
   return pos.distance(new Vector(closestX, closestY, closestZ));
 }
Esempio n. 3
0
  static Boolean isWireHigh(World world, Vector pt, Vector sidePt1, Vector sidePt2) {
    int side1 = CraftBook.getBlockID(world, sidePt1);
    int side1Above = CraftBook.getBlockID(world, sidePt1.add(0, 1, 0));
    int side1Below = CraftBook.getBlockID(world, sidePt1.add(0, -1, 0));
    int side2 = CraftBook.getBlockID(world, sidePt2);
    int side2Above = CraftBook.getBlockID(world, sidePt2.add(0, 1, 0));
    int side2Below = CraftBook.getBlockID(world, sidePt2.add(0, -1, 0));

    if (!BlockType.isRedstoneBlock(side1)
        && !BlockType.isRedstoneBlock(side1Above)
        && (!BlockType.isRedstoneBlock(side1Below) || side1 != 0)
        && !BlockType.isRedstoneBlock(side2)
        && !BlockType.isRedstoneBlock(side2Above)
        && (!BlockType.isRedstoneBlock(side2Below) || side2 != 0)) {
      return CraftBook.getBlockData(world, pt) > 0;
    }

    return null;
  }
Esempio n. 4
0
  /** Make the copy from world. */
  public void copy() {
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
          int index = y * width * length + z * width + x;
          blocks[index] = (byte) CraftBook.getBlockID(origin.add(x, y, z));
          data[index] = (byte) CraftBook.getBlockData(origin.add(x, y, z));
        }
      }
    }

    findTestOffset();
  }
Esempio n. 5
0
  /** Paste to world. */
  public void paste(BlockBag bag) throws BlockSourceException {
    DoubleArrayList<Vector, byte[]> queueAfter = new DoubleArrayList<Vector, byte[]>(false);
    DoubleArrayList<Vector, byte[]> queueLast = new DoubleArrayList<Vector, byte[]>(false);

    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
          int index = y * width * length + z * width + x;
          Vector pt = origin.add(x, y, z);

          if (BlockType.shouldPlaceLast(CraftBook.getBlockID(pt))) {
            CraftBook.setBlockID(pt, 0);
          }

          if (BlockType.shouldPlaceLast(blocks[index])) {
            queueLast.put(pt, new byte[] {blocks[index], data[index]});
          } else {
            queueAfter.put(pt, new byte[] {blocks[index], data[index]});
          }
        }
      }
    }

    for (Map.Entry<Vector, byte[]> entry : queueAfter) {
      byte[] v = entry.getValue();
      try {
        bag.setBlockID(entry.getKey(), v[0]);
        if (BlockType.usesData(v[0])) {
          CraftBook.setBlockData(entry.getKey(), v[1]);
        }
      } catch (OutOfBlocksException e) {
        // Eat error
      }
    }

    for (Map.Entry<Vector, byte[]> entry : queueLast) {
      byte[] v = entry.getValue();
      try {
        bag.setBlockID(entry.getKey(), v[0]);
        if (BlockType.usesData(v[0])) {
          CraftBook.setBlockData(entry.getKey(), v[1]);
        }
      } catch (OutOfBlocksException e) {
        // Eat error
      }
    }

    bag.flushChanges();
  }
  /**
   * Adds a position to be used a source.
   *
   * @param pos
   * @return
   */
  public void addSourcePosition(Vector pos) {
    int ox = pos.getBlockX();
    int oy = pos.getBlockY();
    int oz = pos.getBlockZ();

    for (int x = -3; x <= 3; x++) {
      for (int y = -3; y <= 3; y++) {
        for (int z = -3; z <= 3; z++) {
          Vector cur = pos.add(x, y, z);

          if (CraftBook.getBlockID(cur) == BlockType.CHEST) {
            ComplexBlock complexBlock = etc.getServer().getComplexBlock(ox + x, oy + y, oz + z);

            if (complexBlock instanceof Chest) {
              Chest chest = (Chest) complexBlock;
              Item[] itemArray = chest.getContents();
              boolean occupied = false;

              // Got to make sure that at least one slot is occupied
              for (int i = 0; itemArray.length > i; i++) {
                if (itemArray[i] != null) {
                  // Found an item
                  if (itemArray[i].getAmount() > 0) {
                    occupied = true;
                    break;
                  }
                }
              }

              if (occupied) {
                chests.add(new ComparableComplexBlock<Chest>(cur.toBlockVector(), chest));
              }
            }
          }
        }
      }
    }
  }
Esempio n. 7
0
  /** Clear the area. */
  public void clear(BlockBag bag) throws BlockSourceException {
    List<Vector> queued = new ArrayList<Vector>();

    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
          Vector pt = origin.add(x, y, z);
          if (BlockType.shouldPlaceLast(CraftBook.getBlockID(pt))) {
            bag.setBlockID(pt, 0);
          } else {
            // Can't destroy these blocks yet
            queued.add(pt);
          }
        }
      }
    }

    for (Vector pt : queued) {
      bag.setBlockID(pt, 0);
    }

    bag.flushChanges();
  }
Esempio n. 8
0
 @Override
 public boolean inRange(Vector reference, Vector other) {
   Vector minVec = reference.subtract(distFromCenter);
   Vector maxVec = reference.add(distFromCenter);
   return other.containedWithin(minVec, maxVec);
 }
Esempio n. 9
0
 /**
  * Returns true if the bridge should be turned 'off'.
  *
  * @return
  */
 public boolean shouldClear() {
   Vector v = origin.add(testOffset);
   return CraftBook.getBlockID(v) != 0;
 }