Exemple #1
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();
  }
Exemple #2
0
  static void setTrackTrigger(World world, Vector pos) {
    if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) {
      int data = CraftBook.getBlockData(world, pos);
      int newData = 0;
      boolean state = (data & 0x8) == 0x8;

      if (state) {
        newData = data & 0x7;
      } else {
        newData = data | 0x8;
      }

      CraftBook.setBlockData(world, pos, newData);
      world.updateBlockPhysics(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), newData);
    }
  }
Exemple #3
0
  static void setOutput(World world, Vector pos, boolean state) {
    if (CraftBook.getBlockID(world, pos) == BlockType.LEVER) {
      int data = CraftBook.getBlockData(world, pos);
      int newData = data & 0x7;

      if (!state) {
        newData = data & 0x7;
      } else {
        newData = data | 0x8;
      }

      if (newData != data) {
        CraftBook.setBlockData(world, pos, newData);
        world.updateBlockPhysics(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), newData);
      }
    }
  }