Exemplo n.º 1
0
 /**
  * Detecting factory, based on the position of the rails. The base must be one block below and the
  * sign if it exists must be two or three blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * <p>This is the most important constructor, since it is the one invoked when processing cart
  * move events.
  *
  * @param rail the block containing the rails.
  */
 public static CartMechanismBlocks findByRail(Block rail) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(rail.getTypeId()))
     throw new InvalidMechanismException("rail argument must be a rail!");
   if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 2));
   } else if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 3).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 3));
   }
   return new CartMechanismBlocks(rail, rail.getFace(BlockFace.DOWN, 1), null);
 }
Exemplo n.º 2
0
 /**
  * Detecting factory; defers to one of the other three specific detecting factories based on
  * whether the given unknown block appears to be a sign, rail, or base.
  *
  * @param unknown the block to examine.
  */
 public static CartMechanismBlocks find(Block unknown) throws InvalidMechanismException {
   final int ti = unknown.getTypeId();
   if (SignUtil.isSign(ti)) return findBySign(unknown);
   else if (BlockType.isRailBlock(ti)) return findByRail(unknown);
   else return findByBase(unknown);
 }