示例#1
0
  @Override
  public Entity getNearestEntity(Point position, Entity ignore, int range) {
    Entity best = null;
    double bestDistance = range * range;

    for (Entity entity : getEntitiesNearRegion(position, range)) {
      if (entity != null && entity != ignore) {
        double distance = position.distanceSquared(entity.getScene().getPosition());
        if (distance < bestDistance) {
          bestDistance = distance;
          best = entity;
        }
      }
    }
    return best;
  }
示例#2
0
  @Override
  public List<Entity> getNearbyEntities(Point position, Entity ignore, int range) {
    ArrayList<Entity> foundEntities = new ArrayList<Entity>();
    final int RANGE_SQUARED = range * range;

    for (Entity entity : getEntitiesNearRegion(position, range)) {
      if (entity != null && entity != ignore) {
        double distance = position.distanceSquared(entity.getScene().getPosition());
        if (distance < RANGE_SQUARED) {
          foundEntities.add(entity);
        }
      }
    }

    return Collections.unmodifiableList(foundEntities);
  }
示例#3
0
  /**
   * Gets the absolute closest player from the specified point within a specified range.
   *
   * @param position to search from
   * @param ignore to ignore while searching
   * @param range to search
   * @return nearest player
   */
  @Override
  @LiveRead
  @Threadsafe
  public Player getNearestPlayer(Point position, Player ignore, int range) {
    Entity best = null;
    double bestDistance = range * range;

    for (Entity entity : getEntitiesNearRegion(position, range)) {
      if (entity != null && entity instanceof Player && entity != ignore) {
        double distance = position.distanceSquared(entity.getScene().getPosition());
        if (distance < bestDistance) {
          bestDistance = distance;
          best = entity;
        }
      }
    }
    return (Player) best;
  }
 @Override
 protected void sendPosition(Point p, Quaternion rot) {
   // TODO: Implement Spout Protocol
   Session session = owner.getSession();
   if (p.distanceSquared(entity.getPosition()) >= 16) {
     EntityTeleportMessage ETMMsg =
         new EntityTeleportMessage(
             entity.getId(),
             (int) p.getX(),
             (int) p.getY(),
             (int) p.getZ(),
             (int) rot.getYaw(),
             (int) rot.getPitch());
     PlayerLookMessage PLMsg = new PlayerLookMessage(rot.getYaw(), rot.getPitch(), true);
     session.sendAll(false, ETMMsg, PLMsg);
   } else {
     PlayerPositionLookMessage PPLMsg =
         new PlayerPositionLookMessage(
             p.getX(), p.getY() + STANCE, p.getZ(), STANCE, rot.getYaw(), rot.getPitch(), true);
     session.send(false, PPLMsg);
   }
 }