Exemple #1
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));
 }
Exemple #2
0
  protected static boolean damagePlayers(World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    for (Player player : etc.getServer().getPlayerList()) {
      Location pLoc = player.getLocation();
      Vector pVec = new Vector(pLoc.x, pLoc.y, pLoc.z);

      if (player.getWorld() == world
          && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
          && pVec.getBlockY() == y
          && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
        if (!id.isEmpty()) {
          if ((id.charAt(0) == 'g' && player.isInGroup(id.substring(2)))
              || (id.charAt(0) == 'p' && player.getName().equalsIgnoreCase(id.substring(2)))) {
            player.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        } else {
          player.getEntity().a(ODamageSource.j, damage);
          damaged = true;
        }
      }
    }

    return damaged;
  }
  /**
   * Rotate the clipboard in 2D. It can only rotate by angles divisible by 90.
   *
   * @param angle in degrees
   */
  public void rotate2D(int angle) {
    angle = angle % 360;
    if (angle % 90 != 0) { // Can only rotate 90 degrees at the moment
      return;
    }
    boolean reverse = angle < 0;
    int numRotations = Math.abs((int) Math.floor(angle / 90.0));

    int width = getWidth();
    int length = getLength();
    int height = getHeight();
    Vector sizeRotated = size.transform2D(angle, 0, 0, 0, 0);
    int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0;
    int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0;

    BaseBlock newData[][][] =
        new BaseBlock[Math.abs(sizeRotated.getBlockX())][Math.abs(sizeRotated.getBlockY())]
            [Math.abs(sizeRotated.getBlockZ())];

    for (int x = 0; x < width; ++x) {
      for (int z = 0; z < length; ++z) {
        Vector v = (new Vector(x, 0, z)).transform2D(angle, 0, 0, 0, 0);
        int newX = v.getBlockX();
        int newZ = v.getBlockZ();
        for (int y = 0; y < height; ++y) {
          BaseBlock block = data[x][y][z];
          newData[shiftX + newX][y][shiftZ + newZ] = block;

          if (reverse) {
            for (int i = 0; i < numRotations; ++i) {
              block.rotate90Reverse();
            }
          } else {
            for (int i = 0; i < numRotations; ++i) {
              block.rotate90();
            }
          }
        }
      }
    }

    data = newData;
    size =
        new Vector(
            Math.abs(sizeRotated.getBlockX()),
            Math.abs(sizeRotated.getBlockY()),
            Math.abs(sizeRotated.getBlockZ()));
    offset = offset.transform2D(angle, 0, 0, 0, 0).subtract(shiftX, 0, shiftZ);
  }
  @Override
  public boolean contains(Vector position) {
    double x = position.getX();
    double y = position.getY();
    double z = position.getZ();

    Vector min = getMinimumPoint();
    Vector max = getMaximumPoint();

    return x >= min.getBlockX()
        && x <= max.getBlockX()
        && y >= min.getBlockY()
        && y <= max.getBlockY()
        && z >= min.getBlockZ()
        && z <= max.getBlockZ();
  }
Exemple #5
0
  /**
   * Do cauldron.
   *
   * @param pt
   * @param player
   */
  public void preCauldron(Vector pt, Player player) {
    int x = pt.getBlockX();
    int y = pt.getBlockY();
    int z = pt.getBlockZ();

    World world = player.getWorld();

    int rootY = y;
    int below = CraftBook.getBlockID(world, x, y - 1, z);
    int below2 = CraftBook.getBlockID(world, x, y - 2, z);
    int s1 = CraftBook.getBlockID(world, x + 1, y, z);
    int s3 = CraftBook.getBlockID(world, x - 1, y, z);
    int s2 = CraftBook.getBlockID(world, x, y, z + 1);
    int s4 = CraftBook.getBlockID(world, x, y, z - 1);

    // Preliminary check so we don't waste CPU cycles
    if ((BlockType.isLava(below) || BlockType.isLava(below2))
        && (s1 == BlockType.STONE
            || s2 == BlockType.STONE
            || s3 == BlockType.STONE
            || s4 == BlockType.STONE)) {
      // Cauldron is 2 units deep
      if (BlockType.isLava(below)) {
        rootY++;
      }

      performCauldron(new BlockVector(x, rootY, z), player);
    }
  }
  /**
   * Adds a position to be used a source.
   *
   * @param pos
   * @return
   */
  public void addSingleSourcePosition(Vector pos) {
    int x = pos.getBlockX();
    int y = pos.getBlockY();
    int z = pos.getBlockZ();

    if (CraftBook.getBlockID(pos) == BlockType.CHEST) {
      ComplexBlock complexBlock = etc.getServer().getComplexBlock(x, y, 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>(pos.toBlockVector(), chest));
        }
      }
    }
  }
  @Command(
      aliases = {"clipboard", "copy"},
      usage = "",
      desc = "Choose the clipboard brush",
      help =
          "Chooses the clipboard brush.\n"
              + "The -a flag makes it not paste air.\n"
              + "Without the -p flag, the paste will appear centered at the target location. "
              + "With the flag, then the paste will appear relative to where you had "
              + "stood relative to the copied area when you copied it.")
  @CommandPermissions("worldedit.brush.clipboard")
  public void clipboardBrush(
      Player player,
      LocalSession session,
      EditSession editSession,
      @Switch('a') boolean ignoreAir,
      @Switch('p') boolean usingOrigin)
      throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    Clipboard clipboard = holder.getClipboard();

    Vector size = clipboard.getDimensions();

    worldEdit.checkMaxBrushRadius(size.getBlockX());
    worldEdit.checkMaxBrushRadius(size.getBlockY());
    worldEdit.checkMaxBrushRadius(size.getBlockZ());

    BrushTool tool = session.getBrushTool(player.getItemInHand());
    tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin), "worldedit.brush.clipboard");

    player.print("Clipboard brush shape equipped.");
  }
