예제 #1
0
  /**
   * Compute the direction to take
   *
   * @param IPaddress the destination address
   * @param sign the BC sign
   * @param RoutingTableWritable the routing table contained in the chest
   * @return the direction to destination, or to ring 0. If ring 0 does not exist, random direction
   */
  protected BlockFace SelectRoute(
      AddressRouted IPaddress, Address sign, RoutingTableWritable RoutingTable) {

    DirectionRegistry face;
    // same region : lookup destination track
    if (IPaddress != null
        && IPaddress.getRegion().getAmount() == sign.getRegion().getAmount()
        && IPaddress.getTTL() != 0) {
      int destination = this.destination.getTrack().getAmount();
      DirectionRegistry out = RoutingTable.getDirection(destination);
      if (out != null) {
        // trigger event
        SignPreRouteEvent event =
            new SignPreRouteEvent(this, this.getRoutingTable().getDirectlyConnected(out));
        Bukkit.getServer().getPluginManager().callEvent(event);
        return RoutingTable.getDirection(event.getTargetTrack()).getBlockFace();
      }
    }

    // If not in same region, or if TTL is 0, or the ring does not exist then we lookup track 0
    if ((face = RoutingTable.getDirection(0)) != null) return face.getBlockFace();

    // If everything has failed, then we randomize output direction
    return AbstractWanderer.getRandomBlockFace(RoutingTable, getCardinal().getOppositeFace());
  }
예제 #2
0
 @Override
 public BlockFace giveRouterDirection() {
   // check if we are in the good region
   if (this.getSignAddress().isValid()
       && this.getSignAddress().getRegion().getAmount() != getWandererRegion()) {
     // case this is not the right region
     DirectionRegistry dir = RoutingTable.getDirection(getWandererRegion());
     if (dir != null) return dir.getBlockFace();
     return this.getFrom().getBlockFace();
   }
   // the route where we went the lesser
   int preferredroute = this.getContent().getMinDistanceRing(RoutingTable, getFrom());
   DirectionRegistry dir;
   if ((dir = RoutingTable.getDirection(preferredroute)) != null) return dir.getBlockFace();
   return DefaultRouterWanderer.getRandomBlockFace(RoutingTable, getFrom().getBlockFace());
 }