Exemple #8
0
 /**
  * Construct the object. This is to create a new copy at a certain location.
  *
  * @param origin
  * @param size
  */
 public CuboidCopy(Vector origin, Vector size) {
   this.origin = origin;
   width = size.getBlockX();
   height = size.getBlockY();
   length = size.getBlockZ();
   blocks = new byte[width * height * length];
   data = new byte[width * height * length];
 }
 /**
  * Copy to the clipboard.
  *
  * @param editSession
  */
 public void copy(EditSession editSession) {
   for (int x = 0; x < size.getBlockX(); ++x) {
     for (int y = 0; y < size.getBlockY(); ++y) {
       for (int z = 0; z < size.getBlockZ(); ++z) {
         data[x][y][z] = editSession.getBlock(new Vector(x, y, z).add(getOrigin()));
       }
     }
   }
 }
  @Override
  public Set<Vector2D> getChunks() {
    Set<Vector2D> chunks = new HashSet<Vector2D>();

    Vector min = getMinimumPoint();
    Vector max = getMaximumPoint();

    for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS;
        x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS;
        ++x) {
      for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS;
          z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS;
          ++z) {
        chunks.add(new BlockVector2D(x, z));
      }
    }

    return chunks;
  }
Exemple #11
0
  @SuppressWarnings("rawtypes")
  protected static boolean damageEntities(
      List list, World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    boolean isNamed =
        !id.isEmpty()
            && !id.equalsIgnoreCase("animal")
            && !id.equalsIgnoreCase("animals")
            && !id.equalsIgnoreCase("mob")
            && !id.equalsIgnoreCase("mobs");

    for (Object obj : list) {
      BaseEntity entity = (BaseEntity) obj;
      if (entity != null
          && entity
              .getWorld()
              .isChunkLoaded((int) entity.getX(), (int) entity.getY(), (int) entity.getZ())
          && (entity.isMob() || entity.isAnimal())) {
        Vector pVec = new Vector(entity.getX(), entity.getY(), entity.getZ());

        if (entity.getWorld() == world
            && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
            && pVec.getBlockY() == y
            && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
          if (isNamed) {
            // Mob mob = (Mob)entity;
            if (entity.getName().equalsIgnoreCase(id)) {
              entity.getEntity().a(ODamageSource.j, damage);
              damaged = true;
            }
          } else {
            entity.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        }
      }
    }

    return damaged;
  }
  /**
   * Places the blocks in a position from the minimum corner.
   *
   * @param editSession
   * @param pos
   * @param noAir
   * @throws MaxChangedBlocksException
   */
  public void place(EditSession editSession, Vector pos, boolean noAir)
      throws MaxChangedBlocksException {
    for (int x = 0; x < size.getBlockX(); ++x) {
      for (int y = 0; y < size.getBlockY(); ++y) {
        for (int z = 0; z < size.getBlockZ(); ++z) {
          if (noAir && data[x][y][z].isAir()) {
            continue;
          }

          editSession.setBlock(new Vector(x, y, z).add(pos), data[x][y][z]);
        }
      }
    }
  }
Exemple #13
0
 /**
  * Save the copy to file.
  *
  * @param dest
  * @throws IOException
  */
 public void save(File dest) throws IOException {
   FileOutputStream out = new FileOutputStream(dest);
   DataOutputStream writer = new DataOutputStream(out);
   writer.writeByte(1);
   writer.writeInt(origin.getBlockX());
   writer.writeInt(origin.getBlockY());
   writer.writeInt(origin.getBlockZ());
   writer.writeInt(width);
   writer.writeInt(height);
   writer.writeInt(length);
   writer.write(blocks, 0, blocks.length);
   writer.write(data, 0, data.length);
   writer.close();
   out.close();
 }
 /**
  * Constructs the clipboard.
  *
  * @param size
  * @param origin
  * @param offset
  */
 public CuboidClipboard(Vector size, Vector origin, Vector offset) {
   this.size = size;
   data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
   this.origin = origin;
   this.offset = offset;
 }
 /**
  * Constructs the clipboard.
  *
  * @param size
  */
 public CuboidClipboard(Vector size) {
   this.size = size;
   data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
   origin = new Vector();
   offset = new Vector();
 }
 /**
  * Get one point in the copy. The point is relative to the origin of the copy (0, 0, 0) and not to
  * the actual copy origin.
  *
  * @param pos
  * @return null
  * @throws ArrayIndexOutOfBoundsException
  */
 public void setBlock(Vector pt, BaseBlock block) {
   data[pt.getBlockX()][pt.getBlockY()][pt.getBlockZ()] = block;
 }
 /**
  * Get one point in the copy. The point is relative to the origin of the copy (0, 0, 0) and not to
  * the actual copy origin.
  *
  * @param pos
  * @return null
  * @throws ArrayIndexOutOfBoundsException
  */
 public BaseBlock getPoint(Vector pos) throws ArrayIndexOutOfBoundsException {
   return data[pos.getBlockX()][pos.getBlockY()][pos.getBlockZ()];
 }
 /**
  * Get the length (Z-direction) of the clipboard.
  *
  * @return length
  */
 public int getLength() {
   return size.getBlockZ();
 }